Magento 折扣优惠券代码即时创建但无法正常工作
这是我动态创建优惠券代码的代码:
$productId = (int) $this->getRequest()->getParam('id');
$discountprice=$_POST['product']['discountprice'];
$model = Mage::getModel('salesrule/rule');
$couponCode=generateUniqueId(8);
$model->setName($couponCode);
$model->setCouponCode($couponCode);
$model->setDescription('Discount coupon for Surger.');
$model->setUsesPerCoupon(1);
$model->setUsesPerCustomer(1);
$model->setCustomerGroupIds('0,1');
$model->setIsActive(1);
// $model->setConditionsSerialized('a:6:{s:4:\"type\";s:32:\"salesrule/rule_condition_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
//$model->setActionsSerialized('a:6:{s:4:\"type\";s:40:\"salesrule/rule_condition_product_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
$model->setStopRulesProcessing(0);
$model->setIsAdvanced(1);
$model->setProductIds($productId);
$model->setSortOrder(1);
$model->setSimpleAction('by_percent');
$model->setDiscountAmount($discountprice);
$model->setDiscountStep(0);
$model->setSimpleFreeShipping(0);
$model->setTimesUsed(0);
$model->setIsRss(0);
$model->setWebsiteIds('1');
$model->save();
但是当我结帐特定产品时折扣会自动应用,我的要求是折扣必须在我在折扣代码框中输入代码后以及当我在折扣代码显示代码无效...
请帮助任何人。我也在尽力解决这个问题;如果我找到任何解决方案,我会放在这里。
Here is my code which create the coupon code on the fly:
$productId = (int) $this->getRequest()->getParam('id');
$discountprice=$_POST['product']['discountprice'];
$model = Mage::getModel('salesrule/rule');
$couponCode=generateUniqueId(8);
$model->setName($couponCode);
$model->setCouponCode($couponCode);
$model->setDescription('Discount coupon for Surger.');
$model->setUsesPerCoupon(1);
$model->setUsesPerCustomer(1);
$model->setCustomerGroupIds('0,1');
$model->setIsActive(1);
// $model->setConditionsSerialized('a:6:{s:4:\"type\";s:32:\"salesrule/rule_condition_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
//$model->setActionsSerialized('a:6:{s:4:\"type\";s:40:\"salesrule/rule_condition_product_combine\";s:9:\"attribute\";N;s:8:\"operator\";N;s:5:\"value\";s:1:\"1\";s:18:\"is_value_processed\";N;s:10:\"aggregator\";s:3:\"all\";}');
$model->setStopRulesProcessing(0);
$model->setIsAdvanced(1);
$model->setProductIds($productId);
$model->setSortOrder(1);
$model->setSimpleAction('by_percent');
$model->setDiscountAmount($discountprice);
$model->setDiscountStep(0);
$model->setSimpleFreeShipping(0);
$model->setTimesUsed(0);
$model->setIsRss(0);
$model->setWebsiteIds('1');
$model->save();
but when I checkout particular product the discount apply automatically, my requirement is the discount must be apply after I enter the code in the Discount Codes box, also when I enter the code in Discount Codes it shows the code is not valid...
Please help anyone. I am also trying my best to solve this; if I find any solution I'll put here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我创建 1000 张优惠券的代码。
把$model->save();循环外?
you should set a right $productId
This is my code to create 1000 coupons.
put $model->save(); outside the loop?
you should set a right $productId
感谢您查看我的问题,答案代码在这里,您可以自行设置优惠券代码并在结帐时应用它。
thanks for viewing my question the answer code is here u can set the coupan code your self and apply it while checkout.