Update of delivery methods
See original GitHub issueHi I have a delivery method, which is only valid if a customer is living in a certain area in which she/he lives in.
class ClimateNeutralShippingModifier(ShippingModifier):
identifier = 'climate-neutral-shipping'
def get_choice(self):
return (self.identifier, _("Climate neutral shipping"))
def is_disabled(self, cart):
# geolocate address of customer
if cart.shipping_address:
postal_code = cart.shipping_address.postal_code
city = cart.shipping_address.city
country = cart.shipping_address.country
distance = checkdistance(postal_code, city, country)
if distance > settings.SHIPPING_DISTANCE:
return True
return False
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.BIKING_PRICE)
instance = {'label': _("Shipping costs"), 'amount': amount}
cart.extra_rows[self.identifier] = ExtraCartRow(instance)
cart.total += amount
def ship_the_goods(self, delivery):
super().ship_the_goods(delivery)
But somehow it will not be disabled, if distance is greater than my configured shipping distance. And now in my production instance I am getting errors like:
But it should not even be a possibilty to select anyways… This error always occurs for the first shipping. After that this error does not occur anymore.
I guess it has to do something with saving shipping address to a customer… but I do not really get any other error than WARNING: Forbidden: /shop/api/shipping_address/add
Any suggestions how to either adapt the error message or check for distance in another way?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Update Your Delivery Method Component - Salesforce Help
When a buyer makes a purchase, we changed the way delivery methods are updated in your buyer user profiles. If you previously cloned...
Read more >Editing the delivery methods - IBM
Editing the delivery methods. You can change the delivery method, update the pickup store, and edit or add a new shipping address for...
Read more >Manage transfers - Western Union
Update delivery method. You can make your cash transfer even more convenient by having it deposited directly into your receiver's bank account.
Read more >Move Update Data Delivery Method - Official Mail Guide (OMG)
Postage Meter Changes: New Intelligent Mail Indicia (IMI) Mandated In 2024. WASHINGTON, DC — The U.S. Postal Service is moving to a new...
Read more >Edit the delivery method for an active transfer | Remitly Help
Update your recipient's delivery method on Remitly.com · Navigate to Remitly.com and sign in to your account · Click Transfer History in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I think that I have a workaround for at least changing the page display…you may be able to use it in order to just hide the limited delivery option that you’re trying to implement…it’s a little messy and it sometimes loses synchronization but bear with me.
In each one of my modifiers, I made and instantiated an handler class with a
getService()
function that I can call using AJAX from the clicking the NEXT button or numbered steps at the top of the page that contains the service name.Then I overrode the
pre_process_cart()
function that it inherits fromBaseModifier
. Unfortunately that function will run on every single step of the checkout process, even before any address info has been entered, instead of just at the point where the modifier is activated (i.e. after the address has been entered and on the payment/shipping page). This requires some checking in order to ensure that you’re not trying to do anything with address information before it’s even available…which’ll crash the checkout process. This is also the reason for the default values at the top of the class (i.e.shippingCost
,postCode
, etc.,)From there, you can create a
checkout
folder in yourtemplates
folder and copy and paste theshipping-method-form.html
,next-step-button.html
,process-bar.html
, etc., and modify them to your liking. For instance, I needed to break out each individual option that I had so I got rid of the{{shipping_modifier.as_div}}
and replaced it with a modified version of the template that it generates.I also modified the
next-step-button.html
file to run thenextAjax()
on every click in order to make sure that the information being provided to/by the Python AJAX handler is current.I’m not sure if any of this helps you but you may be able to use the AJAX call to just outright hide the shipping modifier from view instead of changing its name. Let me know what you think.
Thanks for the extensive research. I wil have a look at it, and will come back to you. It looks promising.