Dựa trên các bài đăng trên stackoverflow khác, tôi đã có thể sử dụng mã sau đây để tạo các phiếu giảm giá quy tắc giá giỏ hàng cá nhân theo lập trình trong Magento.Lập trình tự động tạo mã phiếu giảm giá được tạo tự động trong Magento?
Làm cách nào tôi có thể gọi tính năng "Tự động tạo phiếu thưởng" theo chương trình để tạo 100 phiếu thưởng duy nhất cho từng quy tắc giá mà tôi thực hiện? Cảm ơn!
$coupon = Mage::getModel('salesrule/rule');
$coupon->setName($_coupon['name'])
->setDescription('this is a description')
->setFromDate(date('Y-m-d'))
->setCouponType(2)
->setCouponCode($_coupon['code'])
->setUsesPerCoupon(1000)
->setUsesPerCustomer(100)
->setCustomerGroupIds(array(1)) //an array of customer groupids
->setIsActive(1)
//serialized conditions. the following examples are empty
->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";}')
->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";}')
->setStopRulesProcessing(0)
->setIsAdvanced(1)
->setProductIds('')
->setSortOrder(0)
->setSimpleAction('by_percent')
->setDiscountAmount(100)
->setDiscountQty(null)
->setDiscountStep('0')
->setSimpleFreeShipping('0')
->setApplyToShipping('0')
->setIsRss(0)
->setWebsiteIds(array(1));
$coupon->save();
Ví dụ, một quy tắc mức giá này có thể có một danh sách toàn bộ mã số Coupon Auto-Generated (htgf-7774, htgf-2345, vv) sử dụng các chức năng có sẵn khi tự tạo ra quy tắc giá trong quản trị bảng điều khiển.
EDIT:
tôi đã nhận được gần hơn, sử dụng đoạn mã sau. Vẫn không biết làm thế nào để đặc biệt gán mô hình thế hệ tự động
->setName('Name')
->setDescription('this is a description')
->setFromDate('2013-03-06')
->setToDate(NULL)
->setUsesPerCustomer('100')
->setIsActive('1')
->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";}')
->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";}')
->setStopRulesProcessing('0')
->setIsAdvanced('1')
->setProductIds(NULL)
->setSortOrder('0')
->setSimpleAction('by_percent')
->setDiscountAmount('100.0000')
->setDiscountQty(NULL)
->setDiscountStep('0')
->setSimpleFreeShipping('0')
->setApplyToShipping('0')
->setTimesUsed('1')
->setIsRss('0')
->setCouponType('2')
->setUseAutoGeneration('1')
->setUsesPerCoupon('1000')
->setCustomerGroupIds(array('1',))
->setWebsiteIds(array('1',))
->setCouponCode(NULL)
phiên bản Magento này là gì? – Meabed
phiên bản 1.702 (cài đặt gần đây) –
Tôi vui mừng báo cáo rằng điều này hoạt động trong Magento 1.9. yay. –