• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python cart_modifiers_pool.get_modifiers_list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shop.cart.modifiers_pool.cart_modifiers_pool.get_modifiers_list函数的典型用法代码示例。如果您正苦于以下问题:Python get_modifiers_list函数的具体用法?Python get_modifiers_list怎么用?Python get_modifiers_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: update

    def update(self, request):
        """
        This should be called whenever anything is changed in the cart (added
        or removed).
        
        It will loop on all line items in the cart, and call all the price
        modifiers on each row.
        After doing this, it will compute and update the order's total and
        subtotal fields, along with any payment field added along the way by
        modifiers.

        Note that theses added fields are not stored - we actually want to
        reflect rebate and tax changes on the *cart* items, but we don't want
        that for the order items (since they are legally binding after the
        "purchase" button was pressed)
        """
        from shop.models import CartItem, Product

        # This is a ghetto "select_related" for polymorphic models.
        items = CartItem.objects.filter(cart=self).order_by('pk')
        product_ids = [item.product_id for item in items]
        products = Product.objects.filter(pk__in=product_ids)
        products_dict = dict([(p.pk, p) for p in products])

        self.extra_price_fields = []  # Reset the price fields
        self.subtotal_price = Decimal('0.0')  # Reset the subtotal

        # The request object holds extra information in a dict named 'cart_modifier_state'.
        # Cart modifiers can use this dict to pass arbitrary data from and to each other.
        if not hasattr(request, 'cart_modifier_state'):
            setattr(request, 'cart_modifier_state', {})

        # This calls all the pre_process_cart methods (if any), before the cart
        # is processed. This allows for data collection on the cart for
        # example)
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.pre_process_cart(self, request)

        for item in items:  # For each CartItem (order line)...
            # This is still the ghetto select_related
            item.product = products_dict[item.product_id]
            self.subtotal_price = self.subtotal_price + item.update(request)

        self.current_total = self.subtotal_price
        # Now we have to iterate over the registered modifiers again
        # (unfortunately) to pass them the whole Order this time
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.process_cart(self, request)

        self.total_price = self.current_total

        # This calls the post_process_cart method from cart modifiers, if any.
        # It allows for a last bit of processing on the "finished" cart, before
        # it is displayed
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.post_process_cart(self, request)

        # Cache updated cart items
        self._updated_cart_items = items
开发者ID:jrutila,项目名称:django-shop,代码行数:59,代码来源:__init__.py


示例2: update

    def update(self, state=None):
        """
        This should be called whenever anything is changed in the cart (added
        or removed).
        It will loop on all line items in the cart, and call all the price
        modifiers on each row.
        After doing this, it will compute and update the order's total and
        subtotal fields, along with any payment field added along the way by
        modifiers.

        Note that theses added fields are not stored - we actually want to
        reflect rebate and tax changes on the *cart* items, but we don't want
        that for the order items (since they are legally binding after the
        "purchase" button was pressed)
        """
        from shop.models import CartItem, Product

        # This is a ghetto "select_related" for polymorphic models.
        items = CartItem.objects.filter(cart=self)
        product_ids = [item.product_id for item in items]
        products = Product.objects.filter(id__in=product_ids)
        products_dict = dict([(p.id, p) for p in products])

        self.extra_price_fields = []  # Reset the price fields
        self.subtotal_price = Decimal("0.0")  # Reset the subtotal

        # This will hold extra information that cart modifiers might want to pass
        # to each other
        if state == None:
            state = {}

        # This calls all the pre_process_cart methods (if any), before the cart
        # is processed. This allows for data collection on the cart for example)
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.pre_process_cart(self, state)

        for item in items:  # For each OrderItem (order line)...
            item.product = products_dict[item.product_id]  # This is still the ghetto select_related
            self.subtotal_price = self.subtotal_price + item.update(state)

        self.current_total = self.subtotal_price
        # Now we have to iterate over the registered modifiers again (unfortunately)
        # to pass them the whole Order this time
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.process_cart(self, state)

        self.total_price = self.current_total

        # This calls the post_process_cart method from cart modifiers, if any.
        # It allows for a last bit of processing on the "finished" cart, before
        # it is displayed
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.post_process_cart(self, state)
开发者ID:powellc,项目名称:django-shop,代码行数:53,代码来源:bases.py


示例3: update

 def update(self):
     """
     This should be called whenever anything is changed in the cart (added or removed)
     It will loop on all line items in the cart, and call all the price modifiers
     on each row.
     After doing this, it will compute and update the order's total and
     subtotal fields, along with any payment field added along the way by
     modifiers.
     
     Note that theses added fields are not stored - we actually want to reflect
     rebate and tax changes on the *cart* items, but we don't want that for
     the order items (since they are legally binding after the "purchase" button
     was pressed)
     """
     items = CartItem.objects.filter(cart=self)
     self.subtotal_price = Decimal('0.0') # Reset the subtotal
     
     for item in items: # For each OrderItem (order line)...
         self.subtotal_price = self.subtotal_price + item.update()
         item.save()
     
     # Now we have to iterate over the registered modifiers again (unfortunately)
     # to pass them the whole Order this time
     for modifier in cart_modifiers_pool.get_modifiers_list():
         modifier.process_cart(self)
         
     self.total_price = self.subtotal_price
     # Like for line items, most of the modifiers will simply add a field
     # to extra_price_fields, let's update the total with them
     for label, value in self.extra_price_fields:
         self.total_price = self.total_price + value
