Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for syncing the "Mark as Sold Out" field value during inventory sync. #277

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

iamdharmesh
Copy link
Member

@iamdharmesh iamdharmesh commented Jan 29, 2025

All Submissions:

  • Does your code follow the WooCommerce Sniffs variant of WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Will this change require new documentation or changes to existing documentation?

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 to 0, which will reflect on the WooCommerce side as well since stock levels are pulled from Square during inventory sync.
    image

  • 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.
    image

Closes #21

Steps to test the changes in this Pull Request:

Square SOR:

  1. Create a product in the Square Dashboard with inventory tracking disabled and marked as "Sold out."
  2. Click "Import Products" from the Square settings in the WordPress admin.
  3. Verify that the product is imported successfully with "Manage stock" disabled and the stock status set to "Out of stock."
  4. Go to the Square Dashboard and make the product available.
  5. Go to WooCommerce > Settings > Square > Update. Click the Sync button and wait for the sync process to complete.
  6. Verify that the product is updated successfully on the WooCommerce side and that the stock status is now "In stock."
  7. Go to the Square Dashboard again and mark the product as sold out. Wait for 15 minutes or trigger an interval polling sync from Tools > Scheduled Actions by manually running the wc_square_sync action.
  8. Verify that the product's stock status has been updated to "Out of stock."
  9. In the Square Dashboard, set time to make a product for sale again to the future time (2–3 minutes ahead). Once the product becomes available in Square, wait for 15 minutes or manually trigger an interval poll sync.
  10. Verify that the product's stock status has been updated to "In stock."

Woo SOR:

  1. Create a product in WooCommerce with "Manage stock" disabled and the stock status set to "Out of stock."
  2. Verify that the product is created on the Square side with inventory tracking enabled and stock set to 0.
  3. Follow steps 3 to 10 from Square SOR and ensure the sync works as expected.

Changelog entry

Add - Support for syncing the "Mark as Sold Out" field value during inventory sync.

@dkotter
Copy link
Contributor

dkotter commented Feb 3, 2025

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

I think I agree, this is fine for the initial implementation as long as we document this. If we get customer requests to change this, we can look into that at that point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Inventory Sync] Sync the "Mark as sold out" field value during inventory sync.
3 participants