Cart Fee Condition

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 3 weeks ago #360668

-- HikaShop version -- : 5.04
-- Joomla version -- : 5.1.0
-- PHP version -- : 8.2.18
-- Browser(s) name and version -- : Firefox 125.0.2

we need to charge an additional fee of 50 € on checkout for certain products that need to be shipped on dry ice.
I thought the Cart Fee plugin would be nice to accomplish this fee.
So, I added a custom field for Products called "dyriceshipment" and entered a "1" in this field for products to be shipped on dry ice.
I entered the following information in the Cart Fee plugin:
Label: "Dry Ice Surcharge"
Condition: "{product.dryiceshipment}==1"
Formula: "50"



Apparently, this condition is always evaluated as "false", no matter if the cart contains dry ice products or not, because the surcharge is never shown on Checkout.
When I leave the condition empty the Dry Ice Surcharge is always added to the cart, no matter which products it contains.

Does anyone know what I am doing wrong??

Thanks in advance,

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 months 3 weeks ago #360674

Hi,

I think the plugin is indeed adapted to what you want to do.
I think there is a problem between how the custom field is configured / filled and the condition.
Could you provide a screenshot of the settings of the custom field ? Could you provide a screenshot of the settings of a product you've configured to match with this condition ?
Also, I don't think you want to have the double quotes around the 1 in your condition.
Did you try without them ?

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

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 3 weeks ago #360676

thanks for the quick response!
indeed, the double quotation marks were not normally used. I added them for a quick test, just before I took the screen shot.
Products without the dry ice charge show a "0", whereas products with the charge show a 1 in the custom field.
here are the requested screen shots:




Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 months 3 weeks ago #360681

Hi,

Thanks for the details.
I was able to fix the bug with this. It was a typo in the code of the cart fee plugin.
I've made a new version of the plugin available.
Download again the install package of the plugin with the same download link you used after your purchase, and install it on your website and you'll get the patch for this problem.

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

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 3 weeks ago #360682

great - thanks. Glad I could help.
I installed the new version. Now I can see the dry ice charge when the cart contains only one dry ice product. If the cart contains an additional, regular product, the charge is not shown. If the cart contains two different dry ice products the dry ice charge is doubled. See attached screen shots.
Would it be possible to charge the dry ice fee only once, whenever there is a single or multiple dry ice products in the cart - and also when there are additional products, that don't require dry ice shipment?

Cart 1:



Cart 2:


Cart 3:


Cart 4:

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 months 3 weeks ago #360684

Hi,

Thanks for the details and the idea on the logic operator.
I've made a new version of the plugin available with an extra option to cater to that need.
Download again the install package of the plugin with the same download link you used after your purchase, and install it on your website and you'll get the modifications for that new option and the fix for the amount being multiplied when it shouldn't.

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

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 3 weeks ago #360695

Thank you for the new version.
I installed and tested it.
I understand that the new Plugin Products Logic Operator has to be set to "OR" for my application. Correct?

With this setting the dry ice charge is added only once, no matter how many dry ice products are in the cart. That is the good news.
However, when there are no dry ice products in the cart, the dry ice charge is still added. See attached screen shots.

Meanwhile, I took the liberty to fiddle with the fees.php file myself. I attach a version that works for me as a text file. It contains changes around line 45 and line 70.

Cart 1:




Cart 2:


Cart 3:


Modified fees.php:

File Attachment:

File Name: fees.txt
File Size:8 KB

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 months 3 weeks ago #360696

Hi,

Yes, you would want to set this option to "OR" in your case.

Indeed, I missed the case when no dry ice products are in the cart in my tests.
However, while your modifications fix the problem, you run the _evaluate function twice for each product and don't take into account the new setting. I don't want this, so I've made the solution differently.
The thing is that in some cases, people will want that all the products in the cart match with the condition for the fee to be added, not just one of the products.
Also, without the line
$this->productTags = array();
before the line:
$skip = $this->_replaceMainTags($formula->formula, $cart);
you'll end up with the fee being multiplied in the cart, like before.

I've made a new patch in order to take all this into account.
Download again the install package of the plugin with the same download link you used after your purchase, and install it on your website and you'll get the extra modifications.

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

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 3 weeks ago #360701

great - now your solution works perfectly.
I am not good at programming php - so I will gladly use your solution.
Thank you for looking into this again - and thank you for your good work

The following user(s) said Thank You: nicolas

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

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 1 week ago #360957

Sorry - I have another problem with the Cart Fee:

the additional Cart Fee (Dry Ice Surcharge) is not added to the Total. As an example, in the atttached screenshot the Total is shown as 264 €. However, the sum of Subtotal, Shipping and Dry Ice Surcharge is 315 €.



Could you please help again?

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 months 1 week ago #360959

Hi,

Can you check the settings of the cart fee plugin ? In there, there is a setting called "fee included". If that setting is turned on for your fee, the fee will appear on the cart, but it won't change the amount.
I'm suspecting that this setting is activated on your end.

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

  • Posts: 11
  • Thank you received: 2
  • Hikashop Business
6 months 1 week ago #360993

indeed, the seting "fee included" was turned on.
Now I turned it off and the additional fee is added as intended.
Thank you very much.

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

Time to create page: 0.175 seconds
Powered by Kunena Forum