Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. To add this feature in our module we had to:
  2.  
  3. 1) add a new field max_discount in the table salesrule
  4.  
  5. 2) observe event salesrule_validator_process
  6.  
  7. <salesrule_validator_process>
  8. <observers>
  9. <amasty_rules_model_observer>
  10. <type>singleton</type>
  11. <class>amrules/observer</class>
  12. <method>handleValidation</method>
  13. </amasty_rules_model_observer>
  14. </observers>
  15. </salesrule_validator_process>
  16. 3) keep track of all discounts given to item by rule_id (just remember them in a variable)
  17.  
  18. protected function _limitMaxDiscount($r, $rule, $itemId, $quote)
  19. {
  20. if ($rule->getMaxDiscount()==0) {
  21. return $r[$itemId];
  22. }
  23. if (isset($this->_ruleDiscount[$rule->getId()])) {
  24. $this->_ruleDiscount[$rule->getId()]['base_discount'] += $r[$itemId]['base_discount'];
  25. } else {
  26. $this->_ruleDiscount[$rule->getId()]['base_discount'] = $r[$itemId]['base_discount'];
  27. }
  28. if ($this->_ruleDiscount[$rule->getId()]['base_discount'] > $rule->getMaxDiscount()) {
  29. $r[$itemId]['base_discount'] = $r[$itemId]['base_discount'] - ($this->_ruleDiscount[$rule->getId()]['base_discount'] - $rule->getMaxDiscount());
  30. $r[$itemId]['discount'] = $quote->getStore()->convertPrice(
  31. $r[$itemId]['base_discount']
  32. );
  33. }
  34. return $r[$itemId];
  35. }
  36. 4) when apply next discount to an item, check if it is in the range.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement