为django SHOP提供简单易用的产品变体模块
项目描述
此应用旨在提供一种快速创建产品变体的方法,适用于大多数简单情况。
它将变体视为购物车修饰符中的 {label: value} 条目,因此非常适合不同价格的颜色或自建电脑等。
安装
此功能需要django SHOP工作(https://github.com/chrisglass/django-shop)
将应用添加到settings.py中的INSTALLED_APPS
将shop_simplevariations.cart_modifier.ProductOptionsModifier添加到您的SHOP_CART_MODIFIERS设置中。
在urls.py中添加以下内容(r’^shop/cart/’, include(simplevariations_urls)),在(r’^shop/’, include(shop_urls))之前。
您的urls.py应如下所示
from django.conf.urls.defaults import *
from django.contrib import admin
from shop import urls as shop_urls
from shop_simplevariations import urls as simplevariations_urls
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^shop/cart/', include(simplevariations_urls)),
(r'^shop/', include(shop_urls)),
)
用法
在管理视图中创建一个选项组
将其绑定到产品上
向组中添加选项及其对应的价格。
当CartItemOption对象与CartItem对象相关联时,选项的值将添加到购物项的价格中,并在购物车/订单中添加相应的额外字段。
覆盖django-shop的product_detail.html模板,并添加选择元素,以便用户可以选择变体。
product_detail.html模板
shop附带的基本product_detail.html模板不考虑变体。
因此您需要覆盖模板。django-shop-simplevariations附带两个帮助创建下拉列表的模板标签,以便客户可以实际选择变体。
首先确保加载simplevariation模板标签
{% load simplevariation_tags %}
<h1>Product detail:</h1>
...
然后创建选项组和选项的下拉列表
<form method="post" action="{% url cart %}">{% csrf_token %}
{% with option_groups=object|get_option_groups %}
{% if option_groups %}
<div>
<h2>Variations:</h2>
{% for option_group in option_groups %}
<label for="add_item_option_group_{{ option_group.id }}">{{ option_group.name }}</label>
{% with option_group|get_options as options %}
<select name="add_item_option_group_{{ option_group.id }}">
{% for option in options %}
<option value="{{ option.id }}">{{ option.name }}</option>
{% endfor %}
</select>
{% endwith %}
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% with text_options=object.text_options.all %}
{% if text_options %}
<div>
<h2>Text options:</h2>
{% for text_option in text_options %}
<label for="add_item_text_option_{{ text_option.id }}">{{ text_option.name }}</label>
<input type="text" name="add_item_text_option_{{ text_option.id }}" value=""/>
{% endfor %}
</div>
{% endif %}
{% endwith %}
<input type="hidden" name="add_item_id" value="{{object.id}}">
<input type="hidden" name="add_item_quantity" value="1">
<input type="submit" value="Add to cart">
</form>
贡献
请随意在github上分叉此项目,发送pull请求……开发讨论在django SHOP邮件列表(django-shop@googlegroups.com)上进行。