- Posts: 66
- Thank you received: 1
Problem with calculation of product price by "decimal" length
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).
-- 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.
9 months 1 week ago #369773
by nicolas
Replied by nicolas on topic Problem with calculation of product price by "decimal" length
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.
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.
3 months 1 week ago - 3 months 1 week ago #372226
by yanliom
Replied by yanliom on topic Problem with calculation of product price by "decimal" length
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
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.
3 months 1 week ago #372229
by nicolas
Replied by nicolas on topic Problem with calculation of product price by "decimal" length
Hi,
I've updated the plugin. Thanks for the feedback.
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