Mage_GiftMessage_Helper_Message Class Reference

Inheritance diagram for Mage_GiftMessage_Helper_Message:

Mage_Core_Helper_Data Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 getButton ($type, Varien_Object $entity)
 getInline ($type, Varien_Object $entity, $dontDisplayContainer=false)
 isMessagesAvailable ($type, Varien_Object $entity, $store=null)
 getIsMessagesAvailable ($type, Varien_Object $entity, $store=null)
 getEscapedGiftMessage (Varien_Object $entity)
 getGiftMessageForEntity (Varien_Object $entity)
 getCached ($key)
 isCached ($key)
 setCached ($key, $value)
 getAvailableForQuoteItems ($quote, $store=null)
 getAvailableForAddressItems ($items, $store=null)
 getGiftMessage ($messageId=null)

Public Attributes

const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS = 'sales/gift_messages/allow_items'
const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER = 'sales/gift_messages/allow_order'

Protected Member Functions

 _getDependenceFromStoreConfig ($productGiftMessageAllow, $store=null)

Protected Attributes

 $_nextId = 0
 $_innerCache = array()


Detailed Description

Definition at line 35 of file Message.php.


Member Function Documentation

_getDependenceFromStoreConfig ( productGiftMessageAllow,
store = null 
) [protected]

Check availablity of gift messages from store config if flag eq 2.

Parameters:
int $productGiftMessageAllow
Mage_Core_Model_Store|integer $store
Returns:
boolean

Definition at line 169 of file Message.php.

00170     {
00171         $result = Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
00172 
00173         if ($productGiftMessageAllow==2 || is_null($productGiftMessageAllow)) {
00174             return $result;
00175         } else {
00176             return $productGiftMessageAllow == 1;
00177         }
00178     }

getAvailableForAddressItems ( items,
store = null 
)

Check availability for multishiping checkout items

Parameters:
array $items
Mage_Core_Model_Store|integer $store
Returns:
boolen

Definition at line 289 of file Message.php.

00290     {
00291         foreach($items as $item) {
00292             if($this->isMessagesAvailable('address_item', $item, $store)) {
00293                 return true;
00294             }
00295         }
00296         return false;
00297     }

getAvailableForQuoteItems ( quote,
store = null 
)

Check availability for onepage checkout items

Parameters:
array $items
Mage_Core_Model_Store|integer $store
Returns:
boolen

Definition at line 271 of file Message.php.

00272     {
00273         foreach($quote->getAllItems() as $item) {
00274             if($this->isMessagesAvailable('item', $item, $store)) {
00275                 return true;
00276             }
00277         }
00278 
00279         return false;
00280     }

getButton ( type,
Varien_Object entity 
)

Retrive old stule edit button html for editing of giftmessage in popup

Parameters:
string $type
Varien_Object $entity
Returns:
string

Definition at line 65 of file Message.php.

00066     {
00067         if (!$this->isMessagesAvailable($type, $entity)) {
00068             return ' ';
00069         }
00070 
00071         return Mage::getSingleton('core/layout')->createBlock('giftmessage/message_helper')
00072             ->setId('giftmessage_button_' . $this->_nextId++)
00073             ->setCanDisplayContainer(true)
00074             ->setEntity($entity)
00075             ->setType($type)->toHtml();
00076     }

getCached ( key  ) 

Retrive internal cached data with specified key.

If cached data not found return null.

Parameters:
string $key
Returns:
mixed|null

Definition at line 231 of file Message.php.

00232     {
00233         if($this->isCached($key)) {
00234             return $this->_innerCache[$key];
00235         }
00236 
00237         return null;
00238     }

getEscapedGiftMessage ( Varien_Object entity  ) 

Retrive escaped and preformated gift message text for specified entity

Parameters:
Varien_Object $entity
Returns:
unknown

Definition at line 199 of file Message.php.

00200     {
00201         $message = $this->getGiftMessageForEntity($entity);
00202         if ($message) {
00203             return nl2br($this->htmlEscape($message->getMessage()));
00204         }
00205         return null;
00206     }

getGiftMessage ( messageId = null  ) 

Retrive gift message with specified id

Parameters:
integer $messageId
Returns:
Mage_GiftMessage_Model_Message

Definition at line 305 of file Message.php.

00306     {
00307         $message = Mage::getModel('giftmessage/message');
00308         if(!is_null($messageId)) {
00309             $message->load($messageId);
00310         }
00311 
00312         return $message;
00313     }

getGiftMessageForEntity ( Varien_Object entity  ) 

Retrive gift message for entity. If message not exists return null

