我创建了一个代码来创建新的购物车规则,它运行良好,但有一个问题,产品的限制不起作用...... 希望有人可以提供帮助,我试着查看PrestaShop课程和控制器,我试图复制,但这就是我所做的并且没有用。
$coupon = new Discount();
$coupon->quantity = 1;
$coupon->quantity_per_user = 1;
$coupon->id_discount_type = 2;// reduction amount
$coupon->value = '10';
$coupon->id_customer = 1;
$coupon->minimum_amount = 0;
$coupon->minimum_amount_currency = 1;
$coupon->minimum_amount_tax = 0;
$coupon->minimum_amount_shipping = 0;
$coupon->quantity = 1;
$coupon->quantity_per_user = 1;
$coupon->product_restriction = 1;
$coupon->product_rule_group[] = 1;
$coupon->product_rule_group_1_quantity = 1;
$coupon->product_rule_1[] = 1;
$coupon->product_rule_1_1_type = 'products';
$coupon->product_rule_select_1_1[] = 9;
$coupon->reduction_percent = 100;
$coupon->reduction_amount = 0;
$coupon->reduction_currency = 1;
$coupon->reduction_tax = 0;
$coupon->apply_discount_to = 'specific';
$coupon->reductionProductFilter = '191072 Air Freshener Refill';
$coupon->reduction_product = 6;
$coupon->free_gift = 0;
$start_date = date('Y-m-d H:i:s');
$coupon->date_from = $start_date;
$end_date = date('Y-m-d H:i:s'); //some end date
$coupon->date_to = $end_date;
$gen_pass = strtoupper(Tools::passwdGen(8));
$vouchercode = 'somecode';
$name_v = $vouchercode.'-'.$gen_pass;
$namelang = array();
$namelang[1] = $name_v;
$namelang[2] = $name_v;;
//Add Name array
$coupon->name = $namelang;
$current_language = 1;
$coupon->id_customer = 1;
// fixed bug for currency
$coupon->reduction_currency = 1;
$coupon->minimum_amount_currency = 1;
$code_v = $vouchercode.'-'.$gen_pass;
$coupon->code = $code_v;
//$coupon->minimal = $coupon->value;
$coupon->active = 1;
//$coupon->cart_display = 1;
//$coupon->cart_rule_restriction = 0;
$coupon->description = '';
$coupon->highlight = 1;
$coupon->add();
答案 0 :(得分:0)
我们建议您使用以下代码来创建购物车规则。
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'cart_rule_shop
set id_cart_rule = ' . (int) $cart_rule_id . ', id_shop = ' . (int) $this->context->shop->id);
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'cart_rule_lang
set id_cart_rule = ' . (int) $cart_rule_id . ', id_lang = ' . (int) $this->context->language->id . ',
name = "' . strip_tags($coupon_name) . '"');
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'cart_rule_product_rule_group
set id_product_rule_group = NULL, id_cart_rule = ' . (int) $cart_rule_id . ',
quantity = 1');
$product_rule_group_id = Db::getInstance()->Insert_ID();
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'cart_rule_product_rule
set id_product_rule = NULL, id_product_rule_group = ' . (int) $product_rule_group_id . ',
type = "products"');
$product_rule_id = Db::getInstance()->Insert_ID();
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'cart_rule_product_rule_value
set id_product_rule =' . (int) $product_rule_id . ', id_item = ' . (int) $id_product . '');
答案 1 :(得分:0)
我知道现在不重要但是,无论如何,如果您正在寻找将产品绑定或添加到特定购物车规则的方法,这可能会有所帮助
$mail ->setFrom('dkdev006@gmail.com', 'Kreatz.in');
因此,在您获得$products = [1 => "32232", 2 => "23232", 3 => "45343"];
之后,$cartrule->add()
$cartRuleId = $cartrule->id
答案 2 :(得分:0)
如果您不想参与复杂的代码,这种方法可能会对您有所帮助:
使用您对管理面板
在您的php文件上创建示例优惠券的对象
克隆对象到newObject
更改(代码和活动等),然后从中添加新优惠券