2012-09-26 370 views
0

如何添加此模型中的產品到購物車:https://github.com/bmentges/django-cart 如何運行方法add_to_cart?在模板中,我會有按鈕「添加到購物車」。由於如何添加產品到購物車?

from django.db import models 
from sorl.thumbnail import ImageField 

class Product(models.Model): 
    name = models.CharField(max_length=50) 
    slug = models.SlugField() 
    price = models.DecimalField(max_digits=5, decimal_places=2) 
    desc = models.TextField() 
    image = ImageField(upload_to='images') 

    class Meta: 
     verbose_name = _('Product') 
     verbose_name_plural = _('Products') 

    def __unicode__(self): 
     return self.name 

什麼是quantityunit_price從Django的購物車的基本用法:https://github.com/bmentges/django-cart

def add_to_cart(request, product_id, quantity): 
    product = Product.objects.get(id=product_id) 
    cart = Cart(request) 
    cart.add(product, product.unit_price, quantity) 

回答

1

什麼是從Django的購物車的基本使用量和UNIT_PRICE:

數量是在你的訂單項產品的數量。

如果您說3,則表示您的購物車中有3個「產品」。這通常與其旁邊的添加到購物車按鈕的input type='text'字段相關。

unit_price是您的產品單個單位的價格。它不會自動從產品中拉出,因爲它可能與產品實際價格有很大差異。

例如,也許有20%的銷售;這個系統可以讓你的購物車中的價格與產品價格不同。

相關問題