def add_extra_cart_row(self, cart, request): if not self.is_active(cart) and len( cart_modifiers_pool.get_shipping_modifiers()) > 1: return weight = max(cart.weight, Decimal('0.001')).quantize(Decimal('0.000')) cheapest_destination = ShippingDestination.objects.filter( shipping_method__carrier=self.carrier, country=cart.shipping_address.country if cart.shipping_address else None, shipping_method__min_weight__lte=weight, shipping_method__max_weight__gte=weight, ).order_by('price').first() if cheapest_destination: parcel = self.get_sendcloud_parcel(cart) parcel.update( shipment={'id': cheapest_destination.shipping_method_id}, weight=str(weight), ) cart.extra['sendcloud_data'] = {'parcel': parcel} amount = EUR(cheapest_destination.price) instance = {'label': _("Shipping costs"), 'amount': amount} cart.extra_rows[self.identifier] = ExtraCartRow(instance) cart.total += amount else: instance = {'label': _("Unable to ship"), 'amount': EUR()} cart.extra_rows[self.identifier] = ExtraCartRow(instance)
def get_formset(self, request, obj=None, **kwargs): """ Convert the field `shipping_method` into a select box with all possible shipping methods. """ choices = [sm.get_choice() for sm in cart_modifiers_pool.get_shipping_modifiers()] kwargs.update(widgets={'shipping_method': widgets.Select(choices=choices)}) formset = super(DeliveryInline, self).get_formset(request, obj, **kwargs) return formset
def add_extra_cart_row(self, cart, request): if not self.is_active(cart.extra.get('shipping_modifier')) and len( cart_modifiers_pool.get_shipping_modifiers()) > 1: return amount = Money(settings.WELTLADEN_BIKING_PRICE) instance = {'label': _("Shipping costs"), 'amount': amount} cart.extra_rows[self.identifier] = ExtraCartRow(instance) cart.total += amount
def add_extra_cart_row(self, cart, request): if not self.is_active(cart) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1: return # add a shipping flat fee amount = Money('5') instance = {'label': _("Shipping costs"), 'amount': amount} cart.extra_rows[self.identifier] = ExtraCartRow(instance) cart.total += amount
def get_shipping_method(self, instance): for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): value, label = shipping_modifier.get_choice() if value == shipping_modifier.identifier: break else: value, label = instance.shipping_method, instance.shipping_method return {'value': value, 'label': label}
def __init__(self, *args, **kwargs): choices = [ m.get_choice() for m in cart_modifiers_pool.get_shipping_modifiers() if not m.is_disabled(kwargs['cart']) ] self.base_fields['shipping_modifier'].choices = choices super(ShippingMethodForm, self).__init__(*args, **kwargs)
def render(self, context, instance, placeholder): self.super(ShippingMethodFormPlugin, self).render(context, instance, placeholder) for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): shipping_modifier.update_render_context(context) context['show_additional_charge'] = instance.glossary.get( 'show_additional_charge', False) return context
def __init__(self, *args, **kwargs): super(DeliveryMethodForm, self).__init__(*args, **kwargs) choices = [ x.get_choice() for x in cart_modifiers_pool.get_shipping_modifiers() if not x.is_disabled(self.cart) ] self.fields['shipping_modifier'].choices = choices if len(choices) == 1: self.fields['shipping_modifier'].initial = choices[0][0]
def __init__(self, *args, **kwargs): choices = [m.get_choice() for m in cart_modifiers_pool.get_shipping_modifiers() if not m.is_disabled(kwargs['cart'])] self.base_fields['shipping_modifier'].choices = choices if len(choices) == 1: # with only one choice, initialize with it try: kwargs['initial']['shipping_modifier'] = choices[0][0] except KeyError: pass super(ShippingMethodForm, self).__init__(*args, **kwargs)
def add_extra_cart_row(self, cart, request): if not self.is_active(cart) and len( cart_modifiers_pool.get_shipping_modifiers()) > 1: return # postal tarifs by Siarhei if cart.total_weight < 1: amount = Money('6') elif cart.total_weight >= 1 and cart.total_weight < 3: amount = Money('9') elif cart.total_weight >= 3 and cart.total_weight < 15: amount = Money('12') elif cart.total_weight >= 15 and cart.total_weight < 30: amount = Money('23') elif cart.total_weight > 30: amount = Money('500') else: amount = Money('999') # add a shipping flat fee instance = {'label': _("Shipping costs to home"), 'amount': amount} cart.extra_rows[self.identifier] = ExtraCartRow(instance) cart.total += amount
def add_extra_cart_row(self, cart, request): if not self.is_active(cart.extra.get('shipping_modifier')) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1: return # add a shipping flat fee amount = Money('5') if cart.total_weight<1: amount = Money('4') elif cart.total_weight >=1 and cart.total_weight < 3: amount = Money('7.5') elif cart.total_weight >=3 and cart.total_weight < 15: amount = Money('10') elif cart.total_weight >=15 and cart.total_weight < 30: amount = Money('20') elif cart.total_weight > 30: amount = Money('500') else: amount = Money('999') instance = {'label': _("Shipping costs"), 'amount': amount} cart.extra_rows[self.identifier] = ExtraCartRow(instance) cart.total += amount
def add_extra_cart_row(self, cart, request): if not self.is_active(cart) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1: return destinations = ShippingDestination.objects.filter( shipping_method__carrier=self.carrier, country=cart.shipping_address.country, shipping_method__min_weight__lte=cart.weight, shipping_method__max_weight__gte=cart.weight, ).order_by('price') if destinations: destination = destinations.first() parcel = self.get_sendcloud_parcel(cart) parcel['shipment'] = {'id': destination.shipping_method_id} cart.extra['sendcloud_data'] = {'parcel': parcel} amount = EUR(destination.price) instance = {'label': _("Shipping costs"), 'amount': amount} cart.extra_rows[self.identifier] = ExtraCartRow(instance) cart.total += amount else: instance = {'label': _("Unable to ship"), 'amount': EUR()} cart.extra_rows[self.identifier] = ExtraCartRow(instance)
def get_shipping_choices(): choices = [sm.get_choice() for sm in cart_modifiers_pool.get_shipping_modifiers()] return choices
def render(self, context, instance, placeholder): super(ShippingMethodFormPlugin, self).render(context, instance, placeholder) for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): shipping_modifier.update_render_context(context) return context
if cart: form_data.update( initial={ 'shipping_modifier': cart.extra.get('shipping_modifier') }) return form_data def render(self, context, instance, placeholder): super(ShippingMethodFormPlugin, self).render(context, instance, placeholder) for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): shipping_modifier.update_render_context(context) return context if cart_modifiers_pool.get_shipping_modifiers(): # Plugin is registered only if at least one shipping modifier exists DialogFormPluginBase.register_plugin(ShippingMethodFormPlugin) class ExtraAnnotationFormPlugin(DialogFormPluginBase): name = _("Extra Annotation Form") form_class = 'shop.forms.checkout.ExtraAnnotationForm' template_leaf_name = 'extra-annotation-{}.html' def get_form_data(self, context, instance, placeholder): form_data = super(ExtraAnnotationFormPlugin, self).get_form_data(context, instance, placeholder) cart = form_data.get('cart') if cart: form_data.update(
def render(self, context, instance, placeholder): self.super(ShippingMethodFormPlugin, self).render(context, instance, placeholder) for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): shipping_modifier.update_render_context(context) return context
template_leaf_name = 'shipping-method-{}.html' def get_form_data(self, context, instance, placeholder): form_data = self.super(ShippingMethodFormPlugin, self).get_form_data(context, instance, placeholder) cart = form_data.get('cart') if cart: form_data.update(initial={'shipping_modifier': cart.extra.get('shipping_modifier')}) return form_data def render(self, context, instance, placeholder): self.super(ShippingMethodFormPlugin, self).render(context, instance, placeholder) for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): shipping_modifier.update_render_context(context) return context if cart_modifiers_pool.get_shipping_modifiers(): # Plugin is registered only if at least one shipping modifier exists DialogFormPluginBase.register_plugin(ShippingMethodFormPlugin) class ExtraAnnotationFormPlugin(DialogFormPluginBase): name = _("Extra Annotation Form") form_class = 'shop.forms.checkout.ExtraAnnotationForm' template_leaf_name = 'extra-annotation-{}.html' def get_form_data(self, context, instance, placeholder): form_data = self.super(ExtraAnnotationFormPlugin, self).get_form_data(context, instance, placeholder) cart = form_data.get('cart') if cart: form_data.update(initial={'annotation': cart.extra.get('annotation', '')}) return form_data
def get_shipping_choices(): choices = [ sm.get_choice() for sm in cart_modifiers_pool.get_shipping_modifiers() ] return choices
def render(self, context, instance, placeholder): self.super(ShippingMethodFormPlugin, self).render(context, instance, placeholder) for shipping_modifier in cart_modifiers_pool.get_shipping_modifiers(): shipping_modifier.update_render_context(context) context['show_additional_charge'] = instance.glossary.get('show_additional_charge', False) return context