Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Set different headers for product and variant attributes
IKarbowiakd9908e9c480a
diff --git a/saleor/csv/utils/products_data.py b/saleor/csv/utils/products_data.pyindex 3f97e4429f..3723e9f69b 100644--- a/saleor/csv/utils/products_data.py+++ b/saleor/csv/utils/products_data.py@@ -250,7 +250,7 @@ def prepare_attribute_products_data("value": data[attribute_fields["value"]],}result_data, attribute_header = add_attribute_info_to_data(- pk, attribute, result_data+ pk, attribute, "product attribute", result_data)if attribute_header:attributes_headers.add(attribute_header)@@ -368,7 +368,7 @@ def update_variant_data(if attribute_ids and attribute_pk in attribute_ids:result_data, attribute_header = add_attribute_info_to_data(- pk, attribute_data, result_data+ pk, attribute_data, "variant attribute", result_data)if attribute_header:variant_attributes_headers.add(attribute_header)@@ -408,6 +408,7 @@ def add_image_uris_to_data(def add_attribute_info_to_data(pk: int,attribute_data: Dict[str, Optional[Union[str]]],+ attribute_owner: str,result_data: Dict[int, dict],) -> Tuple[Dict[int, dict], Optional[str]]:"""Add info about attribute to variant or product data.@@ -420,7 +421,7 @@ def add_attribute_info_to_data(slug = attribute_data["slug"]header = Noneif slug:- header = f"{slug} (attribute)"+ header = f"{slug} ({attribute_owner})"if header in result_data[pk]:result_data[pk][header].add(attribute_data["value"]) # type: ignoreelse:diff --git a/tests/test_csv_products_data.py b/tests/test_csv_products_data.pyindex 684382c893..b26ac4ad61 100644--- a/tests/test_csv_products_data.py+++ b/tests/test_csv_products_data.py@@ -149,7 +149,7 @@ def test_prepare_products_data(product, product_with_image, collection, image):assigned_attribute = product.attributes.first()if assigned_attribute:- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (product attribute)"product_data[header] = assigned_attribute.values.first().slugexpected_headers.add(header)@@ -177,7 +177,7 @@ def test_prepare_products_data(product, product_with_image, collection, image):assigned_attribute = variant.attributes.first()if assigned_attribute:- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (variant attribute)"data[header] = assigned_attribute.values.first().slugexpected_headers.add(header)@@ -206,7 +206,7 @@ def test_prepare_products_data_for_specified_attributes(for assigned_attribute in product.attributes.all():if assigned_attribute:- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (product attribute)"if str(assigned_attribute.attribute.pk) in attribute_ids:product_data[header] = assigned_attribute.values.first().slugexpected_headers.add(header)@@ -216,7 +216,7 @@ def test_prepare_products_data_for_specified_attributes(data.update(product_data)data["sku"] = variant.skufor assigned_attribute in variant.attributes.all():- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (variant attribute)"if str(assigned_attribute.attribute.pk) in attribute_ids:data[header] = assigned_attribute.values.first().slugexpected_headers.add(header)@@ -293,7 +293,7 @@ def test_prepare_products_data_for_specified_warehouses_and_attributes(for assigned_attribute in product.attributes.all():if assigned_attribute:- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (product attribute)"if str(assigned_attribute.attribute.pk) in attribute_ids:product_data[header] = assigned_attribute.values.first().slugexpected_headers.add(header)@@ -313,7 +313,7 @@ def test_prepare_products_data_for_specified_warehouses_and_attributes(expected_headers.update(warehouse_headers)for assigned_attribute in variant.attributes.all():- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (variant attribute)"if str(assigned_attribute.attribute.pk) in attribute_ids:data[header] = assigned_attribute.values.first().slugexpected_headers.add(header)@@ -354,7 +354,7 @@ def test_prepare_products_relations_data(product_with_image, collection_list):assigned_attribute = product_with_image.attributes.first()if assigned_attribute:- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (product attribute)"expected_result[pk][header] = assigned_attribute.values.first().slugassert result == expected_result@@ -388,7 +388,7 @@ def test_prepare_variants_data(product):}assigned_attribute = variant.attributes.first()if assigned_attribute:- header = f"{assigned_attribute.attribute.slug} (attribute)"+ header = f"{assigned_attribute.attribute.slug} (variant attribute)"variant_data[header] = assigned_attribute.values.first().slugattribute_headers.add(header)@@ -476,9 +476,11 @@ def test_add_attribute_info_to_data(product):"value": value,}input_data = {pk: {}}- result, header = add_attribute_info_to_data(product.pk, attribute_data, input_data)+ result, header = add_attribute_info_to_data(+ product.pk, attribute_data, "product attribute", input_data+ )- expected_header = f"{slug} (attribute)"+ expected_header = f"{slug} (product attribute)"assert header == expected_headerassert result[pk][header] == {value}@@ -488,14 +490,16 @@ def test_add_attribute_info_to_data_update_attribute_data(product):pk = product.pkslug = "test_attribute_slug"value = "test value"- expected_header = f"{slug} (attribute)"+ expected_header = f"{slug} (variant attribute)"attribute_data = {"slug": slug,"value": value,}input_data = {pk: {expected_header: {"value1"}}}- result, header = add_attribute_info_to_data(product.pk, attribute_data, input_data)+ result, header = add_attribute_info_to_data(+ product.pk, attribute_data, "variant attribute", input_data+ )assert header == expected_headerassert result[pk][header] == {value, "value1"}@@ -508,7 +512,9 @@ def test_add_attribute_info_to_data_no_slug(product):"value": None,}input_data = {pk: {}}- result, header = add_attribute_info_to_data(product.pk, attribute_data, input_data)+ result, header = add_attribute_info_to_data(+ product.pk, attribute_data, "variant attribute", input_data+ )assert not headerassert result == input_data