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


Python Cart.create_cart方法代码示例

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


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

示例1: done

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import create_cart [as 别名]
    def done(self, form_list, **kwargs):
        cart = Cart(self.request)
        cart.create_cart()
        order = Order(cart=cart.cart)

        client = form_list[0].save(commit=False)
        address = form_list[1].save()
        client.shipping_address = address
        billing_address = address
        if condition_step_3(self):
            billing_address = form_list[2].save()
        client.billing_address = billing_address
        client.save()

        order.client = client

        payment_option = self.get_cleaned_data_for_step("4").get("payment_options", None)
        print ("PAYMENT {0}".format(self.get_cleaned_data_for_step("4")))
        language = translation.get_language().upper()
        if payment_option == "PayPal":
            result = self.create_paypalpayment(cart)
            order.payment = result.paypal_payment_db
            order.save()
            # we need to do the checkout after saving the order,
            # if something went wrong
            cart.check_out()

            mail_result = EMailTemplate.objects.send("{0}_ORDER_SUCCESS_PAYPAL".format(language), client.email,
                                                     {"order": order, "billing_address": billing_address,
                                                      "shipping_address": address,
                                                      "paypal_url": order.payment.approval_url})

            if result.payment.error:
                logger.error("PayPal payment went wrong! Errors: {0}".format(result.payment.error))
                return render(self.request, "cuescience_shop/failure_paypal.html", {"order": order})
            elif not result.payment.errors and order.payment.approval_url:
                return render(self.request, "cuescience_shop/success_paypal.html", {"order": order})

        elif payment_option == "Prepayment":
            payment = PrePayment()
            payment.save()
            order.payment = payment
            order.save()
            cart.check_out()
            mail_result = EMailTemplate.objects.send("{0}_ORDER_SUCCESS_PREPAYMENT".format(language), client.email,
                                                     {"order": order, "billing_address": billing_address,
                                                      "shipping_address": address})
            return render(self.request, "cuescience_shop/success.html", {"order": order})

        return render_to_response("cuescience_shop/cart/index.html", RequestContext(self.request))
开发者ID:cuescience,项目名称:cuescience-shop,代码行数:52,代码来源:cart_views.py


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