Calculation of shipping costs

  • Posts: 26
  • Thank you received: 2
1 year 2 months ago #348760

-- HikaShop version -- : 4.7.0
-- Joomla version -- : 4.2.6
-- PHP version -- : 8.1.14
-- Browser(s) name and version -- : Firefox

I'm using Hikashop for renting goods. Instead of the number of products I record the number of months. Therefore, for the shipping cost, the individual weight of the product should be taken into account and not the weight multiplied by the quantity. So if someone orders two items with a rental period of two months each, only the single weight of item 1 and the single weight of item 2 need to be added.

In which file is this calculation done? How can I customize the script?

I have to save everything with backups for the updates anyway, so it is not a problem to adjust the file directly

Thanks for the support.
Best regards
langi

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #348761

Hi,

The calculation of the total weight for the min/max weight settings of the shipping methods is done in the function getShippingProductsData of the file administrator/components/com_hikashop/classes/shipping.php
The main line there is:

$order->shipping_prices[$key]->weight += $row->product_weight * $row->cart_product_quantity;

Now, for plugins like FedEx, USPS, UPS, etc, the system has to first generate packages within the allowed dimensions and weight restrictions of the shipping service before contacting the server of the shipping service to get the shipping cost of each package.
So we can't use the previous mechanism in getShippingProductsData. Instead, the number of elements of a product in an order is taken into account in the getOrderPackage function of the file administrator/components/com_hikashop/helpers/shippingplugin.php
The simplest would be to just remove the lines:
if(isset($product->cart_product_quantity))
				$qty = (int)$product->cart_product_quantity;
			if(isset($product->order_product_quantity))
				$qty = (int)$product->order_product_quantity;
to always use 1 for the $qty variable.

Note also that both can be overridden if necessary:
www.hikashop.com/support/documentation/6...ntation.html#classes
I would recommend to do it as an override. That way, you don't have to think about this if you do your overrides properly (by extending from the original class, overridding only the method you want to change, and in your method, making a copy of the quantities for backup, changing the quantities to 1 before calling the parent function, and then restoring the quantities before returning with the result from the parent method. That way, any fix we add in these methods will be taken into account, and no problem with updates).

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

  • Posts: 26
  • Thank you received: 2
1 year 2 months ago #348778

Many thanks. It works.
In fact, I had not looked in the administration.

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

Time to create page: 0.058 seconds
Powered by Kunena Forum