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?
Asked
Active
Viewed 785 times
4

sentence
- 8,213
- 4
- 31
- 40

Ashraf Emad
- 183
- 10
-
Related - [Django-Oscar Basket customization](https://stackoverflow.com/questions/53557546/django-oscar-basket-customization) – shad0w_wa1k3r May 02 '19 at 06:53
-
@shad0w_wa1k3r thanks for reply, and it's useful in other ways but it didn't help me in this issue – Ashraf Emad May 07 '19 at 09:29
1 Answers
4
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 :)

Ashraf Emad
- 183
- 10
-
how did you get your Option assigned to a product. in the database (otherwise, the form will not validate)? I was not able doing this with the dashboard... – benzkji Oct 06 '19 at 11:49
-
@benzkji mainly the Option is attached to Basket Line (Option as a foreign key - Value as text or whatever, see AbstractLineAttribute class and the Line object has a Product object related or attached to it – Ashraf Emad Oct 20 '19 at 13:49
-
@AshrafEmad Could you please elaborate it a little more? can i see the code? you are talking here about the product option or the multi option group ? – yajant b Apr 29 '20 at 13:25