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