owebia / magento2-module-advanced-shipping

Other
91 stars 29 forks source link

Shipping Costs and Cart Total Problem #23

Closed storepeinture closed 5 years ago

storepeinture commented 7 years ago

I found a funny issue for stores who offer Free Shipping for orders with a grandtotal of e.g. 100 EUR and above (in EU we include taxes). So all prices are TAXES INCLUDED. Find code sample below.

Scenario If the cart value is close to the free shipping limit of 100 EUR, say Cart Value = 98 EUR Shipping Fee = 5 EUR

addMethod('id_001', [
    'title'      => "Free Shipping OVER 100 EUR",
    'enabled'    => $quote->grand_total >= 100.00,
    'price'      => 0,
]);

That means, the customer should be paying in total 98 + 5 = 103 EUR But not only that. It also seems that the grandtotal variable has increased to 103 EUR - and has now passed the threshold of 100 EUR!!

If a customer has to reload the checkout page for whatever reason (because he forgot something or whatever) he would now be offered FREE SHIPPING!

Result: With a Grand Total of 98 EUR, the customer would be able to checkout with FREE shipping.

My solution I use $quote->subtotal * VAT That gives me the shopping cart including tax WITHOUT Shipping fees.

It is better to put the following code (1.2 = 20% VAT)

addMethod('id_001', [
    'title'      => "Free Shipping OVER 100 EUR",
    'enabled'    => $quote->subtotal * 1.2 >= 100.00,
    'price'      => 0,
]);

The best thing, however, would be, if there was "SUBTOTAL INCL VAT" variable.

owebia commented 7 years ago

Hi,

I can't reproduce this issue. I think it is depending on tax calculation settings.

The $quote variable gives you access to properties of a \Magento\Quote\Model\Quote object: http://htmlpreview.github.io/?https://github.com/owebia/magento2-module-advanced-shipping-setting/blob/master/view/doc_en_US.html#formulas_variables

The module Advanced Shipping doesn't add properties to magento objects. The existing grand_total property is calculated by Magento.

Perhaps can you send here your Magento version, your Advanced Shipping version, and your tax calculation settings.

Regards, A.L.

bexdoggett commented 6 years ago

Hello,

I am getting the same issue as above. We have different shipping methods depending on whether the order total is below or above 100 and are using $quote->grand_total < 100.00

This works well in the basket (cart) page and on the first step of the checkout, but when a user proceeds to payment if their order is close to 100 e.g 95.90, the shipping cost 7.95 is added to the grand total and then the $quote->grand_total is now above the 100 threshold and the shipping method above 100 is selected which is 5.95.

As you've mentioned above this is probably due to how Magento calculates grand total so I have been looking into using $quote->subtotal, but this only gets me the subtotal minus any tax, despite all of my store configuration settings (catalog, cart and shipping) being 'include tax'. I've gone through your documentation and I cant see a way of getting the subtotal including tax. Could you advise a work around?

Our Magento version is 2.2.5, module version 2.1.1

Thank you

Becky

owebia commented 6 years ago

Hi,

Have you tried to use these variables ?

$request->package_value
$request->package_value_with_discount

Best Regards,
A.L.

bexdoggett commented 6 years ago

Hi,

No I hadn't and now I'm using them its working great!

Thank you,

Becky

bhargav-rupapara commented 5 years ago

Hello, I've read the documentation and also went through the module, but still I don't know how I can call addMethod function,

Can anyone please explain how and where I can call addMethod function.

Thanks Bhargav

owebia commented 5 years ago

Hi,

In Magento backend, go to Stores > Configuration > Sales > Shipping Methods > Advanced Shipping by Owebia.

Then click on the pencil icon right to "Config" field.

You can then write your own configuration using addMethod function.
The PHP code of the configuration is not evaluated but it is interpreted as an Abstract Syntax Tree (as explained in the documentation).

Best Regards, A.L.

mobweb commented 4 years ago

Found this via Google, so I'm adding my feedback here: Unfortunately the _$request->package_value_withdiscount variable that was proposed as an alternative does not seem to include taxes for me.