[WIP] Add support for syncing the "Mark as Sold Out" field value during inventory sync. #277
+93
−32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
As mentioned in #21, on the Square side, we can mark an inventory-tracking-disabled product as "Out of Stock" using the "Mark as Sold Out on Point of Sale and Online" option. However, currently, when inventory tracking is disabled for a product in Square, it always updates the stock status to "In Stock," regardless of the value of the
sold_out
field.This PR adds support for the
sold_out
field, ensuring it is considered during inventory sync and updating the stock status to "Out of Stock" whenever a product is marked as sold on the Square side while inventory tracking is disabled.Notes
The
sold_out
field is read-only, so using API we can't mark Square products as sold out while keeping inventory tracking disabled. The closest alternative is to mark the product as sold out with inventory tracking enabled. This means enabling inventory tracking and setting the stock value to0
, which will reflect on the WooCommerce side as well since stock levels are pulled from Square during inventory sync.When we mark an item as sold out, Square allows us to set a time for it to become available again. At that time, it will automatically be marked as in stock. I didn’t add support for this in this PR, as we already have a sync running every 15 minutes (interval polling). The product will become available within 15 minutes once it is marked as available on the Square side, which I think is acceptable. @dkotter, please let me know if you think we should sync this in real time. We could schedule an Action Scheduler task for the specific availability time, but if the number of products is high, this would increase the number of scheduled actions. Since 15 minutes is a relatively short interval, it should be fine for now. However, we can consider implementing real-time syncing if we receive customer requests for it.
Closes #21
Steps to test the changes in this Pull Request:
Square SOR:
WooCommerce
>Settings
>Square
>Update
. Click the Sync button and wait for the sync process to complete.Tools
>Scheduled Actions
by manually running thewc_square_sync
action.Woo SOR:
0
.Changelog entry