/** * add item to wishlist */ public function addAction() { // init $status = array('title' => 'Wishlist', 'text' => 'error', 'success' => false); // add item to wishlist if ($id = $this->getParam('item')) { $product = Object_Product::getById($id); /* @var Website_DefaultProduct $product */ if ($product) { $this->wishlist->addItem($product, 1); $this->wishlist->save(); $status['title'] = 'Added'; $status['success'] = true; $status['text'] = $product->getOSName(); $status['image'] = $product->getFirstImage(array('width' => 48, 'height' => 48, 'aspectratio' => true))->__toString(); } } // its a ajax request? if ($this->getRequest()->isXmlHttpRequest()) { $this->_helper->json($status); } else { $url = $this->view->url(array('action' => 'list'), 'wishlist'); $this->redirect($url); } }
/** * add item to cart */ public function addAction() { // init $status = array('title' => 'Cart', 'text' => 'error', 'success' => false, 'snippet' => array()); // add item to cart if ($id = $this->getParam('item')) { $product = Object_Product::getById($id); /* @var Website_DefaultProduct $product */ $qty = (int) $this->getParam('qty', 1); if ($product) { $this->cart->addItem($product, $qty); $this->cart->save(); $status['title'] = 'Added'; $status['success'] = true; $status['text'] = sprintf('%dx %s', $qty, $product->getOSName()); $image = $product->getFirstImage(array('width' => 48, 'height' => 48, 'aspectratio' => true)); if ($image) { $status['image'] = $image->__toString(); } } } // its a ajax request? if ($this->getRequest()->isXmlHttpRequest()) { // add header cart snippet $this->snippetHeaderAction(); $status['snippet']['snippetHeader'] = $this->view->render('cart/snippet-header.php'); $this->_helper->viewRenderer->setNoRender(true); $this->getResponse()->setHeader('Content-Type', 'application/json'); echo Zend_Json::encode($status); } else { $url = $this->view->url(array('action' => 'list'), 'cart'); $this->redirect($url); } }