Commit Graph

1565 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
Nestor Soriano 039f81ea50
Implement the product attributes lookup table data creation.
Lookup entries for a product or a variation are created whenever
the product is created, including untrashing and duplication
(not yet when an existing product is modified).
2021-06-08 17:53:45 +02:00
Nestor Soriano e54ff461f9
Implement the product attributes lookup table data deletion.
Lookup entries for a product or a variation are deleted whenever
the product is deleted or trashed.
2021-06-07 16:54:08 +02:00
Nestor Soriano f237642af4
Refactor save method in WC_Product and WC_Product_Variable
The 'save' method in WC_Product_Variable was almost identical
to the parent method in WC_Product, only adding a few bits
of extra processing before and after the actual datastore save.
This commit adds a couple of protected methods,
before_data_store_save_or_update and after_data_store_save_or_update,
and implements them in WC_Product_Variable so that the extra
'save' method in WC_Product_Variable can be removed.
2021-06-04 12:21:29 +02:00
Michael P. Pfeiffer 3e36432d94 Widgets: show instance in Rest API 2021-05-31 12:20:57 +02:00
Claudio Sanches 855f48d53b
Merge pull request #29314 from woocommerce/fix/prevent-missing-order-error
Return 0 if order isn't available in WC_Payment_Gateway::get_order_total
2021-04-06 17:06:54 -03:00
Claudio Sanches 1c40a28409
Merge pull request #29145 from mariovalney/patch-1
Add the support to optgroups in single select on Settings API
2021-04-01 19:08:43 -03:00
James Allan 09b5fb4691 Update the rate when recalculating and updating order tax items 2021-03-30 22:27:11 -03:00
Claudio Sanches f6b4614225 Return 0 if order isn't available 2021-03-09 16:57:08 -03:00
Saggre 24167a5eed Fix typos in docs 2021-03-05 11:19:58 +02:00
Mário Valney 323fc32959
Added esc_attr to selected like before 2021-02-16 15:01:07 -03:00
Mário Valney 9a8cbfbd73
Support to optgroups on select from Settings API
Add the optgroups support to single select from Settings API.
The multiselect input already has this feature.
2021-02-16 14:49:25 -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
Viktor Szépe ac3acc3df0
Fix CS 2020-11-20 18:53:39 +01:00
Viktor Szépe 996fb293a8
Fix types in WC_Payment_Gateway 2020-11-20 18:37:45 +01: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
vedanshujain 6ed8ffe850 Addressed PR review comments #27734 2020-11-10 14:23:45 +05:30
vedanshujain eeb8851717 Minor fixups for PR #27734 2020-11-10 14:23:44 +05:30
vedanshujain bb1e2f44ae Removed/reverted more unnecessary changes. 2020-11-10 14:23:43 +05:30
vedanshujain a5fb3178f0 Drop CacheHydration class and do it directly.
Primary reason for dropping the cache hydration is that seems like we can acheive the same results without it, so no need to add this additional complexity to our code.
2020-11-10 14:23:43 +05:30
vedanshujain f5d0275786 Refactor methods to break down into smaller units for re-usability.
This commit breaks down `read_meta_data` so that individual methods for cache key and setting raw meta data can be reused.

Also adds set_meta_data_from_raw_data to initialize metadata from manual cache.
2020-11-10 14:23:39 +05:30
Roy Ho 5007d17596
Merge pull request #27514 from helgatheviking/has_options
Add woocommerce_product_has_options filter to has_options() method
2020-10-27 09:48:26 -07: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
Kathy Daring 0db54ecec3 Add woocommerce_product_has_options filter 2020-08-28 12:01:11 -06:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
Nestor Soriano c074f085cc Remove two phpcs:ignores, improve code instead 2020-07-28 08:55:55 +02:00
Nestor Soriano 50e8f27bc7 Fix visibility of variable products with layered nav filtering.
The layered nav filtering doesn't work well with variable products
when some variations have stock and other don't. When a term is
selected in the widget, a variable product having no stock for
the variation corresponding to that term but having stock for
other variations will be displayed, but it shouldn't.

This commit fixes that by introducing two changes:

- A new override of "is_visible" for WC_Product_Variable that
  looks at the supplied filters, compares them against the corresponding
  available variations and calculates the visibility based on
  the query type (OR or AND).

- A hook on the "found_posts" filter in WC_Query, that adjusts
  the posts count based on the found products visibility
  when there are filters available; this is needed to sync the
  "displaying X posts" messages and the paging when variable
  products are hidden due to stock status.

Additionally, the visibility calculated in "found_posts" is cached
as loop variables so that it isn't calculated again when actually
displaying the products.
2020-07-28 08:55:52 +02:00
Nestor Soriano c27283dffe Fix code sniffer errors in some files.
Fixed files:

includes/abstracts/abstract-wc-product.php
includes/class-wc-query.php
includes/wc-template-functions.php
includes/widgets/class-wc-widget-layered-nav.php
templates/loop/result-count.php
tests/unit-tests/util/class-wc-tests-wc-query.php
2020-07-28 08:47:29 +02: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
Claudio Sanches 32a3d29bd9
Merge pull request #26798 from danielmorell/patch-1
Fixed wc_get_order function name in doc block
2020-07-01 12:37:06 -03:00
Nestor Soriano 9aa3c54bd9 Fix variable product stock status not being properly set on save
When a product is saved its validate_props method is invoked,
and this recalculates the stock_status property based on whether
the product manages stock or not, the stock quantity, and the
value of the woocommerce_notify_no_stock_amount option.

In the case of variable products, and when stock is managed, the stock
was set to "instock" when the current stock was enough, but only
if the "stock_quantity" property was in the list of changed properties
for the object (the method in the base product class doen't check
for changed properties). This is a problem because the
wc_update_product_stock function updates stock_quantity but via direct
database modification, and thus stock_quantity isn't considered
modified. Therefore stock modifications via wc_update_product_stock
don't update stock_status on the product (e.g. when going from 0 to 1
after a refund the stock status will remain as "outofstock").

The fix consists of removing the check for changed properties since
it's not done anyway in the other cases (when stock is below the
woocommerce_notify_no_stock_amount threshold) nor in the base class.

Also, validate_props is refactored for readabiliyy, and an useless
set_stock_status() call placed right before save()
in wc_update_product_stock is removed.
2020-06-29 14:32:17 +02:00
Néstor Soriano 7b3e902952
Merge pull request #26629 from woocommerce/fix/25552
Schedule a deferred product sync for products with parent on delete.
2020-06-29 14:15:10 +02:00
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
Peter Fabian 14a26aca2c Update min files and selectWoo 2020-06-16 17:15:12 +02:00
Nestor Soriano b43679c181 Schedule a deferred product sync for products with parent on delete.
Right now, when a product having a parent (e.g. a variation having a
parent variable product) is saved, wc_deferred_product_sync is
executed so that product sync is performed at the end of the request.
This commit implements the same when the product is deleted.
2020-05-28 14:07:51 +02: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