[Answer]-How to break the item name and size in Django Cartridge cart page?

1๐Ÿ‘

โœ…

I think it requires changes of the models, because when product is added to cart the name and options are saved to description:

class Cart(models.Model):
    ...
    item.description = unicode(variation)

and

class ProductVariation(Priced):
    ...
    def __unicode__(self):
        """
        Display the option names and values for the variation.
        """
        options = []
        for field in self.option_fields():
            if getattr(self, field.name) is not None:
                options.append("%s: %s" % (unicode(field.verbose_name),
                                           getattr(self, field.name)))
        return ("%s %s" % (unicode(self.product), ", ".join(options))).strip()

UPD:

You can add field to SelectedProduct class:

options = CharField(_("Options"), max_length=200)

Add method to ProductVariation class:

def options_text(self):
    options = []
    for field in self.option_fields():
        if getattr(self, field.name) is not None:
            options.append("%s: %s" % (unicode(field.verbose_name),
                                       getattr(self, field.name)))
    return ", ".join(options).strip() 

def __unicode__(self):
    """
    Display the option names and values for the variation.
    """        
    return ("%s %s" % (unicode(self.product), self.options_text())).strip()

Change add_item method in Cart class:

item.description = unicode(variation.product)
item.options = variation.options_text()
๐Ÿ‘คsneawo

Leave a comment