Mage_GiftMessage_Model_Observer Class Reference

Inheritance diagram for Mage_GiftMessage_Model_Observer:

Varien_Object

List of all members.

Public Member Functions

 salesEventConvertQuoteItemToOrderItem ($observer)
 salesEventConvertQuoteAddressToOrder ($observer)
 salesEventConvertQuoteToOrder ($observer)
 checkoutEventCreateGiftMessage ($observer)
 catalogEventProductCollectionAfterLoad ($observer)
 salesEventOrderToQuote ($observer)
 salesEventOrderItemToQuoteItem ($observer)

Protected Member Functions

 _getAvailable ($product)


Detailed Description

Definition at line 35 of file Observer.php.


Member Function Documentation

_getAvailable ( product  )  [protected]

Geter for available gift messages value from product

Parameters:
Mage_Catalog_Model_Product|integer $product
Returns:
integer|null

Definition at line 86 of file Observer.php.

00087     {
00088         if(is_object($product)) {
00089             return $product->getGiftMessageAvailable();
00090         }
00091         return Mage::getModel('catalog/product')->load($product)->getGiftMessageAvailable();
00092     }

catalogEventProductCollectionAfterLoad ( observer  ) 

Set giftmessage available default value to product on catalog products collection load

Parameters:
Varien_Object $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 167 of file Observer.php.

00168     {
00169         $collection = $observer->getEvent()->getCollection();
00170         foreach ($collection as $item) {
00171             if($item->getGiftMessageAvailable()===null) {
00172                 $item->setGiftMessageAvailable(2);
00173             }
00174         }
00175         return $this;
00176     }

checkoutEventCreateGiftMessage ( observer  ) 

Operate with gift messages on checkout proccess

Parameters:
Varieb_Object $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 100 of file Observer.php.

00101     {
00102         $giftMessages = $observer->getEvent()->getRequest()->getParam('giftmessage');
00103         $quote = $observer->getEvent()->getQuote();
00104         /* @var $quote Mage_Sales_Model_Quote */
00105         if(is_array($giftMessages)) {
00106             foreach ($giftMessages as $entityId=>$message) {
00107 
00108                 $giftMessage = Mage::getModel('giftmessage/message');
00109 
00110                 switch ($message['type']) {
00111                     case 'quote':
00112                         $entity = $quote;
00113                         break;
00114                     case 'quote_item':
00115                         $entity = $quote->getItemById($entityId);
00116                         break;
00117                     case 'quote_address':
00118                         $entity = $quote->getAddressById($entityId);
00119                         break;
00120                     case 'quote_address_item':
00121                         $entity = $quote->getAddressById($message['address'])->getItemById($entityId);
00122                         break;
00123                     default:
00124                         $entity = $quote;
00125                         break;
00126                 }
00127 
00128                 if($entity->getGiftMessageId()) {
00129                     $giftMessage->load($entity->getGiftMessageId());
00130                 }
00131 
00132                 if(trim($message['message'])=='') {
00133                     if($giftMessage->getId()) {
00134                         try{
00135                             $giftMessage->delete();
00136                             $entity->setGiftMessageId(0)
00137                                 ->save();
00138                         }
00139                         catch (Exception $e) { }
00140                     }
00141                     continue;
00142                 }
00143 
00144                 try {
00145                     $giftMessage->setSender($message['from'])
00146                         ->setRecipient($message['to'])
00147                         ->setMessage($message['message'])
00148                         ->save();
00149 
00150                     $entity->setGiftMessageId($giftMessage->getId())
00151                         ->save();
00152 
00153                 }
00154                 catch (Exception $e) { }
00155             }
00156         }
00157         return $this;
00158     }

salesEventConvertQuoteAddressToOrder ( observer  ) 

Set gift messages to order from quote address

Parameters:
Varien_Object $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 58 of file Observer.php.

00059     {
00060         if($observer->getEvent()->getAddress()->getGiftMessageId()) {
00061             $observer->getEvent()->getOrder()
00062                 ->setGiftMessageId($observer->getEvent()->getAddress()->getGiftMessageId());
00063         }
00064         return $this;
00065     }

salesEventConvertQuoteItemToOrderItem ( observer  ) 

Set gift messages to order item on import item

Parameters:
Varien_Object $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 44 of file Observer.php.

00045     {
00046         $observer->getEvent()->getOrderItem()
00047             ->setGiftMessageId($observer->getEvent()->getItem()->getGiftMessageId())
00048             ->setGiftMessageAvailable($this->_getAvailable($observer->getEvent()->getItem()->getProductId()));
00049         return $this;
00050     }

salesEventConvertQuoteToOrder ( observer  ) 

Set gift messages to order from quote address

Parameters:
Varien_Object $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 73 of file Observer.php.

00074     {
00075         $observer->getEvent()->getOrder()
00076             ->setGiftMessageId($observer->getEvent()->getQuote()->getGiftMessageId());
00077         return $this;
00078     }

salesEventOrderItemToQuoteItem ( observer  ) 

Duplicates giftmessage from order item to quote item on import or reorder

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 202 of file Observer.php.

00203     {
00204         $orderItem = $observer->getEvent()->getOrderItem();
00205         $quoteItem = $observer->getEvent()->getQuoteItem();
00206         /* @var $orderItem Mage_Sales_Model_Order_Item */
00207         /* @var $quoteItem Mage_Sales_Model_Quote_Item */
00208         if ($giftMessageId = $orderItem->getGiftMessageId()) {
00209             $giftMessage = Mage::getModel('giftmessage/message')->load($giftMessageId)
00210                 ->setId(null)
00211                 ->save();
00212             $quoteItem->setGiftMessageId($giftMessage->getId());
00213         }
00214 
00215         return $this;
00216     }

salesEventOrderToQuote ( observer  ) 

Duplicates giftmessage from order to quote on import or reorder

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_GiftMessage_Model_Observer

Definition at line 184 of file Observer.php.

00185     {
00186         if($giftMessageId = $observer->getEvent()->getOrder()->getGiftMessageId()) {
00187             $giftMessage = Mage::getModel('giftmessage/message')->load($giftMessageId)
00188                 ->setId(null)
00189                 ->save();
00190             $observer->getEvent()->getQuote()->setGiftMessageId($giftMessage->getId());
00191         }
00192 
00193         return $this;
00194     }


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

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