|
@@ -0,0 +1,30 @@
|
|
|
|
+from .BaseClient import BaseClient
|
|
|
|
+import urllib.parse
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class PrestaShopClient(BaseClient):
|
|
|
|
+ def __init__(self, base_url, token):
|
|
|
|
+ self.token = token
|
|
|
|
+ self.base_url = base_url
|
|
|
|
+
|
|
|
|
+ def build_url(self, url, params={}):
|
|
|
|
+ updated_params = {**params, 'ws_key': self.token}
|
|
|
|
+ return f'{self.base_url}{url}?{urllib.parse.urlencode(updated_params)}'
|
|
|
|
+
|
|
|
|
+ def get_products(self, params={}):
|
|
|
|
+ constructed_params = {
|
|
|
|
+ 'display': '[name,id,id_default_image,id_category_default,price,wholesale_price,manufacturer_name,ean13,delivery_in_stock,additional_shipping_cost,description,quantity]',
|
|
|
|
+ **params,
|
|
|
|
+ }
|
|
|
|
+ full_url = self.build_url('/products', constructed_params)
|
|
|
|
+ # we need to parse these since the response is in XML
|
|
|
|
+ # check parsers folder for relevant functions/classes
|
|
|
|
+ products = self.get(full_url)
|
|
|
|
+
|
|
|
|
+ return products
|
|
|
|
+
|
|
|
|
+ def get_categories(self, params={}):
|
|
|
|
+ constructed_params = {'display': '[id,name]', **params}
|
|
|
|
+ full_url = self.build_url('/categories', constructed_params)
|
|
|
|
+ categories = self.get(full_url)
|
|
|
|
+ return categories
|