【问题标题】:prestashop add discount to cart by code - prestashop 1.4prestashop 通过代码将折扣添加到购物车 - prestashop 1.4
【发布时间】:2013-10-01 17:30:11
【问题描述】:

我是 Prestashop 的初学者,我正在编写一个模块,允许客户对当前购物车应用折扣。

尝试使用 Cart 和 Discount 类来了解如何做到这一点。我发现 Cart 类有 addDiscount 方法,而 Discount 类有 de createOrderDiscount 方法。

如何在订购前为购物车创建折扣?

我的方法是否正确,还是有其他更好的方法?

非常感谢。

【问题讨论】:

    标签: add prestashop cart discount


    【解决方案1】:

    最后,我创建了自己的 add 函数,在这种情况下,从钩子中调用,并在 $params 参数中提供 id_customer 和 value:

    public function addDiscount($params = array()) {
            try {
                $params['description'] = "Discount description";
    
                $d = array(
                    'id_discount_type' => 2,
                    'behavior_not_exhausted' => 1,
                    'id_customer' => $params['id_customer'],
                    'id_group' => 0,
                    'id_currency' => 1,
                    'name' => "discount_name",
                    'value' => $params['value'],
                    'quantity' => 1,
                    'quantity_per_user' => 1,
                    'cumulable' => 1,
                    'cumulable_reduction' => 1,
                    'date_from' => date("Y-m-d H:i:s", time()),
                    'date_to' => date("Y-m-d H:i:s", time() + 86400),
                    'minimal' => (float) 0.00,
                    'include_tax' => 1,
                    'active' => 1,
                    'cart_display' => 1,
                    'date_add' => date("Y-m-d H:i:s"),
                    'date_upd' => date("Y-m-d H:i:s")
                );
    
                $this->db->autoExecute('ps_discount', $d, 'INSERT');
    
                $discount_id = $this->db->Insert_ID();
    
    //            /* insertar dicount_category */
                $this->db->autoExecute('ps_discount_category', array(
                    'id_category' => 1,
                    'id_discount' => $discount_id
                        ), 'INSERT');
    
    //            /* insertar dicount_lang */
                if ($rs_langs = $this->db->executeS("select id_lang from ps_lang")) {
                    foreach ($rs_langs as $lang) {
                        $this->db->autoExecute('ps_discount_lang', array(
                            'id_discount' => $discount_id,
                            'id_lang' => $lang['id_lang'],
                            'description' => $params['description']
                                ), 'INSERT');
                    }
                }
            } catch (Exception $e) {
                $this->Log($e->getTraceAsString());
            }
        }
    

    该函数基本上在 ps_discount 表中插入一次,在 ps_discount_category 表中插入一次,在 ps_discount_lang 表中为每种语言插入一次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多