I have made a coupon [coupon_code = SWIMFREE]
if category
is swimming equipment
and hobby
is swimming
will be discount b
already found the answer by myself:
It is possible to create a customized coupon condition.
rewrite the Mage_SalesRule_Model_Rule_Condition_Product
public function validate(Varien_Object $object){
if ($this->getAttribute() == 'quote_item_with_hobby') {
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$hobby= $quote->getHobbyByItemId($object->getId());
if ($hobby){
if ($this->getOperator() == '=='){
if (strtolower($this->getValue()) == $hobby->getHobby()) return true;
else return false;
}
else if ($this->getOperator() == '!='){
if (strtolower($this->getValue()) == $hobby->getHobby()) return false;
else return true;
}
}
return true;
}
return parent::validate($object);
}
this function will be called every step loaded. then checked if return true, then the coupon will be applied, if return false then the coupon won't be applied.
Thank's to All Who Participated. i appreciate it.
You should implement your custom collector for collecting totals. It could be based on Mage_SalesRule_Model_Quote_Discount
.
How to create custom collectors: see stackoverflow answer, or you can check this article.
Yes, that would be my idea.
You implement a new salesrule condition which gives 50% discount.
The salesrules are called for every product. then you need to check, wether the attribute is swimming and the hobby is set. If that is the case, you can copy the rest from the %-salesrule
You find code to have a look on in Mage_SalesRule_Model_Validator::process()
An example for a self implemented condition can be found here: https://github.com/magento-hackathon/DiscountForATweet/blob/master/app/code/community/Hackathon/DiscountForATweet/Model/Condition/Tweet.php