Skip to content

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

Change method name to get_category

Anna Siwik40b008648912
diff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.py
index e33af67ccd..71dfad3576 100644
--- a/saleor/data_feeds/google_merchant.py
+++ b/saleor/data_feeds/google_merchant.py
@@ -133,7 +133,7 @@ def item_google_product_category(item, category_paths):
Read more:
https://support.google.com/merchants/answer/6324436
"""
- category = item.product.get_first_category()
+ category = item.product.get_category()
if category:
if category.pk in category_paths:
return category_paths[category.pk]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index c06280d726..f32d4f590d 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -145,7 +145,7 @@ class Product(models.Model, ItemRange):
def is_in_stock(self):
return any(variant.is_in_stock() for variant in self)
- def get_first_category(self):
+ def get_category(self):
return self.category if not self.category.is_hidden else None
def is_available(self):
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
index 5faea63550..fd3f6a34d2 100644
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -572,7 +572,7 @@ def test_product_list_filters_is_published(
admin_client, product_list, default_category):
data = {'price_1': [''], 'price_0': [''], 'is_featured': [''],
'name': ['Test'], 'sort_by': ['name'],
- 'categories': [default_category.pk], 'is_published': ['1']}
+ 'category': default_category.pk, 'is_published': ['1']}
url = reverse('dashboard:product-list')
response = admin_client.get(url, data)
assert response.status_code == 200
diff --git a/tests/test_data_feeds.py b/tests/test_data_feeds.py
index 94fb1fa7e7..64012cc4a2 100644
--- a/tests/test_data_feeds.py
+++ b/tests/test_data_feeds.py
@@ -32,11 +32,11 @@ def test_category_formatter(db):
main_category = Category(name='Main', slug='main')
main_category.save()
main_category_item = Mock(
- product=Mock(get_first_category=lambda: main_category))
+ product=Mock(get_category=lambda: main_category))
sub_category = Category(name='Sub', slug='sub', parent=main_category)
sub_category.save()
sub_category_item = Mock(
- product=Mock(get_first_category=lambda: sub_category))
+ product=Mock(get_category=lambda: sub_category))
assert item_google_product_category(
main_category_item, {}) == 'Main'
assert item_google_product_category(