Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

i Need Help with customizing the Coupon behavior
 
M.S.
Member
 
Total Posts:  39
Joined:  2008-04-20
 

Hi,
i must change the coupon Sale rules to act like the following:

if coupon code was applied to the matching products, the number of the coupon uses will be reduced by the numbers of the products it was applied to in the cart.

for example :

if “Discount Coupon” = 100 Uses X 10$ Discount Per Product.
and customer was buying 5 matching products he will get 10$ discount for each matching product
and discount coupon will be - 5 uses = 95 left.

i found where the nuber of uses counted :  app/code/core/Mage/SalesRule/Model/observer.php
lines 71 , 79 , 85,

class Mage_SalesRule_Model_Observer
{
    
protected $_validator;

    public function 
getValidator($event)
    
{
        
if (!$this->_validator{
            $this
->_validator Mage::getModel('salesrule/validator')
                ->
init($event->getWebsiteId(), $event->getCustomerGroupId(), $event->getCouponCode());
        
}
        
return $this->_validator;
    
}

    
public function sales_quote_address_discount_item($observer)
    
{
        $this
->getValidator($observer->getEvent())
            ->
process($observer->getEvent()->getItem());
    
}

    
public function sales_order_afterPlace($observer)
    
{
        $order 
$observer->getEvent()->getOrder();

        if (!
$order{
            
return $this;
        
}

        
// lookup rule ids
        
$ruleIds explode(','$order->getAppliedRuleIds());
        
$ruleIds array_unique($ruleIds);

        
$ruleCustomer null;
        
$customerId $order->getCustomerId();

        
// use each rule (and apply to customer, if applicable)

        
foreach ($ruleIds as $ruleId{
            
if (!$ruleId{
                
continue;
            
}
            $rule 
Mage::getModel('salesrule/rule');
            
$rule->load($ruleId);
            if (
$rule->getId()) {
75                $rule
->setTimesUsed($rule->getTimesUsed() + 1);
                
$rule->save();

                if (
$customerId{
                    $ruleCustomer 
Mage::getModel('salesrule/rule_customer');
                    
$ruleCustomer->loadByCustomerRule($customerId$ruleId);

                    if (
$ruleCustomer->getId()) {
79                        $ruleCustomer
->setTimesUsed($ruleCustomer->getTimesUsed()+1);
                    
}
                    
else {
                        $ruleCustomer
                        
->setCustomerId($customerId)
                        ->
setRuleId($ruleId)
81                        ->setTimesUsed(1);
                    
}
                    $ruleCustomer
->save();
                
}
            }
        }
    }
}

when i was changing those lines from “ +1 “ to + 4 or +6 that was what counted for the coupon uses - i just want to change it to the number of the products it was applied to in the cart, and also make it appear in the coupon report in admin reports

Help will be appreciated
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
M.S.
Member
 
Total Posts:  39
Joined:  2008-04-20
 

is it related to cookies or session ?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top