Bladeren bron

fix todos, price/name/urls/availability

Nikos Atlas 8 maanden geleden
bovenliggende
commit
852921ea93
1 gewijzigde bestanden met toevoegingen van 17 en 10 verwijderingen
  1. 17 10
      src/telecaster/Clients/CosmohomeClient.py

+ 17 - 10
src/telecaster/Clients/CosmohomeClient.py

@@ -2,6 +2,7 @@ import hashlib
 import struct
 from collections import defaultdict
 from datetime import datetime
+from functools import lru_cache
 
 from dicttoxml import dicttoxml
 
@@ -72,8 +73,7 @@ class CosmohomeClient(PrestaShopClient):
         serialized_product = {
             "productId": product.get('id'),
             "title": self.sanitize_language(product.get('name')),
-            # TODO FIX PRODUCT_URL - it has no domain + path!!
-            "productURL": product.get('link_rewrite'),
+            "productURL": self.generate_product_url(product),
             # add to the url the attributes like #/attr_id/attr_id/...
             "Category": self.get_category_tree(product.get('id_category_default'),
                                                min_depth=1),
@@ -82,11 +82,11 @@ class CosmohomeClient(PrestaShopClient):
             "Manufacturer": product.get('manufacturer_name'),
             "MPN": product.get('reference') or product.get('mpn'),
             "Barcode": product.get('ean13'),
-            "Price": self.calculate_final_price(product),
+            "price": self.calculate_final_price(product),
             "image": self.generate_image_url(product),
             "stock": "Y" if int(product.get('quantity')) > 0 else "N",
             "Availability": "Available from 1 to 3 days" if int(
-                product.get('quantity')) > 0 else "",
+                product.get('quantity')) > 0 else "Available from 1 to 3 days",
             "Quantity": product.get('quantity'),
             "Color": self.get_color(product),
             "Size": self.get_size(product),
@@ -100,14 +100,13 @@ class CosmohomeClient(PrestaShopClient):
                     combination.get('reference'), 10),
                 "Barcode": combination.get('ean13') or serialized_product.get(
                     'Barcode'),
-                # TODO: Product-URL should be overriden for combination
-                # TODO: Name is not a good idea it does not exist
-                # "Name": combination.get('name'),
+                "productURL": self.generate_combination_url(product, combination),
+
                 "weight": product.get('weight'),
                 "MPN": combination.get('reference') or combination.get(
                     'mpn') or serialized_product.get('MPN'),
 
-                "Price": self.calculate_final_price(
+                "price": self.calculate_final_price(
                     combination,
                     float(product.get('price')) + float(combination.get('price'))
                 ),
@@ -147,6 +146,14 @@ class CosmohomeClient(PrestaShopClient):
         link_rewrite = self.sanitize_language(product.get('link_rewrite'))
         return f"{CANONICAL_DOMAIN}/{image_id}-thickbox_default/{link_rewrite}.jpg"
 
+    def generate_product_url(self, product):
+        link_rewrite = self.sanitize_language(product.get('link_rewrite'))
+        return f"{CANONICAL_DOMAIN}/{product.get('id')}-{link_rewrite}.html"
+
+    def generate_combination_url(self, product, combination):
+        link_rewrite = self.sanitize_language(product.get('link_rewrite'))
+        return f"{CANONICAL_DOMAIN}/{product.get('id')}-{combination.get('id')}-{link_rewrite}.html"
+
     def get_color(self, product):
         options = product.get('associations').get('product_option_values') or []
         for option in options:
@@ -184,7 +191,7 @@ class CosmohomeClient(PrestaShopClient):
 
         price_with_tax = float(price) * (1 + TAX)
 
-        sp = self.caches['specific_prices'].get(product.get('id'))
+        sp = self.caches['specific_prices'].get(str(product.get('id')))
         if sp:
             discount = sp.get('reduction')
             type = sp.get('reduction_type')
@@ -238,7 +245,7 @@ def generate_xml():
 
     products = []
     for product in batch_products(client, params={'filter[active]': '1'},
-                                  batch_size=200):
+                                  batch_size=10, hard_limit=1):
         products += client.parse_product(product)
 
     xml = dicttoxml(