|
@@ -4,6 +4,7 @@ from rest_framework.request import Request
|
|
from django.http import JsonResponse
|
|
from django.http import JsonResponse
|
|
from ..Clients.PrestaShopClient import PrestaShopClient
|
|
from ..Clients.PrestaShopClient import PrestaShopClient
|
|
from ..parsers.PrestaShopParser import PrestaShopParser
|
|
from ..parsers.PrestaShopParser import PrestaShopParser
|
|
|
|
+from ..serializers import PrestaShopProductSerializer
|
|
|
|
|
|
|
|
|
|
class XmlGeneratorView(views.APIView):
|
|
class XmlGeneratorView(views.APIView):
|
|
@@ -18,9 +19,20 @@ class XmlGeneratorView(views.APIView):
|
|
|
|
|
|
prestashop_client = PrestaShopClient(base_url=url, token=token)
|
|
prestashop_client = PrestaShopClient(base_url=url, token=token)
|
|
|
|
|
|
- products_response = prestashop_client.get_products({'limit': 4})
|
|
|
|
- categories_response = prestashop_client.get_categories({'limit': 4})
|
|
|
|
|
|
+ products_response = prestashop_client.get_products({'limit': 10})
|
|
|
|
+ categories_response = prestashop_client.get_categories()
|
|
|
|
+
|
|
|
|
+ products = PrestaShopParser.parse_products(products_response)
|
|
categories = PrestaShopParser.parse_categories(categories_response)
|
|
categories = PrestaShopParser.parse_categories(categories_response)
|
|
|
|
|
|
- response_json = {categories, products_response}
|
|
|
|
- return JsonResponse(response_json, safe=False)
|
|
|
|
|
|
+ for product in products:
|
|
|
|
+ # worst line in the world
|
|
|
|
+ # maybe we should have the name directly in the parser
|
|
|
|
+ product['category'] = (
|
|
|
|
+ categories.get(product['id_category_default'], {}).get('name', {}).get('language', '')
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ serializer = PrestaShopProductSerializer(data=products, many=True)
|
|
|
|
+ serializer.is_valid()
|
|
|
|
+
|
|
|
|
+ return JsonResponse(serializer.data, safe=False)
|