Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore payment step during checkout if the order total is equal to zero #307

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Remiz
Copy link

@Remiz Remiz commented Sep 7, 2016

It seems to be working for me... I ran the tests and didn't get any issue either, but I would appreciate if anyone else gave their opinion.

Thanks.

@@ -282,6 +299,15 @@ def checkout_steps(request, form_class=OrderForm, extra_context=None):
# and send the order receipt email.
order = form.save(commit=False)
order.setup(request)

if (not settings.SHOP_PAYMENT_STEP_ENABLED or
order.total == 0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. Doesn't the step+=1 part skip the payment step entirely? When would order.total == 0 at this point?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step += 1 for some reason doesn't completely skip the payment. You can try with the master branch, activate a payment provider (like stripe) and SHOP_PAYMENT_STEP_ENABLED = False, you'll get an error from the payment processor...

By adding this line I just use the dummy payment processor when the order is zero.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried it but that makes sense. SHOP_PAYMENT_STEP_ENABLED seems to only effect the template context. But now that you've added step += 1, neither of these conditions should be possible, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first condition not settings.SHOP_PAYMENT_STEP_ENABLE is to handle the issue I mentioned, and the second order.total == 0 is to handle the original problem.

These conditions will be evaluated during the very last step of the checkout, so these are possible. step += 1 just skip the payment form page.

Sorry if it isn't clear, this problem isn't as easy to fix as I initially though it would be.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon closer analysis I understand what you're doing here. This view was difficult to grok to begin with. I'd have to dig in with a debugger to understand it well enough to do any further review.

@Remiz
Copy link
Author

Remiz commented Sep 8, 2016

If this can help you understand better what I'm trying to do, here are the 4 things my changes are doing.

If order total is 0 and payment step enabled:

  1. Skip the payment page step
  2. Replace the payment handler by the dummy payment (that does nothing)
  3. Remove the card_ fields in the OrderForm so they don't throw an error
  4. When the back button is pressed and the previous step is the payment step, skip it

@stephenmcd
Copy link
Owner

Like Ryne I found the diff on this a bit confusing, but I get the general idea - just bump up the current step if the order total is zero.

Unfortunately as I think you've discovered, I think it might be a bit difficult to implement this way, ending up with hacks and probably some unhandled edge cases (going back in the form steps comes to mind).

I feel like the correct thing to do would be to refactor all the cartridge.checkout.CHECKOUT_FOO constants, so that they're returned by a function with takes a cart or request or something user/session specific, that can then return those vars for the given user and their cart at runtime (as opposed to import time as those vars are currently defined).

@ryneeverett
Copy link
Collaborator

I feel like the correct thing to do would be to refactor all the cartridge.checkout.CHECKOUT_FOO constants, so that they're returned by a function with takes a cart or request or something user/session specific, that can then return those vars for the given user and their cart at runtime (as opposed to import time as those vars are currently defined).

Seems like the handlers are constants which could continue to be defined at import time, but the abstraction Stephen is suggesting means the checkout_steps view wouldn't access them directly from their module names, they would be passed by another function.

Implementation details aside, I agree with Stephen that this view is in need of abstraction -- even without trying to implement this feature. checkout_steps is the most complex piece of the code base and I look forward to being able to fully understand it through mental static analysis without having to step through with pdb.

@Remiz, if you want to make this happen my recommendation would be to start a new branch, refactor as Stephen suggested (or maybe you'll find a better/different abstraction), and then implement this feature.

Remiz and others added 6 commits January 25, 2017 17:55
…rtridge into free_order_skip_payment

* 'free_order_skip_payment' of https://github.com/Remiz/cartridge:
  Remove email handling from checkout view. Now done within the post-checkout process.
  Only send email confirmation based on order type
  Don't rely on order.setup() otherwise it saves an empty order on each step. Use cart total instead.
  Replace dummy processor handler by dummy payment handler
  Ignore payment step during checkout if the order total is equal to zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants