Skip to content

Saleor Core: the high performance, composable, headless commerce API.

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.py
index 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.graphql
index e7b528342c..dc54b45335 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -3395,9 +3395,9 @@ input ProductCreateInput {
weight: WeightScalar
sku: String
trackInventory: Boolean
+ basePrice: Decimal
productType: ID!
stocks: [StockInput!]
- basePrice: Decimal
}
type ProductDelete {
@@ -3509,6 +3509,7 @@ input ProductInput {
weight: WeightScalar
sku: String
trackInventory: Boolean
+ basePrice: Decimal
}
input ProductOrder {
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 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(
descriptionJson
isPublished
chargeTaxes
+ variants {
+ price {
+ amount
+ }
+ }
taxType {
taxCode
description
@@ -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.00
product_is_published = True
product_charge_taxes = True
product_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_json
assert data["product"]["isPublished"] == product_is_published
assert data["product"]["chargeTaxes"] == product_charge_taxes
+ assert data["product"]["variants"][0]["price"]["amount"] == basePrice
assert data["product"]["taxType"]["taxCode"] == product_tax_rate
assert not data["product"]["category"]["name"] == category.name