/** * Performed before data is saved * * @param Varieb_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function beforeSave($object) { if ($object->getShipment()) { $object->setParentId($object->getShipment()->getId()); } return parent::beforeSave($object); }
/** * Operate with gift messages on checkout proccess * * @param Varieb_Object $observer * @return Mage_GiftMessage_Model_Observer */ public function checkoutEventCreateGiftMessage($observer) { $giftMessages = $observer->getEvent()->getRequest()->getParam('giftmessage'); if (is_array($giftMessages)) { foreach ($giftMessages as $entityId => $message) { $giftMessage = Mage::getModel('giftmessage/message'); $entity = $giftMessage->getEntityModelByType($message['type']); if ($message['type'] == 'quote') { $entity->setStoreId(Mage::app()->getStore()->getId()); } $entity->load($entityId); if ($entity->getGiftMessageId()) { $giftMessage->load($entity->getGiftMessageId()); } if (trim($message['message']) == '') { if ($giftMessage->getId()) { try { $giftMessage->delete(); $entity->setGiftMessageId(0)->save(); } catch (Exception $e) { } } continue; } try { $giftMessage->setSender($message['from'])->setRecipient($message['to'])->setMessage($message['message'])->save(); $entity->setGiftMessageId($giftMessage->getId())->save(); } catch (Exception $e) { } } } return $this; }
/** * Operate with gift messages on checkout proccess * * @param Varieb_Object $observer * @return Mage_GiftMessage_Model_Observer */ public function checkoutEventCreateGiftMessage($observer) { $giftMessages = $observer->getEvent()->getRequest()->getParam('giftmessage'); $allowed_gitf = $observer->getEvent()->getRequest()->getParam('allow_gift_options'); $quote = $observer->getEvent()->getQuote(); /* @var $quote Mage_Sales_Model_Quote */ if (is_array($giftMessages)) { foreach ($giftMessages as $entityId => $message) { $giftMessage = Mage::getModel('giftmessage/message'); switch ($message['type']) { case 'quote': $entity = $quote; break; case 'quote_item': $entity = $quote->getItemById($entityId); break; case 'quote_address': $entity = $quote->getAddressById($entityId); break; case 'quote_address_item': $entity = $quote->getAddressById($message['address'])->getItemById($entityId); break; default: $entity = $quote; break; } if ($entity->getGiftMessageId()) { $giftMessage->load($entity->getGiftMessageId()); } if (trim($message['message']) == '' && !$allowed_gitf) { if ($giftMessage->getId()) { try { $giftMessage->delete(); $entity->setGiftMessageId(0)->save(); } catch (Exception $e) { } } continue; } try { $giftMessage->setSender($message['from'])->setRecipient($message['to'])->setMessage($message['message'])->save(); $entity->setGiftMessageId($giftMessage->getId())->save(); } catch (Exception $e) { } } } return $this; }