开发者ID:matthiasnuesch,项目名称:django-shop,代码行数:31,代码来源:cartmodel.py


示例4: update

 def update(self):
     '''
     This should be called whenever anything is changed in the cart (added or removed)
     It will loop on all line items in the cart, and call all the price modifiers
     on each row.
     After doing this, it will compute and update the order's total and
     subtotal fields, along with any payment field added along the way by
     modifiers.
     
     Note that theses added fields are not stored - we actually want to reflect
     rebate and tax changes on the *cart* items, but we don't want that for
     the order items (since they are legally binding after the "purchase" button
     was pressed)
     '''
     items = list(CartItem.objects.filter(cart=self)) # force query to "cache" it
     
     self.subtotal_price = Decimal('0.0') # Reset the subtotal
     for item in items: # For each OrderItem (order line)...
         
         item.line_subtotal = item.product.unit_price * item.quantity
         item.line_total = item.line_subtotal
         
         for modifier in cart_modifiers_pool.get_modifiers_list():
             # We now loop over every registered price modifier,
             # most of them will simply add a field to extra_payment_fields
             item = modifier.process_cart_item(item)
             for value in item.extra_price_fields.itervalues():
                 item.line_total = item.line_total + value
             
         # Let's update the Order's subtotal with this line's total while 
         # we're at it
         self.subtotal_price = self.subtotal_price + item.line_total
         item.save()
     
     # Now we have to iterate over the registered modifiers again (unfortunately)
     # to pass them the whole Order this time
     for modifier in cart_modifiers_pool.get_modifiers_list():
         modifier.process_cart(self)
         
     self.total_price = self.subtotal_price
     # Like for line items, most of the modifiers will simply add a field
     # to extra_price_fields, let's update the total with them
     for value in self.extra_price_fields.itervalues():
         self.total_price = self.total_price + value
         
     self.save()
开发者ID:jsma,项目名称:django-shop,代码行数:46,代码来源:cartmodel.py


示例5: update

    def update(self, state):
        self.extra_price_fields = []  # Reset the price fields
        self.line_subtotal = self.product.get_price() * self.quantity
        self.current_total = self.line_subtotal

        for modifier in cart_modifiers_pool.get_modifiers_list():
            # We now loop over every registered price modifier,
            # most of them will simply add a field to extra_payment_fields
            modifier.process_cart_item(self, state)

        self.line_total = self.current_total
        return self.line_total
开发者ID:lookup,项目名称:django-shop,代码行数:12,代码来源:__init__.py


示例6: update

 def update(self):
     self.line_subtotal = self.product.get_price() * self.quantity
     self.line_total = self.line_subtotal
     
     for modifier in cart_modifiers_pool.get_modifiers_list():
         # We now loop over every registered price modifier,
         # most of them will simply add a field to extra_payment_fields
         modifier.process_cart_item(self)
         for value in self.extra_price_fields.itervalues():
             self.line_total = self.line_total + value
             
     return self.line_total
开发者ID:audreyr,项目名称:django-shop,代码行数:12,代码来源:cartmodel.py


示例7: update

    def update(self):
        """
        This should be called whenever anything is changed in the cart (added
        or removed).
        It will loop on all line items in the cart, and call all the price
        modifiers on each row.
        After doing this, it will compute and update the order's total and
        subtotal fields, along with any payment field added along the way by
        modifiers.

        Note that theses added fields are not stored - we actually want to
        reflect rebate and tax changes on the *cart* items, but we don't want
        that for the order items (since they are legally binding after the
        "purchase" button was pressed)
        """
        from shop.models import CartItem, Product
        
        # This is a ghetto "select_related" for polymorphic models. 2 queries!
        items = CartItem.objects.filter(cart=self)
        product_ids = [item.product_id for item in items]
        products = Product.objects.filter(id__in=product_ids)
        products_dict = dict([(p.id, p) for p in products])
        
        self.extra_price_fields = [] # Reset the price fields
        self.subtotal_price = Decimal('0.0') # Reset the subtotal

        for item in items: # For each OrderItem (order line)...
            item.product = products_dict[item.product_id] #This is still the ghetto select_related
            self.subtotal_price = self.subtotal_price + item.update()
            item.save()
        
        self.current_total = self.subtotal_price
        # Now we have to iterate over the registered modifiers again (unfortunately)
        # to pass them the whole Order this time
        for modifier in cart_modifiers_pool.get_modifiers_list():
            modifier.process_cart(self)
        
        self.total_price = self.current_total
开发者ID:avenpace,项目名称:django-shop,代码行数:38,代码来源:bases.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cartmodel.Cart类代码示例发布时间:2022-05-27
下一篇:
Python basketish_order_source.BasketishOrderSource类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap