Skip to content

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

Remove product get_category method

Anna Siwikd4be7b00f774
diff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.py
index 71dfad3576..db6b4e2c91 100644
--- a/saleor/data_feeds/google_merchant.py
+++ b/saleor/data_feeds/google_merchant.py
@@ -133,17 +133,14 @@ def item_google_product_category(item, category_paths):
Read more:
https://support.google.com/merchants/answer/6324436
"""
- category = item.product.get_category()
- if category:
- if category.pk in category_paths:
- return category_paths[category.pk]
- ancestors = [ancestor.name for ancestor
- in list(category.get_ancestors())]
- category_path = CATEGORY_SEPARATOR.join(ancestors + [category.name])
- category_paths[category.pk] = category_path
- return category_path
- else:
- return ''
+ category = item.product.category
+ if category.pk in category_paths:
+ return category_paths[category.pk]
+ ancestors = [
+ ancestor.name for ancestor in list(category.get_ancestors())]
+ category_path = CATEGORY_SEPARATOR.join(ancestors + [category.name])
+ category_paths[category.pk] = category_path
+ return category_path
def item_price(item):
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 6f383bbcde..4e7eea6faa 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -144,9 +144,6 @@ class Product(models.Model, ItemRange):
def is_in_stock(self):
return any(variant.is_in_stock() for variant in self)
- def get_category(self):
- return self.category if not self.category.is_hidden else None
-
def is_available(self):
today = datetime.date.today()
return self.available_on is None or self.available_on <= today
diff --git a/tests/test_data_feeds.py b/tests/test_data_feeds.py
index 64012cc4a2..a518ec100c 100644
--- a/tests/test_data_feeds.py
+++ b/tests/test_data_feeds.py
@@ -31,16 +31,12 @@ def test_saleor_feed_items(product_in_stock):
def test_category_formatter(db):
main_category = Category(name='Main', slug='main')
main_category.save()
- main_category_item = Mock(
- product=Mock(get_category=lambda: main_category))
+ main_category_item = Mock(product=Mock(category=main_category))
sub_category = Category(name='Sub', slug='sub', parent=main_category)
sub_category.save()
- sub_category_item = Mock(
- product=Mock(get_category=lambda: sub_category))
- assert item_google_product_category(
- main_category_item, {}) == 'Main'
- assert item_google_product_category(
- sub_category_item, {}) == 'Main > Sub'
+ sub_category_item = Mock(product=Mock(category=sub_category))
+ assert item_google_product_category(main_category_item, {}) == 'Main'
+ assert item_google_product_category(sub_category_item, {}) == 'Main > Sub'
def test_write_feed(product_in_stock, monkeypatch):