Commit Graph

90 Commits

Author SHA1 Message Date
Shahlin Ibrahim e06466b2b7 Minor docblock grammar/typo/casing fixes 2020-10-23 17:27:39 +04:00
Néstor Soriano c15488d840
Merge pull request #27830 from woocommerce/php8/fix-round-function-with-non-numeric-argument 2020-10-09 08:01:44 +02:00
Nestor Soriano 7485b9165f Convert optional-before-required arguments to required.
In PHP 8 required parameters after optional parameters in
function/method signatures trigger a deprecation notice. These type
of parameters are pointless since a value needs to always be
provided for them anyway, so they are actually de-facto required.

This commit converts all these not-so-optional parameters into
truly required parameters by removing their default values.
2020-10-02 09:45:09 +02:00
Nestor Soriano 52eed70f04 Add a 'NumberUtil' class with a 'round' method.
There's a number of places in the WooCommerce codebase where the
built-in function 'round' is executed passing a non-numeric value
(not a number and not a string that can be parsed as a number),
for example round(''). In PHP 7 this yields a value of 0, but in
PHP 8 this throws an error.

This commit adds a 'NumberUtil' class with a static 'round' method,
this method checks if the passed value is numeric and if so it just
executes the built-in function, otherwise it returns 0. And all the
calls to 'round' in the codebase are replaced with 'NumberUtil::round'.
2020-10-01 11:08:51 +02:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
vedanshujain a413952784 Use round_item_subtotal for shipping because shipping prices never include taxes so no need to wc_round_tax_total. 2020-07-24 19:12:25 +05:30
vedanshujain 541d9ca483 Remove individual rounding because lines would have already rounded.
When rounding at subtotal is enabled, line items are already rounded where they need to, so we only should do any further rounding when displaying values and no where else.

This is part of our larger attempt to remove individual rounding as much as possible.
2020-07-24 19:09:59 +05:30
vedanshujain d8388ef266 Remove rounding because we already appropriately round in `get_rounded_items_total`. 2020-03-03 16:34:35 +05:30
vedanshujain 3546e60d96 Use common rounding method for consistency. 2020-03-02 15:19:16 +05:30
vedanshujain aaa85ac74c Use standard way to calculate total in `get_subtotal_to_display` for consistency.
We were calculating subtotal to display slightly differently then we would have calculated subtotal in the cart. This was affecting subtotal value in invoices and in order confirmation screen.

This patch updates how we calculate subtotal to display such that we calculate in same way.
2019-11-27 04:43:23 +05:30
vedanshujain 8c2c83d488 Use `wc_round_tax_total` to make it consistent with how we round taxes.
When price includes taxes, we round down. This patch uses the correct method to round taxes depending on the mode instead of plain rounding.
2019-11-27 03:13:39 +05:30
vedanshujain 1de30e8963 Refactor so that trait don't have class specific functions. 2019-11-26 01:30:45 +05:30
vedanshujain 60cd7b3651 Refactor Order Class to use shared calculation logic.
We added a trait to move shared logic betweem Orders and Cart. This commit refactors Order class to use that shared logic.
Also adds a test for a failing case.
2019-11-25 17:53:14 +05:30
vedanshujain bee7ea4490 Add trait which contains common total calc logic.
`WC_Abstract_Order` and `WC_Cart_Totals` have their own logic to calculate totals. This means that we would have to fix in two places. This commit adds a trait which can be used to place shared logic between above two classes.
2019-11-25 17:53:14 +05:30
Claudio Sanches 6e6ca196f9
Merge branch 'master' into fix/23340 2019-07-09 16:32:43 -03:00
vedanshujain 8ab6cb2b5a Round late when rounding at subtotal to reduce rounding error.
We were earlier rounding different tax rate values while they are merged, even if rounding at subtotal setting is enabled. This increases the rounding error, especially when prices are inclusive of taxes, and thus there is a chance that the total will be slightly different from when add the original values. For egs: https://github.com/woocommerce/woocommerce/issues/23917 .

