Esempio n. 1
0
def get_price(request, product_slug):
    quantity = 1

    try:
        product = Product.objects.get(active=True, slug=product_slug)
    except Product.DoesNotExist:
        return http.HttpResponseNotFound(simplejson.dumps(("", _("not available"))), mimetype="text/javascript")

    prod_slug = product.slug

    if request.POST.has_key("quantity"):
        quantity = int(request.POST["quantity"])

    if "ConfigurableProduct" in product.get_subtypes():
        cp = product.configurableproduct
        chosenOptions = optionset_from_post(cp, request.POST)
        pvp = cp.get_product_from_options(chosenOptions)

        if not pvp:
            return http.HttpResponse(simplejson.dumps(("", _("not available"))), mimetype="text/javascript")
        prod_slug = pvp.slug
        price = moneyfmt(pvp.get_qty_price(quantity))
    else:
        price = moneyfmt(product.get_qty_price(quantity))

    if not price:
        return http.HttpResponse(simplejson.dumps(("", _("not available"))), mimetype="text/javascript")

    return http.HttpResponse(simplejson.dumps((prod_slug, price)), mimetype="text/javascript")
Esempio n. 2
0
def get_price(request, product_slug):
    quantity = 1

    try:
        product = Product.objects.get(active=True, slug=product_slug)
    except Product.DoesNotExist:
        return http.HttpResponseNotFound(simplejson.dumps(
            ('', _("not available"))),
                                         mimetype="text/javascript")

    prod_slug = product.slug

    if request.POST.has_key('quantity'):
        quantity = int(request.POST['quantity'])

    if 'ConfigurableProduct' in product.get_subtypes():
        cp = product.configurableproduct
        chosenOptions = optionset_from_post(cp, request.POST)
        pvp = cp.get_product_from_options(chosenOptions)

        if not pvp:
            return http.HttpResponse(simplejson.dumps(
                ('', _("not available"))),
                                     mimetype="text/javascript")
        prod_slug = pvp.slug
        price = moneyfmt(pvp.get_qty_price(quantity))
    else:
        price = moneyfmt(product.get_qty_price(quantity))

    if not price:
        return http.HttpResponse(simplejson.dumps(('', _("not available"))),
                                 mimetype="text/javascript")

    return http.HttpResponse(simplejson.dumps((prod_slug, price)),
                             mimetype="text/javascript")
Esempio n. 3
0
    def isValid(self, cart=None):
        """
        Make sure this discount still has available uses and is in the current date range.
        If a cart has been populated, validate that it does apply to the products we have selected.
        """
        if not self.active:
            return (False, ugettext('This coupon is disabled.'))
        if self.startDate > date.today():
            return (False, ugettext('This coupon is not active yet.'))
        if self.endDate < date.today():
            return (False, ugettext('This coupon has expired.'))
        if self.numUses > self.allowedUses:
            return (False, ugettext('This discount has exceeded the number of allowed uses.'))
        if not cart:
            return (True, ugettext('Valid.'))

        minOrder = self.minOrder or 0
        if cart.total < minOrder:
            return (False, ugettext('This discount only applies to orders of at least %s.' % moneyfmt(minOrder)))

        #Check to see if the cart items are included
        validProducts = self.validProducts.all()
        # Skip validProducts check if validProducts is empty
        validItems = not bool(validProducts)
        if validProducts:
            for cart_item in cart.cartitem_set.all():
                if cart_item.product in validProducts:
                    validItems = True
                    break   #Once we have 1 valid item, we exit
        if validItems:
            return (True, ugettext('Valid.'))
        else:
            return (False, ugettext('This discount cannot be applied to the products in your cart.'))
Esempio n. 4
0
 def _amount_total(self):
     return moneyfmt(self.amount)
Esempio n. 5
0
 def _order_total(self):
     #Needed for the admin list display
     return moneyfmt(self.total)
Esempio n. 6
0
 def balance_forward(self):
     return moneyfmt(self.balance)
Esempio n. 7
0
 def _amount_total(self):
     return moneyfmt(self.amount)
Esempio n. 8
0
 def _order_total(self):
     #Needed for the admin list display
     return moneyfmt(self.total)
Esempio n. 9
0
 def balance_forward(self):
     return moneyfmt(self.balance)