2012-05-10 9 views
10

クーポンコードに関連付けられたルールを取得して、そのルールのディスカウントパーセンテージを表示する必要があります。 最も簡単な方法は、見積もり金額から直接計算することですが、ルールを直接取得してから、割引率を取得したいと考えています。Magento - クーポンコードからルールを取得

これは私が試したものです:私はまだ検索されたルールをhaventは、この方法によって

$rule = Mage::getModel('salesrule/coupon'); 
$rule->load($couponCode); 

属性。どんな助け?

ありがとうございました。

答えて

29

コードでクーポンを読み込むには、'code'を2番目のパラメータとしてload()に渡します。次に、あなたのクーポンインスタンスのrule_id値を使用して、適切なルールのインスタンスを取得することができます。

$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code'); 
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId()); 
var_dump($oRule->getData()); 
+0

正しく動作します。 – jruzafa

3

まず

$orderNumber = 100000105; //order number with coupon code 

$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber); 

$orderDetails = $order->getData(); 

$couponCode = $orderDetails['coupon_code']; 

が続いユルゲンThelenによるソリューションを使用クーポンコードを取得します。

0

このソリューションは、クーポンコードでクーポンコードの金額を取得するのに役立ちますか。

$ couponCode = 'あなたのCOUPONCODE';

$ oCoupon = Mage :: getModel( 'salesrule/coupon') - > load($ couponCode、 'code');

$ oRule = Mage :: getModel( 'salesrule/rule') - > load($ oCoupon-> getRuleId());

print_r($ oRule-> getData()); exit();