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


Python Cart.discount方法代码示例

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


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

示例1: submit_orders

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import discount [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.discount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。