prestashop按代码添加购物车折扣 - prestashop 1.4

时间:2013-10-01 17:30:12

标签: add prestashop cart discount

我在Prestashop打招呼,我正在编写一个模块,允许客户对当前购物车应用折扣。

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

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

我是在正确的方式,还是有其他更好的方式?

非常感谢。

1 个答案:

答案 0 :(得分:1)

最后,我为muy创建了自己的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表中每个语言都有一个插入。