Sort products when fetching from Woo API
default sort is by 'date desc' which is not always determinate also, combine logic for fetching products
This commit is contained in:
parent
ddced3e90c
commit
3d0f5ddd81
3 changed files with 63 additions and 35 deletions
|
@ -35,6 +35,7 @@ from rattail.core import get_uuid
|
|||
from rattail.util import OrderedDict
|
||||
from rattail.time import localtime, make_utc
|
||||
from rattail_woocommerce import importing as rattail_woocommerce_importing
|
||||
from rattail_woocommerce.woocommerce.util import get_woocommerce_products
|
||||
|
||||
|
||||
class FromWooCommerceToRattail(importing.ToRattailHandler):
|
||||
|
@ -68,21 +69,6 @@ class FromWooCommerce(importing.Importer):
|
|||
|
||||
self.api = WooAPI(**kwargs)
|
||||
|
||||
def get_woocommerce_products(self):
|
||||
products = []
|
||||
page = 1
|
||||
while True:
|
||||
block = self.api.get('products', params={'per_page': 100,
|
||||
'page': page})
|
||||
products.extend(block.json())
|
||||
link = block.headers.get('Link')
|
||||
if link and 'rel="next"' in link:
|
||||
page += 1
|
||||
else:
|
||||
break
|
||||
|
||||
return products
|
||||
|
||||
|
||||
class ProductImporter(FromWooCommerce, rattail_woocommerce_importing.model.ProductImporter):
|
||||
"""
|
||||
|
@ -114,7 +100,7 @@ class ProductImporter(FromWooCommerce, rattail_woocommerce_importing.model.Produ
|
|||
query=query)
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.get_woocommerce_products()
|
||||
return get_woocommerce_products(self.api)
|
||||
|
||||
def find_rattail_product(self, api_product):
|
||||
product = self.get_product_by_woo_id(api_product['id'])
|
||||
|
@ -271,7 +257,7 @@ class WooCacheProductImporter(FromWooCommerce, rattail_woocommerce_importing.mod
|
|||
pass
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.get_woocommerce_products()
|
||||
return get_woocommerce_products(self.api)
|
||||
|
||||
def normalize_host_object(self, api_product):
|
||||
data = dict(api_product)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue