Commit Graph

70 Commits

Author SHA1 Message Date
Nestor Soriano d214eab157
Use int cast instead of intval in wc_get_low_stock_amount 2021-04-20 16:35:42 +02:00
Nestor Soriano 76a613a5bb
Modify wc_get_low_stock_amount so that it always returns an integer.
Previously, if the product didn't have an explicit low stock value
amount the value of the woocommerce_notify_low_stock_amount option,
which is a string, was returned verbatim.

Also, update related unit tests to create the option value as a string,
and to check that the value returned by woocommerce_notify_low_stock_amount
is always an integer.
2021-04-20 10:17:50 +02:00
Nestor Soriano 1008835488
Fix code sniffer violations in stock functions and its tests 2021-04-20 09:42:07 +02:00
Peter Fabian aa9b6ab691 Change got merged sooner than expected. 2021-03-17 10:13:28 +01:00
Peter Fabian e6cdd74a79 Add parent's default for low stock if notthing is set on individual variation.
I.e. use variation low stock amount value, if not available, use parent product's value, if not available, use the store-wide default.
2021-03-15 18:31:31 +01:00
Peter Fabian aac4ecc943 Added comment documenting the history of the function. 2021-03-11 16:58:51 +01:00
Peter Fabian e2e589b049 Don't take the low stock amount info from the parent of the variation, but the variation itself.
Potentially bw incompatible.
2021-03-10 17:57:56 +01:00
pjv 73ccb72acc fix whitespace 2020-10-02 08:22:33 -05:00
pjv ff9a3f2e1e Add before set stock action
Add product and variation `before_set_stock` actions to allow 3rd party plugins to snapshot a product’s stock quantity before it is updated.
2020-09-01 14:37:02 -05:00
Claudio Sanches 02cf0dfaed
Merge pull request #27239 from woocommerce/fix/package-tag
Fix usage of "package" tag in file headers
2020-08-07 13:37:24 -03:00
Claudio Sanches 2d2e40c484 Applied woocommerce_order_item_quantity to ReserveStock 2020-08-06 14:15:50 -03:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
Claudio Sanches 1194225d71
Merge pull request #26503 from Knyazevich/origin/fix/wc_update_product_stock_status-phpdoc
Fix parameter type and add an empty line in wc_update_product_stock_s…
2020-07-01 13:21:21 -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
vedanshujain b8a1a69b2b Updated annotations to 4.3 2020-06-15 18:55:00 +05:30
Vedanshu Jain b45373fe0c Revert "Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout"" 2020-06-05 15:18:01 +05:30
Knyazevich 9458730a1c Fix parameter type and add an empty line in wc_update_product_stock_status 2020-05-14 03:36:13 +03:00
Vedanshu Jain ee119e0a7e
Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout" 2020-04-21 15:37:21 +05:30
Mike Jolley 1acae4ef92 woocommerce_payment_complete priority 2020-04-03 15:58:59 +01:00
Mike Jolley f248902454 Update versions 2020-04-03 15:56:43 +01:00
Mike Jolley 4faea42c23 Change priorities 2020-04-03 15:55:15 +01:00
Mike Jolley e965f854d6 Missing class name 2020-04-03 15:55:15 +01:00
Mike Jolley c983677a6f Implement stock functions 2020-04-03 15:55:15 +01:00
vedanshujain 3bd34184e4 Fixed bool error on when to disable feature 2020-04-03 15:55:14 +01:00
Claudio Sanches 2ebd86f2dc Revert "Revert "Add support for '_held_for_checkout` records to prevent race conditions."" 2020-04-03 15:55:13 +01:00
Rodrigo Primo 62d6b05b58 Fix Generic.Formatting.MultipleStatementAlignment violations
This commit fixes all violations of the Generic.Formatting.MultipleStatementAlignment sniff automatically using phpcbf.
2019-12-20 14:21:08 -03:00
Claudio Sanches a12c25862b
Revert "Add support for '_held_for_checkout` records to prevent race conditions." 2019-12-04 16:03:05 -03:00
Claudio Sanches 988b72e461 Updated filter name to woocommerce_hold_stock_for_checkout
Also fixed coding standards
2019-12-03 16:38:17 -03:00
vedanshujain e87024bb81 Add support for '_held_for_checkout` records to prevent race conditions.
When creating an order, if manage inventory is enabled then add a `_held_for_checkout` record with a expiry timestamp embedded. This is added in an atomic manner along with making a check whether we have current stock or not.
This record is removed when order status goes to either `processing` or `completed`.
2019-11-21 01:21:08 +05:30
Sören Schwert c22fcfd98f
Correct comments in stock increase methods
Fixes some comments and a variable name in the stock increase methods.

