2

I'm working with Magento 1.9.2.

I need to check (via code) if a coupon is a "free shipping" one: how can I do it? I searched everywhere online but I didn't find a solution yet.

I know there are two tables used to store coupons: salesrule and salesrule_coupon. I noticed that my "free shipping" coupons seem to be recognized by the following combination of columns:

  • simple_free_shipping == 2 and
  • coupon_type == 2

Is this a safe way to check the "free shipping" of a coupon?

Thank you!

1
  • Can you please explain what you want to do with this coupon code, so that i can give you proper logic for this? Feb 14, 2017 at 18:03

1 Answer 1

0

with your guidance I knew how to find it.

please look at the following

Mage_SalesRule_Model_Resource_Rule_Collection

and

Mage_SalesRule_Model_Rule

as you see you have the method getSimpleFreeShipping so you have to find the correct model which is a sales rule model and go from there:

<?php

$rootPath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
require_once $rootPath . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
Mage::app();
$shopping_cart_rules = Mage::getResourceModel('salesrule/rule_collection');
echo "<pre>";
foreach ($shopping_cart_rules as $rule) {
    echo "RULE ID:" . $rule->getRuleId()."<br/>";
    echo "coupon code ID:" . $rule->getCode()."<br/>";
    echo "Simple free shipping:" . $rule->getSimpleFreeShipping()."<br/>";
}
echo "</pre>";

Then:

<?php

$rootPath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
require_once $rootPath . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
Mage::app();
$shopping_cart_rules = Mage::getResourceModel('salesrule/rule_collection');
echo "<pre>";

foreach ($shopping_cart_rules as $rule) {
    if( $rule->getSimpleFreeShipping()==1):
         echo "coupon code ID:" . $rule->getCode()."is used for free shipping<br/>";
    endif;
}
echo "</pre>";
1
  • It seems my free shipping coupons don't respect the $rule->getSimpleFreeShipping() == 1 condition :/ Thank you anyway!
    – user50647
    Feb 16, 2017 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy