get latest added cart_product_id

  • Posts: 73
  • Thank you received: 1
10 years 5 months ago #158447

-- HikaShop version -- : 1.6
-- Joomla version -- : 2.5
-- PHP version -- : 5.3.x
-- Browser(s) name and version -- : Firefox (latest)

I'm developing a little plugin and I'm trying to get the cart_product_id of the last added product to the cart. I'm using this event trigger:

onAfterCartUpdate

Currently I'm just selecting the max() key but that's unreliable. Is there a way to select the latest added cart_product_id? Note that this should also work when another item of the same kind is added (meaning that the highest key does not work if there was another product (B ) was added before another product (A) was added)

thanks!

Last edit: 10 years 5 months ago by Ortix.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 5 months ago #158549

Hi,

To get the id of the latest product added in the cart, you just have to get the third parameter of the function "onAfterCartupdate()".
It is the id of the last product.

Please Log in or Create an account to join the conversation.

  • Posts: 73
  • Thank you received: 1
10 years 5 months ago #158578

yes that gives me the product_id, but i need to know the cart_product_id. I need to do some manipulating to the latest added product.

I think i can achieve it by iterating over each product and matching the product id to get the cart_product_id


But is it also possible to add/replace a product in the cart with another one with one of the API triggers?

Last edit: 10 years 5 months ago by Ortix.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 5 months ago #158594

Hi,

Yes you can manage the products in the cart in the plugin directly by replacing the product_id by the desired one, or return an array of product_ids, quantity, etc.

Please Log in or Create an account to join the conversation.

  • Posts: 73
  • Thank you received: 1
10 years 5 months ago #158727

I'm not quite sure how to do that? Do you have some code examples? Because the $product_id is not passed by reference, so changing that wouldn't do much right?

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
10 years 5 months ago #158780

Hello,
As it's said on the lines :

$dispatcher->trigger( 'onAfterCartUpdate',array( &$this, &$cart, &$product_id, &$quantity, &$add, &$type,&$resetCartWhenUpdate,&$force,&$return ));
product_id/quantity/add... are passed by reference, so you'll just have to directly change the value of these variables.

The following user(s) said Thank You: Ortix

Please Log in or Create an account to join the conversation.

  • Posts: 73
  • Thank you received: 1
10 years 5 months ago #159273

Ah not in my version (1.6). I'll update :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.082 seconds
Powered by Kunena Forum