Skip to content

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

Run plugin method product_updated on variant creation / change

Tomasz Szymanski25e404999859
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 9e4ccbca6e..ec5fa2262a 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -1321,6 +1321,7 @@ class ProductVariantCreate(ModelMutation):
AttributeAssignmentMixin.save(instance, attributes)
instance.name = generate_name_for_variant(instance)
instance.save(update_fields=["name"])
+ info.context.plugins.product_updated(instance.product)
@classmethod
def create_variant_stocks(cls, variant, stocks):
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
index d23c3c1c09..d13ab6d42c 100644
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -1887,7 +1887,9 @@ def test_product_create_with_collections_webhook(
get_graphql_content(response)
+@patch("saleor.plugins.manager.PluginsManager.product_updated")
def test_update_product(
+ updated_webhook_mock,
staff_api_client,
category,
non_default_category,
@@ -2025,6 +2027,8 @@ def test_update_product(
assert attributes[0]["values"][0]["name"] == "Rainbow"
assert attributes[0]["values"][0]["slug"] == "rainbow"
+ updated_webhook_mock.assert_called_once_with(product)
+
UPDATE_PRODUCT_SLUG_MUTATION = """
mutation($id: ID!, $slug: String) {
diff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.py
index cc4d0ee206..583ab0dcfd 100644
--- a/saleor/graphql/product/tests/test_variant.py
+++ b/saleor/graphql/product/tests/test_variant.py
@@ -1,4 +1,4 @@
-from unittest.mock import ANY
+from unittest.mock import ANY, patch
from uuid import uuid4
import graphene
@@ -88,8 +88,14 @@ def test_fetch_variant(
assert data["weight"]["unit"] == WeightUnitsEnum.G.name
+@patch("saleor.plugins.manager.PluginsManager.product_updated")
def test_create_variant(
- staff_api_client, product, product_type, permission_manage_products, warehouse
+ updated_webhook_mock,
+ staff_api_client,
+ product,
+ product_type,
+ permission_manage_products,
+ warehouse,
):
query = """
mutation createVariant (
@@ -196,6 +202,7 @@ def test_create_variant(
assert len(data["stocks"]) == 1
assert data["stocks"][0]["quantity"] == stocks[0]["quantity"]
assert data["stocks"][0]["warehouse"]["slug"] == warehouse.slug
+ updated_webhook_mock.assert_called_once_with(product)
def test_create_product_variant_without_price(
@@ -461,7 +468,10 @@ def test_create_product_variant_update_with_new_attributes(
assert attributes[0]["attribute"]["id"] == size_attribute_id
-def test_update_product_variant(staff_api_client, product, permission_manage_products):
+@patch("saleor.plugins.manager.PluginsManager.product_updated")
+def test_update_product_variant(
+ updated_webhook_mock, staff_api_client, product, permission_manage_products
+):
query = """
mutation updateVariant (
$id: ID!,
@@ -517,6 +527,7 @@ def test_update_product_variant(staff_api_client, product, permission_manage_pro
assert data["costPrice"]["amount"] == cost_price
assert data["price"]["amount"] == price
assert data["sku"] == sku
+ updated_webhook_mock.assert_called_once_with(product)
def test_update_product_variant_with_negative_weight(