|
@@ -26,7 +26,7 @@ class XmlGeneratorSerializer(serializers.Serializer):
|
|
|
return True
|
|
|
|
|
|
@classmethod
|
|
|
- def for_xml(self, products=[], categories={}):
|
|
|
+ def for_xml(self, products=[], categories={}, site_url=''):
|
|
|
"""Generates an xml based on -> https://developer.skroutz.gr/el/feedspec/#xml"""
|
|
|
|
|
|
root = gfg.Element("mywebstore")
|
|
@@ -46,13 +46,23 @@ class XmlGeneratorSerializer(serializers.Serializer):
|
|
|
skroutz_products = []
|
|
|
|
|
|
for product in products:
|
|
|
+ category_object = categories.get(product.get('category', {}).category_id, {})
|
|
|
+ # Probably all this logic with link must be moved into sanitizer
|
|
|
+ # Link must be refactored since it is heavily depended on Prestashop Settings.
|
|
|
+ category_name = category_object.get('name', '')
|
|
|
+ category_slug = category_object.get('slug', '')
|
|
|
+ product_slug = product.get('slug', '')
|
|
|
+ link = ''
|
|
|
+ if product_slug and category_slug and site_url:
|
|
|
+ link = f'{site_url}/{category_slug}/{product_slug}'
|
|
|
+
|
|
|
skroutz_product = {
|
|
|
'id': str(product.get('product_id')),
|
|
|
'name': product.get('name'),
|
|
|
- 'link': product.get('link', 'hardcodedlin.com'), # fix this from prestashop API
|
|
|
+ 'link': link, # fix this from prestashop API
|
|
|
'image': product.get('image'),
|
|
|
'additionalimage': product.get('additionalimage'),
|
|
|
- 'category': categories.get(product.get('category', {}).category_id, {}).get('name', ''),
|
|
|
+ 'category': category_name,
|
|
|
'price_with_vat': product.get('wholesale_price'),
|
|
|
'vat': product.get('vat'),
|
|
|
'manufacturer': product.get('manufacturer'),
|
|
@@ -61,7 +71,7 @@ class XmlGeneratorSerializer(serializers.Serializer):
|
|
|
'instock': product.get('in_stock'),
|
|
|
'availability': str(
|
|
|
product.get('availability', 'Παραδοση 1 εως 3 ημερε')
|
|
|
- ), # fix this from prestashop API
|
|
|
+ ), # fix this from Sanitizer
|
|
|
'size': product.get('size'),
|
|
|
'weight': product.get('weight'),
|
|
|
'color': product.get('color'), # maybe make it array based on skroutz
|
|
@@ -80,8 +90,6 @@ class XmlGeneratorSerializer(serializers.Serializer):
|
|
|
|
|
|
child = gfg.Element(key)
|
|
|
if key in skroutz_cdata_fields:
|
|
|
- print(key, value)
|
|
|
-
|
|
|
child.text = cdata_parser(value)
|
|
|
else:
|
|
|
child.text = value
|