【问题标题】:Override all products price when checkout if quantity more than specific quantity如果数量超过特定数量,则在结帐时覆盖所有产品价格
【发布时间】:2013-05-03 13:45:58
【问题描述】:

我的商店在$ 25 销售所有产品。然后我想在客户结帐时根据产品总数量做一些折扣。

如果客户购买的总数量超过 50 个,则每个产品的每个产品价格将从 $25 覆盖到 $22

如下所示:

if (total_quantity > 80) {
   price for each product is $19
}

elseif (total_quantity > 50) {
  price for each product is $22
}
else {
  normal price
}

现在我可以在客户结账时使用$this->cart->countProducts() 检测总数量,但现在我不确定如何覆盖价格(我确定这与文件控制器\checkout\confirm.php 相关)。

希望有人可以指导我。

更新:

现在我可以根据总数量过滤所有产品价格:

if ($this->cart->countProducts() > 3) {
    $product_price = '24.00';
}
elseif ($this->cart->countProducts() > 2) {
    $product_price = '23.00';
}
else {
    $product_price = $product['price'];
}

$this->data['products'][] = array(
    'product_id' => $product['product_id'],
    'name'       => $product['name'],
    'model'      => $product['model'],
    'option'     => $option_data,
    'quantity'   => $product['quantity'],
    'subtract'   => $product['subtract'],
    'price'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax'))),
    'total'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
    'href'       => $this->url->link('product/product', 'product_id=' . $product['product_id'])
); 

但现在我不确定在哪里覆盖小计和总计。

p/s:所有产品价格固定为 25 美元

OC 版本:最新版本

【问题讨论】:

    标签: php opencart


    【解决方案1】:

    这更多的是寻找用法和方法的答案,而不是直接的具体答案。

    如果您不确定如何使用对象可用的方法/变量,请尝试使用类似的方式输出它们。

    <?php
    echo "<pre>";
    print_r(get_class_methods($objectName));
    print_r(get_object_vars($objectName));
    echo "</pre>";
    ?>
    

    它将显示可用方法的列表。它可能有一个名为 setPrice() 或类似的方法,至少它会让您更深入地了解一些可用的选项?

    【讨论】:

      【解决方案2】:

      这是我的解决方案:

      目录/控制器/结帐

      $this-&gt;data['products'][] = array(之前添加以下代码(第361行)

      if ($this->cart->countProducts() > 80) {
          $product_price = '24.00';
      }
      elseif ($this->cart->countProducts() > 50) {
          $product_price = '23.00';
      }
      else {
          $product_price = $product['price'];
      }
      

      $this-&gt;data['products'][] = array( ...替换为

      $this->data['products'][] = array(
          'product_id' => $product['product_id'],
          'name'       => $product['name'],
          'model'      => $product['model'],
          'option'     => $option_data,
          'quantity'   => $product['quantity'],
          'subtract'   => $product['subtract'],
          'price'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax'))),
          'total'      => $this->currency->format($this->tax->calculate($product_price, $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
          'href'       => $this->url->link('product/product', 'product_id=' . $product['product_id'])
      );
      

      系统/库

      if (!$this-&gt;data) {(第22行)之后添加以下代码

      //Count how many product in cart
      $total_quantity = $this->session->data['cart'];
      $total_product_in_cart = 0;
      foreach ($total_quantity as $t_q) {
          $total_product_in_cart += $t_q;
      }
      $total_product_in_cart;
      

      将此$price = $product_query-&gt;row['price'];(第 173 行)替换为

      if ($quantity > 80) {
          $price = '24.00';
      }
      elseif ($quantity > 50) {
          $price = '23.00';
      }
      else {
          $price = $product_query->row['price'];
      }
      

      【讨论】:

        猜你喜欢
        • 2018-05-18
        • 1970-01-01
        • 2016-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-22
        • 2017-11-06
        • 2021-09-26
        相关资源
        最近更新 更多