Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Feed takes item brand from attibutes
Krzysztof Wolski9e3d74e32d1a
diff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.pyindex 77eb0f4071..fbd4f7c541 100644--- a/saleor/data_feeds/google_merchant.py+++ b/saleor/data_feeds/google_merchant.py@@ -11,7 +11,7 @@ from django.core.files.storage import default_storagefrom django.utils import sixfrom ..discount.models import Sale-from ..product.models import ProductVariant, Category+from ..product.models import Category, ProductAttribute, ProductVariantCATEGORY_SEPARATOR = ' > '@@ -31,8 +31,9 @@ def get_feed_items():items = ProductVariant.objects.all()items = items.select_related('product')items = items.prefetch_related(- 'images', 'stock', 'product__attributes', 'product__categories',- 'product__images')+ 'images', 'stock', 'product__categories',+ 'product__images', 'product__product_class__product_attributes',+ 'product__product_class__variant_attributes')return items@@ -71,13 +72,16 @@ def item_condition(item):return 'new'-def item_brand(item):+def item_brand(item, brand_attribute_pk):"""This field is required.Read more:https://support.google.com/merchants/answer/6324351?hl=en&ref_topic=6324338"""- return 'Saleor'+ brand = item.get_attribute(brand_attribute_pk)+ if brand is None:+ brand = item.product.get_attribute(brand_attribute_pk)+ return branddef item_tax(item, discounts):@@ -140,7 +144,7 @@ def item_sale_price(item, discounts):def item_attributes(item, categories, category_paths, current_site,- discounts):+ discounts, attributes_dict):product_data = {'id': item_id(item),'title': item_title(item),@@ -151,8 +155,7 @@ def item_attributes(item, categories, category_paths, current_site,'availability': item_availability(item),'google_product_category': item_google_product_category(item, category_paths),- 'link': item_link(item, current_site),- 'brand': item_brand(item)}+ 'link': item_link(item, current_site)}image_link = item_image_link(item, current_site)if image_link:@@ -168,9 +171,11 @@ def item_attributes(item, categories, category_paths, current_site,if tax:product_data['tax'] = tax- brand = item_brand(item)- if brand:- product_data['brand'] = brand+ brand_attribute_pk = attributes_dict.get('brand')+ if brand_attribute_pk:+ brand = item_brand(item, brand_attribute_pk)+ if brand:+ product_data['brand'] = brandreturn product_data@@ -184,11 +189,12 @@ def write_feed(file_obj):categories = Category.objects.all()discounts = Sale.objects.all().prefetch_related('products','categories')+ attributes_dict = {a.name: a.pk for a in ProductAttribute.objects.all()}category_paths = {}current_site = Site.objects.get_current()for item in get_feed_items():item_data = item_attributes(item, categories, category_paths,- current_site, discounts)+ current_site, discounts, attributes_dict)writer.writerow(item_data)diff --git a/tests/test_data_feeds.py b/tests/test_data_feeds.pyindex 428c3b1b88..8461cd311b 100644--- a/tests/test_data_feeds.py+++ b/tests/test_data_feeds.py@@ -24,9 +24,10 @@ def test_saleor_feed_items(product_in_stock):categories = Category.objects.all()discounts = []category_paths = {}+ attributes_dict = {}current_site = Site.objects.get_current()attributes = item_attributes(items[0], categories, category_paths,- current_site, discounts)+ current_site, discounts, attributes_dict)assert attributes.get('mpn') == valid_variant.skuassert attributes.get('availability') == 'in stock'