Magento添加到购物车并重定向到结帐(产品页面:" Checkout"按钮,"添加到购物车"重定向到购物车)

时间:2014-07-09 15:52:03

标签: magento redirect checkout product

我有两个"添加到购物车"我的产品页面上的按钮。

第一个默认功能只是"添加到购物车",它可以正常运行,将产品添加到购物车,然后重定向到购物车。

第二个标有" Checkout"我希望将产品添加到购物车,并重定向到结帐而不是购物车。 (但仅在单击“结帐”按钮时)。

我看过了,似乎可能会使用观察者?我不确定如何实现这一点,或区分点击了哪个按钮,或者将Checkout按钮指向哪个url。

2 个答案:

答案 0 :(得分:3)

addActioncartController.php)的函数app/code/core/checkout/controllers/的副本创建到myaddAction()。

将以下内容添加到end view.phtml (app/design/frontend/your package/your template/template/catalog/product/view.phtml)

    <script type="text/javascript">
    //<![CDATA[
 productAddToCartForm.submit = 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);
        //]]>
    </script>

将checkout按钮添加到addtocart.phhtml (app/design/frontend/your package/your template/template/catalog/product/view

 <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submitmy(this)"><span><span><?php echo "Checkout"; ?></span></span></button>

我告诉你将addAction复制到mycartAction 改变

$this->_goBack();

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

endof

 if (!$cart->getQuote()->getHasError()){
                    $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
                    $this->_getSession()->addSuccess($message);
                }

添加

答案 1 :(得分:3)

我认为你可以使用jQuery。

list.phtml中的结帐按钮

<button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

将此脚本添加到相同的list.phtml文件

<script>
function setcheckoutLocation(location)
{
jQuery.ajax({
                    type:"GET",
                    url:location,
                    success:function(data){
                         window.location.href = "http://your-checkout-page-url";
                    }
                 });

}
</script>