Commit Graph

489 Commits

Author SHA1 Message Date
Nestor Soriano d254f2703c
Add a unit test for WC_Abstract_Order->add_product
The test verifies that if an order is passed in arguments, that order
is passed in turn to wc_get_price_excluding_tax.
2021-09-21 16:40:36 +02:00
Nestor Soriano 319b95b6f1
Modify "wc_get_price_excluding_tax" to use order location for rates
The order is optional and must be passed as an "order" key in "$args".
If present, the order customer will be passed to "WC_Tax::get_rates"
in order to calculate the taxes to substract (provided that
"$product->is_taxable() && wc_prices_include_tax()")

Also "WC_Abstract_Order->add_product" and "WC_AJAX::maybe_add_order_item"
are modified to pass the order being processed so that ultimately
"wc_get_price_excluding_tax" uses it.

This prevents the base tax location to be wrongly used instead of the
customer location when the "woocommerce_adjust_non_base_location_prices"
hook is set to return false.
2021-09-10 11:45:01 +02:00
James Allan 09b5fb4691 Update the rate when recalculating and updating order tax items 2021-03-30 22:27:11 -03:00
roykho 93e528f8ea
Type cast floats to prevent string addition errors in PHP 8 closes #29087 2021-02-10 10:06:25 -08:00
roykho b2eb2d8724
Update tax rate label when saving order closes #28649 2021-01-28 14:42:40 -08:00
Claudio Sanches 6701ce9c9d
Merge pull request #26983 from woocommerce/fix/25082
Use tax location from order while computing tax in discount.
2021-01-28 16:59:59 -03:00
Gregory Karpinsky 6cb569047a
abstract_wc_order:add_product() - removed `throws`
Exception 'WC_Data_Exception' is never thrown in the function
2020-12-21 11:26:50 -05:00
vedanshujain 00b7b40c37 Add method to get rates based on order.
This method will prioritize getting rates from billing/shipping address instead of `WC()->customer` which in irrevelant in context of editing order from admin screen.
2020-11-12 22:58:05 +05:30
vedanshujain 74de152535 Use tax location from order while computing tax in discount.
We were not passing tax location while computing discount in orders, hence it was defaulting to shop's base address resulting in incorrect tax calculation.

This commit refactors `get_rates` method into another method that allows getting rates from location directly.
2020-11-12 22:57:56 +05:30
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 57c105a3fe Remove wc_round_tax_total calls because lines would have already been rounded appropriately before reaching here. 2020-07-24 19:12:24 +05:30
Daniel Morell 94e317f9f8
Fixed wc_get_order function name
The WC_Abstract_Order __construct() method doc block had the wc_get_order() method referred to as get_order().
2020-06-17 10:49:40 -05:00
vedanshujain 3dc7df7af9 Use common code and round in subtotal.
We round in `get_subtotal` because its a front-end method. If more precision is required then `get_cart_subtotal_for_order` needs to be called. Also use same `get_cart_subtotal_for_order` method here as well for consistency.
2020-05-27 23:48:47 +05:30
vedanshujain 57d336433a Fix regression caused by merging #25092 conflicting with #24828 2020-05-22 22:08:42 +05:30
Nestor Soriano 0eed82b3b7 Fix code standards violations introduced in #25092 2020-04-07 12:28:30 +02:00
Vedanshu Jain 237463c39b
Merge pull request #25800 from woocommerce/fix/25748
Fixes tax rounding issues
2020-04-07 00:24:34 +05:30
Néstor Soriano 13765d9e91
Merge pull request #25092 from leanzafrancesco/fix/25091
Fix/25091 - Wrong totals in orders with taxable and non-taxable products and percentage coupons
2020-04-06 12:31:07 +02:00
Rodrigo Primo e40ddc5291
Merge pull request #25727 from leanzafrancesco/add/order-tax-location-filter
Add woocommerce_order_get_tax_location filter
2020-03-05 13:48:40 -03:00
vedanshujain a0c209193b Remove rounding because individual lines would already have been rounded at this point if needed. 2020-03-02 15:19:16 +05:30
vedanshujain 740e2c8a92 Treat individual tax totals as line items because they will be totalled later.
This means that we won't round them individually unless we have setting for round at line item enabled.
2020-03-02 15:19:16 +05:30
vedanshujain 48e63adf77 Make rounding methods consistent in orders and cart 2020-03-02 15:19:16 +05:30
Peter Fabian 150c77ba29 Improve coupon name output handling. 2020-02-26 12:24:04 +01:00
Francesco Leanza 5dfb618ff9 Add woocommerce_order_get_tax_location filter 2020-02-21 11:45:06 +01:00
Peter Fabian 147266f44f Updates to reflect PR feedback. 2020-02-04 21:43:29 +01:00
Peter Fabian 248e69960b Merge branch 'master' into update/order-detail-summary 2020-01-30 17:41:32 +01:00
Peter Fabian ec8d477b09 PHPCS fix. 2020-01-30 17:09:33 +01:00
David Levin d25178b793 rename fee method again 2019-12-18 22:19:34 -08:00
Matt Harvey 4326e39250 Leave other fee total logic alone, reduce the fee array to get a simple sum 2019-12-18 22:08:39 -08:00
Matt Harvey 4eeec4705d Abstract fee calculation and expose as method to abstract Object class. 2019-12-18 20:58:39 -08:00
vedanshujain 72545c44b7 Add support for `_held_for_checkout` records to improve performance.
This will also improve transactional stability and avoid race conditions by providing a way to lock usage counts.
2019-12-17 19:13:19 +05:30
Francesco Leanza 59af851069
Merge branch 'master' into fix/25091 2019-12-09 16:46:02 +01:00
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 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
Francesco Leanza dd3427958b Fixed order totals calculation if it contains taxable and non-taxable products and percentage coupons
Added PHPUnit tests
2019-11-21 11:28:22 +01:00
Vedanshu Jain 9641963001
Merge pull request #24740 from woocommerce/feature/24654
Make WC_Abstract_Order::recalculate_coupons() public
2019-10-02 15:56:36 +05:30
Claudio Sanches 8c88cd9b6f Make WC_Abstract_Order::recalculate_coupons() public 2019-10-01 17:19:33 -03:00
vedanshujain 6f2d64dcb4 Check for max discount to be -ve to prevent overwriting fee.
When we refund fee and some other line item whose value is more than fee in a single requst, value of line item will overwrite refund fee.

