2

I want following actions to work on

  • Add to cart will add product in the cart only.

  • Buy Now will directly redirect the customer to the checkout page skipping cart step.

1

Rewrite you can do this magento two process

Process One:

one is rewrite the class Mage_Checkout_CartController and in this addAction() at code if (!$cart->getQuote()->getHasError()) { add redirection code $this->_redirect('checkout/onepage');

Process two:

Using event/Observer

Event:

checkout_cart_add_product_complete

This event provide the data of product object and cart request parameters

Mage::dispatchEvent('checkout_cart_add_product_complete',
    array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
);

Config.xml code:

<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>

Observer code:

using this event you can set your return url

$observer->getEvent()->getRequest()->setParam('return_url',Mage::getUrl('checkout/onepage')); this redirect to you at checkout Onepage function:

public function addToCartComplete(Varien_Event_Observer $observer) {
 $product = $observer->getEvent()->getProduct();
 $Request=$observer->getEvent()->getRequest();
 $Request->setParam('return_url',Mage::getUrl('checkout/onepage'));
}

this redirect to you at Checkout onepage

1
  • Will this work with items with custom option and configurable? – KiD Cajes May 21 '16 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.