Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_GiftMessage_Block_Adminhtml_Product_Helper_Form_Config
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_Create_Form
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_Create_Giftoptions
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_Create_Items
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Form
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Giftoptions
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Items
  • Mage_GiftMessage_Block_Message_Inline
  • Mage_GiftMessage_Helper_Data
  • Mage_GiftMessage_Helper_Message
  • Mage_GiftMessage_Helper_Url
  • Mage_GiftMessage_Model_Api
  • Mage_GiftMessage_Model_Api_V2
  • Mage_GiftMessage_Model_Message
  • Mage_GiftMessage_Model_Mysql4_Message
  • Mage_GiftMessage_Model_Mysql4_Message_Collection
  • Mage_GiftMessage_Model_Mysql4_Setup
  • Mage_GiftMessage_Model_Observer
  • Mage_GiftMessage_Model_Resource_Message
  • Mage_GiftMessage_Model_Resource_Message_Collection
  • Mage_GiftMessage_Model_Resource_Setup
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_GiftMessage
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Gift Message helper
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_GiftMessage
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_GiftMessage_Helper_Message extends Mage_Core_Helper_Data
 36: {
 37:     /**
 38:      * Giftmessages allow section in configuration
 39:      *
 40:      */
 41:     const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS = 'sales/gift_options/allow_items';
 42:     const XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER = 'sales/gift_options/allow_order';
 43: 
 44:     /**
 45:      * Next id for edit gift message block
 46:      *
 47:      * @var integer
 48:      */
 49:     protected $_nextId = 0;
 50: 
 51:     /**
 52:      * Inner cache
 53:      *
 54:      * @var array
 55:      */
 56:     protected $_innerCache = array();
 57: 
 58:     /**
 59:      * Retrive old stule edit button html for editing of giftmessage in popup
 60:      *
 61:      * @param string $type
 62:      * @param Varien_Object $entity
 63:      * @return string
 64:      */
 65:     public function getButton($type, Varien_Object $entity)
 66:     {
 67:         if (!$this->isMessagesAvailable($type, $entity)) {
 68:             return '&nbsp;';
 69:         }
 70: 
 71:         return Mage::getSingleton('core/layout')->createBlock('giftmessage/message_helper')
 72:             ->setId('giftmessage_button_' . $this->_nextId++)
 73:             ->setCanDisplayContainer(true)
 74:             ->setEntity($entity)
 75:             ->setType($type)->toHtml();
 76:     }
 77: 
 78:     /**
 79:      * Retrive inline giftmessage edit form for specified entity
 80:      *
 81:      * @param string $type
 82:      * @param Varien_Object $entity
 83:      * @param boolean $dontDisplayContainer
 84:      * @return string
 85:      */
 86:     public function getInline($type, Varien_Object $entity, $dontDisplayContainer=false)
 87:     {
 88:         if (!in_array($type, array('onepage_checkout','multishipping_adress')) && !$this->isMessagesAvailable($type, $entity)) {
 89:             return '';
 90:         }
 91: 
 92:         return Mage::getSingleton('core/layout')->createBlock('giftmessage/message_inline')
 93:             ->setId('giftmessage_form_' . $this->_nextId++)
 94:             ->setDontDisplayContainer($dontDisplayContainer)
 95:             ->setEntity($entity)
 96:             ->setType($type)->toHtml();
 97:     }
 98: 
 99:     /**
100:      * Check availability of giftmessages for specified entity.
101:      *
102:      * @param string $type
103:      * @param Varien_Object $entity
104:      * @param Mage_Core_Model_Store|integer $store
105:      * @return boolean
106:      */
107:     public function isMessagesAvailable($type, Varien_Object $entity, $store = null)
108:     {
109:         if ($type == 'items') {
110:             $items = $entity->getAllItems();
111:             if(!is_array($items) || empty($items)) {
112:                 return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
113:             }
114:             if($entity instanceof Mage_Sales_Model_Quote) {
115:                 $_type = $entity->getIsMultiShipping() ? 'address_item' : 'item';
116:             }
117:             else {
118:                 $_type = 'order_item';
119:             }
120: 
121:             foreach ($items as $item) {
122:                 if ($item->getParentItem()) {
123:                     continue;
124:                 }
125:                 if ($this->isMessagesAvailable($_type, $item, $store)) {
126:                     return true;
127:                 }
128:             }
129:         } elseif ($type == 'item') {
130:             return $this->_getDependenceFromStoreConfig(
131:                 $entity->getProduct()->getGiftMessageAvailable(),
132:                 $store
133:             );
134:         } elseif ($type == 'order_item') {
135:             return $this->_getDependenceFromStoreConfig(
136:                 $entity->getGiftMessageAvailable(),
137:                 $store
138:             );
139:         } elseif ($type == 'address_item') {
140:             $storeId = is_numeric($store) ? $store : Mage::app()->getStore($store)->getId();
141: 
142:             if (!$this->isCached('address_item_' . $entity->getProductId())) {
143:                 $this->setCached(
144:                     'address_item_' . $entity->getProductId(),
145:                     Mage::getModel('catalog/product')
146:                         ->setStoreId($storeId)
147:                         ->load($entity->getProductId())
148:                         ->getGiftMessageAvailable()
149:                 );
150:             }
151:             return $this->_getDependenceFromStoreConfig(
152:                 $this->getCached('address_item_' . $entity->getProductId()),
153:                 $store
154:             );
155:         } else {
156:             return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store);
157:         }
158: 
159:         return false;
160:     }
161: 
162:     /**
163:      * Check availablity of gift messages from store config if flag eq 2.
164:      *
165:      * @param int $productGiftMessageAllow
166:      * @param Mage_Core_Model_Store|integer $store
167:      * @return boolean
168:      */
169:     protected function _getDependenceFromStoreConfig($productGiftMessageAllow, $store=null)
170:     {
171:         $result = Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $store);
172:         if ($productGiftMessageAllow === '' || is_null($productGiftMessageAllow)) {
173:             return $result;
174:         } else {
175:             return $productGiftMessageAllow;
176:         }
177:     }
178: 
179:     /**
180:      * Alias for isMessagesAvailable(...)
181:      *
182:      * @param string $type
183:      * @param Varien_Object $entity
184:      * @param Mage_Core_Model_Store|integer $store
185:      * @return boolen
186:      */
187:     public function getIsMessagesAvailable($type, Varien_Object $entity, $store=null)
188:     {
189:         return $this->isMessagesAvailable($type, $entity, $store);
190:     }
191: 
192:     /**
193:      * Retrive escaped and preformated gift message text for specified entity
194:      *
195:      * @param Varien_Object $entity
196:      * @return unknown
197:      */
198:     public function getEscapedGiftMessage(Varien_Object $entity)
199:     {
200:         $message = $this->getGiftMessageForEntity($entity);
201:         if ($message) {
202:             return nl2br($this->htmlEscape($message->getMessage()));
203:         }
204:         return null;
205:     }
206: 
207:     /**
208:      * Retrive gift message for entity. If message not exists return null
209:      *
210:      * @param Varien_Object $entity
211:      * @return Mage_GiftMessage_Model_Message
212:      */
213:     public function getGiftMessageForEntity(Varien_Object $entity)
214:     {
215:         if($entity->getGiftMessageId() && !$entity->getGiftMessage()) {
216:             $message = $this->getGiftMessage($entity->getGiftMessageId());
217:             $entity->setGiftMessage($message);
218:         }
219:         return $entity->getGiftMessage();
220:     }
221: 
222:     /**
223:      * Retrive internal cached data with specified key.
224:      *
225:      * If cached data not found return null.
226:      *
227:      * @param string $key
228:      * @return mixed|null
229:      */
230:     public function getCached($key)
231:     {
232:         if($this->isCached($key)) {
233:             return $this->_innerCache[$key];
234:         }
235: 
236:         return null;
237:     }
238: 
239:     /**
240:      * Check availability for internal cached data with specified key
241:      *
242:      * @param string $key
243:      * @return boolean
244:      */
245:     public function isCached($key)
246:     {
247:         return isset($this->_innerCache[$key]);
248:     }
249: 
250:     /**
251:      * Set internal cache data with specified key
252:      *
253:      * @param string $key
254:      * @param mixed $value
255:      * @return Mage_GiftMessage_Helper_Message
256:      */
257:     public function setCached($key, $value)
258:     {
259:         $this->_innerCache[$key] = $value;
260:         return $this;
261:     }
262: 
263:     /**
264:      * Check availability for onepage checkout items
265:      *
266:      * @param array $items
267:      * @param Mage_Core_Model_Store|integer $store
268:      * @return boolen
269:      */
270:     public function getAvailableForQuoteItems($quote, $store=null)
271:     {
272:         foreach($quote->getAllItems() as $item) {
273:             if($this->isMessagesAvailable('item', $item, $store)) {
274:                 return true;
275:             }
276:         }
277: 
278:         return false;
279:     }
280: 
281:     /**
282:      * Check availability for multishiping checkout items
283:      *
284:      * @param array $items
285:      * @param Mage_Core_Model_Store|integer $store
286:      * @return boolen
287:      */
288:     public function getAvailableForAddressItems($items, $store=null)
289:     {
290:         foreach($items as $item) {
291:             if($this->isMessagesAvailable('address_item', $item, $store)) {
292:                 return true;
293:             }
294:         }
295:         return false;
296:     }
297: 
298:     /**
299:      * Retrive gift message with specified id
300:      *
301:      * @param integer $messageId
302:      * @return Mage_GiftMessage_Model_Message
303:      */
304:     public function getGiftMessage($messageId=null)
305:     {
306:         $message = Mage::getModel('giftmessage/message');
307:         if(!is_null($messageId)) {
308:             $message->load($messageId);
309:         }
310: 
311:         return $message;
312:     }
313: 
314: }
315: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0