This is because where we check to make sure that we do not discount more than total possible value (to prevent negative total), we do not account for the fact that sometimes the cart could contain refund items. In those cases max_discount * -1 will always be larges then fees total.

This commit adds a check to make sure that max discount * -1 is indeed negative before overwriting fee total.
2019-09-03 20:45:33 +05:30
Claudio Sanches 01f5a09d27
Merge pull request #23338 from woocommerce/update/23335
More useful actions in during CRUD save events
2019-07-08 18:56:14 -03:00
Jared Burke 332c94c13a Fix fatal error when applying a virtual coupon to an order placed by a guest 2019-06-06 15:37:08 -05:00
Ajay Ghaghretiya c9bcce3a31 #23850 Fixed the coupon usage limit issue when apply coupon from admin panel (#23851)
* fix the coupon usage limit issue

* fix the if condition for the usage limit

* fixed coding standard

* fix the if conditions for coupon usage limit per user
2019-06-03 10:47:32 -03:00
Gerhard Potgieter b2ed079520 Manual orders coupon usage limits by email (#23775)
* Add functionality to wp-admin order to check for coupon usage based on email addresses, similar to how WC_Cart handles this seperately, included unit tests.

* Only do the coupon by email usage check if order is from a guest. Fix issue with unit test.
2019-05-27 11:45:29 -03:00
Claudio Sanches 28d49031d3
Merge pull request #23695 from james-allan/calc-base-zip-city
Calculate base store taxes including the store's zip and city
2019-05-22 20:49:57 -03:00
Boris Djemrovski c45e06a130 get_formatted_line_subtotal takes Item object instead of an array 2019-05-16 12:04:34 +02:00
Gerhard Potgieter 30ce9ff6a3
Merge pull request #23689 from woocommerce/add/get_used_coupon_codes
Deprecate get_used_coupons in favor of get_coupon_codes
2019-05-15 15:34:40 +02:00
James Allan 6069854d9f Replace wc_get_base_location() with individual getters 2019-05-15 15:43:15 +10:00
Gerhard Potgieter b7facc0674
Merge pull request #23663 from danielbitzer/add_get_coupons_method
Add WC_Abstract_Order::get_coupons()
2019-05-14 11:35:21 +02:00
Gerhard efe3e4c5d6 Move get_used_coupons to WC_Abstract_Legacy_Order and renamed get_used_coupon_codes to get_coupon_codes. 2019-05-14 11:19:48 +02:00