enthusiast-source-solidus 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- enthusiast_source_solidus/__init__.py +1 -0
- enthusiast_source_solidus/source.py +81 -0
- enthusiast_source_solidus-0.1.2.dist-info/LICENCE.md +8 -0
- enthusiast_source_solidus-0.1.2.dist-info/METADATA +21 -0
- enthusiast_source_solidus-0.1.2.dist-info/RECORD +6 -0
- enthusiast_source_solidus-0.1.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .source import SolidusProductSource as SolidusProductSource
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
from enthusiast_common import ProductDetails, ProductSourcePlugin
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SolidusProductSource(ProductSourcePlugin):
|
|
7
|
+
def __init__(self, data_set_id, config: dict):
|
|
8
|
+
"""
|
|
9
|
+
Initialize the plugin with the parameters to access source.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
data_set_id (int): identifier of a data set that products are assigned to.
|
|
13
|
+
config (dict): Parameters such as shop url or access token to configure a plugin.
|
|
14
|
+
"""
|
|
15
|
+
super().__init__(data_set_id, config)
|
|
16
|
+
|
|
17
|
+
# Source specific parameters.
|
|
18
|
+
self._base_url = config.get("base_url")
|
|
19
|
+
self._api_key = config.get("api_key")
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def get_properties(solidus_properties):
|
|
23
|
+
properties = [f"{item['property_name']} -> {item['value']}" for item in solidus_properties]
|
|
24
|
+
return "|".join(properties)
|
|
25
|
+
|
|
26
|
+
def get_product(self, solidus_product) -> ProductDetails:
|
|
27
|
+
"""Translates product definition received from Solidus into Enthusiast product.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
solidus_product: a product returned by Solidus API
|
|
31
|
+
Returns:
|
|
32
|
+
ProductDetails: product definition used by ECL to sync a product.
|
|
33
|
+
"""
|
|
34
|
+
product = ProductDetails(
|
|
35
|
+
entry_id=solidus_product.get("id"),
|
|
36
|
+
name=solidus_product.get("name"),
|
|
37
|
+
slug=solidus_product.get("slug"),
|
|
38
|
+
description=solidus_product.get("description") or "-",
|
|
39
|
+
sku=solidus_product.get("master", [{}]).get("sku") if solidus_product.get("master") else None,
|
|
40
|
+
price=float(solidus_product.get("price")),
|
|
41
|
+
properties=self.get_properties(solidus_product.get("product_properties")),
|
|
42
|
+
categories=str(
|
|
43
|
+
[taxon.get("name") for taxon in solidus_product.get("classifications", {}).get("taxon", [])]
|
|
44
|
+
if solidus_product.get("collection")
|
|
45
|
+
else []
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return product
|
|
50
|
+
|
|
51
|
+
def fetch(self) -> list[ProductDetails]:
|
|
52
|
+
"""Fetch product list.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
list[ProductDetails]: A list of products.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
endpoint = f"{self._base_url}/api/products"
|
|
59
|
+
|
|
60
|
+
products = []
|
|
61
|
+
page = 1
|
|
62
|
+
headers = {"Authorization": f"Bearer {self._api_key}"}
|
|
63
|
+
|
|
64
|
+
while True:
|
|
65
|
+
response = requests.get(endpoint, headers=headers, params={"page": page})
|
|
66
|
+
|
|
67
|
+
if response.status_code == 404:
|
|
68
|
+
raise Exception("The endpoint was not found. Please verify the URL.")
|
|
69
|
+
elif response.status_code != 200:
|
|
70
|
+
raise Exception(f"Failed to fetch products: {response.status_code} - {response.text}")
|
|
71
|
+
|
|
72
|
+
data = response.json()
|
|
73
|
+
solidus_products = data.get("products", [])
|
|
74
|
+
for solidus_product in solidus_products:
|
|
75
|
+
products.append(self.get_product(solidus_product))
|
|
76
|
+
if page >= data["pages"]:
|
|
77
|
+
break
|
|
78
|
+
|
|
79
|
+
page += 1
|
|
80
|
+
|
|
81
|
+
return products
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2025 Upside Lab sp. z o.o.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: enthusiast-source-solidus
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Rafal Cymerys
|
|
6
|
+
Author-email: rafal@upsidelab.io
|
|
7
|
+
Requires-Python: >=3.9,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: enthusiast-common (>=0.2,<1)
|
|
15
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Enthusiast Source Solidus E-Commerce Platform
|
|
19
|
+
|
|
20
|
+
This Enthusiast plugin enables the import of product data directly from Solidus E-Commerce Platform (former Spree).
|
|
21
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
enthusiast_source_solidus/__init__.py,sha256=GkSsePcMBvSnYsXzTT72RJ5dkKQ7tHeqjFu-E8j4M5o,65
|
|
2
|
+
enthusiast_source_solidus/source.py,sha256=xN6EbJP7xZQgYvuyIa1mEcJUubjJSeUB-atnUPXOc8M,2964
|
|
3
|
+
enthusiast_source_solidus-0.1.2.dist-info/LICENCE.md,sha256=jyE5zsXoI2vR5O1EsCyc9BKsy286yOOLhZPZkbwCj1w,1070
|
|
4
|
+
enthusiast_source_solidus-0.1.2.dist-info/METADATA,sha256=z7xU5jkjFytcmiJuZbAvK2VBZdZ8Uml2M9s-x8r4aVg,757
|
|
5
|
+
enthusiast_source_solidus-0.1.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
6
|
+
enthusiast_source_solidus-0.1.2.dist-info/RECORD,,
|