There is however a logic problem remaining, I think, where the value taken for the per-item `_reduced_stock` meta value falls back to `true` when the meta key does not exists (line 266), however the key is deleted at the end of the loop (line 281), thus allowing the `wc_increase_stock_levels` methods to increase the stock again when re-run directly.
2019-09-27 11:28:46 +02:00
Chris Eich 354b248b28
Only count orders created via checkout in held stock qty
Plugins may create orders without the meta tag "_created_via"="checkout" for various purposes, e.g. a balance-due order for purchases via deposit, because only the deposit order should reduce stock on checkout. The SUMO Payment Plans plugin does exactly this, but core WC handles such orders inconsistently:
- wc_get_held_stock_quantity() counts their items against held stock, but
- wc_cancel_unpaid_orders() only cancels old orders with a meta tag of "_created_via"="checkout"

This PR fixes that inconsistency, which on my site was preventing a user from adding an in-stock product to her cart, just because a balance-due order for the same product was pending.

Workaround: clear the setting WC > Products > Inventory > Hold Time (default 60 minutes), which inhibits the use of wc_get_held_stock_quantity().
2019-07-15 21:59:02 -07:00
Peter Fabian 1d29b36c4c Removed comments that are no longer relevant. 2019-05-15 15:46:53 +02:00
Peter Fabian 35c63ee475 Added some comments to hopefully make the function a bit clearer. 2019-05-02 20:19:28 +02:00
Mike Jolley 1a1b3e7654 Improved wc_update_product_stock
Allow product object to be passed through, remove cache clearing which is done during save(), and allow the caller to define whether or not an update routine is already in progress.
2019-04-26 17:20:50 +01:00
Mike Jolley 0cd429dad9 Avoid post update in wc_update_product_stock 2019-04-09 12:47:51 +01:00
Mike Jolley 600510ea6f Using wrong post type name in comparison 2019-02-04 13:56:35 +00:00
Gerhard a3f3b282ac Initialise $changes before usage. 2018-11-15 14:36:56 +02:00
Joey Gilham 58cdd7dad2
Merge branch 'master' into master 2018-07-03 15:41:15 +01:00
Joey 4e0412e0d8 removed redundant trigger for low stock notifications 2018-07-03 14:48:53 +01:00
Joey 375ef48186 updated wc_get_low_stock_amount function 2018-07-03 14:42:58 +01:00
Joey cd8416122f removed low stock options for variations, and addressed changes 2018-06-19 12:40:27 +01:00
Mike Jolley e92463632b Held stock qty check for pay page 2018-06-08 16:58:33 +01:00
Mike Jolley d76474789d variable name 2018-06-08 16:30:58 +01:00
Mike Jolley 52854b7690 Add qty to order via modal, include stock qty in formatted name display for reference 2018-06-08 16:18:32 +01:00
Mike Jolley 8084100cbb Tweak meta naming and order notes 2018-06-08 12:18:33 +01:00
Mike Jolley 2657db4a97 Pending should restore stock too 2018-06-07 17:42:58 +01:00
Mike Jolley 70c9cff608 Increase/decrease stock handling 2018-06-07 17:41:36 +01:00
Joey e5800b66b0 updated low_stock_amount fields to use global value if no value is entered 2018-05-27 06:43:23 +01:00
Joey 5f36ba44cd variable product confirmed before processing low stock notifications in function 'wc_update_product_stock' 2018-05-27 05:49:01 +01:00
Joey b08b55a651 added changes for low stock notifications per product 2018-05-27 05:40:58 +01:00