在产品页面显示优惠券代码[magento v1.9.x]

时间:2016-04-17 14:22:40

标签: php magento

我想在产品页面上显示优惠券代码。在购物车价格规则中,我已将优惠券应用于特定类别。我想在购物车价格规则中指定了类别ID的每个产品页面上显示优惠券。

$current_sku=$_product->getSku(); // Sku you are looking for

$rules = Mage::getResourceModel('salesrule/rule_collection')->load();

foreach ($rules as $rule) {
if ($rule->getIsActive()) {
$rule = Mage::getModel('salesrule/rule')->load($rule->getId()); 

$conditions = $rule->getConditions()->asArray();

foreach( $conditions['conditions'] as $_conditions ):
    foreach( $_conditions['conditions'] as $_condition ):
        $string = explode(',', $_condition['value']);
        for ($i=0; $i<count($string); $i++) {
            $sku = trim($string[$i]);
            if ($sku==$current_sku) {
                    echo $rule->getCouponCode(); // Return coupon code that matches the sku condition
            }
        }
    endforeach;
endforeach;
}
}

上面的代码显示了在产品页面上应用于sku的优惠券代码。

ref- https://magento.stackexchange.com/questions/1117/get-shopping-cart-rule-coupon-code

0 个答案:

没有答案