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_Customer
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: * Account dashboard sidebar
29: *
30: * @category Mage
31: * @package Mage_Customer
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Customer_Block_Account_Dashboard_Sidebar extends Mage_Core_Block_Template
36: {
37: protected $_cartItemsCount;
38:
39: /**
40: * Enter description here...
41: *
42: * @var Mage_Wishlist_Model_Wishlist
43: */
44: protected $_wishlist;
45:
46: protected $_compareItems;
47:
48: public function getShoppingCartUrl()
49: {
50: return Mage::getUrl('checkout/cart');
51: }
52:
53: public function getCartItemsCount()
54: {
55: if( !$this->_cartItemsCount ) {
56: $this->_cartItemsCount = Mage::getModel('sales/quote')
57: ->setId(Mage::getModel('checkout/session')->getQuote()->getId())
58: ->getItemsCollection()
59: ->getSize();
60: }
61:
62: return $this->_cartItemsCount;
63: }
64:
65: public function getWishlist()
66: {
67: if( !$this->_wishlist ) {
68: $this->_wishlist = Mage::getModel('wishlist/wishlist')
69: ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer());
70: $this->_wishlist->getItemCollection()
71: ->addAttributeToSelect('name')
72: ->addAttributeToSelect('price')
73: ->addAttributeToSelect('small_image')
74: ->addAttributeToFilter('store_id', array('in' => $this->_wishlist->getSharedStoreIds()))
75: ->addAttributeToSort('added_at', 'desc')
76: ->setCurPage(1)
77: ->setPageSize(3)
78: ->load();
79: }
80:
81: return $this->_wishlist->getItemCollection();
82: }
83:
84: public function getWishlistCount()
85: {
86: return $this->getWishlist()->getSize();
87: }
88:
89: public function getWishlistAddToCartLink($wishlistItem)
90: {
91: return Mage::getUrl('wishlist/index/cart', array('item' => $wishlistItem->getId()));
92: }
93:
94: public function getCompareItems()
95: {
96: if( !$this->_compareItems ) {
97: $this->_compareItems = Mage::getResourceModel('catalog/product_compare_item_collection')
98: ->setStoreId(Mage::app()->getStore()->getId());
99: $this->_compareItems->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
100: $this->_compareItems
101: ->addAttributeToSelect('name')
102: ->useProductItem()
103: ->load();
104:
105: }
106:
107: return $this->_compareItems;
108: }
109:
110: public function getCompareJsObjectName()
111: {
112: return "dashboardSidebarCompareJsObject";
113: }
114:
115: public function getCompareRemoveUrlTemplate()
116: {
117: return $this->getUrl('catalog/product_compare/remove',array('product'=>'#{id}'));
118: }
119:
120: public function getCompareAddUrlTemplate()
121: {
122: return $this->getUrl('catalog/product_compare/add',array('product'=>'#{id}'));
123: }
124:
125: public function getCompareUrl()
126: {
127: return $this->getUrl('catalog/product_compare');
128: }
129: }
130: