4

I'm trying to figure out the best way to display products inside my homepage. I'm building my website using the sandbox that already comes with django-oscar (I cloned the project from Github).

I discovered that the default homepage is controlled by 'promotions' app. However, my products are just being displayed inside 'http://localhost:8000/catalogue' (controlled by 'catalogue' app).

Is there a way to display the products in my homepage? Or will I have to change the default app that controls the homepage? (in this case, how can I do that?)

EDIT 1: I believe that I found a solution. You can follow the tutorial How to Customize an Existing View; however, you need to make some changes, so your code must looks like this:

 from oscar.apps.catalogue.views import CatalogueView

 class HomeView(CatalogueView):
     template_name = 'promotions/home.html'

This way you will have access to the products in your 'promotions/home.html'. I'm not sure if it is the best way to implement this, if someone else has an alternative to this solution, please comment.

Alexandre Lara
  • 2,464
  • 1
  • 28
  • 35

2 Answers2

12

For this purpose Oscar has an app called promotions. This application is responsible for rendering blocks of content on the homepage, among other things (as I can see you found out from the documentation).

Usually you would use the promotion app to add products and other types of content to a page. This can be done from the Dashboard, using Content blocks, which can be found under the Content menu.

There are a few types of promotions that you can define (single product, automatic, and hand picked product list, and others).

After defining your promotion, you will be able to associate it with a page route, which in your case should be /.

If you choose to change this behaviour, then the documentation should provide a good starting point.

Update 2021.02.12:

Django Oscar Promotions is an app for Dashboard-editable promotional content in Oscar. It was formerly a part of Oscar core, but has now been separated into a standalone app.

See here: https://github.com/django-oscar/django-oscar-promotions

Rufat
  • 536
  • 1
  • 8
  • 25
Claudiu
  • 1,819
  • 18
  • 22
  • I've tried to add a block content to a page; however, there is an error ocurring "The URL "/" does not exist", seems that I can't insert a block content into my root URL. Do you know how to solve that? – Alexandre Lara May 03 '15 at 14:36
  • What version of Oscar are you using, and can you show me how you're adding its url's to your projects `urls.py`? (just the line concerning oscar) – Claudiu May 03 '15 at 14:45
  • Actually I imported the project from Github, so I'm not using an official release. I'm adding the Oscar's urls using `url(r'', include(application.urls)),`. I imported the project from Github because after I install Oscar in an virtualenv environment, I wasn't able to find its folder (that I'd like to have access to make some changes in its files). – Alexandre Lara May 03 '15 at 14:55
  • Everything looks fine, have you tried leaving the input box empty? (although I'm quite sure the same error will pop up) You should probably go through Oscar's documentation a little bit, one of the nicer features it has is the ability to let you swap out any of it's pieces for your own. I wouldn't recommend forking it unless you're actually doing some very heavy changes, and you don't mind giving up on future updates. – Claudiu May 03 '15 at 15:13
  • I installed it again and I discovered where the original folder is. My question now is how can I display the products using a customized template? Will I have to import some tag or to alter something in the view? – Alexandre Lara May 06 '15 at 01:39
  • I'm guessing you want to modify the default templates for the different promotions content types. You can achieve this by overriding the templates provided by Oscar (found here - https://github.com/django-oscar/django-oscar/tree/master/src/oscar/templates/oscar/promotions). This is described here - http://django-oscar.readthedocs.org/en/latest/howto/how_to_customise_templates.html, I recommend that you consider overriding the default templates (second method). – Claudiu May 06 '15 at 11:05
  • Yes, I was overriding the default templates; however, I was trying to figure out how could I import the products to the new templates. I realized that I need to load the promotions_tags and also loop through the promotions, something like that: {% for promotion in promotions_page %} {% render_promotion promotion %}{% endfor %}, I still don't know all the variables that I have access in my templates, do you know if there is any documentation for this? – Alexandre Lara May 06 '15 at 17:59
  • As far as I know, the documentation doesn't go that far. You will have to make do by taking the default templates as examples, and by navigating through the source of the project. – Claudiu May 06 '15 at 22:23
0

I also wanted to watching catalogue as a default page and I had find solution through nginx rewrite func at the end of /etc/nginx/sites-available/myproject

This file looks like this:

server {
server_name yourdomainorip.com;

access_log off;

location /static/ {
    alias /opt/myenv/static/;
}
location /media/ {
    alias /opt/myenv/media/;
}

location / {
    proxy_pass http://127.0.0.1:8001;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
    rewrite ^(/)$ http://yourdomainorip.com/catalogue/$2 permanent;
}