1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Wishlist_SharedController extends Mage_Wishlist_Controller_Abstract
36: {
37: 38: 39: 40: 41:
42: protected function _getWishlist()
43: {
44: $code = (string)$this->getRequest()->getParam('code');
45: if (empty($code)) {
46: return false;
47: }
48:
49: $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($code);
50: if (!$wishlist->getId()) {
51: return false;
52: }
53:
54: Mage::getSingleton('checkout/session')->setSharedWishlist($code);
55:
56: return $wishlist;
57: }
58:
59: 60: 61: 62:
63: public function indexAction()
64: {
65: $wishlist = $this->_getWishlist();
66: $customerId = Mage::getSingleton('customer/session')->getCustomerId();
67:
68: if ($wishlist && $wishlist->getCustomerId() && $wishlist->getCustomerId() == $customerId) {
69: $this->_redirectUrl(Mage::helper('wishlist')->getListUrl($wishlist->getId()));
70: return;
71: }
72:
73: Mage::register('shared_wishlist', $wishlist);
74:
75: $this->loadLayout();
76: $this->_initLayoutMessages('checkout/session');
77: $this->_initLayoutMessages('wishlist/session');
78: $this->renderLayout();
79: }
80:
81: 82: 83: 84: 85: 86: 87:
88: public function cartAction()
89: {
90: $itemId = (int) $this->getRequest()->getParam('item');
91:
92:
93: $item = Mage::getModel('wishlist/item')->load($itemId);
94:
95:
96:
97: $session = Mage::getSingleton('wishlist/session');
98: $cart = Mage::getSingleton('checkout/cart');
99:
100: $redirectUrl = $this->_getRefererUrl();
101:
102: try {
103: $options = Mage::getModel('wishlist/item_option')->getCollection()
104: ->addItemFilter(array($itemId));
105: $item->setOptions($options->getOptionsByItem($itemId));
106:
107: $item->addToCart($cart);
108: $cart->save()->getQuote()->collectTotals();
109:
110: if (Mage::helper('checkout/cart')->getShouldRedirectToCart()) {
111: $redirectUrl = Mage::helper('checkout/cart')->getCartUrl();
112: }
113: } catch (Mage_Core_Exception $e) {
114: if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SALABLE) {
115: $session->addError(Mage::helper('wishlist')->__('This product(s) is currently out of stock'));
116: } else {
117: Mage::getSingleton('catalog/session')->addNotice($e->getMessage());
118: $redirectUrl = $item->getProductUrl();
119: }
120: } catch (Exception $e) {
121: $session->addException($e, Mage::helper('wishlist')->__('Cannot add item to shopping cart'));
122: }
123:
124: return $this->_redirectUrl($redirectUrl);
125: }
126: }
127: