Repository: saleor/saleor

Issue:
Migrate from `deprecated` fields
Some GraphQL fields were recently deprecated in our API:
- OrderLine.thumbnailUrl
- Page.availableOn
- Page.isVisible
- ProductVariant.availability
- Product.availability -> pricing
- Product.availableOn
- Product.price
- Product.thumbnailUrl
- Collection.publishedDate

We should migrate queries in Dashboard 2.0 to use the new fields, so that we'll be able to drop the old ones from the schema.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -270,7 +270,11 @@ class ProductInput(graphene.InputObjectType):
         description="Determines if product is visible to customers."
     )
     name = graphene.String(description="Product name.")
-    price = Decimal(description="Product price.")
+    price = Decimal(
+        description="""
+        Product price. Note: this field is deprecated, use basePrice instead."""
+    )
+    base_price = Decimal(description="Product price.")
     tax_rate = TaxRateType(description="Tax rate.")
     seo = SeoInput(description="Search engine optimization fields.")
     weight = WeightScalar(description="Weight of the Product.", required=False)
@@ -323,6 +327,12 @@ def clean_input(cls, info, instance, data):
             instance.product_type if instance.pk else cleaned_input.get("product_type")
         )
 
+        # Try to get price from "basePrice" or "price" field. Once "price" is removed
+        # from the schema, only "basePrice" should be used here.
+        price = data.get("base_price", data.get("price"))
+        if price is not None:
+            cleaned_input["price"] = price
+
         if attributes and product_type:
             qs = product_type.product_attributes.prefetch_related("values")
             try:
diff --git a/saleor/product/models.py b/saleor/product/models.py
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -279,7 +279,11 @@ def check_quantity(self, quantity):
 
     @property
     def base_price(self):
-        return self.price_override or self.product.price
+        return (
+            self.price_override
+            if self.price_override is not None
+            else self.product.price
+        )
 
     def get_price(self, discounts=None, taxes=None):
         price = calculate_discounted_price(self.product, self.base_price, discounts)


Test patch:
diff --git a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
--- a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
+++ b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
@@ -57380,7 +57380,7 @@ Ctrl + K"
                       />
                       <input
                         class="MuiPrivateSwitchBase-input-id"
-                        name="isVisible"
+                        name="isPublished"
                         type="checkbox"
                       />
                     </span>
@@ -57417,7 +57417,7 @@ Ctrl + K"
                   <input
                     aria-invalid="false"
                     class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id"
-                    name="availableOn"
+                    name="publicationDate"
                     type="date"
                     value=""
                   />
@@ -58116,7 +58116,7 @@ Ctrl + K"
                       />
                       <input
                         class="MuiPrivateSwitchBase-input-id"
-                        name="isVisible"
+                        name="isPublished"
                         type="checkbox"
                       />
                     </span>
@@ -58153,7 +58153,7 @@ Ctrl + K"
                   <input
                     aria-invalid="true"
                     class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id"
-                    name="availableOn"
+                    name="publicationDate"
                     type="date"
                     value=""
                   />
@@ -58692,7 +58692,7 @@ Ctrl + K"
                       <input
                         class="MuiPrivateSwitchBase-input-id"
                         disabled=""
-                        name="isVisible"
+                        name="isPublished"
                         type="checkbox"
                       />
                     </span>
@@ -58730,7 +58730,7 @@ Ctrl + K"
                     aria-invalid="false"
                     class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-disabled-id MuiFilledInput-disabled-id MuiInputBase-inputType-id"
                     disabled=""
-                    name="availableOn"
+                    name="publicationDate"
                     type="date"
                     value=""
                   />
@@ -61662,7 +61662,7 @@ Ctrl + K"
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-disabled-id MuiFilledInput-disabled-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
                       disabled=""
-                      name="price"
+                      name="basePrice"
                       type="number"
                       value="0"
                     />
@@ -62492,7 +62492,7 @@ Ctrl + K"
                     <input
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
-                      name="price"
+                      name="basePrice"
                       type="number"
                       value="0"
                     />
@@ -63321,7 +63321,7 @@ Ctrl + K"
                     <input
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
-                      name="price"
+                      name="basePrice"
                       type="number"
                       value="0"
                     />
@@ -65701,7 +65701,7 @@ Ctrl + K"
                     <input
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
-                      name="price"
+                      name="basePrice"
                       type="number"
                       value="339.39"
                     />
@@ -66820,7 +66820,7 @@ Ctrl + K"
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-disabled-id MuiFilledInput-disabled-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
                       disabled=""
-                      name="price"
+                      name="basePrice"
                       type="number"
                     />
                     <span />
@@ -67887,7 +67887,7 @@ Ctrl + K"
                     <input
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
-                      name="price"
+                      name="basePrice"
                       type="number"
                       value="339.39"
                     />
@@ -69291,7 +69291,7 @@ Ctrl + K"
                     <input
                       aria-invalid="false"
                       class="MuiInputBase-input-id MuiFilledInput-input-id MuiInputBase-inputType-id MuiInputBase-inputAdornedEnd-id MuiFilledInput-inputAdornedEnd-id"
-                      name="price"
+                      name="basePrice"
                       type="number"
                       value="339.39"
                     />
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -146,9 +146,6 @@ def test_product_query(staff_api_client, product, permission_manage_products):
                             stockQuantity
                         }
                         isAvailable
