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_Wishlist_Block_Abstract
  • Mage_Wishlist_Block_Customer_Sharing
  • Mage_Wishlist_Block_Customer_Sidebar
  • Mage_Wishlist_Block_Customer_Wishlist
  • Mage_Wishlist_Block_Customer_Wishlist_Button
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Cart
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Comment
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Image
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Remove
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Options
  • Mage_Wishlist_Block_Customer_Wishlist_Items
  • Mage_Wishlist_Block_Item_Configure
  • Mage_Wishlist_Block_Links
  • Mage_Wishlist_Block_Render_Item_Price
  • Mage_Wishlist_Block_Share_Email_Items
  • Mage_Wishlist_Block_Share_Email_Rss
  • Mage_Wishlist_Block_Share_Wishlist
  • Mage_Wishlist_Controller_Abstract
  • Mage_Wishlist_Helper_Data
  • Mage_Wishlist_IndexController
  • Mage_Wishlist_Model_Config
  • Mage_Wishlist_Model_Config_Source_Summary
  • Mage_Wishlist_Model_Item
  • Mage_Wishlist_Model_Item_Option
  • Mage_Wishlist_Model_Mysql4_Item
  • Mage_Wishlist_Model_Mysql4_Item_Collection
  • Mage_Wishlist_Model_Mysql4_Item_Option
  • Mage_Wishlist_Model_Mysql4_Item_Option_Collection
  • Mage_Wishlist_Model_Mysql4_Product_Collection
  • Mage_Wishlist_Model_Mysql4_Wishlist
  • Mage_Wishlist_Model_Mysql4_Wishlist_Collection
  • Mage_Wishlist_Model_Observer
  • Mage_Wishlist_Model_Resource_Item
  • Mage_Wishlist_Model_Resource_Item_Collection
  • Mage_Wishlist_Model_Resource_Item_Option
  • Mage_Wishlist_Model_Resource_Item_Option_Collection
  • Mage_Wishlist_Model_Resource_Wishlist
  • Mage_Wishlist_Model_Resource_Wishlist_Collection
  • Mage_Wishlist_Model_Session
  • Mage_Wishlist_Model_Wishlist
  • Mage_Wishlist_SharedController
  • 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_Wishlist
 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:  * Wishlist Data Helper
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_Wishlist
 33:  * @author     Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Wishlist_Helper_Data extends Mage_Core_Helper_Abstract
 36: {
 37:     /**
 38:      * Config key 'Display Wishlist Summary'
 39:      */
 40:     const XML_PATH_WISHLIST_LINK_USE_QTY = 'wishlist/wishlist_link/use_qty';
 41: 
 42:     /**
 43:      * Config key 'Display Out of Stock Products'
 44:      */
 45:     const XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
 46: 
 47:     /**
 48:      * Currently logged in customer
 49:      *
 50:      * @var Mage_Customer_Model_Customer
 51:      */
 52:     protected $_currentCustomer = null;
 53: 
 54:     /**
 55:      * Customer Wishlist instance
 56:      *
 57:      * @var Mage_Wishlist_Model_Wishlist
 58:      */
 59:     protected $_wishlist = null;
 60: 
 61:     /**
 62:      * Wishlist Product Items Collection
 63:      *
 64:      * @var Mage_Wishlist_Model_Mysql4_Product_Collection
 65:      */
 66:     protected $_productCollection = null;
 67: 
 68:     /**
 69:      * Wishlist Items Collection
 70:      *
 71:      * @var Mage_Wishlist_Model_Resource_Item_Collection
 72:      */
 73:     protected $_wishlistItemCollection = null;
 74: 
 75:     /**
 76:      * Retreive customer session
 77:      *
 78:      * @return Mage_Customer_Model_Session
 79:      */
 80:     protected function _getCustomerSession()
 81:     {
 82:         return Mage::getSingleton('customer/session');
 83:     }
 84: 
 85:     /**
 86:      * Retrieve customer login status
 87:      *
 88:      * @return bool
 89:      */
 90:     protected function _isCustomerLogIn()
 91:     {
 92:         return $this->_getCustomerSession()->isLoggedIn();
 93:     }
 94: 
 95:     /**
 96:      * Retrieve logged in customer
 97:      *
 98:      * @return Mage_Customer_Model_Customer
 99:      */
100:     protected function _getCurrentCustomer()
101:     {
102:         return $this->getCustomer();
103:     }
104: 
105:     /**
106:      * Set current customer
107:      *
108:      * @param Mage_Customer_Model_Customer $customer
109:      */
110:     public function setCustomer(Mage_Customer_Model_Customer $customer)
111:     {
112:         $this->_currentCustomer = $customer;
113:     }
114: 
115:     /**
116:      * Retrieve current customer
117:      *
118:      * @return Mage_Customer_Model_Customer|null
119:      */
120:     public function getCustomer()
121:     {
122:         if (!$this->_currentCustomer && $this->_getCustomerSession()->isLoggedIn()) {
123:             $this->_currentCustomer = $this->_getCustomerSession()->getCustomer();
124:         }
125:         return $this->_currentCustomer;
126:     }
127: 
128:     /**
129:      * Retrieve wishlist by logged in customer
130:      *
131:      * @return Mage_Wishlist_Model_Wishlist
132:      */
133:     public function getWishlist()
134:     {
135:         if (is_null($this->_wishlist)) {
136:             if (Mage::registry('shared_wishlist')) {
137:                 $this->_wishlist = Mage::registry('shared_wishlist');
138:             }
139:             elseif (Mage::registry('wishlist')) {
140:                 $this->_wishlist = Mage::registry('wishlist');
141:             }
142:             else {
143:                 $this->_wishlist = Mage::getModel('wishlist/wishlist');
144:                 if ($this->getCustomer()) {
145:                     $this->_wishlist->loadByCustomer($this->getCustomer());
146:                 }
147:             }
148:         }
149:         return $this->_wishlist;
150:     }
151: 
152:     /**
153:      * Retrieve wishlist items availability
154:      *
155:      * @deprecated after 1.6.0.0
156:      *
157:      * @return bool
158:      */
159:     public function hasItems()
160:     {
161:         return $this->getWishlist()->getItemsCount() > 0;
162:     }
163: 
164:     /**
165:      * Retrieve wishlist item count (include config settings)
166:      * Used in top link menu only
167:      *
168:      * @return int
169:      */
170:     public function getItemCount()
171:     {
172:         $storedDisplayType = $this->_getCustomerSession()->getWishlistDisplayType();
173:         $currentDisplayType = Mage::getStoreConfig(self::XML_PATH_WISHLIST_LINK_USE_QTY);
174: 
175:         $storedDisplayOutOfStockProducts = $this->_getCustomerSession()->getDisplayOutOfStockProducts();
176:         $currentDisplayOutOfStockProducts = Mage::getStoreConfig(self::XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK);
177:         if (!$this->_getCustomerSession()->hasWishlistItemCount()
178:                 || ($currentDisplayType != $storedDisplayType)
179:                 || $this->_getCustomerSession()->hasDisplayOutOfStockProducts()
180:                 || ($currentDisplayOutOfStockProducts != $storedDisplayOutOfStockProducts)) {
181:             $this->calculate();
182:         }
183: 
184:         return $this->_getCustomerSession()->getWishlistItemCount();
185:     }
186: 
187:     /**
188:      * Retrieve wishlist product items collection
189:      *
190:      * alias for getProductCollection
191:      *
192:      * @deprecated after 1.4.2.0
193:      * @see Mage_Wishlist_Model_Wishlist::getItemCollection()
194:      *
195:      * @return Mage_Wishlist_Model_Mysql4_Product_Collection
196:      */
197:     public function getItemCollection()
198:     {
199:         return $this->getProductCollection();
200:     }
201: 
202:     /**
203:      * Create wishlist item collection
204:      *
205:      * @return Mage_Wishlist_Model_Resource_Item_Collection
206:      */
207:     protected function _createWishlistItemCollection()
208:     {
209:         return $this->getWishlist()->getItemCollection();
210:     }
211: 
212:     /**
213:      * Retrieve wishlist items collection
214:      *
215:      * @return Mage_Wishlist_Model_Resource_Item_Collection
216:      */
217:     public function getWishlistItemCollection()
218:     {
219:         if (is_null($this->_wishlistItemCollection)) {
220:             $this->_wishlistItemCollection = $this->_createWishlistItemCollection();
221:         }
222:         return $this->_wishlistItemCollection;
223:     }
224: 
225:     /**
226:      * Retrieve wishlist product items collection
227:      *
228:      * @deprecated after 1.4.2.0
229:      * @see Mage_Wishlist_Model_Wishlist::getItemCollection()
230:      *
231:      * @return Mage_Wishlist_Model_Mysql4_Product_Collection
232:      */
233:     public function getProductCollection()
234:     {
235:         if (is_null($this->_productCollection)) {
236:             $this->_productCollection = $this->getWishlist()
237:                 ->getProductCollection();
238: 
239:             Mage::getSingleton('catalog/product_visibility')
240:                 ->addVisibleInSiteFilterToCollection($this->_productCollection);
241:         }
242:         return $this->_productCollection;
243:     }
244: 
245:     /**
246:      * Retrieve Item Store for URL
247:      *
248:      * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
249:      * @return Mage_Core_Model_Store
250:      */
251:     protected function _getUrlStore($item)
252:     {
253:         $storeId = null;
254:         $product = null;
255:         if ($item instanceof Mage_Wishlist_Model_Item) {
256:             $product = $item->getProduct();
257:         } elseif ($item instanceof Mage_Catalog_Model_Product) {
258:             $product = $item;
259:         }
260:         if ($product) {
261:             if ($product->isVisibleInSiteVisibility()) {
262:                 $storeId = $product->getStoreId();
263:             }
264:             else if ($product->hasUrlDataObject()) {
265:                 $storeId = $product->getUrlDataObject()->getStoreId();
266:             }
267:         }
268:         return Mage::app()->getStore($storeId);
269:     }
270: 
271:     /**
272:      * Retrieve URL for removing item from wishlist
273:      *
274:      * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
275:      * @return string
276:      */
277:     public function getRemoveUrl($item)
278:     {
279:         return $this->_getUrl('wishlist/index/remove',
280:             array('item' => $item->getWishlistItemId())
281:         );
282:     }
283: 
284:     /**
285:      * Retrieve URL for removing item from wishlist
286:      *
287:      * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
288:      * @return string
289:      */
290:     public function getConfigureUrl($item)
291:     {
292:         return $this->_getUrl('wishlist/index/configure', array(
293:             'item' => $item->getWishlistItemId()
294:         ));
295:     }
296: 
297:     /**
298:      * Retrieve url for adding product to wishlist
299:      *
300:      * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
301:      *
302:      * @return  string|bool
303:      */
304:     public function getAddUrl($item)
305:     {
306:         return $this->getAddUrlWithParams($item);
307:     }
308: 
309:     /**
310:      * Retrieve url for adding product to wishlist
311:      *
312:      * @param int $itemId
313:      *
314:      * @return  string
315:      */
316:     public function getMoveFromCartUrl($itemId)
317:     {
318:         return $this->_getUrl('wishlist/index/fromcart', array('item' => $itemId));
319:     }
320: 
321:     /**
322:      * Retrieve url for updating product in wishlist
323:      *
324:      * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
325:      *
326:      * @return  string|bool
327:      */
328:     public function getUpdateUrl($item)
329:     {
330:         $itemId = null;
331:         if ($item instanceof Mage_Catalog_Model_Product) {
332:             $itemId = $item->getWishlistItemId();
333:         }
334:         if ($item instanceof Mage_Wishlist_Model_Item) {
335:             $itemId = $item->getId();
336:         }
337: 
338:         if ($itemId) {
339:             return $this->_getUrl('wishlist/index/updateItemOptions', array('id' => $itemId));
340:         }
341: 
342:         return false;
343:     }
344: 
345:     /**
346:      * Retrieve url for adding product to wishlist with params
347:      *
348:      * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
349:      * @param array $params
350:      *
351:      * @return  string|bool
352:      */
353:     public function getAddUrlWithParams($item, array $params = array())
354:     {
355:         $productId = null;
356:         if ($item instanceof Mage_Catalog_Model_Product) {
357:             $productId = $item->getEntityId();
358:         }
359:         if ($item instanceof Mage_Wishlist_Model_Item) {
360:             $productId = $item->getProductId();
361:         }
362: 
363:         if ($productId) {
364:             $params['product'] = $productId;
365:             return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params);
366:         }
367: 
368:         return false;
369:     }
370: 
371:     /**
372:      * Retrieve URL for adding item to shoping cart
373:      *
374:      * @param string|Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
375:      * @return  string
376:      */
377:     public function getAddToCartUrl($item)
378:     {
379:         $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
380:         $continueUrl  = Mage::helper('core')->urlEncode(
381:             Mage::getUrl('*/*/*', array(
382:                 '_current'      => true,
383:                 '_use_rewrite'  => true,
384:                 '_store_to_url' => true,
385:             ))
386:         );
387: 
388:         $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
389:         $params = array(
390:             'item' => is_string($item) ? $item : $item->getWishlistItemId(),
391:             $urlParamName => $continueUrl
392:         );
393:         return $this->_getUrlStore($item)->getUrl('wishlist/index/cart', $params);
394:     }
395: 
396:     /**
397:      * Retrieve URL for adding item to shoping cart from shared wishlist
398:      *
399:      * @param string|Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
400:      * @return  string
401:      */
402:     public function getSharedAddToCartUrl($item)
403:     {
404:         $continueUrl  = Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array(
405:             '_current'      => true,
406:             '_use_rewrite'  => true,
407:             '_store_to_url' => true,
408:         )));
409: 
410:         $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
411:         $params = array(
412:             'item' => is_string($item) ? $item : $item->getWishlistItemId(),
413:             $urlParamName => $continueUrl
414:         );
415:         return $this->_getUrlStore($item)->getUrl('wishlist/shared/cart', $params);
416:     }
417: 
418:     /**
419:      * Retrieve url for adding item to shoping cart with b64 referer
420:      *
421:      * @deprecated
422:      * @param   Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
423:      * @return  string
424:      */
425:     public function getAddToCartUrlBase64($item)
426:     {
427:         return $this->getAddToCartUrl($item);
428:     }
429: 
430:     /**
431:      * Retrieve customer wishlist url
432:      *
433:      * @param int $wishlistId
434:      * @return string
435:      */
436:     public function getListUrl($wishlistId = null)
437:     {
438:         $params = array();
439:         if ($wishlistId) {
440:             $params['wishlist_id'] = $wishlistId;
441:         }
442:         return $this->_getUrl('wishlist', $params);
443:     }
444: 
445:     /**
446:      * Check is allow wishlist module
447:      *
448:      * @return bool
449:      */
450:     public function isAllow()
451:     {
452:         if ($this->isModuleOutputEnabled() && Mage::getStoreConfig('wishlist/general/active')) {
453:             return true;
454:         }
455:         return false;
456:     }
457: 
458:     /**
459:      * Check is allow wishlist action in shopping cart
460:      *
461:      * @return bool
462:      */
463:     public function isAllowInCart()
464:     {
465:         return $this->isAllow() && $this->getCustomer();
466:     }
467: 
468:     /**
469:      * Retrieve customer name
470:      *
471:      * @return string|null
472:      */
473:     public function getCustomerName()
474:     {
475:         $customer = $this->_getCurrentCustomer();
476:         if ($customer) {
477:             return $customer->getName();
478:         }
479:     }
480: 
481:     /**
482:      * Retrieve RSS URL
483:      *
484:      * @param $wishlistId
485:      * @return string
486:      */
487:     public function getRssUrl($wishlistId = null)
488:     {
489:         $customer = $this->_getCurrentCustomer();
490:         if ($customer) {
491:             $key = $customer->getId() . ',' . $customer->getEmail();
492:             $params = array(
493:                 'data' => Mage::helper('core')->urlEncode($key),
494:                 '_secure' => false,
495:             );
496:         }
497:         if ($wishlistId) {
498:             $params['wishlist_id'] = $wishlistId;
499:         }
500:         return $this->_getUrl(
501:             'rss/index/wishlist',
502:             $params
503:         );
504:     }
505: 
506:     /**
507:      * Is allow RSS
508:      *
509:      * @return bool
510:      */
511:     public function isRssAllow()
512:     {
513:         return Mage::getStoreConfigFlag('rss/wishlist/active');
514:     }
515: 
516:     /**
517:      * Retrieve default empty comment message
518:      *
519:      * @return string
520:      */
521:     public function defaultCommentString()
522:     {
523:         return $this->__('Please, enter your comments...');
524:     }
525: 
526:     /**
527:      * Retrieve default empty comment message
528:      *
529:      * @return string
530:      */
531:     public function getDefaultWishlistName()
532:     {
533:         return $this->__('Wishlist');
534:     }
535: 
536:     /**
537:      * Calculate count of wishlist items and put value to customer session.
538:      * Method called after wishlist modifications and trigger 'wishlist_items_renewed' event.
539:      * Depends from configuration.
540:      *
541:      * @return Mage_Wishlist_Helper_Data
542:      */
543:     public function calculate()
544:     {
545:         $session = $this->_getCustomerSession();
546:         $count = 0;
547:         if ($this->getCustomer()) {
548:             $collection = $this->getWishlistItemCollection()->setInStockFilter(true);
549:             if (Mage::getStoreConfig(self::XML_PATH_WISHLIST_LINK_USE_QTY)) {
550:                 $count = $collection->getItemsQty();
551:             } else {
552:                 $count = $collection->getSize();
553:             }
554:             $session->setWishlistDisplayType(Mage::getStoreConfig(self::XML_PATH_WISHLIST_LINK_USE_QTY));
555:             $session->setDisplayOutOfStockProducts(
556:                 Mage::getStoreConfig(self::XML_PATH_CATALOGINVENTORY_SHOW_OUT_OF_STOCK)
557:             );
558:         }
559:         $session->setWishlistItemCount($count);
560:         Mage::dispatchEvent('wishlist_items_renewed');
561:         return $this;
562:     }
563: 
564:     /**
565:      * Should display item quantities in my wishlist link
566:      *
567:      * @return bool
568:      */
569:     public function isDisplayQty()
570:     {
571:         return Mage::getStoreConfig(self::XML_PATH_WISHLIST_LINK_USE_QTY);
572:     }
573: }
574: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0