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


Python OrderItem.product方法代码示例

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


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

示例1: create_from_cart

# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import product [as 别名]
    def create_from_cart(self, cart):
        """
        This creates a new Order object (and all the rest) from a passed Cart
        object.

        Specifically, it creates an Order with corresponding OrderItems and
        eventually corresponding ExtraPriceFields

        This will only actually commit the transaction once the function exits
        to minimize useless database access.

        Emits the ``processing`` signal.
        """
        # must be imported here!
        from shop.models.ordermodel import ExtraOrderItemPriceField, ExtraOrderPriceField, OrderItem
        from shop.models.cartmodel import CartItem

        # Let's create the Order itself:
        order = self.model()
        order.user = cart.user
        order.status = self.model.PROCESSING  # Processing

        order.order_subtotal = cart.subtotal_price
        order.order_total = cart.total_price

        order.save()

        # Let's serialize all the extra price arguments in DB
        for label, value in cart.extra_price_fields:
            eoi = ExtraOrderPriceField()
            eoi.order = order
            eoi.label = str(label)
            eoi.value = value
            eoi.save()

        # There, now move on to the order items.
        cart_items = CartItem.objects.filter(cart=cart)
        for item in cart_items:
            item.update(cart)
            order_item = OrderItem()
            order_item.order = order
            order_item.product_reference = item.product.id
            order_item.product_name = item.product.get_name()
            order_item.product = item.product
            order_item.unit_price = item.product.get_price()
            order_item.quantity = item.quantity
            order_item.line_total = item.line_total
            order_item.line_subtotal = item.line_subtotal
            order_item.save()
            # For each order item, we save the extra_price_fields to DB
            for label, value in item.extra_price_fields:
                eoi = ExtraOrderItemPriceField()
                eoi.order_item = order_item
                # Force unicode, in case it has àö...
                eoi.label = unicode(label)
                eoi.value = value
                eoi.save()

        processing.send(self.model, order=order, cart=cart)
        return order
开发者ID:ronkhan,项目名称:django-shop,代码行数:62,代码来源:managers.py

示例2: create_from_cart

# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import product [as 别名]
    def create_from_cart(self, cart, request):
        """
        This creates a new Order object (and all the rest) from a passed Cart
        object.

        Specifically, it creates an Order with corresponding OrderItems and
        eventually corresponding ExtraPriceFields

        This will only actually commit the transaction once the function exits
        to minimize useless database access.

        The `state` parameter is further passed to process_cart_item,
        process_cart, and post_process_cart, so it can be used as a way to
        store per-request arbitrary information.

        Emits the ``processing`` signal.
        """
        # must be imported here!
        from shop.models.ordermodel import (
            ExtraOrderItemPriceField,
            ExtraOrderPriceField,
            OrderItem,
        )
        from shop.models.cartmodel import CartItem

        # First, let's remove old orders
        self.remove_old_orders(cart)

        # Create an empty order object
        order = self.create_order_object(cart, request)
        order.save()

        # Let's serialize all the extra price arguments in DB
        for field in cart.extra_price_fields:
            eoi = ExtraOrderPriceField()
            eoi.order = order
            eoi.label = unicode(field[0])
            eoi.value = field[1]
            if len(field) == 3:
                eoi.data = field[2]
            eoi.save()

        # There, now move on to the order items.
        cart_items = CartItem.objects.filter(cart=cart)
        for item in cart_items:
            item.update(request)
            order_item = OrderItem()
            order_item.order = order
            order_item.product_reference = item.product.get_product_reference()
            order_item.product_name = item.product.get_name()
            order_item.product = item.product
            order_item.unit_price = item.product.get_price()
            order_item.quantity = item.quantity
            order_item.line_total = item.line_total
            order_item.line_subtotal = item.line_subtotal
            order_item.save()
            # For each order item, we save the extra_price_fields to DB
            for field in item.extra_price_fields:
                eoi = ExtraOrderItemPriceField()
                eoi.order_item = order_item
                # Force unicode, in case it has àö...
                eoi.label = unicode(field[0])
                eoi.value = field[1]
                if len(field) == 3:
                    eoi.data = field[2]
                eoi.save()

        processing.send(self.model, order=order, cart=cart)
        return order
开发者ID:AirLee,项目名称:django-shop,代码行数:71,代码来源:managers.py


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