Example #1
0
    def update(self, request, raise_exception=False):
        """
        This should be called after a cart item changed quantity, has been added or removed.

        It will loop over all items in the cart, and call all the configured cart modifiers.
        After this is done, it will compute and update the order's total and subtotal fields, along
        with any supplement 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)
        """
        if not self._dirty:
            return

        if self._cached_cart_items:
            items = self._cached_cart_items
        else:
            items = CartItemModel.objects.filter_cart_items(self, request)

        # This calls all the pre_process_cart methods and the pre_process_cart_item for each item,
        # before processing the cart. This allows to prepare and collect data on the cart.
        for modifier in cart_modifiers_pool.get_all_modifiers():
            modifier.pre_process_cart(self, request, raise_exception)
            for item in items:
                modifier.pre_process_cart_item(self, item, request,
                                               raise_exception)

        self.extra_rows = OrderedDict()  # reset the dictionary
        self.subtotal = 0  # reset the subtotal
        for item in items:
            # item.update iterates over all cart modifiers and invokes method `process_cart_item`
            item.update(request)
            self.subtotal += item.line_total

        # Iterate over the registered modifiers, to process the cart's summary
        for modifier in cart_modifiers_pool.get_all_modifiers():
            for item in items:
                modifier.post_process_cart_item(self, item, request)
            modifier.process_cart(self, request)

        # 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 reversed(cart_modifiers_pool.get_all_modifiers()):
            modifier.post_process_cart(self, request)

        # Cache updated cart items
        self._cached_cart_items = items
        self._dirty = False
Example #2
0
    def update(self, request):
        """
        This should be called after a cart item changed quantity, has been added or removed.

        It will loop on all line items in the cart, and call all the cart modifiers for each item.
        After doing this, it will compute and update the order's total and subtotal fields, along
        with any supplement 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)
        """
        if not self._dirty:
            return

        if self._cached_cart_items:
            items = self._cached_cart_items
        else:
            items = CartItemModel.objects.filter_cart_items(self, request)

        # This calls all the pre_process_cart methods and the pre_process_cart_item for each item,
        # before processing the cart. This allows to prepare and collect data on the cart.
        for modifier in cart_modifiers_pool.get_all_modifiers():
            modifier.pre_process_cart(self, request)
            for item in items:
                modifier.pre_process_cart_item(self, item, request)

        self.extra_rows = OrderedDict()  # reset the dictionary
        self.subtotal = 0  # reset the subtotal
        for item in items:
            # item.update iterates over all cart modifiers and invokes method `process_cart_item`
            item.update(request)
            self.subtotal += item.line_total

        # Iterate over the registered modifiers, to process the cart's summary
        for modifier in cart_modifiers_pool.get_all_modifiers():
            for item in items:
                modifier.post_process_cart_item(self, item, request)
            modifier.process_cart(self, request)

        # 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 reversed(cart_modifiers_pool.get_all_modifiers()):
            modifier.post_process_cart(self, request)

        # Cache updated cart items
        self._cached_cart_items = items
        self._dirty = False
Example #3
0
 def filter_watch_items(self, cart, request):
     """
     Use this method to fetch items from the watch list. It rearranges the result set
     according to the defined modifiers.
     """
     watch_items = self.filter(cart=cart, quantity=0)
     for modifier in cart_modifiers_pool.get_all_modifiers():
         watch_items = modifier.arrange_watch_items(watch_items, request)
     return watch_items
Example #4
0
 def filter_cart_items(self, cart, request):
     """
     Use this method to fetch items for shopping from the cart. It rearranges the result set
     according to the defined modifiers.
     """
     cart_items = self.filter(cart=cart, quantity__gt=0)
     for modifier in cart_modifiers_pool.get_all_modifiers():
         cart_items = modifier.arrange_cart_items(cart_items, request)
     return cart_items
Example #5
0
 def filter_watch_items(self, cart, request):
     """
     Use this method to fetch items from the watch list. It rearranges the result set
     according to the defined modifiers.
     """
     watch_items = self.filter(cart=cart, quantity=0)
     for modifier in cart_modifiers_pool.get_all_modifiers():
         watch_items = modifier.arrange_watch_items(watch_items, request)
     return watch_items
Example #6
0
 def filter_cart_items(self, cart, request):
     """
     Use this method to fetch items for shopping from the cart. It rearranges the result set
     according to the defined modifiers.
     """
     cart_items = self.filter(cart=cart, quantity__gt=0)
     for modifier in cart_modifiers_pool.get_all_modifiers():
         cart_items = modifier.arrange_cart_items(cart_items, request)
     return cart_items
Example #7
0
 def update(self, request):
     """
     Loop over all registered cart modifier, change the price per cart item and optionally add
     some extra rows.
     """
     if not self._dirty:
         return
     self.extra_rows = OrderedDict()  # reset the dictionary
     for modifier in cart_modifiers_pool.get_all_modifiers():
         modifier.process_cart_item(self, request)
     self._dirty = False
Example #8
0
 def update(self, request):
     """
     Loop over all registered cart modifier, change the price per cart item and optionally add
     some extra rows.
     """
     if not self._dirty:
         return
     self.extra_rows = OrderedDict()  # reset the dictionary
     for modifier in cart_modifiers_pool.get_all_modifiers():
         modifier.process_cart_item(self, request)
     self._dirty = False