How to add attributes to product type - programatically ? (Oscar 1.0 / Django 1.7.1)

1,931 views
Skip to first unread message

niko...@gmail.com

unread,
Nov 20, 2014, 6:33:19 AM11/20/14
to django...@googlegroups.com
Hi ,

I understand that this might be trivial, but still i  could not find a way to add product type and attach attribute to it dynamically.

I did found this :

-----------

The first thing you need to is create the product attributes and the options for each attribute:
  1. Go to "Product Attributes" under the "Catalogue" section in the admin (/admin/catalogue/productattribute/)
  2. Click on "Add Product Attribute" and give the attribute a name, such as "Height" and a code and choose "Option" in the "Type" dropdown list. For the "Option Group" click on the plus symbol.
  3. You should now see a popup which allows you to add the possible values for the attribute. For example, "Short", "Medium", "Tall" etc. After clicking save the popup will close and you will now see a value for "option group". Click on save to create the product attribute.
  4. Repeat the above steps for each attribute you want to add.
You can now add these attributes to your products on the "Product" admin screen (admin/catalogue/product/x) under the heading "Product Attribute Values". For example, to add a colour to a product select colour from the "Attribute" dropdown list and choose which colour you want from the "Value Option" dropdown list.

Bear in mind it generally makes sense to add attributes to non canonical products, i.e children products or variants as they are known in Oscar. So if you had a Metallica T-shirt in your catalogue that came in 5 different colours and 2 sizes, you should create one parent product representing the t shirt entity that will be visible when browsing your catalogue. You should then create 10 variant products, one for each colour and size combination, i.e Black Small, Black Medium, Red Small, Red Medium etc.
-----------

But my dashboard does not have "Product Attributes" under Catalogue (I could not find this on my Oscar 1.0 Dashboard).
Moreover, I assume that this i something that can be done programmatically as i will try to dynamically define and populate them.

Can anybody point me out to right direction.


Thanks,
Alex

Joshua Wedekind

unread,
Nov 20, 2014, 3:29:17 PM11/20/14
to django...@googlegroups.com
You are correct. "Product Attributes" do not show up in the Dashboard.

I believe the logic behind this is that these attributes are beyond the scope of what the end user should see. In other words, the Product Attributes should already be entered. I'm not sure I agree with it, but it is really easy to enter in Product Attributes via the Django Admin.

Just in case you are new to Django, the Admin is different from the Dashboard. 
On your local development site, you access the admin via:
localhost:8000/admin
whereas the Dashboard is accessed via:
localhost:8000/dashboard

You can use the same superuser to access the Admin. Product Attributes are under the Catalogue section.

~Josh

Joshua Wedekind

unread,
Nov 20, 2014, 3:58:55 PM11/20/14
to django...@googlegroups.com
And to do this programatically, I create two json files--one for ProductClass and one for ProductAttribute.

Note: ProductAttribute has a field "product_class" that references the ProductClass, so you have to import the ProductClass objects first.

You can import these from the command line:
python manage.py loaddata product_classes.json
python manage
.py loaddata product_attributes.json

I've attached my very simple, text field attributes file. I believe there are docs on how to create the other field types and option groups.
product_classes.json
product_attributes.json

niko...@gmail.com

unread,
Nov 21, 2014, 3:40:23 AM11/21/14
to django...@googlegroups.com
Got it. Thank you Josh

Anentropic

unread,
May 27, 2015, 8:01:21 AM5/27/15
to django...@googlegroups.com
For anyone who's extended the catalogue app, you won't have a 'Catalogue' section in Django admin until you make an admin.py in your extended catalogue app, eg

from oscar.apps.catalogue.admin import *

Rosen Pashov

unread,
Mar 15, 2016, 3:05:51 AM3/15/16
to django-oscar
Hello, I didn't want to start a new discussion so I decided to ask my question here as i find it a bit related to my problem.
What I wanted to ask is if it is possible to make an attribute be dependent on another attribute. Lets say we have a product type that is a ... smartphone for example. This product type has two attributes - "manufacturer" and "model". The "manufacturer" attribute type is "option" and its values are lets say "samsung" "huawei" and "sony", the "model" attribute could hold all models of these 3 manufacturers for example "galaxy s4", "galaxy s5", galaxy s6", "p8", "p8 lite", "honor 7", "xperia z5", "xperia z4", "xperia m4 aqua".
What I want to achieve is to filter the model option values when you select "samsung" in the dashboard (when adding a new product) and the model options get filtered to models of samsung only ("galaxy s4", "galaxy s5", galaxy s6") How would u recommend me to achieve this? Thanks in advance. 
Reply all
Reply to author
Forward
0 new messages