/** * Check availability of giftmessages for specified entity. * * @param string $type * @param Varien_Object $entity * @param Mage_Core_Model_Store|integer $store * @return boolean */ public function isMessagesAvailable($type, Varien_Object $entity, $store = null) { if ($type == 'items') { $items = $entity->getAllItems(); if (!is_array($items) || empty($items)) { return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store); } if ($entity instanceof Mage_Sales_Model_Quote) { $_type = $entity->getIsMultiShipping() ? 'address_item' : 'item'; } else { $_type = 'order_item'; } foreach ($items as $item) { if ($item->getParentItem()) { continue; } if ($this->isMessagesAvailable($_type, $item, $store)) { return true; } } } elseif ($type == 'item') { return $this->_getDependenceFromStoreConfig($entity->getProduct()->getGiftMessageAvailable(), $store); } elseif ($type == 'order_item') { return $this->_getDependenceFromStoreConfig($entity->getGiftMessageAvailable(), $store); } elseif ($type == 'address_item') { $storeId = is_numeric($store) ? $store : Mage::app()->getStore($store)->getId(); if (!$this->isCached('address_item_' . $entity->getProductId())) { $this->setCached('address_item_' . $entity->getProductId(), Mage::getModel('Mage_Catalog_Model_Product')->setStoreId($storeId)->load($entity->getProductId())->getGiftMessageAvailable()); } return $this->_getDependenceFromStoreConfig($this->getCached('address_item_' . $entity->getProductId()), $store); } else { return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store); } return false; }