def validate_cart(self):
cart = self.cart<EOL>user = self.cart.user<EOL>errors = []<EOL>try:<EOL><INDENT>self._test_vouchers(self.cart.vouchers.all())<EOL><DEDENT>except ValidationError as ve:<EOL><INDENT>errors.append(ve)<EOL><DEDENT>items = commerce.ProductItem.objects.filter(cart=cart)<EOL>items = items.select_related("<STR_LIT>", "<STR_LIT>")<EOL>product_quantities = list((i.product, i.quantity) for i in items)<EOL>try:<EOL><INDENT>self._test_limits(product_quantities)<EOL><DEDENT>except ValidationError as ve:<EOL><INDENT>self._append_errors(errors, ve)<EOL><DEDENT>try:<EOL><INDENT>self._test_required_categories()<EOL><DEDENT>except ValidationError as ve:<EOL><INDENT>self._append_errors(errors, ve)<EOL><DEDENT>products = [i.product for i in items]<EOL>discounts_with_quantity = DiscountController.available_discounts(<EOL>user,<EOL>[],<EOL>products,<EOL>)<EOL>discounts = set(i.discount.id for i in discounts_with_quantity)<EOL>discount_items = commerce.DiscountItem.objects.filter(cart=cart)<EOL>for discount_item in discount_items:<EOL><INDENT>discount = discount_item.discount<EOL>if discount.id not in discounts:<EOL><INDENT>errors.append(<EOL>ValidationError("<STR_LIT>")<EOL>)<EOL><DEDENT><DEDENT>if errors:<EOL><INDENT>raise ValidationError(errors)<EOL><DEDENT>
Determines whether the status of the current cart is valid;
        this is normally called before generating or paying an invoice