Hello everyone, happy 2024!
I have an issue with the function cart.remove. On a product page, I want a button to add or remove a related product (think of it as buying a burger and having chips as the related product), but without it being an option on the product - just an add/remove BUTTON for a related product as I'm not a fan of the way options are handled. It adding the primary item as well as the optional extra should be two separate items in the cart/checkout/etc.
I have managed to use onclick="cart.add('123')" to add product ID 123 to the cart, but onclick="cart.remove('123')" simply refreshes the page. If I type "cart.add('123')" in the browser console it adds item 123, while "cart.remove('123')" returns "undefined."
I'm pretty certain that cart.remove('x') must be a valid function, as if I view the source for the page with an item in the cart I see the following in the source code:
<td class="text-center"><button type="button" onclick="cart.remove('123');" title="Remove" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button>
Am I missing something?
I have an issue with the function cart.remove. On a product page, I want a button to add or remove a related product (think of it as buying a burger and having chips as the related product), but without it being an option on the product - just an add/remove BUTTON for a related product as I'm not a fan of the way options are handled. It adding the primary item as well as the optional extra should be two separate items in the cart/checkout/etc.
I have managed to use onclick="cart.add('123')" to add product ID 123 to the cart, but onclick="cart.remove('123')" simply refreshes the page. If I type "cart.add('123')" in the browser console it adds item 123, while "cart.remove('123')" returns "undefined."
I'm pretty certain that cart.remove('x') must be a valid function, as if I view the source for the page with an item in the cart I see the following in the source code:
<td class="text-center"><button type="button" onclick="cart.remove('123');" title="Remove" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button>
Am I missing something?
OC version. URL.Progenix wrote: ↑Sat Jan 06, 2024 11:12 pmHello everyone, happy 2024!
I have an issue with the function cart.remove. On a product page, I want a button to add or remove a related product (think of it as buying a burger and having chips as the related product), but without it being an option on the product - just an add/remove BUTTON for a related product as I'm not a fan of the way options are handled. It adding the primary item as well as the optional extra should be two separate items in the cart/checkout/etc.
I have managed to use onclick="cart.add('123')" to add product ID 123 to the cart, but onclick="cart.remove('123')" simply refreshes the page. If I type "cart.add('123')" in the browser console it adds item 123, while "cart.remove('123')" returns "undefined."
I'm pretty certain that cart.remove('x') must be a valid function, as if I view the source for the page with an item in the cart I see the following in the source code:
<td class="text-center"><button type="button" onclick="cart.remove('123');" title="Remove" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button>
Am I missing something?
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
100%. OC 2.3.0.2, https://progenix.co.za
Yep, items aren't removed from the cart by their Product ID, they are given a different "key" in the cart.
If you look in your common.js file:
view-source:https://progenix.co.za/catalog/view/jav ... /common.js
Under the comment "// Cart add remove functions" you'll see the remove method that takes a key.
You'll probably need a developer to help if you want to find out which key maps to which product ID because it's not immediately obvious to me from the code how to find that.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Hmmh, I see that. With item ID 123 in the cart, the source shows the following:paulfeakins wrote: ↑Mon Jan 08, 2024 6:47 pmYep, items aren't removed from the cart by their Product ID, they are given a different "key" in the cart.
If you look in your common.js file:
view-source:https://progenix.co.za/catalog/view/jav ... /common.js
Under the comment "// Cart add remove functions" you'll see the remove method that takes a key.
You'll probably need a developer to help if you want to find out which key maps to which product ID because it's not immediately obvious to me from the code how to find that.
<td class="text-center"><button type="button" onclick="cart.remove('39631');" title="Remove" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button></td>
Removing and re-adding the same item increments the ID by 1 each time. Adding a different item also increments the ID by 1.
That got me searching and I found oc_cart to contain all current items in all currnet carts with a unique ID for each.
An example of a cart that contains product IDs 123 and 39633 has the following (there are 8 column, but the important ones are here):
cart_id: 39631
product_id: 123
cart_id: 39634
product_id: 5025
Clearly not that easy

If I enter cart.remove('[id from DB]') in the console it still spews out "undefined" but does indeed remove the item, so now I need to figure out how to pull cart_id.
Have a look at the code for the little cart popup at the top right and the cart page itself.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Who is online
Users browsing this forum: No registered users and 20 guests