00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Wishlist_SharedController extends Mage_Core_Controller_Front_Action
00036 {
00037
00038 public function indexAction()
00039 {
00040 $code = (string) $this->getRequest()->getParam('code');
00041 if (empty($code)) {
00042 $this->_forward('noRoute');
00043 return;
00044 }
00045 $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($code);
00046
00047 if ($wishlist->getCustomerId() && $wishlist->getCustomerId() == Mage::getSingleton('customer/session')->getCustomerId()) {
00048 $this->_redirectUrl(Mage::helper('wishlist')->getListUrl());
00049 return;
00050 }
00051
00052 if(!$wishlist->getId()) {
00053 $this->_forward('noRoute');
00054 return;
00055 } else {
00056 Mage::register('shared_wishlist', $wishlist);
00057 $this->loadLayout();
00058 $this->_initLayoutMessages('wishlist/session');
00059 $this->renderLayout();
00060 }
00061
00062 }
00063
00064 public function allcartAction()
00065 {
00066 $code = (string) $this->getRequest()->getParam('code');
00067 if (empty($code)) {
00068 $this->_forward('noRoute');
00069 return;
00070 }
00071
00072 $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($code);
00073 Mage::getSingleton('checkout/session')->setSharedWishlist($code);
00074
00075 if (!$wishlist->getId()) {
00076 $this->_forward('noRoute');
00077 return;
00078 } else {
00079 $urls = false;
00080 foreach ($wishlist->getProductCollection() as $item) {
00081 try {
00082 $product = Mage::getModel('catalog/product')
00083 ->load($item->getProductId());
00084 if ($product->isSalable()){
00085 Mage::getSingleton('checkout/cart')->addProduct($product);
00086 }
00087 }
00088 catch (Exception $e) {
00089 $url = Mage::getSingleton('checkout/session')->getRedirectUrl(true);
00090 if ($url){
00091 $url = Mage::getModel('core/url')->getUrl('catalog/product/view', array(
00092 'id'=>$item->getProductId(),
00093 'wishlist_next'=>1
00094 ));
00095
00096 $urls[] = $url;
00097 $messages[] = $e->getMessage();
00098 $wishlistIds[] = $item->getId();
00099 }
00100 }
00101
00102 Mage::getSingleton('checkout/cart')->save();
00103 }
00104 if ($urls) {
00105 Mage::getSingleton('checkout/session')->addError(array_shift($messages));
00106 $this->getResponse()->setRedirect(array_shift($urls));
00107
00108 Mage::getSingleton('checkout/session')->setWishlistPendingUrls($urls);
00109 Mage::getSingleton('checkout/session')->setWishlistPendingMessages($messages);
00110 Mage::getSingleton('checkout/session')->setWishlistIds($wishlistIds);
00111 } else {
00112 $this->_redirect('checkout/cart');
00113 }
00114 }
00115 }
00116 }