Redirect Magento to check one page after adding the item to the cart

How can I redirect the user after adding one product to the cart?
let's say I want him to select one item and go to the checkout / one page, how can I do this?

+3
source share
2 answers

You can create an observer listening for the checkout_cart_add_product_complete event, and there you can do something like the following

  public function addToCartComplete(Varien_Event_Observer $observer) {
    // Send the user to the Item added page
    $response = $observer->getResponse();
    $request = $observer->getRequest();
    $response->setRedirect(Mage::getUrl('checkout/onepage'));
    Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
}

Your configuration will look something like this:

 <frontend>
    <events>
    <checkout_cart_add_product_complete>
      <observers>
        <packagename_modulename_observer>
          <type>singleton</type>
          <class>packagename_modulename/observer</class>
          <method>addToCartComplete</method>
        </packagename_modulename_observer>
      </observers>
      </checkout_cart_add_product_complete>
   </events>
   </frontend>
+14
source

Using checkout_cart_add_product_complete, you will miss the addtocart success message.

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();
}

, ,

<input type="hidden" name="return_url" value="<?php echo $this->getUrl('checkout/onepage')?>"/>

- , magento

+1

Source: https://habr.com/ru/post/1772119/


All Articles