Open trouble2 opened 4 years ago
So, I have investigated this, and I want to discuss my findings.
I found out that when you have a discount (korting) it gets added to Subtotal, but why? Subtotal already has the total price which includes the discounted price.
By adding discount to subtotal you showing what the original price would have been but that is not relevant not only that but by adding the discount to subtotal calculating shipping does not work properly. See example above.
If I remove discount from subtotal, I then get 151,38 this means that the client does needs to pay shipping, because free shipping is subtotal >= 250.
So, if we want to show original price, we need to use another field and not subtotal.
How should we proceed?
Any other suggestions? @leedavi
I'm not sure... but should that discount be a negative figure? Then it would be correct?
Although it is called "discount", the math can dictate it could be a positive or negative amount. And hence displays the sum of the cart, plus discount (negative or positive).
I'm not following, how can a discount be positive? Discount is always negative. (a deduction from the usual cost of something.)
I think that we should use sum of the cart + tax to calculate shipping. This because cart items already includes the discounted price.
I made the following changes and it seems to be working fine.
I went a head and made a few changes.
So now you can now choose subtotal or cart sum to calculate shipping.
What do you think of this approach? @leedavi
I have not had a deep look.
But I think the trouble here is you change the "CartTotal". I'm unsure of where the CartTotal is used or displayed, but this could cause issues with other areas.
You are best to save the value in another xml element, you can create one called anything you wish. And then change the shipping calculation to use the new value if the option "calc of total" is selected.
We must not effect any other site with the new option. Everything must stay the same for other shops without the option selected, This sounds obvious and easy, but the key word is "separation", do not use any existing variables, if you need the values, copy them to a new XML element.
Also, remember that extra plugins and providers work on the data, so although it all looks OK in the core OpenStore code, it may not be OK in a plugin that uses that value.
The new option path should be completely separate, even if it looks perfectly OK to change the code in the core.
@leedavi I need a push into the right direction😆.
I want to create a new XML element and I'm thinking that it should go into typecode ="CART" where genxml/total and genxml/appliedtotal are also being stored.
Where and how should I add this field? And is it as simple as just using the AddSingleNode or AddXmlNode? 🤷♂️
The CartData class inherits the Purchasedata class, which is PurchaseInfo XML.
You can use the nodeXml to add and remove, but it's easier to use a property command, something like this....
PurchaseInfo.SetXmlPropertyDouble("genxml/total2",total)
We've set free shipping for orders above 200 euro's However, when someone orders for 220 euro's and get's a discount of 50 euro's the total of the order is 170 euro's. But the free shipping still applies because it looks at the 220 euro's instead of the 170 euro's. We think this is wrong.
So at least an option should be built in to apply free shipping on the subtotal or on the total amount. This way people can choose which way to apply the shipping costs