Reputation: 73
I am trying to add items from category page. But it is taking me to next product page rather then adding such product into the cart. But same functionality is working ok in product page.
To find the solution i have added
to check what array i am getting. After adding it such functionality of add to cart in category page was working. I am a bit confuse what to do with that. Kindly help or advice. Following is the code for Add-to-Cart button in category.tpl file.
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span> <i class="fa fa-shopping-cart"></i></button>
Upvotes: 0
Views: 988
Reputation: 122
Ok, even though I know nothing about opencart i quickly checked the demo. There seem to be some category items that work to be added as expected:
POST http://demo.opencart.com/index.php?route=checkout/cart/add
200 OK
{"success":"Success: You have added <a href=\"http:\/\/demo.opencart.com\/index.php?route=product\/product
&product_id=41\">iMac<\/a> to your <a href=\"http:\/\/demo.opencart.com\/index.php?route=checkout
\/cart\">shopping cart<\/a>!","total":"2 item(s) - $244.00"}
Other ones return some kind of form error:
POST http://demo.opencart.com/index.php?route=checkout/cart/add
{"error":{"option":{"218":"Radio required!","223":"Checkbox required!","208":"Text required!","217":"Select
required!","209":"Textarea required!","222":"File required!","219":"Date required!","221":"Time required
!","220":"Date & Time required!"}},"redirect":"http:\/\/demo.opencart.com\/index.php?route=product
\/product&product_id=42"}
And instead of showing a decent error message, a redirect url is sent along. Seems that that is the one you then are redirected to. Seems like intended behaviour of the code to hide that an error has happened.
Maybe that helps you to narrow down the bug. Good luck.
Upvotes: 1