[Skip to main content](#vessel-content)

#   get latest added cart\_product\_id

##

- **[Ortix](/forum/user/12608-ortix "View Ortix's Profile")**
- [![Ortix's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12608-ortix "View Ortix's Profile") Topic Author
- [ Offline](/forum/user/12608-ortix)

Less More

- Posts: 73
- Thank you received: 1
-
-

12 years 4 months ago -  12 years 4 months ago [\#158447](#158447) by [Ortix](/forum/user/12608-ortix "View Ortix's Profile")  *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#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&#95;product&#95;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&#95;product&#95;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!")* was created by *[Ortix](/forum/user/12608-ortix "View Ortix's Profile")*

-- 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: 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 4 months ago by [Ortix](/forum/user/12608-ortix "View Ortix's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

12 years 4 months ago [\#158549](#158549) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#158549 "-- 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&#95;product&#95;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&#95;product&#95;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!")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Ortix](/forum/user/12608-ortix "View Ortix's Profile")**
- [![Ortix's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12608-ortix "View Ortix's Profile") Topic Author
- [ Offline](/forum/user/12608-ortix)

Less More

- Posts: 73
- Thank you received: 1
-
-

12 years 4 months ago -  12 years 4 months ago [\#158578](#158578) by [Ortix](/forum/user/12608-ortix "View Ortix's Profile")  Replied by *[Ortix](/forum/user/12608-ortix "View Ortix's Profile")* on topic *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#158578 "-- 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&#95;product&#95;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&#95;product&#95;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!")*

[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?

Last edit: 12 years 4 months ago by [Ortix](/forum/user/12608-ortix "View Ortix's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

12 years 4 months ago [\#158594](#158594) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#158594 "-- 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&#95;product&#95;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&#95;product&#95;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!")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Ortix](/forum/user/12608-ortix "View Ortix's Profile")**
- [![Ortix's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12608-ortix "View Ortix's Profile") Topic Author
- [ Offline](/forum/user/12608-ortix)

Less More

- Posts: 73
- Thank you received: 1
-
-

12 years 4 months ago [\#158727](#158727) by [Ortix](/forum/user/12608-ortix "View Ortix's Profile")  Replied by *[Ortix](/forum/user/12608-ortix "View Ortix's Profile")* on topic *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#158727 "-- 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&#95;product&#95;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&#95;product&#95;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!")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

12 years 4 months ago [\#158780](#158780) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#158780 "-- 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&#95;product&#95;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&#95;product&#95;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!")*

Hello,
As it's said on the lines : Code:

$dispatcher-&gt;trigger( 'onAfterCartUpdate',array( &amp;$this, &amp;$cart, &amp;$product_id, &amp;$quantity, &amp;$add, &amp;$type,&amp;$resetCartWhenUpdate,&amp;$force,&amp;$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](/forum/user/12608-ortix "View Ortix's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Ortix](/forum/user/12608-ortix "View Ortix's Profile")**
- [![Ortix's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12608-ortix "View Ortix's Profile") Topic Author
- [ Offline](/forum/user/12608-ortix)

Less More

- Posts: 73
- Thank you received: 1
-
-

12 years 4 months ago [\#159273](#159273) by [Ortix](/forum/user/12608-ortix "View Ortix's Profile")  Replied by *[Ortix](/forum/user/12608-ortix "View Ortix's Profile")* on topic *[get latest added cart\_product\_id](/forum/31-development/868692-get-latest-added-cart-product-id#159273 "-- 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&#95;product&#95;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&#95;product&#95;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!")*

Ah not in my version (1.6). I'll update ![:)](/media/kunena/emoticons/8.png ":)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2ODY5Mi1nZXQtbGF0ZXN0LWFkZGVkLWNhcnQtcHJvZHVjdC1pZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop- Install &amp; Update- Product &amp; Category Display- Content Creation- Sales and Orders- - Orders management- - Reports &amp; Statistics- Customers- Checkout- Payment Methods- Shipping Methods- Import &amp; Export (CSV, XLS…)- Specific Features- - Affilation- - Taxes- - Wishlist- - Vote- - Carousel &amp; Slider- - Mass Actions- - Filters &amp; Search- - Discount &amp; Coupon- - Feature Request- Integrations- Showcase- General Talk about HikaShop- Development- - HikaShop 3.0 Beta- Translation- Commercial Jobs HikaShop Components- HikaMarket- - Market: Feature requests- - Market: How to?- - Market: Bug Report- HikaSerial- - General talk about HikaSerial- - Serial: Bug Report- - Serial: How to?- - Support en Français de HikaSerial (French Support)- - HikaSubscription- HikaAuction- - Auction: Feature requests- - Auction: How to?- - Auction: Bug report Hikashop around the world- Support en Français (French Support)- Russian- - FAQ. Курс выживания с Hikashop. Частые вопросы и о- - Расширения Hikashop- - Наши сайты на Hikashop- 日本語版サポート(Japanese Support)- Thai- German Archives- Bug Report- How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.141 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
