public function addAction() { $request = $this->getRequest(); $qty = $request->getParam("qty", 1); $request->setParam("qty", $qty * 2); return parent::addAction(); }
/** Adding products to cart */ function addAction() { if ($this->shouldShowIntermediatePage()) { $url = $this->getChooseVehicleUrl($this->getProductId()); return $this->getResponse()->setRedirect($url); } return parent::addAction(); }
public function addAction() { Mage::log('debug : *** addAction'); $_product = $this->processProduct(); $cart = $this->_getCart(); $tokens = SpectrumProductProcessor::getImageProcessingType($_product); if (count($tokens) > 0) { foreach ($tokens as $token) { Mage::log('processing token = ' . $token); if ($token != "" && $token != "None" && $token != "none") { SpectrumProductProcessor::addProcessingProductToCart($token, $cart); $this->_getSession()->addSuccess($token . " was added to your shopping cart."); } else { Mage::log("SKU : " . $_product->getSku() . " requires no image processing"); } } } else { Mage::log("SKU : " . $_product->getSku() . " requires no image processing"); } $cart = $this->_getCart(); if ($this->processRedrawingOption($_product)) { Mage::log("REDRAWING REQUIRED"); $id = Mage::getModel('catalog/product')->getIdBySku("artwork-redrawing-fee"); if ($id) { $cart->addProductsByIDs(array($id)); $message = $this->__('Artwork redrawing fee was added to your shopping cart.'); $this->_getSession()->addSuccess($message); } else { Mage::log("Unable to locate artwork redrawing fee product"); } } if ($this->processOption($_product, "Rush Order Surcharge (If order is required in less than 10 days please apply.)", "Yes Please")) { Mage::log("RUSH ORDER SURCHARGE REQUIRED"); $id = Mage::getModel('catalog/product')->getIdBySku("rush-order-surcharge"); if ($id) { $cart->addProductsByIDs(array($id)); $message = $this->__('Rush order surcharge fee was added to your shopping cart.'); $this->_getSession()->addSuccess($message); } else { Mage::log("Unable to locate rush order surcharge product"); } } if ($this->processOption($_product, "2nd Poll Printing", "Yes Please")) { Mage::log("2nd poll printing REQUIRED"); $id = Mage::getModel('catalog/product')->getIdBySku("2nd-poll-printing-surcharge"); if ($id) { $cart->addProductsByIDs(array($id)); $message = $this->__('2nd poll printing fee was added to your shopping cart.'); $this->_getSession()->addSuccess($message); } else { Mage::log("Unable to locate 2nd poll printing surcharge product"); } } $cart->removeItem($_product->getId())->save(); parent::addAction(); }
/** * Adds products to cart * cancels if the product is giveaway and the max amount * of giveaway products in cart is already reached * * @return void */ public function addAction() { /** @var Sitewards_Giveaway_Helper_Data $oHelper */ $oHelper = Mage::helper('sitewards_giveaway'); $oProductQuantityCollection = $oHelper->getAddCartProductInfo($this->getRequest()); $bCanAddProducts = $oHelper->canAddProducts($oProductQuantityCollection, Sitewards_Giveaway_Helper_Data::I_CART_ACTION_ADD); if ($oHelper->getGiveawayIdentifierValue($oProductQuantityCollection->getFirstItem()->getId()) && $bCanAddProducts == false) { $this->_goBack(); } else { parent::addAction(); } }
/** * Add product to shopping cart * Only one item will be added to cart * * @return Mage_Core_Controller_Varien_Action * @throws Exception */ public function addAction() { $this->_getSession()->getQuote()->removeAllItems(); $product = $this->_initProduct(); if ($product) { if (!Mage::getModel('pixsubscription/subscription')->canBuySubscription($product)) { // Mage::getSingleton('core/session')->addError((string)Mage::getConfig()->getNode('default/pixopc/pix_subscription_amount_error_message/message')); // $this->_redirectUrl(Mage::getBaseUrl()); // return; } } if (isset($_GET['survey_results'])) { Mage::getSingleton('core/session')->setSurveyResults($_GET['survey_results']); } parent::addAction(); }
public function addAction() { if (!Mage::getStoreConfig('ajaxcartpopup/general/enabled') || !Mage::getStoreConfig('ajaxcartpopup/ajax/ajax_enabled')) { return parent::addAction(); } $items = Mage::getSingleton('checkout/cart')->init()->getItems(); $countbefore = count($items); parent::addAction(); $this->getResponse()->clearHeaders()->clearBody(); $this->getResponse()->setHeader("Content-Type", "text/html; charset=UTF-8")->setHttpResponseCode(200)->isRedirect(0); $lastmessage = Mage::getSingleton('checkout/session')->getMessages()->getLastAddedMessage(); $result = $lastmessage->getType() == 'success' ? 'success' : false; $message = ''; $linktext = ''; $popuphtml = ''; $imageurl = ''; $productname = ''; $itemid = ''; $deleteurl = ''; $product = $this->_initProduct(); if ($result == 'success') { $this->loadLayout()->_initLayoutMessages('checkout/session'); $message = Mage::app()->getLayout()->getMessagesBlock()->toHtml(); $message = strip_tags($message); $linktext = $this->_getLinkText(); $popuphtml = $this->getLayout()->getBlock('ajaxcartpopup')->toHtml(); if (Mage::app()->getRequest()->getParam('imagedetail')) { $imageurl = (string) Mage::helper('catalog/image')->init($product, 'small_image')->resize(135); $productname = addslashes($product->getName()); } } elseif ($this->getRequest()->getParam('isproductpage')) { $this->loadLayout()->_initLayoutMessages('checkout/session'); $message = Mage::app()->getLayout()->getMessagesBlock()->toHtml(); $message = strip_tags($message); } else { $result = $product->getProductUrl(); } Mage::helper('ajaxcartpopup')->updateCartCount(); if (Mage::helper('ajaxcartpopup')->getCartItemCount() > $countbefore) { $allitems = Mage::getSingleton('checkout/cart')->getItems()->getData(); $itemid = array_pop($allitems); $itemid = $itemid['item_id']; $deleteurl = Mage::helper('ajaxcartpopup')->getDeleteUrl($itemid); } $this->getResponse()->setBody(Zend_Json::encode(array('result' => $result, 'message' => $message, 'linktext' => $linktext, 'popuphtml' => $popuphtml, 'imageurl' => $imageurl, 'productname' => $productname, 'itemid' => $itemid, 'deleteurl' => $deleteurl))); }
/** * override Add product to shopping cart action */ public function addAction() { if (Mage::helper('ajaxcartsuper/data')->isAjax()) { $cart = $this->_getCart(); $ajaxData = array(); $productInfo = array(); $params = $this->getRequest()->getParams(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); if ($params['type_product'] == 1) { $productInfo['type_product'] = $product->getTypeId(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($productInfo)); return; } $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $ajaxData['status'] = 0; $ajaxData['message'] = $this->__('Unable to find Product ID'); } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName())); // $this->_getSession()->addSuccess($message); $ajaxData['status'] = 1; $this->loadLayout(); $sidebarCart = ""; $mini_cart = ""; $toplink = ""; 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(); } $pimage = Mage::helper('catalog/image')->init($product, 'small_image')->resize(55); $ajaxData['sidebar_cart'] = $sidebarCart; $ajaxData['top_link'] = $toplink; $ajaxData['mini_cart'] = $mini_cart; //show or hide cofirmbox when add product to cart if (Mage::getStoreConfig('ajaxcartsuper/ajaxcartsuper_config/show_confirm')) { $ajaxData['product_info'] = Mage::helper('ajaxcartsuper/data')->productHtml($product->getName(), $product->getProductUrl(), $pimage); } } } } 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/>'; } } $ajaxData['status'] = 0; $ajaxData['message'] = $msg; $ajaxData['type_product_ajax'] = 1; } catch (Exception $e) { $ajaxData['status'] = 0; $ajaxData['message'] = $this->__('Cannot add the this product to shopping cart.'); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($ajaxData)); return; } else { parent::addAction(); } }
public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if ($params['isAjax'] == 1) { $response = array(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->htmlEscape($product->getName())); $response['status'] = 'SUCCESS'; $response['message'] = $message; //New Code Here $this->loadLayout(); $toplink = ""; if ($this->getLayout()->getBlock('cart_cartheader')) { $toplink = $this->getLayout()->getBlock('cart_cartheader')->toHtml(); } $cart_sidebar = ""; if ($this->getLayout()->getBlock('cart_sidebar')) { $cart_sidebar = $this->getLayout()->getBlock('cart_sidebar')->toHtml(); } Mage::register('referrer_url', $this->_getRefererUrl()); $response['toplink'] = $toplink; $response['cart_sidebar'] = $cart_sidebar; } } 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 add the item to shopping cart.'); Mage::logException($e); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } else { return parent::addAction(); } }
public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if ($params['isAjax'] == 1) { $response = array(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); //Check product availability if (!$product) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was added to the shopping cart.', Mage::helper('core')->htmlEscape($product->getName())); $response['status'] = 'SUCCESS'; $response['message'] = $message; $response['message'] = '<ul class="messages"><li class="success-msg"><ul><li><span>' . $product->getName() . ' was added to your shopping cart.</span></li></ul></li></ul>'; $this->loadLayout(); //$this->getLayout()->getBlock('cart_sidebar')->setTemplate('quickview/checkout/cart/sidebar/default.phtml'); $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); $sidecart = $this->getLayout()->getBlock('cart_sidebar')->toHtml(); //Mage::register('referrer_url', $this->_getRefererUrl()); $response['toplink'] = $toplink; $response['sidecart'] = $sidecart; } } 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 add the item to shopping cart.'); Mage::logException($e); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } else { return parent::addAction(); } }
/** * * Add to cart product action * Return product */ public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if ($params['isAjax'] == 1) { $response = array(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); if (!$product) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); } $cart->addProduct($product, $params); if (!empty($related)) { $productarray = array_unique(explode(',', $related)); $cart->addProductsByIds($productarray); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $message = array(); $message[] = '<p>' . $this->__('%s was added to your shopping cart.', Mage::helper('core')->htmlEscape($product->getName())) . '</p>'; $message[] = '<img src="' . $product->getImageUrl() . '" >'; $message[] = '<div class="ajax-action"><a href="' . Mage::helper('checkout/cart')->getCartUrl() . '" class="view-cart"><span>' . $this->__('View cart') . '</span></a>'; $message[] = '<a href="' . Mage::helper('checkout/url')->getCheckoutUrl() . '" class="checkout"><span>' . $this->__('Check Out') . '</span></a></div>'; $response['status'] = 'SUCCESS'; $response['message'] = implode($message); //New Code Here $this->loadLayout(); $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); $output = $this->getLayout()->getBlock('ajaxcart')->toHtml(); $this->getResponse()->setBody($output); Mage::register('referrer_url', $this->_getRefererUrl()); $response['output'] = $output; $response['toplink'] = $toplink; } } 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 add the item to shopping cart.'); Mage::logException($e); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } else { return parent::addAction(); } }
public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if ($params['isAjax'] == 1) { $response = array(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->getQuote()->setTotalsCollectedFlag(false); $cart->save(); $this->_getSession()->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $store = Mage::app()->getStore(); $code = $store->getCode(); $aspect_ratio = Mage::getStoreConfig("porto_settings/category/aspect_ratio", $code); $ratio_width = Mage::getStoreConfig("porto_settings/category/ratio_width", $code); $ratio_height = Mage::getStoreConfig("porto_settings/category/ratio_height", $code); $autoclose = Mage::getStoreConfig('ajaxcart/addtocart/autoclose', $code); if (!($autoclose && is_numeric($autoclose))) { $autoclose = 5; } $product_image_src = ""; if ($aspect_ratio) { $product_image_src = Mage::helper('catalog/image')->init($product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(250); } else { $product_image_src = Mage::helper('catalog/image')->init($product, 'small_image')->resize($ratio_width, $ratio_height); } $product_image = '<img src="' . $product_image_src . '" class="product-image" alt=""/>'; $message = '<div class="msg">' . $this->__("You've just added this product to the cart:") . '<p class="product-name theme-color">' . Mage::helper('core')->htmlEscape($product->getName()) . '</p><div class="timer theme-color">' . $autoclose . '</div></div>' . $product_image; $response['status'] = 'SUCCESS'; $response['message'] = $message; //New Code Here $this->loadLayout(); $toplink = ""; if ($this->getLayout()->getBlock('minicart')) { $toplink = $this->getLayout()->getBlock('minicart')->toHtml(); } $cart_sidebar = ""; if ($this->getLayout()->getBlock('cart_sidebar')) { $cart_sidebar = $this->getLayout()->getBlock('cart_sidebar')->toHtml(); } Mage::register('referrer_url', $this->_getRefererUrl()); $response['toplink'] = $toplink; $response['cart_sidebar'] = $cart_sidebar; } } 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 add the item to shopping cart.'); Mage::logException($e); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } else { return parent::addAction(); } }
public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if ($params['isAjax'] == 1) { $response = array(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); $this->_sendJson($response); return; } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__($this->__('%s was added to your shopping cart.') . '<br/><br/> <button class="button" onclick="setLocation(\'' . Mage::getUrl('checkout/cart') . '\');"><span><span>' . $this->__('View Cart') . '</span></span></button><button class="button" onclick="setLocation(\'' . Mage::helper('checkout/url')->getCheckoutUrl() . '\');"><span><span>' . $this->__('Checkout') . '</span></span></button>', Mage::helper('core')->escapeHtml($product->getName())); $response['status'] = 'SUCCESS'; $response['message'] = $message; $this->loadLayout(); $links = $this->getLayout()->getBlock('top.links'); if ($links) { $response['toplink'] = $links->toHtml(); } $sidebar = $this->getLayout()->getBlock('cart_top'); if ($sidebar) { $response['cart_top'] = $sidebar->toHtml(); } } else { $response['status'] = 'ERROR'; foreach ($cart->getQuote()->getErrors() as $_error) { $response['message'] .= $_error->toString(); } } } } 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 add the item to shopping cart.'); Mage::logException($e); } $this->_sendJson($response); return; } else { return parent::addAction(); } }
public function addAction() { $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); if ($params['isAjax'] == 1) { $response = array(); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); $productId = $params['product_id']; $response['myId'] = $product->getId(); /** * Check product availability */ if (!$product) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); } /** * Reduce item if subtract **/ if (!isset($params['subtract'])) { $cart->addProduct($product, $params); //$quote = Mage::getSingleton('checkout/cart')->getQuote(); /*$cart_id = $quote->getItemByProduct($product)->getId(); $response['cart_id'] = $cart_id;*/ // Get Cart Id if (isset($params['fromList'])) { $quote = Mage::getSingleton('checkout/cart')->getQuote(); $_mCartItem = $quote->getItemByProduct($product); $_mCartId = $_mCartItem->getId(); $response['updateId'] = $_mCartId; } } else { /* $_items = $cart->getItems(); $thisProduct = Mage::getModel('catalog/product')->load($params['product_id']); foreach ($_items as $item) { if ($item->getSku() == $thisProduct->getSku()) { $a = $item->getQty(); $response['found'] = true; $item->setQty($a-1); } */ //$cartHelper = Mage::helper('checkout/cart'); $quote = Mage::getSingleton('checkout/cart')->getQuote(); $_mCartItem = $quote->getItemByProduct($product); if ($_mCartItem) { $_mCartId = $_mCartItem->getId(); $_mCartPrev = $_mCartItem->getQty(); $_mQty = $_mCartPrev - $params['qty']; if ($_mQty <= 0) { $quote->removeItem($_mCartId); } else { $_mCartItem->setQty($_mQty); } } else { if (isset($params['updateid'])) { $updateid = $params['updateid']; $_mCartItem = $quote->getItemById($updateid); if ($_mCartItem) { $_mCartPrev = $_mCartItem->getQty(); $_mQty = $_mCartPrev - $params['qty']; if ($_mQty <= 0) { $quote->removeItem($updateid); } else { $_mCartItem->setQty($_mQty); } } } } } if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName())); $response['status'] = 'SUCCESS'; $response['message'] = $message; $response['cart_id'] = $cart->getQuote()->getId(); //New Code Here $this->loadLayout(); //$toplink = $this->getLayout()->getBlock('top.links')->toHtml(); $sidebar_block = $this->getLayout()->getBlock('topcart'); Mage::register('referrer_url', $this->_getRefererUrl()); $sidebar = $sidebar_block->toHtml(); //$response['toplink'] = $toplink; $response['sidebar'] = $sidebar; } } 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 add the item to shopping cart.'); Mage::logException($e); } //$this->getResponse()->setHeader('Content-type', 'application/json'); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } else { return parent::addAction(); } }
public function addAction() { if (!Mage::getStoreConfigFlag('dailydeals/dailydeals_settings/enabled')) { return parent::addAction(); } $cart = $this->_getCart(); $params = $this->getRequest()->getParams(); $quote = Mage::getSingleton('checkout/session')->getQuote(); $cartItems = $quote->getAllVisibleItems(); foreach ($cartItems as $item) { $cartarr[$item->getProductId()] = $item->getQty(); } $id = $params['product']; $model = Mage::getModel('dailydeals/dailydeals'); $collectiondeal = Mage::getModel('dailydeals/dailydeals')->getCollection()->addFieldToFilter('related_product', $id)->getData(); $datestart = $collectiondeal[0]['date_start']; $dateend = $collectiondeal[0]['date_end']; $date_start = date('Y-m-d H:i:s', strtotime($datestart)); $date_end = date('Y-m-d H:i:s', strtotime($dateend)); $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $query = $read->fetchAll("SELECT TIMEDIFF( NOW() , '" . $date_start . "') AS diff"); $query1 = $read->fetchAll("SELECT TIMEDIFF('" . $date_end . "', NOW( )) AS diffend"); $diff = $query[0]['diff']; $diffend = $query1[0]['diffend']; if (!empty($collectiondeal) && $diff > 0 && $diffend >= 0) { $deal_qty = $collectiondeal[0]['deal_qty']; $proqty = $params['qty'] + $cartarr[$id]; if ($deal_qty < $proqty) { $this->_getSession()->addError('Deal Quantity is not available'); Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']); return; } } try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $product = $this->_initProduct(); $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $this->_goBack(); return; } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); $this->_getSession()->setCartWasUpdated(true); /** * @todo remove wishlist observer processAddToCart */ Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); if (!$this->_getSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName())); $this->_getSession()->addSuccess($message); } $this->_goBack(); } } catch (Mage_Core_Exception $e) { if ($this->_getSession()->getUseNotice(true)) { $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage())); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message)); } } $url = $this->_getSession()->getRedirectUrl(true); if ($url) { $this->getResponse()->setRedirect($url); } else { $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl()); } } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); Mage::logException($e); $this->_goBack(); } }
public function addAction() { Mage::register('_no_redirect_flag', true, true); parent::addAction(); // $this->getResponse() // ->clearHeader('Location') // ->setHttpResponseCode(200); # Version for 1.3.3.0 $response = $this->getResponse(); $headers = $response->getHeaders(); $response->clearHeaders()->setHttpResponseCode(200); foreach ($headers as $header) { if (strtolower($header['name']) != 'location') { $response->setHeader($header['name'], $header['value'], $header['replace']); } } # end part $this->_prepareMessages()->_goBack(); }