Parameters:
Varien_Object $entity
Returns:
Mage_GiftMessage_Model_Message

Definition at line 214 of file Message.php.

00215     {
00216         if($entity->getGiftMessageId() && !$entity->getGiftMessage()) {
00217             $message = $this->getGiftMessage($entity->getGiftMessageId());
00218             $entity->setGiftMessage($message);
00219         }
00220         return $entity->getGiftMessage();
00221     }

getInline ( type,
Varien_Object entity,
dontDisplayContainer = false 
)

Retrive inline giftmessage edit form for specified entity

Parameters:
string $type
Varien_Object $entity
boolean $dontDisplayContainer
Returns:
string

Definition at line 86 of file Message.php.

00087     {
00088         if (in_array($type, array('onepage_checkout','multishipping_adress'))) {
00089             if (!$this->isMessagesAvailable('items', $entity)) {
00090                 return '';
00091             }
00092         } elseif (!$this->isMessagesAvailable($type, $entity)) {
00093             return '';
00094         }
00095 
00096         return Mage::getSingleton('core/layout')->createBlock('giftmessage/message_inline')
00097             ->setId('giftmessage_form_' . $this->_nextId++)
00098             ->setDontDisplayContainer($dontDisplayContainer)
00099             ->setEntity($entity)
00100             ->setType($type)->toHtml();
00101     }

getIsMessagesAvailable ( type,
Varien_Object entity,
store = null 
)

Alias for isMessagesAvailable(...)

Parameters:
string $type
Varien_Object $entity
Mage_Core_Model_Store|integer $store
Returns:
boolen

Definition at line 188 of file Message.php.

00189     {
00190         return $this->isMessagesAvailable($type, $entity, $store);
00191     }

isCached ( key  ) 

Check availability for internal cached data with specified key

Parameters:
string $key
Returns:
boolean

Definition at line 246 of file Message.php.

00247     {
00248         return isset($this->_innerCache[$key]);
00249     }

isMessagesAvailable ( type,
Varien_Object entity,
store = null 
)

Check availability of giftmessages for specified entity.

Parameters:
string $type
Varien_Object $entity
Mage_Core_Model_Store|integer $store
Returns:
boolean

Definition at line 111 of file Message.php.

00112     {
00113         $resultItems = Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
00114         $resultOrder = Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store);
00115 
00116         if ($type == 'items') {
00117             return $resultItems || $resultOrder;
00118         }
00119 
00120         if (is_object($store)) {
00121             $storeId = $store->getId();
00122         } elseif (is_numeric($store)) {
00123             $storeId = $store;
00124         } else {
00125             $storeId = Mage::app()->getStore()->getId();
00126         }
00127 
00128         if ($type=='item') {
00129             return $resultItems && $this->_getDependenceFromStoreConfig(
00130                         $entity->getProduct()->getGiftMessageAvailable(),
00131                         $store
00132                    );
00133         } elseif ($type=='order_item') {
00134             return $resultItems && $this->_getDependenceFromStoreConfig(
00135                         (is_null($entity->getGiftMessageAvailable()) ? 2 : $entity->getGiftMessageAvailable()),
00136                         $store
00137                     );
00138         } elseif ($type=='address_item') {
00139             if (!$resultItems) {
00140                 return false;
00141             }
00142             if (!$this->isCached('address_item_' . $entity->getProductId())) {
00143                 $this->setCached(
00144                     'address_item_' . $entity->getProductId(),
00145                     Mage::getModel('catalog/product')
00146                         ->setStoreId($storeId)
00147                         ->load($entity->getProductId())
00148                         ->getGiftMessageAvailable()
00149                 );
00150             }
00151             return $this->_getDependenceFromStoreConfig(
00152                         $this->getCached('address_item_' . $entity->getProductId()),
00153                         $store
00154                    );
00155         } else {
00156             return $resultOrder;
00157         }
00158 
00159         return false;
00160     }

setCached ( key,
value 
)

Set internal cache data with specified key

Parameters:
string $key
mixed $value
Returns:
Mage_GiftMessage_Helper_Message

Definition at line 258 of file Message.php.

00259     {
00260         $this->_innerCache[$key] = $value;
00261         return $this;
00262     }


Member Data Documentation

$_innerCache = array() [protected]

Definition at line 56 of file Message.php.

$_nextId = 0 [protected]

Definition at line 49 of file Message.php.

const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS = 'sales/gift_messages/allow_items'

Giftmessages allow section in configuration

Definition at line 41 of file Message.php.

const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER = 'sales/gift_messages/allow_order'

Definition at line 42 of file Message.php.


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