Ashraf Emad
Ashraf Emad

Reputation: 183

How to set product attributes to basket line in Oscar

I'm new to Django-oscar and working on Basket now I can add products as lines to the basket easily but what if I want to choose a specific Product attribute to add to basket for example product A has attributes {'size': ['M', 'S'], 'color': ['red', 'blue']} what should i do if i want to add product A with size M and color blue to the basket?

Upvotes: 4

Views: 865

Answers (1)

Ashraf Emad
Ashraf Emad

Reputation: 183

for those who will come looking for the same issue, i found a way to do this: There is an Oscar Model called Option you can add the attributes you generally add to your items eg. Size Color Flavor ..etc and pass the value from product's attributes because

basket.add_product()

has options argument and only accept Option instance so we need to have it it's passed as list of objects in this way:

[
{'option': Option.objects.get(name="name"), 'value': 'Value'},
]

please if you know a better way to do it, comment here :)

Upvotes: 4

Related Questions