Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Opened source to the top products plugin. It's very rough.

  • Loading branch information...
commit 2f5cb7cf873c7dc4a2f92d1ec38c0fb29545a024 1 parent 4f96706
@chrisglass authored
View
11 README.rst
@@ -6,3 +6,14 @@ A set of django CMS plugins to expose some of django SHOP's functionality to CMS
This is a work in progress, so don't exxpect anything to work yet :)
+Some code was roughly open-sourced, so while it should work, it is still very
+ugly and will most likely be renamed.
+
+What you should expect here
+===========================
+
+* Code to display an arbitrary list of django-SHOP Product subclasses (admin
+ gets to choose which products). Think catalogue.
+* A plugin to display the N top selling products
+* A plugin to display the contents of the shop's shopping cart.
+
View
0  cmsplugin_top_products/__init__.py
No changes.
View
24 cmsplugin_top_products/cms_plugins.py
@@ -0,0 +1,24 @@
+from cmsplugin_top_products.models import TopProducts
+from cms.plugin_base import CMSPluginBase
+from cms.plugin_pool import plugin_pool
+from django.template.defaultfilters import title
+from django.utils.translation import ugettext_lazy as _
+
+
+class TopProductsPlugin(CMSPluginBase):
+ model = TopProducts
+ admin_preview = False
+ name = title(_('top products plugin'))
+ placeholders = ('feature_home',)
+ render_template = "top_products/plugins/top_products.html"
+
+ def render(self, context, instance, placeholder):
+ context.update({
+ 'instance': instance,
+ 'product_count': len(instance.products.all()),
+ 'products': instance.products.all(),
+ 'placeholder': placeholder,
+ })
+ return context
+
+plugin_pool.register_plugin(TopProductsPlugin)
View
9 cmsplugin_top_products/models.py
@@ -0,0 +1,9 @@
+from cms.models import CMSPlugin
+from django.db import models
+from shop.models.productmodel import Product
+from django.utils.translation import ugettext_lazy as _
+
+class TopProducts(CMSPlugin):
+ products = models.ManyToManyField(Product, verbose_name=_('products'), blank=True, null=True,
+ help_text=_('Shows the selected products.'))
+
View
22 cmsplugin_top_products/templates/top_products/plugins/top_products.html
@@ -0,0 +1,22 @@
+{% load i18n modulo thumbnail %}
+{% load currency %}
+<div class="teaser-container">
+ <h4>{% blocktrans %}Top {{ product_count }} products{% endblocktrans %}</h4>
+ {% for product in products %}
+ <p class="teaser-item {% cycle 'odd' 'even' %}">
+ <a href="{{ product.get_absolute_url }}" class="clearfix">
+ {% if product.images.all.0 %}
+ {% thumbnail product.images.all.0.image 65x65 upscale crop as image %}
+ <span class="img">
+ <img src="{{ image }}" alt="" />
+ </span>
+ {% endif %}
+ <span class="desc">
+ <span class="title">{{ product.name }}</span><br />
+ {{ product.short_description }}<br />
+ <strong>{{ product.unit_price|currency }}</strong>
+ </span>
+ </a>
+ </p>
+ {% endfor %}
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.