- Posts: 73
- Thank you received: 1
get latest added cart_product_id
12 years 3 months ago - 12 years 3 months ago #158447
by Ortix
get latest added cart_product_id was created by Ortix
-- 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:
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!
-- 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:
Code:
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: 12 years 3 months ago by Ortix.
Please Log in or Create an account to join the conversation.
12 years 3 months ago #158549
by Xavier
Replied by Xavier on topic get latest added cart_product_id
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.
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.
12 years 3 months ago - 12 years 3 months ago #158578
by Ortix
Replied by Ortix on topic get latest added cart_product_id
[strike]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[/strike]
But is it also possible to add/replace a product in the cart with another one with one of the API triggers?
I think i can achieve it by iterating over each product and matching the product id to get the cart_product_id[/strike]
But is it also possible to add/replace a product in the cart with another one with one of the API triggers?
Last edit: 12 years 3 months ago by Ortix.
Please Log in or Create an account to join the conversation.
12 years 3 months ago #158594
by Xavier
Replied by Xavier on topic get latest added cart_product_id
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.
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.
12 years 3 months ago #158727
by Ortix
Replied by Ortix on topic get latest added cart_product_id
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.
Less
More
- Posts: 12953
- Thank you received: 1778
12 years 3 months ago #158780
by Mohamed Thelji
Replied by Mohamed Thelji on topic get latest added cart_product_id
Hello,
As it's said on the lines :
product_id/quantity/add... are passed by reference, so you'll just have to directly change the value of these variables.
As it's said on the lines :
Code:
$dispatcher->trigger( 'onAfterCartUpdate',array( &$this, &$cart, &$product_id, &$quantity, &$add, &$type,&$resetCartWhenUpdate,&$force,&$return ));
The following user(s) said Thank You: Ortix
Please Log in or Create an account to join the conversation.
12 years 3 months ago #159273
by Ortix
Replied by Ortix on topic get latest added cart_product_id
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.212 seconds