- Posts: 2
- Thank you received: 0
Hikashop cart subtotal/total adaptation
7 years 8 months ago - 7 years 8 months ago #302645
by den Otter
Hikashop cart subtotal/total adaptation was created by den Otter
-- 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(&$element,&$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
-- 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(&$element,&$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:
<?php
defined('_JEXEC') or die;
?><?php
class plgHikashopTwelveforeleven extends JPlugin {
function plgTwelveforeleven(&$subject, $config){
parent::__construct($subject, $config);
}
//function onBeforeCartSave(&$element,&$do) {
//$lst1 = $element->cart_products;
//foreach ($lst1 as $item) {
//if ($item->cart_product_total_quantity == 12) {
//$element=null;
//$item->prices[0]->price_value_with_tax = 1 * $item->prices[0]->price_product_id;
//}
//}
//}
function onAfterCartProductsLoad(&$cart) {
$lst1 = $cart->products;
//echo"<pre>";var_dump($lst1);
foreach ($lst1 as $item) {
if ($item->cart_product_total_quantity == 12) {
$item->prices[0]->price_value_with_tax = 11 * $item->prices[0]->price_id;
}
}
}
}
Krgds, Matthieu
Last edit: 7 years 8 months ago by Jerome. Reason: [code] tag is nice
Please Log in or Create an account to join the conversation.
7 years 8 months ago #302664
by nicolas
Replied by nicolas on topic Hikashop cart subtotal/total adaptation
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
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.
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
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 or Create an account to join the conversation.
7 years 8 months ago #302669
by den Otter
Replied by den Otter on topic Hikashop cart subtotal/total adaptation
I just added this code to the plugin. Works great. Thanks!
$tot = 0;
foreach ($lst as $item) {
$tot += $item->prices[0]->price_value_with_tax;
}
$cart->full_total->prices[0]->price_value_with_tax = $tot;
$tot = 0;
foreach ($lst as $item) {
$tot += $item->prices[0]->price_value_with_tax;
}
$cart->full_total->prices[0]->price_value_with_tax = $tot;
Please Log in or Create an account to join the conversation.
Time to create page: 0.177 seconds