2016-07-24 99 views
1

我需要将优惠券代码从$ 100加到通讯中。我做了改写\ Magento的\新闻\型号\用户的方法sendConfirmationSuccessEmail

->setTemplateVars(
['subscriber' => $this, 
'coupon_code' => $this->getCouponCode() 
]) 

protected function getCouponCode() { . . . . . . return $couponCode; }

如何自动生成在Magento 2优惠券代码?

回答

0

您是否定义了购物车价格规则?如果不是,那就从哪里开始。在管理区域中,转到促销>购物车价格规则>添加新规则,并选择使用自动生成选择的特定优惠券。

一旦您为希望提供的任何特定折扣定义规则,请保存规则并记录购物车价格规则行中的规则ID,以显示您刚刚创建的规则。

然后添加类似下文中,使用刚创建的规则的规则ID:

下面的函数将用下列选项关联数组:

RULE_ID =规则的编号,从上述

数量=的优惠券代码数来指示的Magento生成

长度=的每个所生成的优惠券代码长度

format = alphanum(用于字母数字代码)OR alpha(用于字母代码)OR num(用于数字代码)

protected function getCouponCode($couponData) 
{ 
    $rule = $this->_loadSalesRule($ruleId); 
    // Reference the MassGenerator on this rule. 
    /** @var Mage_SalesRule_Model_Coupon_Massgenerator $generator */ 
    $generator = $rule->getCouponMassGenerator(); 
    // Validate the generator 
    if (!$generator->validateData($couponData)) { 
     $this->_critical(Mage::helper('salesrule')->__('Coupon AutoGen API: Invalid parameters passed in.'), 
      Mage_Api2_Model_Server::HTTP_BAD_REQUEST); 
    } else { 
     // Set the data for the generator 
     $generator->setData($couponData); 
     // Generate a pool of coupon codes for the Generate Coupons rule 
     $generator->generatePool(); 
    } 
}