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

#   Hikashop cart subtotal/total adaptation

##

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

Less More

- Posts: 2
- Thank you received: 0
-
-

7 years 9 months ago -  7 years 9 months ago [\#302645](#302645) by [den Otter](/forum/user/57928-den-otter "View den Otter's Profile")  *[Hikashop cart subtotal/total adaptation](/forum/31-development/896678-hikashop-cart-subtotal-total-adaptation#302645 "-- url of the page with the problem -- :   benwijn-d-o-t-nl.alvast-online.nl  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.1 -- PHP version -- : 7.2.10 -- Browser(s) name and version -- : Chrome -- Error-message(debug-mod must be tuned on) -- : None  Hi there,  I'm trying to make a hikashop plugin for 11the bottle for free in my shop.  I've succeeded in adapting the price with a plugin, but the subtotal and the total in the cart are not changing on 12th product. I think i need function onBeforeCartSave(&amp;$element,&amp;$do) to do this. Do you have a documentation about the $element? I don't know how to adress the product price in this element.  Or do i have to make a change in the subtotal/total calculation? I so, what file do i have to adapt?  Thx  My plugin for now:  Krgds, Matthieu")* was created by *[den Otter](/forum/user/57928-den-otter "View den Otter's Profile")*

-- url of the page with the problem -- : [ benwijn-d-o-t-nl.alvast-online.nl](https://benwijn-d-o-t-nl.alvast-online.nl)
-- HikaShop version -- : 4.0.1
-- Joomla version -- : 3.9.1
-- PHP version -- : 7.2.10
-- Browser(s) name and version -- : Chrome
-- Error-message(debug-mod must be tuned on) -- : None

Hi there,

I'm trying to make a hikashop plugin for 11the bottle for free in my shop.

I've succeeded in adapting the price with a plugin, but the subtotal and the total in the cart are not changing on 12th product.
I think i need function onBeforeCartSave(&amp;$element,&amp;$do) to do this. Do you have a documentation about the $element?
I don't know how to adress the product price in this element.

Or do i have to make a change in the subtotal/total calculation? I so, what file do i have to adapt?

Thx

My plugin for now: Code:

&lt;?php defined('_JEXEC') or die; ?&gt;&lt;?php class plgHikashopTwelveforeleven extends JPlugin { function plgTwelveforeleven(&amp;$subject, $config){ parent::__construct($subject, $config); } //function onBeforeCartSave(&amp;$element,&amp;$do) { //$lst1 = $element-&gt;cart_products; //foreach ($lst1 as $item) { //if ($item-&gt;cart_product_total_quantity == 12) { //$element=null; //$item-&gt;prices[0]-&gt;price_value_with_tax = 1 * $item-&gt;prices[0]-&gt;price_product_id; //} //} //} function onAfterCartProductsLoad(&amp;$cart) { $lst1 = $cart-&gt;products; //echo"&lt;pre&gt;";var_dump($lst1); foreach ($lst1 as $item) { if ($item-&gt;cart_product_total_quantity == 12) { $item-&gt;prices[0]-&gt;price_value_with_tax = 11 * $item-&gt;prices[0]-&gt;price_id; } } } }

Krgds, Matthieu

Last edit: 7 years 9 months ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile"). Reason: [code] tag is nice

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

7 years 9 months ago [\#302664](#302664) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Hikashop cart subtotal/total adaptation](/forum/31-development/896678-hikashop-cart-subtotal-total-adaptation#302664 "-- url of the page with the problem -- :   benwijn-d-o-t-nl.alvast-online.nl  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.1 -- PHP version -- : 7.2.10 -- Browser(s) name and version -- : Chrome -- Error-message(debug-mod must be tuned on) -- : None  Hi there,  I'm trying to make a hikashop plugin for 11the bottle for free in my shop.  I've succeeded in adapting the price with a plugin, but the subtotal and the total in the cart are not changing on 12th product. I think i need function onBeforeCartSave(&amp;$element,&amp;$do) to do this. Do you have a documentation about the $element? I don't know how to adress the product price in this element.  Or do i have to make a change in the subtotal/total calculation? I so, what file do i have to adapt?  Thx  My plugin for now:  Krgds, Matthieu")*

Hi,

The total is calculated dynamically when the cart is loaded. So onBeforeCartSave won't help you.
In the function onAfterCartProductsLoad you are called after the total has been calculated in $cart so you would have to recalculate the total in $cart on top of updating the product price.
Alternatively, you could do similarily to what we do in the plugins which dynamically change the price of the products:
[ www.hikashop.com/marketplace/category/39-products.html](https://www.hikashop.com/marketplace/category/39-products.html)
They implement the hikashop_product_price_for_quantity_in_cart function to change the price of the product before the total is calculated by the cart loading system.

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

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

Less More

- Posts: 2
- Thank you received: 0
-
-

7 years 9 months ago [\#302669](#302669) by [den Otter](/forum/user/57928-den-otter "View den Otter's Profile")  Replied by *[den Otter](/forum/user/57928-den-otter "View den Otter's Profile")* on topic *[Hikashop cart subtotal/total adaptation](/forum/31-development/896678-hikashop-cart-subtotal-total-adaptation#302669 "-- url of the page with the problem -- :   benwijn-d-o-t-nl.alvast-online.nl  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.1 -- PHP version -- : 7.2.10 -- Browser(s) name and version -- : Chrome -- Error-message(debug-mod must be tuned on) -- : None  Hi there,  I'm trying to make a hikashop plugin for 11the bottle for free in my shop.  I've succeeded in adapting the price with a plugin, but the subtotal and the total in the cart are not changing on 12th product. I think i need function onBeforeCartSave(&amp;$element,&amp;$do) to do this. Do you have a documentation about the $element? I don't know how to adress the product price in this element.  Or do i have to make a change in the subtotal/total calculation? I so, what file do i have to adapt?  Thx  My plugin for now:  Krgds, Matthieu")*

I just added this code to the plugin. Works great. Thanks!

$tot = 0;
foreach ($lst as $item) {
$tot += $item-&gt;prices[0]-&gt;price_value_with_tax;
}
$cart-&gt;full_total-&gt;prices[0]-&gt;price_value_with_tax = $tot;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NjY3OC1oaWthc2hvcC1jYXJ0LXN1YnRvdGFsLXRvdGFsLWFkYXB0YXRpb24/dG1wbD1tYXJrZG93bg==) 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.048 seconds

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