dpxw7293 2017-06-21 13:24
浏览 40
已采纳

Opencart 1.5.4 - 不验证同一产品的不同选项的最小订单数量

For my Opencart 1.5.4 project, we have set the minimum 12 quantity for product. If the user select the quantity less than 12 it will not allow user to buy it (Opencart validate this on cart page). But if user selects the same product in the group of different option (small, medium, large) individual less than 12 then he can place the order.

For e.g.

Product A (small) 6 Qty

Product A (medium) 6 Qty

Product A (large) 10 Qty

Total quantity is 22.

But I want individual item quantity is minimum 12 like below,

Product A (small) 12 Qty (minimum 12)

Product A (medium) 12 Qty (minimum 12)

Product A (large) 12 Qty (minimum 12)

Opencart is not treated different options as different product in cart and user can easily buy individual product in less than 12 quantity.

Can any one suggest me why this happen and how to fix this issue? Any extension is available for that?

  • 写回答

1条回答 默认 最新

  • dphg63476 2017-06-22 06:16
    关注

    I have found the solution of this issue, for that I have to make changes in the cart and checkout controller. By default Opencart is calculating the product quantity on the cart page by product id. I have customized the code and now it will check the individual quantity of each product in the cart.

    Cart controller ==> Cart.php \catalog\controller\checkout\cart.php make changes in line no 192 to 197

    foreach ($products as $product) {
    
        $product_total = 0;
        $allCartProductId[] = $product['product_id'];
        foreach ($products as $product_2) {
            if ($product_2['product_id'] == $product['product_id']) {
                $product_total += $product_2['quantity'];
            }
        }
    
        if ($product['minimum'] > $product_total) {
            $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']) 
        }
    }
    

    To

    foreach ($products as $product) {
    
                    $product_total = 0;
                    $allCartProductId[] = $product['product_id'];
    
                            $product_total += $product['quantity'];
    
                    if ($product['minimum'] > $product_total) {
                        $this->data['error_warning'] .= sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum'])."<br>";
                    }
    

    Checkout controller ==> checkout.php \catalog\controller\checkout\checkout.php make changes in line no 15 to 20

    foreach ($products as $product) {
            $product_total = 0;
    
            foreach ($products as $product_2) {
                if ($product_2['product_id'] == $product['product_id']) {
                    $product_total += $product_2['quantity'];
                }
            }
    

    To

    foreach ($products as $product) {
        $product_total = 0;         
        $product_total += $product['quantity'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有没有可以帮我搞一个微信建群链接,包括群名称和群资料群头像那种,不会让你白忙
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题