Open vivazzi opened 7 years ago
Interesting use case!
I just digged through the code and it is more tricky than I thought, because we have a chicken-egg problem. If forms are arranged to select the shipping method before the destination country, then we won't be able to restrict the shipping provider. On the other side, shipping costs depend on the destination country.
My proposal for now is to separate the checkout into two (or more) pages. On the first page let the customer select the destination country and on the second page let him choose the shipping provider.
I will further look how to add a feature to disable certain providers depending on the cart/checkout's context.
Thank you, Jacob! Separate the checkout page into some pages is good idea as temporary solution. I do it so. Yes, this task more complicate than I thought too. I think we need load form through ajax when we click Next button.
Not the Next button, but the REST endpoint shop:checkout-upload
. It is invoked whenever one changes the delivery country and then django-SHOP runs all the cart modifiers. Data returned from there could be use to conditionally disable some shipping methods.
In the last few days, I I have been working on a customized checkout in one of my projects, too. In my case, the requirements are:
I agree that the checkout is harder to customize (and also harder to understand) than it should be. I think it would be much easier for developers to customize the checkout if we had a clear, documented ReST API for the checkout, with the cascade plugins being just one consumer of this API. This is more or less the case already, but it is hard to see what exactly that API is. Also, we have some coupling between the server-side API and the client-side code that we should remove or redesign. So, I have some ideas. Now I need to find the time to turn these ideas into code :)
I'm planning to work on this at https://github.com/rfleschenberg/django-shop-rest-checkout, as an add-on package, so we can be sure that we do not break existing shops for now.
@rfleschenberg , you are right that we need clear and documented REST API for the checkout. Do you plan use https://github.com/rfleschenberg/django-shop-rest-checkout as add-on package in the future or merge with django-shop later?
I have ideas too and I want to describe (by code) use-cases of django-shop. As I see, Django-shop needs more practice including checkout as one the most hard section of shop.
My long-term goal would be to merge it. However, I am rather busy at the moment, so I cannot with good conscience give any timeframe as to when that might happen.
If you want to help with this, I will gladly accept pull requests or make you a collaborator on the repository :)
@vivazzi as far as I know, DRF proposes a self documenting API. If you want to help out, please check how to integrate this into our documentation building process. I then will populate the docs on the REST API. That would be a major step forwards.
Has anybody figured anything out on this?
I meet next case in my project: I need use different shipping method on depending of selected country. For example: for Russian Federation I will see "Russian Post Office":
for France I will see "DHL Express":
In modifiers I do:
Code above works very well, but we need reload shipping address form when click Next button on step 2, because we choose country dynamically and we must get relevant shipping method choices dynamically. Could you tell me how do it?