This commit changes this behavior to round *after* we have summed all the precise unround values. Similar for items prices, we now round as late as possible, if rounding at subtotal is enabled.
2019-07-04 22:34:29 +05:30
Mike Jolley 33b1c4205b Fix cart tests - move round so taxes are correct 2019-04-17 16:49:46 +01:00
Mike Jolley b8921f9fba
Merge pull request #22420 from woocommerce/refactor/tax-rounding-methods
Refactor tax rounding methods for consistency
2019-02-12 16:13:58 +00:00
Mike Jolley a77578a989
Merge pull request #22347 from woocommerce/fix/20911
Tweak tax handling when exempt of VAT and woocommerce_adjust_non_base…
2019-01-31 13:33:36 +00:00
Mike Jolley 2d14315f3d woocommerce_cart_totals_get_item_tax_rates 2019-01-21 15:38:48 +00:00
RobertoDonPedro 3a2b3d10ad
Filter get_item_tax_rates in class-wc-cart-totals.php
Adds filter on the return value of function 'get_item_tax_rates' to prevent the mandatory caching of tax rates, described in https://github.com/woocommerce/woocommerce/issues/21855
2019-01-17 13:57:31 +01:00
Mike Jolley 50af71b9bd Calculated items_subtotal_tax using rounded tax subtotals. 2019-01-11 12:59:23 +00:00
Mike Jolley 96ba549b2b Remove type hint 2019-01-10 13:23:49 +00:00
Mike Jolley f67ab4e447 correct version 2019-01-10 13:20:02 +00:00
Mike Jolley 82365fd6d2 Tweak tax handling when exempt of VAT and woocommerce_adjust_non_base_location_prices is off 2019-01-04 16:46:52 +00:00
Grzegorz Rola 9df10fac5a Taxes should be rounded on subtotals in cart when option woocommerce_tax_round_at_subtotal is checked. 2018-08-29 13:43:13 +02:00
Grzegorz Rola 20ac4a8b69 Taxes should be rounded on subtotals in cart when option woocommerce_tax_round_at_subtotal is checked. 2018-08-29 13:34:22 +02:00
Grzegorz Rola 5c3f4c9c10 Revert "Taxes should be rounded on subtotals in cart when option woocommerce_tax_round_at_subtotal is checked."
This reverts commit dafcbc5
2018-08-29 13:25:22 +02:00
Grzegorz Rola dafcbc56b0 Taxes should be rounded on subtotals in cart when option woocommerce_tax_round_at_subtotal is checked. 2018-08-29 13:22:51 +02:00
Boro Sitnikovski 15cbe7daee Pass current object as context 2018-06-20 14:16:14 +02:00
Boro Sitnikovski 1b90d8114c Add filter for tax calculation in cart totals 2018-06-20 10:51:05 +02:00
Mike Jolley e677340fcc No need to load tax rates when taxes are disabled 2018-05-01 11:56:39 +01:00
Claudio Sanches 67cd6b8fbf Fixed includes/class-wc-cart-totals.php PHPCS violations 2018-03-16 14:47:18 -03:00
claudiulodro f39a9ee61a Round fractional cents when oob 2018-03-14 08:35:41 -07:00
Torre Lasley 64f85346c0 Add filter to allow plugins to override the default coupon apply order. (#19339)
* Fix for Issue #10523 - Variations ID lookup by SKU

I copied the code from the bulk() function to look up the Variation ID by the Variation SKU if the Variation ID is missing.

* Added new filter woocommerce_coupon_sort to allow plugins to override the default coupon apply order.
2018-03-13 10:26:22 +00:00
Mike Jolley a44e4f64ac Round correctly when removing taxes from prices. 2018-01-05 14:56:33 +00:00
Mike Jolley 7a94bf06df Reversion changes 2017-12-07 15:39:10 +00:00
Mike Jolley 7e7b79efd0 typo 2017-12-07 15:31:55 +00:00
Mike Jolley b6f87e70d7 round total to cents 2017-12-04 22:42:39 +00:00
Mike Jolley 7da5780c00 Store unrounded, calc rounded. 2017-12-04 21:40:12 +00:00
Mike Jolley 277127a400 Round line totals and taxes per line correctly to the store DP setting. 2017-12-04 20:38:00 +00:00
Mike Jolley 6ef391666f Only remove base taxes in cart totals class if item is taxable
Fixes #17880
2017-11-23 11:08:10 +00:00
Mike Jolley 15230e295c Add precision after multiplying quantity
Closes #17860

Has no effect on core it seems because we only store prices to the DP
setting. This would be to correct precision added by plugins.
2017-11-22 10:49:28 +00:00
Mike Jolley ec5db3b123 When adding precision to taxes, don't round when adding precision. 2017-11-20 16:30:23 +00:00
Mike Jolley 040443a04d Out of base rounding error fixes 2017-11-02 20:00:49 +00:00
Mike Jolley 9ea088f6c9 Adjust discount logic when out of base 2017-11-02 16:18:51 +00:00
Mike Jolley 65f2ee0f49 Cart totals: don't add shipping unless show_shipping is true.
Closes #17412
2017-10-27 17:30:33 +01:00
Claudiu Lodromanean 3aa43ed5d2 Calculate shipping after discounts (#17364)
* Calculate shipping after discounts

* Calculate grand total after shipping is calculated

* Keep fees calculation before shipping
2017-10-26 15:27:10 +01:00
Mike Jolley f27c8a226f Fix issue when customer is VAT exempt and prices include tax
Ref: https://github.com/woocommerce/woocommerce-eu-vat-number/issues/82

In this scenario, base taxes need to be removed from the item price.
2017-10-18 09:31:35 -07:00
Mike Jolley d694483735 Fix tax display issue for discounts 2017-10-13 14:36:35 +01:00