1
votes

I am working with Magento. all I want just a button that add a product to cart and then go to check out page not to view cart. means I want direct order for the registered users. and I am working in PORTO Magento theme I have tried it by creating copy of function addAction of cartController.php(app/code/core/checkout/controllers/) to myaddAction().

added below JS to end view.phtml(app/design/frontend/your package/your template/template/catalog/product/view.phtml)

  productAddToCartForm.submitmy = function(button, url){
  replaceURL = url.replace("add/","myadd/");
        if(this.validator) {
            var nv = Validation.methods;
            delete Validation.methods['required-entry'];
            delete Validation.methods['validate-one-required'];
            delete Validation.methods['validate-one-required-by-name'];
            // Remove custom datetime validators
            for (var methodName in Validation.methods) {
                if (methodName.match(/^validate-datetime-.*/i)) {
                    delete Validation.methods[methodName];
                }
            }

            if (this.validator.validate()) {
                if (url) {
                    this.form.action = replaceURL;
                }
                this.form.submit();
            }
            Object.extend(Validation.methods, nv);
        }
    }.bind(productAddToCartForm);

and changed addaction to myaddAction in cart controller and also changed

$this->_goBack();
to
$this->_redirect('checkout/onepage');
        return; 

But I am getting an error undefined funtion, productAddToCartForm.submitmy

please hope someone help.

1

1 Answers

0
votes

I would create an observer on add_to_cart_after and then set a redirect here. Something as simple as:

$response = $observer->getResponse();
$url = Mage::helper('checkout/url')->getCheckoutUrl();
$response->setRedirect($url);
die();