1
我創建了一個代碼來創建新的購物車規則,它的效果很好,但有一個問題,產品限制不起作用... 希望有人可以幫忙, PrestaShop類和控制器,我嘗試複製,但這是我得到,並沒有工作。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();
你有沒有加入一些數據表cart_rule_product_rule_group,cart_rule_product_rule和cart_rule_product_rule_value你可以看到afterAdd在AdminCartRulesControllerCore控制器 我覺得這段代碼有沒有SENS $ 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; –