diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-29 10:41:22 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-29 10:41:22 +0700 |
| commit | 6ed2316f6aa446bcd5bc7e6cd4d0c0a1136096dd (patch) | |
| tree | 62e6556b8c7fa6fd6f6085b3b3e6ef00b78ee713 /indoteknik_custom/models/solr/product_product.py | |
| parent | 315b832420eb8314e809b1c0f549304d423b45f3 (diff) | |
Update apache solr
- Create get tier name pricelist
- Create solr results on product.template and product.product
- Fix get active flash sale on product template
- Update name "get_single_doc" to "get_doc" in apache solr model
- Add product ids on sync category homepage to solr
Diffstat (limited to 'indoteknik_custom/models/solr/product_product.py')
| -rw-r--r-- | indoteknik_custom/models/solr/product_product.py | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index f3107afa..48ee9daa 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -35,7 +35,7 @@ class ProductProduct(models.Model): category_name = category.name break - document = solr_model.get_single_doc('variants', variant.id) + document = solr_model.get_doc('variants', variant.id) document.update({ 'id': variant.id, 'display_name_s': variant.display_name, @@ -83,7 +83,7 @@ class ProductProduct(models.Model): tier2 = variant._get_pricelist_tier2() tier3 = variant._get_pricelist_tier3() - document = solr_model.get_single_doc('variants', variant.id) + document = solr_model.get_doc('variants', variant.id) document.update({ 'id': variant.id, 'flashsale_id_i': flashsale_data.get('flashsale_id', 0), @@ -112,4 +112,57 @@ class ProductProduct(models.Model): def _sync_delete_solr(self): for rec in self: - self.solr().delete(rec.id)
\ No newline at end of file + self.solr().delete(rec.id) + + def solr_results(self): + solr_model = self.env['apache.solr'] + pricelist = self.env.user_pricelist + price_tier = pricelist.get_tier_name() + + results = [] + for product in self: + doc = solr_model.get_doc('variants', product.id) + if len(doc) == 0: continue + + discount_key = 'discount_f' + price_discount_key = 'price_discount_f' + if price_tier: + discount_key = f'discount_{price_tier}_f' + price_discount_key = f'price_{price_tier}_f' + + flashsale = product._get_active_flash_sale() + if flashsale: + discount_key = 'flashsale_discount_f' + price_discount_key = 'flashsale_price_f' + + result = { + 'id': doc.get('id'), + 'parent': { + 'id': doc.get('template_id_i'), + 'name': doc.get('name_s'), + 'image': doc.get('image_s'), + }, + 'code': doc.get('default_code_s'), + 'name': doc.get('display_name_s'), + 'price': { + 'price': doc.get('price_f'), + 'discount_percentage': doc.get(discount_key), + 'price_discount': doc.get(price_discount_key) + }, + 'stock': doc.get('stock_total_f'), + 'weight': doc.get('weight_f'), + 'manufacture': None + } + + manufacture_id = doc.get('manufacture_id_i') + if manufacture_id: + result['manufacture'] = { + 'id': manufacture_id, + 'name': doc.get('manufacture_name_s'), + 'image_promotion_1': doc.get('image_promotion_1_s'), + 'image_promotion_2': doc.get('image_promotion_2_s'), + } + + results.append(result) + + return results
\ No newline at end of file |
