Skip to content

Commit

Permalink
Add brand field docs and getter
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofwolski committed Dec 22, 2016
1 parent 9e3d74e commit 05aa02c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/integrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ To generate feed use command:
$ python manage.py update_feeds
It's recommended to run this command periodically.
It's recommended to run this command periodically.

Merchant Center has few country dependent settings, so please validate your feed at Google dashboard. You can also specify there your shipping cost, which is required feed parameter in many countries. More info be found at `Google Support pages <https://support.google.com/merchants>`_.

One of required by Google fields is *brand* attribute. Feed generator checks for it in variant attribute named *brand* or *publisher* (if not, checks in product).

Feed can be downloaded from url: ``http://<yourserver>/feeds/google/``


Expand Down
28 changes: 18 additions & 10 deletions saleor/data_feeds/google_merchant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import gzip
import csv
from os import path

from django.conf import settings
from django.contrib.sites.models import Site
Expand Down Expand Up @@ -72,15 +71,26 @@ def item_condition(item):
return 'new'


def item_brand(item, brand_attribute_pk):
def item_brand(item, attributes_dict):
"""
This field is required.
Read more:
https://support.google.com/merchants/answer/6324351?hl=en&ref_topic=6324338
"""
brand = item.get_attribute(brand_attribute_pk)
if brand is None:
brand = item.product.get_attribute(brand_attribute_pk)
brand = None
brand_attribute_pk = attributes_dict.get('brand')
publisher_attribute_pk = attributes_dict.get('publisher')

if brand_attribute_pk:
brand = item.get_attribute(brand_attribute_pk)
if brand is None:
brand = item.product.get_attribute(brand_attribute_pk)

if brand is None and publisher_attribute_pk is not None:
brand = item.get_attribute(publisher_attribute_pk)
if brand is None:
brand = item.product.get_attribute(publisher_attribute_pk)

return brand


Expand Down Expand Up @@ -171,11 +181,9 @@ def item_attributes(item, categories, category_paths, current_site,
if tax:
product_data['tax'] = tax

brand_attribute_pk = attributes_dict.get('brand')
if brand_attribute_pk:
brand = item_brand(item, brand_attribute_pk)
if brand:
product_data['brand'] = brand
brand = item_brand(item, attributes_dict)
if brand:
product_data['brand'] = brand

return product_data

Expand Down

0 comments on commit 05aa02c

Please sign in to comment.