Skip to content

Dynamic Dashboard: Integrate new endpoint for product stock in Networking layer #12756

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

Merged
merged 14 commits into from
May 17, 2024

Conversation

itsmeichigo
Copy link
Contributor

Part of #12748

Description

This PR updates the Networking layer to integrate the new endpoint wc-analytics/reports/stock. Changes include:

  • Added a new model ProductStock.
  • Added a mapper for the stock list.
  • Updated ProductsRemote with a new method to fetch stock list.
  • Added unit tests.

Testing instructions

The endpoint hasn't been integrated yet so just CI passing is sufficient.

Screenshots

N/A


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@itsmeichigo itsmeichigo added the type: task An internally driven task. label May 16, 2024
@itsmeichigo itsmeichigo added this to the 18.7 milestone May 16, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 16, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr12756-32ceaec
Version18.6
Bundle IDcom.automattic.alpha.woocommerce
Commit32ceaec
App Center BuildWooCommerce - Prototype Builds #9105
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@itsmeichigo itsmeichigo marked this pull request as ready for review May 16, 2024 10:46
@hafizrahman hafizrahman self-assigned this May 16, 2024
Copy link
Contributor

@hafizrahman hafizrahman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 👍🏼

I think it will be useful to add a sample json and test to show how this deals with the case where plugins change the type for sku/stockQuantity, as well as the parent case for manageStock. But It's not a blocker for this PR.

struct ProductStockListMapper: Mapper {
/// Site Identifier associated to the products that will be parsed.
///
/// We're injecting this field via `JSONDecoder.userInfo` because SiteID is not returned in any of the Product Endpoints.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 TIL about getting siteID this way.

// could be returned as well (typically with variations) — we need to account for this.
// A "parent" value means that stock mgmt is turned on + managed at the parent product-level, therefore
// we need to set this var as `true` in this situation.
// See: https://github.com/woocommerce/woocommerce-ios/issues/884 for more deets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great research here as well.

let name = try container.decode(String.self, forKey: .name)

// Even though a plain install of WooCommerce Core provides String values,
// some plugins alter the field value from String to Int or Decimal.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great research to find how plugins might alter this value.

/// The card's availability state for the site.
/// To be set externally based on each card's availability check.
public let availability: AvailabilityState

/// User-changeable setting in the Customize screen, whether to enable or disable an available card.
/// An available card will become invisible on the Dashboard, but stay visible on Customize, if `enabled` is set to false.
public let enabled: Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! I had included this is one of my PRs but let's get this one first instead.

@itsmeichigo itsmeichigo modified the milestones: 18.7, 18.8 May 17, 2024
@itsmeichigo
Copy link
Contributor Author

Thanks @hafizrahman for the reviews!

I think it will be useful to add a sample json and test to show how this deals with the case where plugins change the type for sku/stockQuantity, as well as the parent case for manageStock

Good point! I added the mock responses and tests for these cases in 32ceaec.

@itsmeichigo itsmeichigo enabled auto-merge May 17, 2024 08:35
@itsmeichigo itsmeichigo merged commit 10b5254 into trunk May 17, 2024
22 checks passed
@itsmeichigo itsmeichigo deleted the feat/12748-integrate-stock-endpoint branch May 17, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants