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

[Core] [WebBundle] Implemented Guest checkout #1816

Merged
merged 13 commits into from
Sep 17, 2014

Conversation

dbalabka
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #90
License MIT
Doc PR (Sylius/Sylius-Docs#199)
  • Submit changes to the documentation
  • Maybe add more tests
  • Fix tests
  • Make possibility to disable Guest checkout

I have created a possibility for Guest customers to checkout only using email. Order entity now always has information about customer's email(even if customer was registered). I have removed duplicated registration logic from Security step. Registration form still exists on Security step page as is, but registration request will be addressed to main registration controller. After successful registration customer will be redirected back to checkout.

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', 'email'/*, array('label' => 'sylius.form.checkout.')*/)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should remove this comment...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@stloyd
Copy link
Contributor

stloyd commented Aug 21, 2014

Instead of again adding something to order, what about creating something like AnonymousOrder? It could work like Single Table Inheritance...

Additionally that feature should be optional, and probably not enabled by default ;)

@@ -191,6 +192,10 @@
<argument>%sylius.model.cart.class%</argument>
<tag name="form.type" alias="sylius_checkout_payment" />
</service>
<service id="sylius.checkout_form.guest" class="%sylius.checkout_form.guest.class%">
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use same naming as in other forms: sylius.form.order.guest_checkout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So other forms for checkout steps also has incorrect ID's names like:

  • sylius.checkout_form.payment
  • sylius.checkout_form.shipment
  • sylius.checkout_form.shipping

am i right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Those are one of the oldest ones, I have in mind creating PR that fix this, but IMO new one should be named more correctly (note that suggested by my is just proposal).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@dbalabka dbalabka force-pushed the GH90-Implementing-guest-checkout branch from ffee690 to 924bf07 Compare August 21, 2014 21:44
@@ -20,6 +20,7 @@

<parameter key="sylius.form.frontend.profile.type.class">Sylius\Bundle\WebBundle\Form\ProfileFormType</parameter>
<parameter key="sylius.form.frontend.registration.type.class">Sylius\Bundle\CoreBundle\Form\Type\RegistrationFormType</parameter>
<parameter key="sylius.listener.registration.class">Sylius\Bundle\WebBundle\EventListener\RegistrationListener</parameter>
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you removed that file from commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accidentally during rebasing. Now should be good.

@dbalabka dbalabka force-pushed the GH90-Implementing-guest-checkout branch from 924bf07 to 2534b7b Compare August 21, 2014 22:32
@dbalabka
Copy link
Contributor Author

@stloyd the reason why I was added email field into Order was that both types of customers(registered and guest) should have correct history of orders(in this particular case we keep information which email address was used to send Invoice). Keep this information in order entity we cover both cases at once. Even if Guest checkout will be disabled we should keep email history for registered customers.
For big stores with huge amount of order history it is a good to denormalize tables to avoid additional JOINs. From my point of view Single Inheritance as approach is good for customisation to end-point developer that wants to extend Core module and add some new fields w/o changes in it.

According to previous discussion in #90 may be it will be better idea to treat it like proposed @Richtermeister :

Guest checkout would just be a matter of dis-associating customers from users, which is probably a good idea.


