How do I change shipping cost based on a formula?

  • Posts: 13
  • Thank you received: 1
3 years 4 months ago #326790

-- HikaShop version -- : 4.4.0
-- Joomla version -- : 3.9.10
-- PHP version -- : 7.4.13
-- Browser(s) name and version -- : Edge

Our shipping company will charge 7.99 for shipping 1 or 2 boxes, 14.98 for 3 to 4 ... etc.
Using the manual plugin, how do I do this? I've noticed a 'Formula' field, but all of the documentation doesn't seem to be up to date with the 4.4.0 release.

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

  • Posts: 12953
  • Thank you received: 1778
3 years 4 months ago #326837

Hello,

Firstly, can you give us more information about :
- how do you exactly want to configure your shippings throush some screenshots for example
- what do you exactly mean by "boxes", are they products and do they have a defined weight / dimensions ?

Thank you,
Kind regards,
Mohamed.

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

  • Posts: 13
  • Thank you received: 1
3 years 4 months ago #326880

We are selling bottled beers, in a pack of 12, so each box will have a weight (10kgs), and dimensions(Width 20.9cm,Height 20.5cm,Depth 20.2cm
). Our courier charges by weight, so 1 or 2 boxes is 7.99, 3 or 4 is 14.98 etc.
Will there be some up to date documentation soon, as I'm guessing the 'Formula' field may do what I need, but I have found zero information about it?

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

  • Posts: 12953
  • Thank you received: 1778
3 years 4 months ago #326899

Hello,

If your courier charge a fixed price by weight, the solution will be to set the "Formula" filed to : {weight} * PRICE_PER_WEIGHT
You'll just have to replace PRICE_PER_WEIGHT by the price per weight.

Else, the best solution will probably be to directly use that plugin which will do the job :
www.hikashop.com/marketplace/product/136...ghts-by-obsidev.html

Kind regards,
Mohamed.

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

  • Posts: 13
  • Thank you received: 1
3 years 4 months ago #327083

Thanks for the help Mohamed! Can you point me to the documentation that tells me which variables, and expressions can be used in the formula field please?

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

  • Posts: 4508
  • Thank you received: 610
  • MODERATOR
3 years 4 months ago #327117

Hello,

This input is new with the HikaShop 4.4, and unfortunately we are a little late on documentation, let's try to detail this and give you some concrete case.
List of tags :
{price} = Shipping price
{volume} = Current volume of the order
{weight} = Current weight in the order
{quantity} = Current quantity of product in the cart

From this you can create this kind of :
Example :
{weight}*10-{quantity}
Which means for a weight of 5 kg and 3 products which leads to this operation :
5 * 10 - 3 => 47 €
OR
Let's say that you have set in your shipping method a price of 2 € per Kg
Example :
{price}*{weight}
2 * 5 => 10 €

Hope this will help you to achieved what you need.
Regards

Last edit: 3 years 4 months ago by Philip.
The following user(s) said Thank You: evansnp

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

  • Posts: 13
  • Thank you received: 1
3 years 4 months ago #327160

Hi Phillip! Perfect! that's really useful :-)

The following user(s) said Thank You: Philip

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

  • Posts: 13
  • Thank you received: 1
3 years 2 months ago #329175

I've got a bit further by using the information that you kindly gave me, but I need to be able to use some basic maths functions like INT, MOD, CEIL etc. My problem is that our shipping company charges in units of weight i.e. 7.50 per 25Kg (or part of). Our boxes weigh 10Kg each, so 2 boxes could be shipped for 7.50, but 3 boxes would be 15.00 etc. The formula that I would like to achieve is:

ceil({weight}/25) * 7.5

Is this possible?

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
3 years 2 months ago #329205

Hi,

I checked the code of the library we're using for that and it doesn't seem to support ceil.
However, I think you could add that easily.
In the file administrator/components/com_hikashop/inc/expression.php you have this list of supported PHP functions:

var $fb = array(  // built-in functions
        'sin','sinh','arcsin','asin','arcsinh','asinh',
        'cos','cosh','arccos','acos','arccosh','acosh',
        'tan','tanh','arctan','atan','arctanh','atanh',
        'sqrt','abs','ln','log');
So I think you could just add the functions you need in there providing they only use one parameter.
And while you can't cast numbers into integers, you can use the intval() function for that so you could also add in that same array of allowed functions.
Modulo is supported since you can use the % operator.

Let us know how it goes so that we could add these extra functions to the list so that you won't have issues updating in the future.

The following user(s) said Thank You: evansnp

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

  • Posts: 13
  • Thank you received: 1
3 years 2 months ago #329213

Thanks Nicolas, I'll give it a try.

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

  • Posts: 13
  • Thank you received: 1
3 years 2 months ago #329214

That's worked perfectly thanks! I've only added 'ceil' as that's the only one I needed. Thanks for the remarkably quick solution :-)

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
3 years 2 months ago #329224

Hi,

Thanks for your feedback. We'll add that to the next version.

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

  • Posts: 13
  • Thank you received: 1
2 years 8 months ago #334846

Hi Support. Did this feature get added to the new release?

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
2 years 8 months ago #334848

Hi,

Yes. And not just ceil. We've added all these functions to it:
'ceil', 'intval', 'floor', 'round', 'exp'

The following user(s) said Thank You: evansnp

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

  • Posts: 13
  • Thank you received: 1
2 years 8 months ago #334859

Thanks a million! I'll update my site then :-)

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

Time to create page: 0.114 seconds
Powered by Kunena Forum