1

I have customer group id.
I need to get catalog rule for this customer group.
And after that I want to get discount amount in % for this catalog rule;
Now I make something like this:

    $group_id= Mage::getSingleton('customer/session')->getCustomerGroupId();
    $resource = Mage::getSingleton('core/resource');
    $db = $resource->getConnection('core_read');
    $query = "SELECT * FROM catalogrule 
              JOIN catalogrule_customer_group 
              ON catalogrule.rule_id = catalogrule_customer_group.rule_id
              WHERE catalogrule.is_active = 1
              AND catalogrule_customer_group.customer_group_id = {$group_id}
              ORDER BY catalogrule.sort_order
              LIMIT 1";
    $results = $db->fetchAll($query);

Much thanks!

1 Answer 1

1

Not perfect, but still better then a raw query ...

$groupId    = Mage::getSingleton('customer/session')->getCustomerGroupId();
$resource   = Mage::getSingleton('core/resource');
$collection = Mage::getResourceModel('catalogrule/rule_collection')->addIsActiveFilter();
$collection->getSelect()
    ->join(
        array('group' => $resource->getTableName('catalogrule/customer_group')),
        'main_table.rule_id=group.rule_id',
        array('customer_group_id')
    )
    ->where('group.customer_group_id = ?', $groupId)
    ->order('sort_order ASC')
    ->limit(1);

$rule = $collection->getFirstItem();

var_dump(array(
    $rule->getData('name'),
    $rule->getData('simple_action'),
    $rule->getData('discount_amount')
));

Hope it helps.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.