Skip to main content

Problem with calculation of product price by "decimal" length

More
9 months 1 week ago #369772 by yanliom
-- url of the page with the problem -- : www.ravopleko.gr
-- HikaShop version -- : 6.1.1
-- Joomla version -- : 5.4.1
-- PHP version -- : 8.3

Hello,

I'm using your solution for calculating product price by length.

See topics:
-https://www.hikashop.com/forum/product-category-display/898379-calculate-product-price-by-length.html
-https://www.hikashop.com/forum/product-category-display/898421-decimal-calculate-product-price-by-length.html

But at the cart the price is calculated wrong.

Please see the attached screenshot were I'm testing various possibilities (I removed any restrictions for testing purposes).

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

More
9 months 1 week ago #369773 by nicolas
Hi,

I suppose you're using the plugin www.hikashop.com/marketplace/product/221...quantity-plugin.html
So, the probably is probably with your custom item field. The column name of the custom field must be exactly "ordered_length". Otherwise, it will be ignored by the plugin.
Alternatively, you can use the price calculations plugin:
www.hikashop.com/marketplace/product/148...ce-calculations.html
It has many advantages over the plugin you're using:
- you can have different fields for different products
- you can enter complex calculation formulas, not just price * value, and you can combine the value from different fields if necessary
- the plugin directly displays a "calculated price" on the product page when a field value is changed.

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

More
3 months 1 week ago - 3 months 1 week ago #372226 by yanliom
Hello,

you have to provide an updated version of the plugin:
www.hikashop.com/marketplace/product/221...quantity-plugin.html


I changed the code so that it works with the new Hikashop versions.


I don't know if it is 100% correct.


Best,
Yannis
Code:
<?php jimport('joomla.plugin.plugin'); class plgSystemCustom_quantity extends JPlugin{ } if(!function_exists('fid_custom_quantity_normalize_length')) { function fid_custom_quantity_normalize_length($value) { $value = trim((string) $value); $value = str_replace(',', '.', $value); return (float) $value; } } if(!function_exists('hikashop_product_price_for_quantity_in_cart') && !function_exists('hikashop_product_price_for_quantity_in_order')) { function hikashop_product_price_for_quantity_in_cart(&$product){ $currencyClass = hikashop_get('class.currency'); $quantity = @$product->cart_product_quantity; $ordered_length = 1; if(!empty($product->ordered_length)){ $ordered_length = fid_custom_quantity_normalize_length($product->ordered_length); } $currencyClass->quantityPrices($product->prices, $quantity, $product->cart_product_total_quantity); if($ordered_length > 0 && $ordered_length != 1 && !empty($product->prices)) { foreach($product->prices as $k => $price) { if(isset($price->price_value)) { $product->prices[$k]->price_value = (float) $price->price_value * $ordered_length; } if(isset($price->price_value_with_tax)) { $product->prices[$k]->price_value_with_tax = (float) $price->price_value_with_tax * $ordered_length; } } } } function hikashop_product_price_for_quantity_in_order(&$product){ $quantity = $product->order_product_quantity; if(!empty($product->ordered_length)){ $ordered_length = fid_custom_quantity_normalize_length($product->ordered_length); $quantity = $quantity * $ordered_length; } $product->order_product_total_price_no_vat = $product->order_product_price * $quantity; $product->order_product_total_price = ($product->order_product_price + $product->order_product_tax) * $quantity; } }
Last edit: 3 months 1 week ago by nicolas.

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

More
3 months 1 week ago #372229 by nicolas
Hi,

I've updated the plugin. Thanks for the feedback.

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

Time to create page: 0.218 seconds
Powered by Kunena Forum