Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <config>
  3. <modules>
  4. <TimgMage_CustomAddToCart>
  5. <version>0.0.1</version>
  6. </TimgMage_CustomAddToCart>
  7. </modules>
  8. <global>
  9. <models>
  10. <TimgMage_CustomAddToCart>
  11. <class>TimgMage_CustomAddToCart_Model</class>
  12. </TimgMage_CustomAddToCart>
  13. </models>
  14. <events>
  15. <!-- START: Add to cart actions -->
  16. <checkout_cart_product_add_after>
  17. <observers>
  18. <timgmage_customaddtocart_model_observer>
  19. <class>TimgMage_CustomAddToCart_Model_Observer</class>
  20. <method>checkoutCartProductAddAfter</method>
  21. <type>singleton</type>
  22. </timgmage_customaddtocart_model_observer>
  23. </observers>
  24. </checkout_cart_product_add_after>
  25. </events>
  26. </global>
  27. </config>
  28.  
  29. <?php
  30.  
  31. class TimgMage_CustomAddToCart_Model_Observer
  32. {
  33.  
  34. public function checkoutCartProductAddAfter(Varien_Event_Observer $observer) {
  35.  
  36. Mage::log('Entered to checkoutCartProductAddAfter.', null, 'timgmage.log');
  37.  
  38. /* @var $item Mage_Sales_Model_Quote_Item */
  39. $item = $observer->getQuoteItem();
  40. if ($item->getParentItem()) {
  41. $item = $item->getParentItem();
  42. }
  43.  
  44. // Discounted 25% off
  45. $percentDiscount = 0.25;
  46.  
  47. // This makes sure the discount isn't applied over and over when refreshing
  48. $specialPrice = $item->getOriginalPrice() - ($item->getOriginalPrice() * $percentDiscount);
  49.  
  50. // Make sure we don't have a negative
  51. if ($specialPrice > 0) {
  52. $item->setCustomPrice($specialPrice);
  53. $item->setOriginalCustomPrice($specialPrice);
  54. $item->getProduct()->setIsSuperMode(true);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement