]> git.parisson.com Git - diggersdigest.git/commitdiff
Manage Shipping rate rules for France/Euro Zone/World
authorThomas Fillon <thomas@parisson.com>
Tue, 29 Sep 2015 22:30:34 +0000 (00:30 +0200)
committerThomas Fillon <thomas@parisson.com>
Tue, 29 Sep 2015 22:30:34 +0000 (00:30 +0200)
app/diggersdigest/settings.py
app/records/models.py
app/records/utils.py
requirements-dev.txt

index 222327488a0b30ed45568a270e3aa441edc01c21..19dee6aaf165b1db7d5d6806f501ac9dbc5391ed 100644 (file)
@@ -134,8 +134,8 @@ SHOP_CURRENCY_LOCALE = ''
 # is called on submit of the billing/shipping checkout step. This
 # is where shipping calculation can be performed and set using the
 # function ``cartridge.shop.utils.set_shipping``.
-SHOP_HANDLER_BILLING_SHIPPING = \
-#                       "cartridge.shop.checkout.default_billship_handler"
+SHOP_HANDLER_BILLING_SHIPPING = \
+                      "records.utils.custom_billship_handler"
 
 # Dotted package path and name of the function that
 # is called once an order is successful and all of the order
@@ -180,7 +180,8 @@ MIGRATION_MODULES = {
 # PAYPAL
 
 # USE or EXTEND the custom callback-uuid form
-SHOP_CHECKOUT_FORM_CLASS = 'payments.multipayments.forms.base.CallbackUUIDOrderForm'
+#SHOP_CHECKOUT_FORM_CLASS = 'payments.multipayments.forms.base.CallbackUUIDOrderForm'
+SHOP_CHECKOUT_FORM_CLASS = 'records.utils.CustomOrderForm'
 
 PRIMARY_PAYMENT_PROCESSOR_IN_USE = False
 
index bcdaf11e9b809e0b15d77244adf4d8eedc8832b4..fec84e9b0cf330e95f62bedfef90ae6b645b7e49 100644 (file)
@@ -17,7 +17,9 @@ from mezzanine.core.models import CONTENT_STATUS_DRAFT, CONTENT_STATUS_PUBLISHED
 from mezzanine.blog.models import BlogPost
 from mezzanine.utils.models import upload_to
 
-from utils import *
+from cartridge.shop.models import Product
+
+#from utils import *
 
 # Auto-generated Django models with manage.py inspectdb on the old database
 # You'll have to do the following manually to clean this up:
index 8442b5f807cd18bbaa932d6fc36ed85e09f97a04..758b504c8f5c054c34a6b242734a151d5910fdf8 100644 (file)
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
 
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
+from django import forms
 
 import datetime
 import os
@@ -12,10 +13,23 @@ import fnmatch
 from importlib import import_module
 from mezzanine.conf import settings
 
+from cartridge.shop import checkout
 from cartridge.shop.models import Product, Category, Cart, Order, ProductVariation, DiscountCode
+from cartridge.shop.utils import set_shipping
+
+from django_countries.data import COUNTRIES
+COUNTRY_CHOICES = tuple((k,v) for k,v in COUNTRIES.items())
+
+from operator import itemgetter
+
+COUNTRY_CHOICES = tuple(sorted(COUNTRY_CHOICES, key=itemgetter(1)))
+    
+from payments.multipayments.forms.base import CallbackUUIDOrderForm
+
 from paypal.standard.ipn.signals import valid_ipn_received
 
 
+
 def payment_complete(sender, **kwargs):
     """Performs the same logic as the code in
     cartridge.shop.models.Order.complete(), but fetches the session,
@@ -72,3 +86,142 @@ def payment_complete(sender, **kwargs):
             pass
 
 valid_ipn_received.connect(payment_complete)
+
+# See https://github.com/SmileyChris/django-countries/blob/master/django_countries/data.py#L46
+EURO_ZONE = [
+    ## Zone 1
+    'DE', ## Allemagne,
+    'BE', ## Belgique,
+    'LU', ## Luxembourg,
+    'NL', ## Pays-Bas.
+    ## Zone 2 :
+    'AT', ## Autriche,
+    'DK', ## Danemark,
+    'ES', ## Espagne,
+    'FI', ## Finlande,
+    'UK', ## Grande-Bretagne,
+    'GR', ## Grèce,
+    'IE', ## Irlande,
+    'IT', ## Italie,
+    'PT', ## Portugal,
+    'SE', ## Suède.
+    ## Zone 3 :
+    'BG', ## Bulgarie,
+    'CY', ## Chypre,
+    'HR', ## Croatie,
+    'EE', ## Estonie,
+    'HU', ## Hongrie,
+    'LV', ## Lettonie,
+    'LT', ## Lituanie,
+    'MT', ## Malte,
+    'PL', ## Pologne,
+    'CZ', ## République Tchèque,
+    'RO', ## Roumanie,
+    'SK', ## Slovaquie,
+    'SI', ## Slovénie. +
+    ## Hors Zone
+    'NO', ## Norvege
+    'CH', ## Suisse
+    ]
+
+
+def custom_billship_handler(request, order_form):
+    """
+    Default billing/shipping handler - called when the first step in
+    the checkout process with billing/shipping address fields is
+    submitted. Implement your own and specify the path to import it
+    from via the setting ``SHOP_HANDLER_BILLING_SHIPPING``.
+    This function will typically contain any shipping calculation
+    where the shipping amount can then be set using the function
+    ``cartridge.shop.utils.set_shipping``. The Cart object is also
+    accessible via ``request.cart``
+    """
+
+    shipping_type = "shipping rate"
+    shipping_total = 15
+    
+    if order_form is not None:
+        shipping_detail_country = order_form.cleaned_data['shipping_detail_country']
+        if shipping_detail_country == 'FR':
+            if (request.cart.total_price() <= 100) & (request.cart.total_quantity()< 3):
+                shipping_type = _("Colissimo shipping")
+                shipping_total = 7
+            else:
+                shipping_type = _("Colissimo recommande shipping")
+                shipping_total = 10
+                 
+        elif shipping_detail_country in EURO_ZONE:
+            if (request.cart.total_price() <= 50) & (request.cart.total_quantity()< 6):
+                shipping_type = _("SIMPLE  REGISTERED PRIORITY PARCEL shipping")
+                shipping_total = 12
+            elif (request.cart.total_price() <= 150) & (request.cart.total_quantity()< 6):
+                shipping_type = _("SIMPLE  REGISTERED PRIORITY PARCEL shipping")
+                shipping_total = 14.50
+            else:
+                shipping_type = _("INTERNATIONAL COLISSIMO (INSURED) shipping")
+                shipping_total = 18
+
+        else:
+            if (request.cart.total_price() <= 50) & (request.cart.total_quantity()< 6):
+                shipping_type = _("SIMPLE  REGISTERED PRIORITY PARCEL shipping")
+                shipping_total = 13
+            elif (request.cart.total_price() <= 150) & (request.cart.total_quantity()< 6):
+                shipping_type = _("SIMPLE  REGISTERED PRIORITY PARCEL shipping")
+                shipping_total = 16
+            else:
+                shipping_type = _("INTERNATIONAL COLISSIMO (INSURED) shipping")
+                shipping_total = 25
+
+
+    
+    if not request.session.get("free_shipping"):
+        settings.use_editable()
+        print shipping_type, shipping_total
+        set_shipping(request, shipping_type, shipping_total)
+
+
+SHIPPING_CHOICES = ( (0,"SIMPLE REGISTERED PRIORITY PARCEL"),
+                     (1,"INTERNATIONAL COLISSIMO (INSURED)"),
+                     (2,"COLISSIMO (France only)"),
+                     (3,"COLISSIMO RECOMMANDE (France only)"),
+                     ) 
+
+
+
+class CustomOrderForm(CallbackUUIDOrderForm):
+    ## shipping_method = forms.ChoiceField(choices=SHIPPING_CHOICES,
+    ##                                     label=_("Shipping method"))
+
+    def __init__(self, request, step, data=None, initial=None, errors=None,
+            **kwargs):
+        """
+        Setup for each order form step which does a few things:
+        """
+        super(CustomOrderForm, self).__init__(request, step, data=data, initial=initial, **kwargs)
+        billing_country = forms.Select(choices=COUNTRY_CHOICES)
+        shipping_country = forms.Select(choices=COUNTRY_CHOICES)
+        self.fields['billing_detail_country'].widget = billing_country
+        self.fields['shipping_detail_country'].widget = shipping_country
+
+        
+        
+    ##     if step == checkout.CHECKOUT_STEP_PAYMENT:
+    ##         print "Payment step"
+    ##         if self.is_valid():
+    ##             data = self.cleaned_data
+    ##             if data["shipping_detail_country"] == 'France':
+    ##                 print ' ----- FRANCE ----' 
+    ##                 choices = SHIPPING_CHOICES[2:3]
+    ##                 self.fields["shipping_method"].choices = choices
+    ##             else:
+    ##                 print '  ----- PAS FRANCE ---------'
+    ##                 print self.fields["shipping_detail_country"]
+    ##         else:
+    ##             print "Pas VALIDE"
+                
+
+
+    ## class Meta(CallbackUUIDOrderForm.Meta):
+    ##     
+    ##     fields = CallbackUUIDOrderForm.Meta.fields + ["shipping_method"]
+    ##     print fields
index e10f4b5668cd71dbea4e3705af8a7c009aa04cf7..1787476ba44ef9f348454a31546a8bc716cdbb6d 100644 (file)
@@ -1,3 +1,4 @@
 
 -e git+https://github.com/Parisson/cartridge-payments.git#egg=cartridge-payments
 -e git+https://github.com/Parisson/django-paypal.git#egg=django-paypal-0.2.5
+django-countries