Django Shop中一个简单易用的产品变体模块
django-shop-simplevariations的Python项目详细描述
此应用程序的目的是提供一种快速创建产品变体的方法 最简单的情况。
它将变量视为cart修饰符中的{label:value}条目,因此 非常适合不同价位的颜色,或是自己打造 例如计算机。
安装
这需要django shop工作(https://github.com/chrisglass/django-shop)
- 将应用程序添加到您设置中已安装的应用程序中。py
- 将shop_simplevariations.cart_modifier.productoptionsmodifier添加到 购物车修改器设置。
- 将(r'^shop/cart/',include(simplevariations\u url)),添加到url.py 就在(r'^shop/',include(shop_url)),
您的url.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)), )
用法
- 在“管理”视图中创建选项组
- 将其绑定到产品
- 向组中添加选项和相应的价格。
- 当cartitem选项对象链接到cartitem时,该选项的值 将添加到CartItem的价格中,相应的额外字段将是 添加到购物车/订单。
- 覆盖django shop的product\u detail.html模板并添加选择 元素,以便用户可以选择变体。
product_detail.html模板
商店附带的简单的product\u 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上分叉此项目,发送拉取请求… Django Shop邮件列表的开发讨论 (django-shop@googlegroups.com)