-                        price {
-                            amount
-                        }
                         pricing {
                             available,
                             priceRange {
@@ -205,7 +202,6 @@ def test_product_query(staff_api_client, product, permission_manage_products):
     assert purchase_cost.stop.amount == product_data["purchaseCost"]["stop"]["amount"]
     assert product_data["isAvailable"] is product.is_visible
     assert product_data["pricing"]["available"] is product.is_visible
-    assert product_data["price"]["amount"] == product.price.amount
     assert margin[0] == product_data["margin"]["start"]
     assert margin[1] == product_data["margin"]["stop"]
 
@@ -679,7 +675,7 @@ def test_create_product(
             $isPublished: Boolean!,
             $chargeTaxes: Boolean!,
             $taxRate: TaxRateType!,
-            $price: Decimal!,
+            $basePrice: Decimal!,
             $attributes: [AttributeValueInput!]) {
                 productCreate(
                     input: {
@@ -691,7 +687,7 @@ def test_create_product(
                         isPublished: $isPublished,
                         chargeTaxes: $chargeTaxes,
                         taxRate: $taxRate,
-                        price: $price,
+                        basePrice: $basePrice,
                         attributes: $attributes
                     }) {
                         product {
@@ -704,7 +700,7 @@ def test_create_product(
                             chargeTaxes
                             taxRate
                             name
-                            price {
+                            basePrice {
                                 amount
                             }
                             productType {
@@ -757,7 +753,7 @@ def test_create_product(
         "isPublished": product_is_published,
         "chargeTaxes": product_charge_taxes,
         "taxRate": product_tax_rate,
-        "price": product_price,
+        "basePrice": product_price,
         "attributes": [
             {"slug": color_attr_slug, "value": color_value_slug},
             {"slug": size_attr_slug, "value": non_existent_attr_value},
@@ -792,7 +788,7 @@ def test_create_product(
         $categoryId: ID!
         $name: String!,
         $description: String!,
-        $price: Decimal!,
+        $basePrice: Decimal!,
         $sku: String,
         $quantity: Int,
         $trackInventory: Boolean)
@@ -803,7 +799,7 @@ def test_create_product(
                 productType: $productTypeId,
                 name: $name,
                 description: $description,
-                price: $price,
+                basePrice: $basePrice,
                 sku: $sku,
                 quantity: $quantity,
                 trackInventory: $trackInventory
@@ -854,7 +850,7 @@ def test_create_product_without_variants(
         "categoryId": category_id,
         "name": product_name,
         "description": product_description,
-        "price": product_price,
+        "basePrice": product_price,
         "sku": sku,
         "quantity": quantity,
         "trackInventory": track_inventory,
@@ -893,7 +889,7 @@ def test_create_product_without_variants_sku_validation(
         "categoryId": category_id,
         "name": product_name,
         "description": product_description,
-        "price": product_price,
+        "basePrice": product_price,
         "sku": None,
         "quantity": quantity,
         "trackInventory": track_inventory,
@@ -932,7 +928,7 @@ def test_create_product_without_variants_sku_duplication(
         "categoryId": category_id,
         "name": product_name,
         "description": product_description,
-        "price": product_price,
+        "basePrice": product_price,
         "sku": sku,
         "quantity": quantity,
         "trackInventory": track_inventory,
@@ -954,7 +950,7 @@ def test_product_create_without_product_type(
     mutation createProduct($categoryId: ID!) {
         productCreate(input: {
                 name: "Product",
-                price: "2.5",
+                basePrice: "2.5",
                 productType: "",
                 category: $categoryId}) {
             product {
@@ -994,7 +990,7 @@ def test_update_product(
             $isPublished: Boolean!,
             $chargeTaxes: Boolean!,
             $taxRate: TaxRateType!,
-            $price: Decimal!,
+            $basePrice: Decimal!,
             $attributes: [AttributeValueInput!]) {
                 productUpdate(
                     id: $productId,
@@ -1005,7 +1001,7 @@ def test_update_product(
                         isPublished: $isPublished,
                         chargeTaxes: $chargeTaxes,
                         taxRate: $taxRate,
-                        price: $price,
+                        basePrice: $basePrice,
                         attributes: $attributes
                     }) {
                         product {
@@ -1017,7 +1013,7 @@ def test_update_product(
                             chargeTaxes
                             taxRate
                             name
-                            price {
+                            basePrice {
                                 amount
                             }
                             productType {
@@ -1056,7 +1052,7 @@ def test_update_product(
         "isPublished": product_isPublished,
         "chargeTaxes": product_chargeTaxes,
         "taxRate": product_taxRate,
-        "price": product_price,
+        "basePrice": product_price,
     }
 
     response = staff_api_client.post_graphql(
@@ -1860,8 +1856,12 @@ def test_product_variant_price(
         query getProductVariants($id: ID!) {
             product(id: $id) {
                 variants {
-                    price {
-                        amount
+                    pricing {
+                        priceUndiscounted {
+                            gross {
+                                amount
+                            }
+                        }
                     }
                 }
             }
@@ -1872,7 +1872,7 @@ def test_product_variant_price(
     response = user_api_client.post_graphql(query, variables)
     content = get_graphql_content(response)
     data = content["data"]["product"]
-    variant_price = data["variants"][0]["price"]
+    variant_price = data["variants"][0]["pricing"]["priceUndiscounted"]["gross"]
     assert variant_price["amount"] == api_variant_price
 
 
diff --git a/tests/test_product.py b/tests/test_product.py
--- a/tests/test_product.py
+++ b/tests/test_product.py
@@ -638,11 +638,12 @@ def test_product_get_price_range_do_not_charge_taxes(
     assert price == TaxedMoneyRange(start=expected_price, stop=expected_price)
 
 
-def test_variant_base_price(product):
+@pytest.mark.parametrize("price_override", ["15.00", "0.00"])
+def test_variant_base_price(product, price_override):
     variant = product.variants.get()
     assert variant.base_price == product.price
 
-    variant.price_override = Money("15.00", "USD")
+    variant.price_override = Money(price_override, "USD")
     variant.save()
 
     assert variant.base_price == variant.price_override