Problem with calculation of product price by "decimal" length

  • Posts: 66
  • Thank you received: 1
  • Hikashop Business
5 months 3 weeks ago #369772

-- 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).

Attachments:

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

  • Posts: 85725
  • Thank you received: 14054
  • MODERATOR
5 months 3 weeks ago #369773

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.

  • Posts: 66
  • Thank you received: 1
  • Hikashop Business
6 hours 26 minutes ago #372226

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

<?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: 4 hours 19 minutes ago by nicolas.

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

  • Posts: 85725
  • Thank you received: 14054
  • MODERATOR
2 hours 16 minutes ago #372229

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.060 seconds
Powered by Kunena Forum