Skip to content

Commit

Permalink
[User] PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Oct 2, 2015
1 parent 40f66f8 commit cecb4b1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
19 changes: 19 additions & 0 deletions features/frontend/checkout_addressing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Feature: Checkout addressing
| email | password | enabled |
| john@example.com | foo1 | yes |
| rick@example.com | bar1 | yes |
And there are following customers:
| email |
| test@example.com |
And the following zones are defined:
| name | type | members |
| UK + Germany | country | United Kingdom, Germany |
Expand Down Expand Up @@ -52,6 +55,22 @@ Feature: Checkout addressing
And I press "Continue"
Then I should be on the checkout shipping step

Scenario: Filling shipping address as guest with already used email
Given I am not logged in
And I added product "PHP Top" to cart
When I go to the checkout start page
And I fill in guest email with "test@example.com"
And I press "Proceed with your order"
And I should see "This email is already used."

Scenario: Filling shipping address as guest with already registered email
Given I am not logged in
And I added product "PHP Top" to cart
When I go to the checkout start page
And I fill in guest email with "john@example.com"
And I press "Proceed with your order"
And I should see "This email is already registered, please login or use forgotten password."

Scenario: Using different billing address
Given I am logged in user
And I added product "PHP Top" to cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Sylius\Bundle\UserBundle\Form\EventListener;

use Sylius\Bundle\UserBundle\Context\CustomerContext;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\User\Context\CustomerContextInterface;
use Sylius\Component\User\Model\CustomerInterface;
Expand All @@ -31,7 +30,7 @@ class GuestCustomerFormListener implements EventSubscriberInterface
private $customerRepository;

/**
* @var CustomerContext
* @var CustomerContextInterface
*/
private $customerContext;

Expand Down Expand Up @@ -99,7 +98,7 @@ protected function createCustomerIfNecessary($email)
$customer = $this->customerRepository->findOneBy(array('email' => $email));

if (null !== $customer && null !== $customer->getUser()) {
return $customer;
return null;
}

$customer = $this->customerRepository->createNew();
Expand Down
11 changes: 6 additions & 5 deletions src/Sylius/Bundle/UserBundle/Form/Type/CustomerGuestType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ class CustomerGuestType extends AbstractResourceType
/**
* @var EventSubscriberInterface
*/
private $eventSubscriber;
private $guestCustomerSubscriber;

/**
* @param string $dataClass
* @param array $validationGroups
* @param EventSubscriberInterface $eventSubscriber
* @param EventSubscriberInterface $guestCustomerSubscriber
*/
public function __construct($dataClass, array $validationGroups, EventSubscriberInterface $eventSubscriber)
public function __construct($dataClass, array $validationGroups, EventSubscriberInterface $guestCustomerSubscriber)
{
parent::__construct($dataClass, $validationGroups);

$this->eventSubscriber = $eventSubscriber;
$this->guestCustomerSubscriber = $guestCustomerSubscriber;
}

/**
Expand All @@ -48,7 +48,8 @@ public function buildForm(FormBuilderInterface $builder, array $options = array(
->add('email', 'email', array(
'label' => 'sylius.form.customer.email',
))
->addEventSubscriber($this->eventSubscriber)
->addEventSubscriber($this->guestCustomerSubscriber)
->setDataLocked(false)
;
}

Expand Down
13 changes: 8 additions & 5 deletions src/Sylius/Bundle/UserBundle/Resources/config/validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">

<class name="Sylius\Component\User\Model\Customer">
<constraint name="Sylius\Bundle\UserBundle\Validator\Constraints\RegisteredUser">
<option name="message">sylius.customer.email.registered</option>
<option name="groups">sylius_customer_guest</option>
</constraint>
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="message">sylius.customer.email.unique</option>
<option name="fields">email</option>
<option name="groups">sylius</option>
<option name="groups">
<value>sylius</value>
<value>sylius_customer_guest</value>
</option>
</constraint>
<constraint name="Sylius\Bundle\UserBundle\Validator\Constraints\RegisteredUser">
<option name="message">sylius.customer.email.registered</option>
<option name="groups">sylius_customer_guest</option>
</constraint>
<property name="firstName">
<constraint name="NotBlank">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function __construct(RepositoryInterface $customerRepository, CustomerCon
public function validate($customer, Constraint $constraint)
{
$existingCustomer = $this->customerRepository->findOneBy(array('email' => $customer->getEmail()));
if (null !== $existingCustomer && null !== $existingCustomer->getUser() && $this->customerContext->getCustomer() !== $customer) {
if (null !== $existingCustomer && null !== $existingCustomer->getUser()) {
$violations = $this->context->getViolations();

$this->context->addViolationAt(
'email',
$constraint->message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function it_sets_null_as_form_data_if_no_customer_is_logged_in_and_email_was_not
$this->preSubmit($event);
}

function it_sets_existing_customer_as_form_data_if_customer_with_passed_email_already_exist(
function it_sets_null_as_form_data_if_customer_with_passed_email_already_exist(
$customerContext,
$customerRepository,
CustomerInterface $customer,
Expand All @@ -107,7 +107,7 @@ function it_sets_existing_customer_as_form_data_if_customer_with_passed_email_al
$customerRepository->findOneBy(array('email' => 'john.doe@example.com'))->willReturn($customer)->shouldBeCalled();
$customer->getUser()->willReturn($user)->shouldBeCalled();

$form->setData($customer)->shouldBeCalled();
$form->setData(null)->shouldBeCalled();

$this->preSubmit($event);
}
Expand Down

0 comments on commit cecb4b1

Please sign in to comment.