当前位置: 首页>>代码示例>>Python>>正文


Python Cart.count方法代码示例

本文整理汇总了Python中cart.Cart.count方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.count方法的具体用法?Python Cart.count怎么用?Python Cart.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cart.Cart的用法示例。


在下文中一共展示了Cart.count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: subscribe

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import count [as 别名]
def subscribe(request):
    cart = Cart(request)
    if cart.count() < 1:
        sub = Subscription.objects.get(plan="monthly")
        cart.add(sub, sub.price, 1)

    return redirect("checkout")
开发者ID:destos,项目名称:godjango-site,代码行数:9,代码来源:views.py

示例2: checkout

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import count [as 别名]
def checkout(request):
    # import pdb; pdb.set_trace()
    cart=Cart(request)
    if cart.count() == 0:
        return HttpResponseRedirect('/my-cart')

    profile = Profile.objects.get(user__username=request.user)
    form = DeliveryAddress(request.POST or None, instance=profile)
    delivery_form = DeliveryServiceForm(request.POST or None)
    tot_weight = request.session['total_weight']

    if form.is_valid() and delivery_form.is_valid():        
        delivery_cost = delivery_form.cleaned_data['service']
        tot_vat = request.POST.get('tot_vat')
        # import pdb; pdb.set_trace()
        # order data
        order = Order()
        order.user = request.user
        order.amount = float(cart.summary()) + float(delivery_cost.cost) + float(tot_vat)
        order.vat = float(tot_vat)
        order.status = 'NEW'
        order.order_notes = request.POST.get('notes')
        order.save()
        # order detail data
        for ca in cart:
            orderdetail = OrderDetail()
            orderdetail.order = order
            orderdetail.product = ca.product
            orderdetail.weight = ca.product.weight
            orderdetail.surcharge = ca.product.surcharge
            orderdetail.price = ca.unit_price
            orderdetail.qty = ca.quantity
            orderdetail.amount = ca.total_price
            orderdetail.save()
        # order delivery data
        orderdelivery = OrderDelivery ()
        orderdelivery.order = order
        orderdelivery.first_name = form.cleaned_data['first_name']
        orderdelivery.last_name = form.cleaned_data['last_name']
        orderdelivery.business_name = form.cleaned_data['business_name']
        orderdelivery.address_line1 = form.cleaned_data['address_line1']
        orderdelivery.address_line2 = form.cleaned_data['address_line2']
        orderdelivery.city = form.cleaned_data['city']
        orderdelivery.state = form.cleaned_data['state']
        orderdelivery.postcode = form.cleaned_data['postcode']
        orderdelivery.country = form.cleaned_data['country']
        orderdelivery.telephone = form.cleaned_data['telephone']
        orderdelivery.service = delivery_cost.title
        orderdelivery.cost = delivery_cost.cost
        orderdelivery.weight = tot_weight
        orderdelivery.save()
        cart.clear()
        messages.success(request, "Your order was complete.")
        return HttpResponseRedirect('/orderreview/'+ order.order_no)

    try:        
        check_band = PostageCountry.objects.get(country=profile.country)        
        band = check_band.band        
        request.session['vat'] = check_band.vat
    except:
        band = ''    
        
    delivery_form.fields['service'] = forms.ModelChoiceField(required=True, queryset=PostageRate.objects.all().filter(band=band,active=True,weight_start__lte=tot_weight,weight_to__gte=tot_weight), widget=forms.Select(attrs={'class': 'form-control'}))

    data = {'form':form,'delivery_form':delivery_form}
    return render_to_response('order/checkout.html', data, context_instance=RequestContext(request, processors=[custom_proc]))
开发者ID:aijogja,项目名称:Myton_Django_Project,代码行数:68,代码来源:views.py

示例3: submit_orders

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import count [as 别名]
def submit_orders(request):
	# gets logged in user profile, or anonymous profile
	profile = current_profile(request)
	current_cart = Cart(request)

	# the cart has its own discount logic
	# plus we need to account for any user submitted coupons
	total_amount = current_cart.discount_applied() * 100
	discount_amount = current_cart.discount() * 100.0
	coupon_amount = float(request.POST.get('coupon_amount', 0.0))
	shipping_amount = float(request.POST.get('shipping_amount', 0.0))

	# actual amount to charge with stripe
	final_amount = total_amount - coupon_amount + shipping_amount

	print(str(current_cart.count()) + ' items')
	print('total ' + str(total_amount))
	print('coupon amount ' + str(coupon_amount))
	print('shipping amount ' + str(shipping_amount))
	print('final amount ' + str(final_amount))

	# grab email for reference in stripe
	if profile.user.username == 'guest':
		email = request.POST.get('email_address', '')
	else:
		email = profile.user.email

	# subscribing people to mailchimp
	if request.POST.get('email_checkbox','') and email != '':
		ms = MailSnake(settings.MAILCHIMP_KEY)
		lists = ms.lists()
		ms.listSubscribe(
		    id = lists['data'][0]['id'],
		    email_address = email,
		    update_existing = True,
		    double_optin = False,
		)

	# see your keys here https://manage.stripe.com/account
	stripe.api_key = settings.STRIPE_SECRET_KEY # key the binx gave
	stripe_desc = str(email) + ", " + str(current_cart.count()) + " meshus"

	print(stripe_desc)

	# get the credit card details submitted by the form
	token = request.POST['stripe_token']

	# create the charge on Stripe's servers - this will charge the user's card
	charge = stripe.Charge.create(
	    amount = int(final_amount), # amount in cents, again
	    currency = "usd",
	    card = token,
	    description = stripe_desc
	)

	# store the shipping address information
	shipping = ShippingInfo()
	shipping.contact = email
	shipping.shipping_name = request.POST['shipping_name']
	shipping.shipping_address = request.POST['shipping_address']
	shipping.shipping_address_2 = request.POST['shipping_address_2']
	shipping.shipping_city = request.POST['shipping_city']
	shipping.shipping_zip = request.POST['shipping_zip']
	shipping.shipping_region = request.POST['shipping_region']
	shipping.shipping_state = request.POST['shipping_state']
	shipping.shipping_country = request.POST['shipping_country']

	# save shipping separately now, not in Order
	shipping.amount = shipping_amount

	shipping.save()

	items = current_cart.cart.item_set.all()

	if current_cart.count() > 1:
		return submit_multiple(request, shipping, items, final_amount, discount_amount, coupon_amount)
	elif current_cart.count() == 1:
		return submit_single(request, shipping, items, final_amount, coupon_amount)
开发者ID:,项目名称:,代码行数:80,代码来源:


注:本文中的cart.Cart.count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。