开发者

Automatic update the cart on proceed to checkout is clicked

I am u开发者_Python百科sing magento. I want to automatically update the cart on proceed to checkout button is clicked. so that my values are saved without the effort to click on update cart. Ajax based solution is also acceptable.


I was able to "fix" it by changing the behaviour of the Checkout button.

Instead of just going to the checkout page, it submits the cart form. In order to have it redirect to the checkout afterwards, it makes sure that redirect_url is set right before the submission.

This is the code I put in template/checkout/onepage/link.phtml:

<?php if ($this->isPossibleOnepageCheckout()):?>
    <script type="text/javascript">
    // <![CDATA[
      function updateAndGoto(url) {
          var cartForm = $$('.cart form').first();
          var action = cartForm.readAttribute('action');
          if (action.indexOf('return_url') < 0) {
              var glue = action.indexOf('?') < 0 ? '?' : '&';
              action += glue + 'return_url=' + url;
              cartForm.writeAttribute('action', action);
          }

          cartForm.submit();
      }
    // ]]>
    </script>
    <button type="button" title="<?php echo $this->__('Proceed to Checkout') ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="updateAndGoto('<?php echo $this->getCheckoutUrl() ?>');"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php endif?>


This seems like a very poor idea. Customers have expectations about how a cart should function, especially with an update button being present. If you change that functionality so that a customer cannot see that their update was not made until they go through the entire checkout process, they may not order what they had intended, or they may not order at all. Surprising the user is almost always a bad idea.

Otherwise, short of AJAX, you'd want to make the "Checkout" button part of the same form that wraps the cart for updates.

Hope that helps!

Thanks, Joe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