@@ -38,6 +38,7 @@ async def seed_product() -> None:
3838 """Seed product data."""
3939 logger .debug ("Seeding catalog.product ..." )
4040 await init_resource ("catalog.product.id" , create_product )
41+ await publish_product ()
4142 await init_resource ("catalog.unit.id" , create_unit_of_measure )
4243 await init_resource ("catalog.product.item_group.id" , create_item_group )
4344 await init_resource ("catalog.product.item.id" , create_product_item )
@@ -50,6 +51,23 @@ async def seed_product() -> None:
5051 logger .debug ("Seeded catalog.product completed." )
5152
5253
54+ @inject
55+ async def publish_product (
56+ context : Context = Provide [Container .context ],
57+ mpt_vendor : AsyncMPTClient = Provide [Container .mpt_vendor ],
58+ mpt_operations : AsyncMPTClient = Provide [Container .mpt_operations ],
59+ ) -> None :
60+ """Publish product."""
61+ product_id = require_context_id (context , "catalog.product.id" , "publish product" )
62+ product = await mpt_vendor .catalog .products .get (product_id )
63+ if product .status == "Draft" :
64+ product = await mpt_vendor .catalog .products .review (product_id )
65+ if product .status in {"Pending" , "Unpublished" }:
66+ product = await mpt_operations .catalog .products .publish (product_id )
67+ if product .status != "Published" :
68+ raise RuntimeError (f"Product { product_id } is not published" )
69+
70+
5371@inject
5472async def create_terms_variant (
5573 context : Context = Provide [Container .context ],
0 commit comments