integration starts to work
This commit is contained in:
@@ -57,22 +57,32 @@ def migrate_shop_products(url, key, secret, version="wc/v3"):
|
||||
return None
|
||||
|
||||
product_fields = [f.name for f in Product._meta.get_fields()]
|
||||
|
||||
counter = 0
|
||||
products_created = []
|
||||
for product in products:
|
||||
instance_data = {}
|
||||
# remove unwanted fields
|
||||
product.pop('id')
|
||||
instance_data = {'company':company}
|
||||
# parse the product info
|
||||
for key in product:
|
||||
if key in product_fields:
|
||||
instance_data[key] = product[key]
|
||||
# validate data
|
||||
import ipdb; ipdb.set_trace()
|
||||
serializer = ProductSerializer(**instance_data)
|
||||
if serializer.is_valid():
|
||||
import ipdb; ipdb.set_trace()
|
||||
Product.objects.create(**serializer.validated_data)
|
||||
else:
|
||||
import ipdb; ipdb.set_trace()
|
||||
# remove unwanted fields
|
||||
instance_data.pop('id')
|
||||
if instance_data.get('tags') == []:
|
||||
instance_data.pop('tags')
|
||||
if instance_data.get('attributes') == []:
|
||||
instance_data.pop('attributes')
|
||||
# create instance
|
||||
try:
|
||||
new = Product.objects.create(**instance_data)
|
||||
products_created.append(new)
|
||||
counter += 1
|
||||
logging.info(f"Product {instance_data.get('name')} created")
|
||||
print(f"Product {instance_data.get('name')} created")
|
||||
except Exception as e:
|
||||
logging.error(f"Could not create product instance: {str(e)}")
|
||||
|
||||
print(f"Products created: {counter}")
|
||||
return products_created
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user