Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add base_pirce field to update product mutation
Damian W8b6cf2ba850e
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 65eac9f1f4..da292de313 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -532,6 +532,12 @@ class ProductInput(graphene.InputObjectType):"is only used if a product doesn't use variants."))+ base_price = Decimal(+ description=(+ "Default price for product variant. "+ "Note: this field is only used if a product doesn't use variants."+ )+ )class StockInput(graphene.InputObjectType):@@ -555,7 +561,6 @@ class ProductCreateInput(ProductInput):),required=False,)- base_price = Decimal(description="Default price for product variant.",)T_INPUT_MAP = List[Tuple[models.Attribute, List[str]]]@@ -1016,6 +1021,9 @@ class ProductUpdate(ProductCreate):if "sku" in cleaned_input:variant.sku = cleaned_input["sku"]update_fields.append("sku")+ if "base_price" in cleaned_input:+ variant.price = cleaned_input["base_price"]+ update_fields.append("price")if update_fields:variant.save(update_fields=update_fields)# Recalculate the "minimal variant price"diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex e7b528342c..dc54b45335 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3395,9 +3395,9 @@ input ProductCreateInput {weight: WeightScalarsku: StringtrackInventory: Boolean+ basePrice: DecimalproductType: ID!stocks: [StockInput!]- basePrice: Decimal}type ProductDelete {@@ -3509,6 +3509,7 @@ input ProductInput {weight: WeightScalarsku: StringtrackInventory: Boolean+ basePrice: Decimal}input ProductOrder {diff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex cd73c2a816..74a8b53cd8 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -1491,6 +1491,7 @@ def test_update_product($descriptionJson: JSONString!,$isPublished: Boolean!,$chargeTaxes: Boolean!,+ $basePrice: Decimal!,$taxCode: String!,$attributes: [AttributeValueInput!]) {productUpdate(@@ -1499,6 +1500,7 @@ def test_update_product(category: $categoryId,name: $name,slug: $slug,+ basePrice: $basePrice,descriptionJson: $descriptionJson,isPublished: $isPublished,chargeTaxes: $chargeTaxes,@@ -1512,6 +1514,11 @@ def test_update_product(descriptionJsonisPublishedchargeTaxes+ variants {+ price {+ amount+ }+ }taxType {taxCodedescription@@ -1546,6 +1553,7 @@ def test_update_product(category_id = graphene.Node.to_global_id("Category", non_default_category.pk)product_name = "updated name"product_slug = "updated-product"+ basePrice = 10.00product_is_published = Trueproduct_charge_taxes = Trueproduct_tax_rate = "STANDARD"@@ -1564,6 +1572,7 @@ def test_update_product("categoryId": category_id,"name": product_name,"slug": product_slug,+ "basePrice": basePrice,"descriptionJson": other_description_json,"isPublished": product_is_published,"chargeTaxes": product_charge_taxes,@@ -1582,6 +1591,7 @@ def test_update_product(assert data["product"]["descriptionJson"] == other_description_jsonassert data["product"]["isPublished"] == product_is_publishedassert data["product"]["chargeTaxes"] == product_charge_taxes+ assert data["product"]["variants"][0]["price"]["amount"] == basePriceassert data["product"]["taxType"]["taxCode"] == product_tax_rateassert not data["product"]["category"]["name"] == category.name