def add_category_from_breadcrumbs(self, breadcrumb): from istore.apps.catalogue.categories import create_from_breadcrumbs category = create_from_breadcrumbs(breadcrumb) temp = get_model('catalogue', 'ProductCategory')( category=category, product=self) temp.save()
def create_product(self, product_class, attribute_codes, row): ptype, upc, title, description, category, partner, sku, price, stock = row[0:9] # Create product is_variant = ptype.lower() == 'variant' is_group = ptype.lower() == 'group' if upc: try: product = models.Product.objects.get( upc=upc) except models.Product.DoesNotExist: product = models.Product(upc=upc) else: product = models.Product() if not is_variant: product.title = title product.description = description product.product_class = product_class # Attributes if not is_group: for code, value in zip(attribute_codes, row[9:]): # Need to check if the attribute requires an Option instance attr = product_class.attributes.get( code=code) if attr.is_option: value = attr.option_group.options.get(option=value) if attr.type == 'date': value = datetime.datetime.strptime(value, "%d/%m/%Y").date() setattr(product.attr, code, value) # Assign parent for variants if is_variant: product.parent = self.parent product.save() # Save a reference to last group product if is_group: self.parent = product # Category information if category: leaf = categories.create_from_breadcrumbs(category) models.ProductCategory.objects.get_or_create( product=product, category=leaf)