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


Python Order.shipping_method方法代码示例

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


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

示例1: process_order

# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import shipping_method [as 别名]
    def process_order(self, pyOrder, payment_form):
        """
        Takes the following steps:
        1.  Locks the products in the cart, read-only access only (TBD, I have no idea how to do this ATM)
        2.  Creates an Order instance from the form data in this checkout process, and validates it (it should checkout
            ok, if it doesn't there was a bug in my forms.
        3.  Authorize credit-card, payment information  (the payment form will have a hidden containing the amount to
            put on the card.  This way the number the user sees and the number I charge are guaranteed to be the same.
        4.  Submit the order (save it)
        5.  Decrement product stock
        6.  Unlock the products that were locked in step 1
        7.  Redirect the user to a receipt page
        """
        order = Order()               # db class

        if not payment_form.is_valid():
            return False

        # link user information, even if that user is a guest (lazy) account.  They'll need this information set in
        # order to view their order receipt at the end of the process.
        order.user = self.request.user
        order.first_name = pyOrder.first_name
        order.last_name = pyOrder.last_name
        order.email = pyOrder.email
        order.phone = pyOrder.phone
        order.contact_method = pyOrder.contact_method

        order.shipping_method = pyOrder.shipping_method
        order.shipping_charge = pyOrder.shipping_charge
        order.save()

        # save the payment information
        payment_form.save(order)

        shipping_address = pyOrder.shipping_address.as_address(OrderShippingAddress)
        shipping_address.order = order
        shipping_address.save()

        billing_address = pyOrder.billing_address.as_address(OrderBillingAddress)
        billing_address.order = order
        billing_address.save()

        for order_item in pyOrder.items:
            order_item.order = order
            order_item.full_clean()
            order_item.save()

            # decrement stock for products
            if order_item.is_product():
                in_stock = order_item.item.quantity
                order_item.item.quantity = max(0, in_stock - order_item.quantity)
                order_item.item.save()

            # mark wish list items as sold
            wishlist_links = order_item.cart_item.wishlist_links.all()
            for link in wishlist_links:
                link.wishlist_item.order_item = order_item
                link.wishlist_item.full_clean()
                link.wishlist_item.save()

        for (name, rate, total) in pyOrder.tax_breakdown():
            orderTax = OrderTax(name=name, rate=rate, total=total, order=order)
            orderTax.save()

        # save the order-id in the session dictionary
        self.save('order', order.id)
        return True
开发者ID:arthurcode,项目名称:arthurcode,代码行数:69,代码来源:views.py


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