Magento Forum

   
Custom discount module
 
sanya_g
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2011-09-03
 

Hello.

I need to program a discount module, which would give some % of discount to customers who already made several orders from the site (distinguishing them by email).
But I cant figure out which method should I override to do that.
There is so much magic going on until the final price comes out.

What should I do to make custom discount module like I described?

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MrManners
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2011-08-16
Frankfurt am Main
 
sanya_g - 19 October 2011 01:06 AM

Hello.

I need to program a discount module, which would give some % of discount to customers who already made several orders from the site (distinguishing them by email).
But I cant figure out which method should I override to do that.
There is so much magic going on until the final price comes out.

What should I do to make custom discount module like I described?

Thanks in advance.

Hi Sanya,

It looks like the function calculateSpecialPrice in the class Mage_Catalog_Model_Product_Type_Price might be the best place to start looking.

Please let me know if this helps you out.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sanya_g
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2011-09-03
 
MrManners - 19 October 2011 02:59 AM

It looks like the function calculateSpecialPrice in the class Mage_Catalog_Model_Product_Type_Price might be the best place to start looking.

It seems that class you have mentioned doesn’t help with my issue.

I guess I have to dig into backend promotion modules and edit them to meet my requirements.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MrManners
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2011-08-16
Frankfurt am Main
 
sanya_g - 19 October 2011 05:56 AM

MrManners - 19 October 2011 02:59 AM

It looks like the function calculateSpecialPrice in the class Mage_Catalog_Model_Product_Type_Price might be the best place to start looking.

It seems that class you have mentioned doesn’t help with my issue.

I guess I have to dig into backend promotion modules and edit them to meet my requirements.

Hi,

Sorry this hasn’t helped your problem. I have extended this class in the past to give a custom price that changed per customer.

Hope you find a solution soon.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sanya_g
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2011-09-03
 

So, as I thought I dug into Magento promotion features and hopefully find out a solution. smile

First I override Mage_SalesRule_Model_Rule_Condition_Combine
and made some changes to add new condition:

$conditions array_merge_recursive($conditions, array(
            array(`
value`=>`salesrule/rule_condition_orders`, `label` => `Order count`), // <-- this is my line
            
array(`value`=>`salesrule/rule_condition_product_found`, `label`=>Mage::helper(`salesrule`)->__(`Product attribute combination`)),
            array(`
value`=>`salesrule/rule_condition_product_subselect`, `label`=>Mage::helper(`salesrule`)->__(`Products subselection`)),
            array(`
value`=>`salesrule/rule_condition_combine`, `label`=>Mage::helper(`salesrule`)->__(`Conditions combination`)),
            array(`
label`=>Mage::helper(`salesrule`)->__(`Cart Attribute`), `value`=>$attributes),
        ));
Than I`ve created Mage_SalesRule_Model_Rule_Condition_Orders class
class Mage_SalesRule_Model_Rule_Condition_Orders extends Mage_Rule_Model_Condition_Abstract
{
    
public function getAttributeElementHtml()
    
{
        
return `Number of orders with the same Email`;
    
}
    
    
public function validate(Varien_Object $object)
    
{
        $email 
$object->getEmail();
        
        
$orderCollection Mage::getResourceModel(`sales/order_collection`);
        
$orderCollection->addFieldToFilter(`state`, array(`in` => `complete`));
        
$orderCollection->addFieldToFilter(`customer_email`, array(`in` => $email));
        
$orderCollection->load();
        
$count $orderCollection->count();
        
        return 
$this->validateAttribute($count);
    
}
}

After that I`ve added discount rules from Promotion -> Shopping Cart Price Rules.

Maybe code is not ideal, but it works smile
I hope this post can help someone else.

P.S. MrManners, Thanks for your trials to help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MrManners
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2011-08-16
Frankfurt am Main
 

Great news that you found a solution. This code looks like it could be really useful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rex@123789.org
Jr. Member
 
Total Posts:  1
Joined:  2010-07-15
 

@sanya_g

This post rocks. Really Helped a lot..

Thanks.

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