Question

I was adding a Buy Now button in opencart product page (also add to cart will be there)

First i edited catalog/view/theme/mytheme/template/product/product.tpl (to get Buy Now button in product page)

<?php if ($stock == "In Stock") { echo '<input type="button" value="Add to Cart" id="button-cart" class="button-product-page" />'; echo " "; echo '<input type="button" value="Buy Now" id="button-cart-buy" class="button-product-page" />'; } else {echo '<input type="button" value="Out Of Stock" class="button-product-page"/>'; } ?>

And after this,in product.tpl, i made a new function (button-cart-buy) for Buy Now similar to button-cart function but i changed the json['success'] as below for Buy Now:

if (json['success']) {window.location='index.php?route=checkout/checkout'; }

Its working when we click Buy Now on product page with link as (http://domain.com/Product) but its not working if we click Buy now after browsing product from categories i.e http://domain.com/MainCategory/SubCategory/Product then i am getting url as http://domain.com/MainCategory/SubCategory/index.php?route=checkout/checkout. But the product is getting added to the Cart.

This issue is mainly in IE and sometimes it occurs in Mozilla also.

I had also tried copying addtoCart function in common.js. But still not working out.

Am i missing something or need to alter..? Please help

A word for thanks for Jay Gilford:

Thanks Jay Gilford for your response.

This answer helps in resolving 5-6 open threads at opencart forum.

Was it helpful?

Solution

Its because you're not using an absolute URL path. If this is in the template you've got this Javascript, you can just use

if (json['success']) {window.location='<?php echo $this->url->link('checkout/checkout', '', 'SSL'); ?>'; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top