if ($guestForm->handleRequest($request)->isValid()) {
$this->getManager()->persist($order);
$this->getManager()->flush();
Copy link
Member

Choose a reason for hiding this comment

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

Blank line before return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@pjedrzejewski
Copy link
Member

Nice work @torinaki, I think it is the simplest (and best for now) approach for this. I also like the registration code duplication removal. 👍

One thing to consider, when I merge this, we need to be always aware that Order does not always contain a reference to user. This is important for promotions, shipping and pretty much everything else.

It seems quite ready to me (at least for initial implemenation), so I'd love to gather some feedback. @kayue @stloyd @umpirsky @Arn0d @Sylius/core-team

I know that @umpirsky and @kayue implemented something like this, right? For HB?

{% if order.user %}
<p>{{ order.user.fullName }} <br><a href="{{ path('sylius_backend_user_show', {'id': order.user.id}) }}">{{ order.user.email }}</a></p>
{% else %}
<p>{{ order.email }}</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this?

<a href="mailto:{{order.email}}">{{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }}</a>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fix it a little bit different. I did not added mailto links, because I want make different look between user that have profile and link to it and user that do not have profile.
Please take a look I guess you will like it.

@kayue
Copy link
Contributor

kayue commented Aug 26, 2014

@pjedrzejewski @torinaki I like this too.

I think we can use the name from the billing address. This can avoid some if order.user check too.

In our project we create user on the fly to avoid changing the core. This PR is better 👍

@robholmes
Copy link
Contributor

@kayue Its quite possible that the billing address is not your customer. It could be a wife using the husband's card, or an employee using the company card, etc.

For these scenarios the billing address cannot reliably give you the customer details. Even the shipping address would be unreliable, as it could be a gift being sent to a relative, etc.

@kayue
Copy link
Contributor

kayue commented Aug 27, 2014

@robholmes I tend to disagree with you. If customer info can be different from billing address, then we should ask for customer info in addressing page. (ie: a separated Customer model)
With your current approach, guest customer has no way to provide his full name :p

And in fact I think having a separated Customer model could be a good idea, because all order details (name, address) should be immutable. Relying on user name maybe not so good, user can change his name after order is placed, this could be misleading.

@kayue
Copy link
Contributor

kayue commented Aug 28, 2014

@robholmes I am working on a payment gateway and it has the following XML model, I think we can use it as reference.

I like how they have a Contact model, and has phone number etc. I need it in my project too. (I store phone number to Address model at the moment, I don't think it is the best way to do it.)

<Checkout>
  <Card>
    <BrandId>master</BrandId>
    <BrandName>MasterCard</BrandName>
    <AccountNumber>5204740009900071</AccountNumber>
    <BillingAddress>
      <City>St Louis</City>
      <Country>US</Country>
      <CountrySubdivision>US-MO</CountrySubdivision>
      <Line1>123 Main Street</Line1>
      <PostalCode>63123</PostalCode>
    </BillingAddress>
    <CardHolderName>JOE Test</CardHolderName>
    <ExpiryMonth>12</ExpiryMonth>
    <ExpiryYear>2015</ExpiryYear>
  </Card>
  <TransactionId>5007680</TransactionId>
  <Contact>
    <FirstName>JOE</FirstName>
    <LastName>Test</LastName>
    <Country>US</Country>
    <EmailAddress>joe.test@email.com</EmailAddress>
    <PhoneNumber>1-9876543210</PhoneNumber>
  </Contact>
  <ShippingAddress>
    <City>hk</City>
    <Country>HK</Country>
    <CountrySubdivision>123</CountrySubdivision>
    <Line1>testing</Line1>
    <Line2>testing</Line2>
    <RecipientName>JOE Test</RecipientName>
    <RecipientPhoneNumber>1-9876543210</RecipientPhoneNumber>
  </ShippingAddress>
  <PayPassWalletIndicator>101</PayPassWalletIndicator>
</Checkout>

@kayue
Copy link
Contributor

kayue commented Aug 28, 2014

In fact the current Sylius checkout flow is not perfect:

1. Billing -> 2. Shipping -> 3. Payment

If customer choose to pay with PayPal, he shouldn't have to provide billing address to Sylius, because billing address will be returned from PayPal anyway. The current checkout flow is duplicated.

So it is better to use Contact to replace Billing Address at the first step. It also solve @robholmes 's wife scenario.

1. Contact -> 2. Shipping -> 3. Payment (and billing address form if needed)

Fixed fatal on checkout.
Improved guest customer info in admin.
}

/**
* Render step.
*
* @param ProcessContextInterface $context
* @param FormInterface $registrationForm
* @param FormInterface $guestForm
Copy link
Contributor

Choose a reason for hiding this comment

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

$guestForm and $registrationForm should be aligned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I have adjusted my IDE settings, hope it will be last comments about code style :)

@dbalabka
Copy link
Contributor Author

Do I need to wait green build on travis? I guess there is a problem with Behat execution time.

@@ -50,6 +50,7 @@
<field name="currency" length="3" />
<field type="string" name="paymentState" column="payment_state" />
<field type="string" name="shippingState" column="shipping_state" />
<field type="string" name="email" column="email" nullable="true"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this is acceptable to land in OrderBundle instead of CoreBundle, along with code changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think CoreBundle is a better place. In OrderBundle we don't even have address there.

https://github.com/Sylius/Sylius/blob/9264b61c40b4578f3b160dcefe1408e2a0181a36/src/Sylius/Component/Order/Model/OrderInterface.php

Copy link
Member

Choose a reason for hiding this comment

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

I would agree that e-mail field could go to the Order component & bundle, but only this field.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... in fact, we could even consider this field on address instead of order...

Copy link
Member

Choose a reason for hiding this comment

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

No, I think it should stay on the order, that's what Spree does and it feels most natural. Simplifies searching by e-mail etc.

Fixed and added spec tests
@@ -46,6 +46,7 @@ public function __construct(TwigMailerInterface $mailer, array $parameters)
*/
protected function sendEmail(array $context, $recipient)
{
echo $this->parameters['template'];
Copy link
Contributor

Choose a reason for hiding this comment

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

This is for sure something that can't be in accepted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:D Sorry about that. Fixed

@stloyd
Copy link
Contributor

stloyd commented Sep 12, 2014

@torinaki Please merge dbalabka#2 as it finishes this PR so it can be merged into Sylius! =)

@stloyd
Copy link
Contributor

stloyd commented Sep 17, 2014

@pjedrzejewski Can you have a look on this? IMO it's good for merge!

pjedrzejewski pushed a commit that referenced this pull request Sep 17, 2014
[Core] [WebBundle] Implemented Guest checkout
@pjedrzejewski pjedrzejewski merged commit 256f1bb into Sylius:master Sep 17, 2014
@pjedrzejewski
Copy link
Member

Thank you @torinaki for this super-cool feature and Joseph + Arnaud for the review! :)

pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
…checkout

[Core] [WebBundle] Implemented Guest checkout
pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
…checkout

[Core] [WebBundle] Implemented Guest checkout
pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
…checkout

[Core] [WebBundle] Implemented Guest checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants