Mage_SalesRule_Model_Observer Class Reference

List of all members.

Public Member Functions

 getValidator ($event)
 sales_quote_address_discount_item ($observer)
 sales_order_afterPlace ($observer)

Protected Attributes

 $_validator


Detailed Description

Definition at line 28 of file Observer.php.


Member Function Documentation

getValidator ( event  ) 

Definition at line 32 of file Observer.php.

00033     {
00034         if (!$this->_validator) {
00035             $this->_validator = Mage::getModel('salesrule/validator')
00036                 ->init($event->getWebsiteId(), $event->getCustomerGroupId(), $event->getCouponCode());
00037         }
00038         return $this->_validator;
00039     }

sales_order_afterPlace ( observer  ) 

Definition at line 47 of file Observer.php.

00048     {
00049         $order = $observer->getEvent()->getOrder();
00050 
00051         if (!$order) {
00052             return $this;
00053         }
00054 
00055         // lookup rule ids
00056         $ruleIds = explode(',', $order->getAppliedRuleIds());
00057         $ruleIds = array_unique($ruleIds);
00058 
00059         $ruleCustomer = null;
00060         $customerId = $order->getCustomerId();
00061 
00062         // use each rule (and apply to customer, if applicable)
00063         foreach ($ruleIds as $ruleId) {
00064             if (!$ruleId) {
00065                 continue;
00066             }
00067             $rule = Mage::getModel('salesrule/rule');
00068             $rule->load($ruleId);
00069             if ($rule->getId()) {
00070                 $rule->setTimesUsed($rule->getTimesUsed() + 1);
00071                 $rule->save();
00072 
00073                 if ($customerId) {
00074                     $ruleCustomer = Mage::getModel('salesrule/rule_customer');
00075                     $ruleCustomer->loadByCustomerRule($customerId, $ruleId);
00076 
00077                     if ($ruleCustomer->getId()) {
00078                         $ruleCustomer->setTimesUsed($ruleCustomer->getTimesUsed()+1);
00079                     }
00080                     else {
00081                         $ruleCustomer
00082                         ->setCustomerId($customerId)
00083                         ->setRuleId($ruleId)
00084                         ->setTimesUsed(1);
00085                     }
00086                     $ruleCustomer->save();
00087                 }
00088             }
00089         }
00090     }

sales_quote_address_discount_item ( observer  ) 

Definition at line 41 of file Observer.php.

00042     {
00043         $this->getValidator($observer->getEvent())
00044             ->process($observer->getEvent()->getItem());
00045     }


Member Data Documentation

$_validator [protected]

Definition at line 30 of file Observer.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:50 2009 for Magento by  doxygen 1.5.8