2016-07-24 104 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(); 
    } 
} 
相關問題