61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
|
# -*- coding: utf-8; -*-
|
||
|
"""
|
||
|
Rattail Demo -> Rattail Demo "self" data import
|
||
|
"""
|
||
|
|
||
|
from rattail.importing.local import FromRattailLocalToRattail, FromRattailLocal
|
||
|
from rattail.importing.shopfoo import ShopfooProductImporterMixin
|
||
|
from rattail.util import OrderedDict
|
||
|
from rattail_demo import importing as rattail_demo_importing
|
||
|
|
||
|
|
||
|
class FromRattailDemoToSelf(FromRattailLocalToRattail):
|
||
|
"""
|
||
|
Handler for Rattail Demo -> Rattail Demo ("self") imports
|
||
|
"""
|
||
|
|
||
|
def get_importers(self):
|
||
|
importers = OrderedDict()
|
||
|
importers['ShopfooProduct'] = ShopfooProductImporter
|
||
|
return importers
|
||
|
|
||
|
|
||
|
class ShopfooProductImporter(ShopfooProductImporterMixin, FromRattailLocal, rattail_demo_importing.model.ShopfooProductImporter):
|
||
|
"""
|
||
|
Product -> ShopfooProduct
|
||
|
"""
|
||
|
supported_fields = [
|
||
|
'uuid',
|
||
|
'product_uuid',
|
||
|
'upc',
|
||
|
'description',
|
||
|
'price',
|
||
|
'enabled',
|
||
|
]
|
||
|
|
||
|
def normalize_base_product_data(self, product):
|
||
|
|
||
|
price = None
|
||
|
if product.regular_price:
|
||
|
price = product.regular_price.price
|
||
|
|
||
|
return {
|
||
|
'product_uuid': product.uuid,
|
||
|
'upc': str(product.upc or '') or None,
|
||
|
'description': product.full_description,
|
||
|
'price': price,
|
||
|
'enabled': True, # will maybe unset this in mark_unwanted()
|
||
|
}
|
||
|
|
||
|
def product_is_unwanted(self, product, data):
|
||
|
if super(ShopfooProductImporter, self).product_is_unwanted(product, data):
|
||
|
return True
|
||
|
if not data['price']: # let's say this is a required field for Shopfoo
|
||
|
return True
|
||
|
return False
|
||
|
|
||
|
def mark_unwanted(self, product, data):
|
||
|
data = super(ShopfooProductImporter, self).mark_unwanted(product, data)
|
||
|
data['enabled'] = False
|
||
|
return data
|