public function updateItemOptionsAction() { if (!$this->getRequest()->isXmlHttpRequest()) { return parent::updateItemOptionsAction(); } $message = ''; $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { //Mage::throwException($this->__('Quote item is not found.')); return; } $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { //Mage::throwException($item); return; } if ($item->getHasError()) { //Mage::throwException($item->getMessage()); return; } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $message = $this->__('<span><strong>%s</strong> was added to your shopping cart.</span><br /><p><a class="simple-button" href="%s">Continue Shopping</a><span> or </span><a class="button" href="%s">Checkout</a></p>', Mage::helper('core')->escapeHtml($item->getProduct()->getName()), 'javascript:weltpixel.lightbox.close()', Mage::helper('checkout/url')->getCheckoutUrl()); } } catch (Mage_Core_Exception $e) { $message = Mage::helper('core')->escapeHtml($e->getMessage()); } catch (Exception $e) { $message = $this->__('Cannot update the item.'); Mage::logException($e); } $this->loadLayout(); $body = array('message' => $message, 'blocks' => array()); if ($this->getLayout()->getBlock('cart_sidebar')) { $body['blocks']['cart_sidebar'] = array('class' => Mage::helper('weltpixel_quickview')->isMageEnterprise() ? 'top-cart' : 'block-cart', 'content' => preg_replace('/\\/uenc\\/[^\\/]*/', '', $this->getLayout()->getBlock('cart_sidebar')->toHtml())); } if ($this->getLayout()->getBlock('quick_access')) { $body['blocks']['quick_access'] = array('id' => 'quick-access', 'content' => preg_replace('/\\/uenc\\/[^\\/]*/', '', $this->getLayout()->getBlock('quick_access')->toHtml())); } $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($body)); }
/** * Update product configuration for a cart item * Modified to allow the switching of product ids in the cart if selected from a configurable parent. */ public function updateItemOptionsAction() { $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { Mage::throwException($this->__('Quote item is not found.')); } //Switch quote item with new select product id. if ($params['product'] != $quoteItem->getProduct()->getId()) { $newProduct = Mage::getSingleton('catalog/product')->load($params['product']); $quoteItem->setProduct($newProduct); } parent::updateItemOptionsAction(); }
/** * override Update product configuration for a cart item */ public function updateItemOptionsAction() { if (Mage::helper('ajaxcartsuper/data')->isAjax()) { $ajaxData = array(); $productInfo = array(); $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { Mage::throwException($this->__('Quote item is not found.')); } $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { Mage::throwException($item); } if ($item->getHasError()) { Mage::throwException($item->getMessage()); } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->htmlEscape($item->getProduct()->getName())); // $this->_getSession()->addSuccess($message); } } } catch (Mage_Core_Exception $e) { if ($this->_getSession()->getUseNotice(true)) { $this->_getSession()->addNotice($e->getMessage()); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->_getSession()->addError($message); } } $url = $this->_getSession()->getRedirectUrl(true); } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('Cannot update the item.')); Mage::logException($e); } $this->loadLayout(); if ($this->getLayout()->getBlock('cart_sidebar')) { $sidebarCart = $this->getLayout()->getBlock('cart_sidebar')->toHtml(); } if ($this->getLayout()->getBlock('cart_sidebar_mini')) { $mini_cart = $this->getLayout()->getBlock('cart_sidebar_mini')->toHtml(); } if ($this->getLayout()->getBlock('top.links')) { $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); } $ajaxData['status'] = 1; $ajaxData['top_link'] = $toplink; $ajaxData['sidebar_cart'] = $sidebarCart; $ajaxData['mini_cart'] = $mini_cart; $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($ajaxData)); } else { parent::updateItemOptionsAction(); } }
/** * Update product configuration for a cart item */ public function updateItemOptionsAction() { $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('id'); $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } if ($params['isAjax'] == 1) { $response = array('params' => $params); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { $this->_sendJson(array('status' => 'ERROR', 'message' => $this->__('Quote item is not found.'))); return; } $item = $cart->updateItem($id, new Varien_Object($params)); if (is_string($item)) { $this->_sendJson(array('status' => 'ERROR', 'message' => $item)); return; } if ($item->getHasError()) { Mage::throwException($item->getMessage()); $this->_sendJson(array('status' => 'ERROR', 'message' => $item->getMessage())); return; } $related = $this->getRequest()->getParam('related_product'); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $response['status'] = 'SUCCESS'; $response['message'] = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->htmlEscape($item->getProduct()->getName())); $this->loadLayout(); Mage::register('referrer_url', $this->_getRefererUrl()); $sidebar_header = $this->getLayout()->getBlock('cart_top')->toHtml(); $response['cart_top'] = $sidebar_header; } } } catch (Mage_Core_Exception $e) { $msg = ""; if ($this->_getSession()->getUseNotice(true)) { $msg = $e->getMessage(); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $msg .= $message . '<br/>'; } } $response['status'] = 'ERROR'; $response['message'] = $msg; } catch (Exception $e) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Cannot update the item.'); Mage::logException($e); } $this->_sendJson($response); return; } else { return parent::updateItemOptionsAction(); } }