-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-16325 Publish product during the seeding process #159
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
albertsola
merged 1 commit into
main
from
MPT-16325-Product-listing-seeding-fail-due-to-product-not-being-published
Dec 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ async def seed_product() -> None: | |
| """Seed product data.""" | ||
| logger.debug("Seeding catalog.product ...") | ||
| await init_resource("catalog.product.id", create_product) | ||
| await publish_product() | ||
| await init_resource("catalog.unit.id", create_unit_of_measure) | ||
| await init_resource("catalog.product.item_group.id", create_item_group) | ||
| await init_resource("catalog.product.item.id", create_product_item) | ||
|
|
@@ -50,6 +51,23 @@ async def seed_product() -> None: | |
| logger.debug("Seeded catalog.product completed.") | ||
|
|
||
|
|
||
| @inject | ||
| async def publish_product( | ||
| context: Context = Provide[Container.context], | ||
| mpt_vendor: AsyncMPTClient = Provide[Container.mpt_vendor], | ||
| mpt_operations: AsyncMPTClient = Provide[Container.mpt_operations], | ||
| ) -> None: | ||
| """Publish product.""" | ||
| product_id = require_context_id(context, "catalog.product.id", "publish product") | ||
| product = await mpt_vendor.catalog.products.get(product_id) | ||
| if product.status == "Draft": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use a Enum for those statuses? |
||
| product = await mpt_vendor.catalog.products.review(product_id) | ||
| if product.status in {"Pending", "Unpublished"}: | ||
| product = await mpt_operations.catalog.products.publish(product_id) | ||
| if product.status != "Published": | ||
| raise RuntimeError(f"Product {product_id} is not published") | ||
|
|
||
albertsola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @inject | ||
| async def create_terms_variant( | ||
| context: Context = Provide[Container.context], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use an ActionEnum instead of passing a str? It would avoid having different str for the same action, I can see different patterns like starting with uppercase and other with lowercase