Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move cart splitting logic to satchless
Patryk Zawadzkic7d6a243c95f
diff --git a/cart/__init__.py b/cart/__init__.pyindex 0e0c7a8c84..cf0b7b4917 100755--- a/cart/__init__.py+++ b/cart/__init__.py@@ -1,11 +1,9 @@-from itertools import groupby-from django.utils.translation import pgettextfrom satchless import cart-from satchless.item import ItemSet, Partitioner+from satchless.item import ItemSet, ClassifyingPartitionerfrom delivery import DummyShipping, DigitalDelivery-from product.models import StockedProduct, DigitalShip+from product.models import DigitalShipclass BaseGroup(list, ItemSet):@@ -63,27 +61,19 @@ class DigitalGroup(BaseGroup):yield DigitalDelivery(self)-class CartPartitioner(Partitioner):+class CartPartitioner(ClassifyingPartitioner):'''Dividing cart into groups.'''- def __iter__(self):- '''- Change this method to provide custom delivery groups.- '''- self.subject = sorted(self.subject, key=self.classify)- for classifier, items in groupby(self.subject, self.classify):- delivery_class = self.get_delivery_class(classifier)- delivery = delivery_class(items)- yield delivery-def classify(self, item):- return item.product.__class__+ if isinstance(item.product, DigitalShip):+ return 'digital'+ return 'shippable'- def get_delivery_class(self, classifier):- if issubclass(classifier, DigitalShip):- return DigitalGroup- return ShippedGroup+ def get_partition(self, classifier, items):+ if classifier == 'digital':+ return DigitalGroup(items)+ return ShippedGroup(items)def get_delivery_subtotal(self, partion, **kwargs):return partion.get_delivery_total(**kwargs)@@ -100,9 +90,6 @@ class CartPartitioner(Partitioner):total = super(CartPartitioner, self).get_total()return total + self.get_delivery_total()- def __repr__(self):- return 'CartPartitioner(%r)' % (list(self),)-class Cart(cart.Cart):'''diff --git a/setup.py b/setup.pyindex 6217c8d3e0..e122d2bc99 100755--- a/setup.py+++ b/setup.py@@ -28,7 +28,7 @@ setup('django-payments>=0.3,<0.4a0','django-prices>=0.2,<0.3a0','prices>=0.4.2,<0.5a0',- 'satchless>=1.0.3,<1.1a0',+ 'satchless>=1.0.4,<1.1a0','South>=0.7.6','requests>=1.2.0','unidecode'],