Skip to content

Commit d8b0f76

Browse files
Merge pull request #85 from django-oscar/search-child-upc
[FEAT] Search for child upc should return parent product
2 parents 9f418c2 + ba6d9a9 commit d8b0f76

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

oscar_elasticsearch/search/fixtures/catalogue/catalogue.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,40 @@
8989
"is_discountable": true
9090
}
9191
},
92+
{
93+
"model": "catalogue.product",
94+
"pk": 6,
95+
"fields": {
96+
"structure": "parent",
97+
"upc": "jk4000",
98+
"parent": null,
99+
"title": "sixty eight",
100+
"slug": "sixty-eight",
101+
"description": "<p style=\"margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;\">Nullam sapien eros, facilisis vel, eleifend non, auctor dapibus, pede.</p>",
102+
"product_class": 2,
103+
"rating": null,
104+
"date_created": "2018-11-16T08:28:11.730Z",
105+
"date_updated": "2018-11-16T08:37:39.853Z",
106+
"is_discountable": true
107+
}
108+
},
109+
{
110+
"model": "catalogue.product",
111+
"pk": 7,
112+
"fields": {
113+
"structure": "child",
114+
"upc": "kq8000",
115+
"parent": 6,
116+
"title": "forty five",
117+
"slug": "forty-five",
118+
"description": "<p style=\"margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;\">Nullam sapien eros, facilisis vel, eleifend non, auctor dapibus, pede.</p>",
119+
"product_class": 2,
120+
"rating": null,
121+
"date_created": "2018-11-16T08:28:11.730Z",
122+
"date_updated": "2018-11-16T08:37:39.853Z",
123+
"is_discountable": true
124+
}
125+
},
92126
{
93127
"model": "catalogue.category",
94128
"pk": 1,
@@ -147,6 +181,14 @@
147181
"category": 1
148182
}
149183
},
184+
{
185+
"model": "catalogue.productcategory",
186+
"pk": 5,
187+
"fields": {
188+
"product": 6,
189+
"category": 1
190+
}
191+
},
150192
{
151193
"model": "catalogue.productattribute",
152194
"pk": 1,
@@ -846,6 +888,22 @@
846888
"date_updated": "2018-11-16T08:28:11.797Z"
847889
}
848890
},
891+
{
892+
"model": "partner.stockrecord",
893+
"pk": 5,
894+
"fields": {
895+
"product": 7,
896+
"partner": 1,
897+
"partner_sku": "jik090",
898+
"price_currency": "EUR",
899+
"price": "12.00",
900+
"num_in_stock": 34,
901+
"num_allocated": null,
902+
"low_stock_threshold": 8,
903+
"date_created": "2018-11-16T08:28:11.797Z",
904+
"date_updated": "2018-11-16T08:28:11.797Z"
905+
}
906+
},
849907
{
850908
"model": "partner.partner",
851909
"pk": 1,

oscar_elasticsearch/search/mappings/products/mappings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def string_attrs(self):
148148
if self.source.structure == Product.PARENT:
149149
for child in self.source.children:
150150
attrs.append(child.title)
151+
attrs.append(child.upc)
151152
attrs.extend([str(a) for a in child.attributes.values()])
152153

153154
return attrs

oscar_elasticsearch/search/tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ def test_search_suggestion(self):
6161
response = self.client.get("%s?q=prods" % url)
6262
self.assertEqual(response.context["suggestion"], "produ")
6363

64+
def test_child_upc_search_suggests_parent(self):
65+
url = reverse("search:search")
66+
# searching for child upc
67+
response = self.client.get("%s?q=kq8000" % url)
68+
self.assertEqual(response.context["paginator"].count, 1)
69+
self.assertEqual(response.context["paginator"].instances[0].upc, "jk4000")
70+
# searching for child title
71+
response = self.client.get("%s?q=forty" % url)
72+
self.assertEqual(response.context["paginator"].count, 1)
73+
self.assertEqual(response.context["paginator"].instances[0].upc, "jk4000")
74+
6475
def test_browse(self):
6576
url = reverse("catalogue:index")
6677
response = self.client.get(url)

0 commit comments

Comments
 (0)