private function isCheckCartIndex(Mage_Checkout_CartController $ctr) { $controllerName = $ctr->getRequest()->getControllerName(); $moduleName = $ctr->getRequest()->getModuleName(); $actionName = $ctr->getRequest()->getActionName(); return $controllerName == "cart" && $moduleName == "checkout" && $actionName == "index"; }
public static function applyCouponCode($coupon) { require_once 'Mage/Checkout/controllers/CartController.php'; $request = Mage::app()->getRequest(); $request->setParam('coupon_code', $coupon); $response = Mage::app()->getResponse(); $controller = new Mage_Checkout_CartController($request, $response); $controller->couponPostAction(); }
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 indexAction() { $mageSessHandler = Mage::getSingleton("vbw_punchout/session"); if ($mageSessHandler->getPunchoutId()) { $this->_redirect('checkout/cart/punchout'); } else { parent::indexAction(); } }
public function indexAction() { $cart = $this->_getCart(); if (Mage::helper("apiplugin")->checkPreOrder()) { $warning = "It is not possible to preorder and buy already released products in the same order. Pleace place 2 orders."; $cart->getCheckoutSession()->addNotice($warning); } parent::indexAction(); }
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)); }
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(); }
public function indexAction() { $h = Mage::helper('gomage_checkout'); if ($h->getConfigData('general/disable_cart') && $h->getConfigData('general/enabled')) { $quote = Mage::getSingleton('gomage_checkout/type_onestep')->getQuote(); if ($quote->hasItems()) { $this->_redirect('*/onepage'); } } return parent::indexAction(); }
/** * Shopping cart display action */ public function indexAction() { // Buy X get Y Free $this->buyXgetYfree(); // Spend X get Y Free $this->spendXgetYfree(); // Coupon X get Y Free $this->couponXgetYfree(); // Category X get Y Free $this->categoryXgetYfree(); return parent::indexAction(); }
/** * Updates info in the cart. Adds a notice if trying to increase * the amount of giveaway product over the allowed limit */ public function updatePostAction() { $aParams = $this->getRequest()->getParams(); /** @var Sitewards_Giveaway_Helper_Data $oHelper */ $oHelper = Mage::helper('sitewards_giveaway'); $aProductInformation = $oHelper->getUpdateCartProductInfo($this->getRequest()); $bIsCartActionUpdate = $aParams[self::S_CART_ACTION_KEY] == self::S_CART_ACTION_UPDATE; if ($bIsCartActionUpdate && $oHelper->canAddProducts($aProductInformation) == false) { $this->_goBack(); } else { parent::updatePostAction(); } }
protected function _goBack() { $url = $this->_getRefererUrl(); if (strpos($url, "onepage") !== false) { Mage::getSingleton('j2tonecheckout/session')->unsetAll(); Mage::getSingleton('j2tonecheckout/session')->setJ2tMessages(Mage::getSingleton('checkout/session')->getMessages()); $backUrl = $this->_getRefererUrl(); $this->getResponse()->setRedirect($backUrl); return $this; } else { return parent::_goBack(); } }
/** * 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(); }
/** * 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(); }
public function preDispatch() { $checkCookie = in_array($this->getRequest()->getActionName(), $this->_cookieCheckActions); $checkCookie = $checkCookie && !$this->getRequest()->getParam('nocookie', false); $cookies = Mage::getSingleton('core/cookie')->get(); if ($checkCookie && empty($cookies)) { Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start(); $this->getResponse()->setRedirect($this->getRequest()->getRequestUri() . '?cookies')->sendResponse(); exit; } parent::preDispatch(); /*if (!$this->getRequest()->isXmlHttpRequest()) { $cartUrl = str_replace('/icart/', '/cart/', $this->getRequest()->getRequestUri()); $this->getResponse()->setRedirect($cartUrl)->sendResponse(); exit; }*/ }
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() { 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(); }
/** * 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(); } }
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(); } }
/** * Initialize the coupon controller. * @param Zend_Controller_Request_Abstract * @param Zend_Controller_Response_Abstract * @param array */ public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) { list($this->couponService) = $this->checkTypes($this->nullCoalesce($invokeArgs, 'coupon_service', Mage::getModel('ebayenterprise_multiplecoupons/service'))); parent::__construct($request, $response, $invokeArgs); }
/** * Delete shoping cart item action */ public function deleteAction() { $session = Mage::getSingleton('core/session', array('name' => 'frontend')); Mage::log($session->getData('catid')); if ($session->getData('catid') && $session->getData('catid') != 0) { $catId = $session->getData('catid'); $url = Mage::getModel('catalog/category')->load($catId)->getUrl(); $rout = explode(Mage::getBaseUrl(), $url); $id = (int) $this->getRequest()->getParam('id'); if ($id) { try { $this->_getCart()->removeItem($id)->save(); } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot remove the item.')); Mage::logException($e); } } $this->_redirect($rout[1]); } else { parent::deleteAction(); } }
public function preDispatch() { parent::preDispatch(); $action = $this->getRequest()->getActionName(); }
/** * * 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 couponPostAction() { // applies a discount if it's there Mage::helper('idpas400')->apply_coupon($this->_getQuote(), $this->getRequest()); parent::couponPostAction(); }
public function couponPostAction() { $couponCode = (string) $this->getRequest()->getParam('coupon_code'); if (Mage::getModel('cartex/cart_coupon')->isIncommCoupon($couponCode)) { //$couponCode = Mage::getModel('checkout/session') // ->getQuote()->getCouponCode(); Mage::log('Line 23 Coupon code->' . $couponCode); $url = 'http://milws.incomm.com:8080/transferedvalue/gateway'; //$surl = https://milws.incomm.com:8443/transferedvalue/gateway //$testurl = 'http://66.147.172.198:8080/transferedvalue/gateway'; $pst = '<TransferredValueTxn>'; $pst .= '<TransferredValueTxnReq><ReqCat>TransferredValue</ReqCat><ReqAction>Redeem</ReqAction><Date>20110503</Date><Time>121511</Time>'; $pst .= '<PartnerName>Toonprint</PartnerName>'; $pst .= '<CardActionInfo>'; //$pst.= '<PIN>DEW-7ALZE14N1Z8L</PIN>'; $pst .= '<PIN>' . $couponCode . '</PIN>'; //sent 4/29/11 //$pst.= '<AcctNum>jane22</AcctNum>'; // $pst.= '<SrcRefNum>000001</SrcRefNum>'; $pst .= '</CardActionInfo>'; $pst .= '</TransferredValueTxnReq></TransferredValueTxn>'; /** * Define POST URL and also payload */ define('XML_PAYLOAD', '<?xml version="1.0"?>' . $pst); define('XML_POST_URL', $url); /** * Initialize handle and set options */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, XML_POST_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close')); /** * Execute the request and also time the transaction */ $start = array_sum(explode(' ', microtime())); $result = curl_exec($ch); $stop = array_sum(explode(' ', microtime())); $totalTime = $stop - $start; /** * Check for errors */ if (curl_errno($ch)) { $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch); } else { $returnCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); switch ($returnCode) { case 404: $result = 'ERROR -> 404 Not Found'; break; default: break; } } /** * Close the handle */ curl_close($ch); /** * Output the results and time */ //echo 'Total time for request: ' . $totalTime . "\n"; //echo $result; $oXML = new SimpleXMLElement($result); $session = Mage::getSingleton('checkout/session'); $error = true; //print_r($oXML->TransferredValueTxnResp->RespCode); foreach ($oXML->TransferredValueTxnResp as $oEntry) { Mage::log('code from incomm->' . $oEntry->RespCode . 'code->' . $couponCode); if ($oEntry->RespCode == 0) { $error = false; //echo "Success"; $session->addSuccess('Your card was redeemed'); } elseif ($oEntry->RespCode == 43) { $session->addError('Your Card is Invalid'); } elseif ($oEntry->RespCode == 46) { $session->addError('Your Card is Deactivated'); } elseif ($oEntry->RespCode == 38) { $session->addError('Your Card has already been redeemed.'); } if ($error) { parent::_goBack(); } } /** * Exit the script */ //exit(0); } parent::couponPostAction(); }
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 updatePostAction() { parent::updatePostAction(); if ($this->getRequest()->getParam('ajaxcartpopup') && $this->getRequest()->getParam('ajaxupdatequantity')) { $result = 'success'; $this->loadLayout()->_initLayoutMessages('checkout/session'); foreach (Mage::getSingleton('checkout/session')->getMessages()->getItems() as $message) { if ($message->getType() == 'error' || $message->getType() == 'exception') { $result = Mage::helper('checkout/cart')->getCartUrl(); } break; } $this->getResponse()->clearHeaders()->clearBody(); $this->getResponse()->setHeader("Content-Type", "text/html; charset=UTF-8")->setHttpResponseCode(200)->isRedirect(0); if ($this->getRequest()->getParam('iscartpage')) { $totals = ''; if ($result == 'success') { $totals = $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('checkout/cart/totals.phtml')->toHtml(); } $this->getResponse()->setBody(Zend_Json::encode(array('result' => $result, 'totals' => $totals))); } else { $linktext = ''; $popuphtml = ''; $emptycart = ''; if ($result == 'success') { $this->loadLayout()->_initLayoutMessages('checkout/session'); $linktext = $this->_getLinkText(); $popuphtml = $this->getLayout()->getBlock('ajaxcartpopup')->toHtml(); $emptycart = Mage::helper('ajaxcartpopup')->getCartCount() ? false : true; } $this->getResponse()->setBody(Zend_Json::encode(array('result' => $result, 'linktext' => $linktext, 'popuphtml' => $popuphtml, 'emptycart' => $emptycart))); } } }
/** * 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(); } }
public function deleteAction() { $params = $this->getRequest()->getParams(); if (isset($params['isAjax']) && $params['isAjax'] == 1) { $id = (int) $this->getRequest()->getParam('id'); $response = array(); if ($id) { try { $this->_getCart()->removeItem($id)->save(); $response['status'] = 'SUCCESS'; $response['message'] = ''; } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot remove the item.')); $response['status'] = 'ERROR'; $response['message'] = $this->__('Cannot remove the item.'); Mage::logException($e); } } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); } else { parent::deleteAction(); } }
public function updateItemOptionsAction() { $cart = $this->_getCart(); $id = (int) $this->getRequest()->getParam('product'); $params = $this->getRequest()->getParams(); $product = $this->_initProduct(); if (!isset($params['options'])) { $params['options'] = array(); } 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']); } $qq = Mage::getModel('checkout/cart')->getQuote(); foreach ($qq->getAllItems() as $item) { if ($id == $item->getProductId()) { $quoteItem = $cart->getQuote()->getItemById($item->getId()); $itemId = $item->getId(); } } if (!$quoteItem) { Mage::throwException($this->__('Quote item is not found.')); } $item = $cart->updateItem($itemId, 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_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::updateAction(); } }