Introduce customer context and adjust user and customer dependencies

This commit is contained in:
michalmarcinkowski 2015-04-27 23:20:52 +02:00
parent 4be3710bae
commit 2137205d06
115 changed files with 1024 additions and 979 deletions

View file

@ -29,25 +29,6 @@ payum_capture:
payum_notify:
resource: "@PayumBundle/Resources/config/routing/notify.xml"
# fos_user_security:
# resource: "@FOSUserBundle/Resources/config/routing/security.xml"
# fos_user_profile:
# resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
# prefix: /account/profile
# fos_user_register:
# resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
# prefix: /register
# fos_user_resetting:
# resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
# prefix: /resetting
# fos_user_change_password:
# resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
# prefix: /account
fos_oauth_server_token:
resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"

View file

@ -132,10 +132,10 @@ Feature: User account orders page
Given I am on my account orders page
Then I should not see an "#order-000000007-invoice" element
#@invoice
#Scenario: Generating an invoice for an order that has been sent
#Given I go to the order invoice page for 000000001
#Then the response status code should be 200
# @invoice
# Scenario: Generating an invoice for an order that has been sent
# Given I go to the order invoice page for 000000001
# Then the response status code should be 200
Scenario: Trying to generate an invoice for an order that has not been sent
Given I go to the order invoice page for 000000007

View file

@ -14,17 +14,18 @@ Feature: User account profile edition
Given I follow "My personal information"
Then I should be on my account profile edition page
# Scenario: Editing my information with a blank email
# Given I am on my account profile edition page
# When I leave "Email" field blank
# And I fill in "First name" with "John"
# And I fill in "Last name" with "Doe"
# And I press "Save changes"
# Then I should still be on my account profile edition page
# And I should see "Please enter an email"
Scenario: Editing my information with a blank email
Given I am on my account profile edition page
When I leave "Email" field blank
And I fill in "First name" with "John"
And I fill in "Last name" with "Doe"
And I press "Save changes"
Then I should still be on my account profile edition page
And I should see "Please enter your email"
Scenario: Editing my information with a blank first name
Given I am on my account profile edition page
When I fill in "Email" with "username@example.com"
And I leave "First name" field blank
And I fill in "Last name" with "Doe"
And I press "Save changes"
@ -33,25 +34,27 @@ Feature: User account profile edition
Scenario: Editing my information with a blank last name
Given I am on my account profile edition page
When I fill in "Email" with "username@example.com"
And I fill in "First name" with "John"
And I leave "Last name" field blank
And I press "Save changes"
Then I should still be on my account profile edition page
And I should see "Please enter your last name"
# Scenario: Editing my information with an invalid email
# Given I am on my account profile edition page
# When I fill in "Email" with "wrongemail"
# And I fill in "First name" with "John"
# And I fill in "Last name" with "Doe"
# And I press "Save changes"
# Then I should still be on my account profile edition page
# And I should see "The email is not valid"
Scenario: Editing my information with an invalid email
Given I am on my account profile edition page
When I fill in "Email" with "wrongemail"
And I fill in "First name" with "John"
And I fill in "Last name" with "Doe"
And I press "Save changes"
Then I should still be on my account profile edition page
And I should see "This email is invalid"
Scenario: Successfully editing my personal information
Given I am on my account profile edition page
When I fill in "Email" with "johndoe@example.com"
And I fill in "First name" with "John"
And I fill in "Last name" with "Doe"
And I press "Save changes"
Then I should be on my account homepage
And I should see "User has been successfully updated."
And I should see "Customer has been successfully updated."

View file

@ -29,6 +29,7 @@ suites:
Variation : { namespace: Sylius\Component\Variation, psr4_prefix: Sylius\Component\Variation, spec_path: src/Sylius/Component/Variation, src_path: src/Sylius/Component/Variation }
Mailer : { namespace: Sylius\Component\Mailer, psr4_prefix: Sylius\Component\Mailer, spec_path: src/Sylius/Component/Mailer, src_path: src/Sylius/Component/Mailer }
Rbac : { namespace: Sylius\Component\Rbac, psr4_prefix: Sylius\Component\Rbac, spec_path: src/Sylius/Component/Rbac, src_path: src/Sylius/Component/Rbac }
User : { namespace: Sylius\Component\User, psr4_prefix: Sylius\Component\User, spec_path: src/Sylius/Component/User, src_path: src/Sylius/Component/User }
AddressingBundle : { namespace: Sylius\Bundle\AddressingBundle, psr4_prefix: Sylius\Bundle\AddressingBundle, spec_path: src/Sylius/Bundle/AddressingBundle, src_path: src/Sylius/Bundle/AddressingBundle }
AttributeBundle : { namespace: Sylius\Bundle\AttributeBundle, psr4_prefix: Sylius\Bundle\AttributeBundle, spec_path: src/Sylius/Bundle/AttributeBundle, src_path: src/Sylius/Bundle/AttributeBundle }
@ -59,3 +60,4 @@ suites:
VariationBundle : { namespace: Sylius\Bundle\VariationBundle, psr4_prefix: Sylius\Bundle\VariationBundle, spec_path: src/Sylius/Bundle/VariationBundle, src_path: src/Sylius/Bundle/VariationBundle }
MailerBundle : { namespace: Sylius\Bundle\MailerBundle, psr4_prefix: Sylius\Bundle\MailerBundle, spec_path: src/Sylius/Bundle/MailerBundle, src_path: src/Sylius/Bundle/MailerBundle }
RbacBundle : { namespace: Sylius\Bundle\RbacBundle, psr4_prefix: Sylius\Bundle\RbacBundle, spec_path: src/Sylius/Bundle/RbacBundle, src_path: src/Sylius/Bundle/RbacBundle }
UserBundle : { namespace: Sylius\Bundle\UserBundle, psr4_prefix: Sylius\Bundle\UserBundle, spec_path: src/Sylius/Bundle/UserBundle, src_path: src/Sylius/Bundle/UserBundle }

View file

@ -93,7 +93,7 @@ class CoreContext extends DefaultContext
$order->setShippingAddress($address);
$order->setBillingAddress($address);
$order->setUser($this->thereIsUser($data['user'], 'sylius'));
$order->setCustomer($this->thereIsUser($data['user'], 'sylius', 'ROLE_USER')->getCustomer());
if (isset($data['shipment']) && '' !== trim($data['shipment'])) {
$order->addShipment($this->createShipment($data['shipment']));
@ -193,11 +193,6 @@ class CoreContext extends DefaultContext
$group = $repository->createNew();
$group->setName(trim($data['name']));
$roles = explode(',', $data['roles']);
$roles = array_map('trim', $roles);
$group->setRoles($roles);
$manager->persist($group);
}
@ -213,8 +208,8 @@ class CoreContext extends DefaultContext
foreach ($table->getHash() as $data) {
$address = $this->createAddress($data['address']);
$user = $this->thereIsUser($data['user'], 'sylius', null, 'yes', null, array(), false);
$user->addAddress($address);
$user = $this->thereIsUser($data['user'], 'sylius', 'ROLE_USER', 'yes', null, array(), false);
$user->getCustomer()->addAddress($address);
$manager->persist($address);
$manager->persist($user);
}
@ -230,8 +225,11 @@ class CoreContext extends DefaultContext
/* @var $user UserInterface */
$user = $this->getRepository('user')->createNew();
$user->setFirstname(null === $address ? $this->faker->firstName : $addressData[0]);
$user->setLastname(null === $address ? $this->faker->lastName : $addressData[1]);
$customer = $user->getCustomer();
$customer->setFirstname(null === $address ? $this->faker->firstName : $addressData[0]);
$customer->setLastname(null === $address ? $this->faker->lastName : $addressData[1]);
$customer->setEmail($email);
$user->setUsername($email);
$user->setEmail($email);
$user->setEnabled('yes' === $enabled);
$user->setCreatedAt(null === $createdAt ? new \DateTime() : $createdAt);
@ -240,7 +238,7 @@ class CoreContext extends DefaultContext
$user->setEmailCanonical($email);
$this->getService('sylius.user.password_updater')->updatePassword($user);
if (null !== $address) {
$user->setShippingAddress($this->createAddress($address));
$customer->setShippingAddress($this->createAddress($address));
}
if (null !== $role) {
@ -547,7 +545,7 @@ class CoreContext extends DefaultContext
*/
private function iAmLoggedInAsRole($role, $email = 'sylius@example.com', array $authorizationRoles = array())
{
$this->thereIsUser($email, 'sylius', null, 'yes', null, array(), true, $authorizationRoles);
$this->thereIsUser($email, 'sylius', $role, 'yes', null, array(), true, $authorizationRoles);
$this->getSession()->visit($this->generatePageUrl('sylius_user_security_login'));
$this->fillField('Email', $email);

View file

@ -146,8 +146,8 @@ class ItemResolver implements ItemResolverInterface
$context = array('quantity' => $quantity);
if (null !== $user = $cart->getUser()) {
$context['groups'] = $user->getGroups()->toArray();
if (null !== $customer = $cart->getCustomer()) {
$context['groups'] = $customer->getGroups()->toArray();
}
$item->setUnitPrice($this->priceCalculator->calculate($variant, $context));

View file

@ -16,16 +16,17 @@ use Sylius\Component\Addressing\Matcher\ZoneMatcherInterface;
use Sylius\Component\Addressing\Model\AddressInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Sylius\Component\User\Context\CustomerContextInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
class RestrictedZoneChecker implements RestrictedZoneCheckerInterface
{
private $securityContext;
private $customerContext;
private $zoneMatcher;
public function __construct(SecurityContextInterface $securityContext, ZoneMatcherInterface $zoneMatcher)
public function __construct(CustomerContextInterface $customerContext, ZoneMatcherInterface $zoneMatcher)
{
$this->securityContext = $securityContext;
$this->customerContext = $customerContext;
$this->zoneMatcher = $zoneMatcher;
}
@ -38,11 +39,11 @@ class RestrictedZoneChecker implements RestrictedZoneCheckerInterface
throw new UnexpectedTypeException($subject, 'Sylius\Component\Core\Model\ProductInterface');
}
if (!$this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
if (null === $customer = $this->customerContext->getCustomer()) {
return false;
}
if (null === $address && null === $address = $this->securityContext->getToken()->getUser()->getShippingAddress()) {
if (null === $address && null === $address = $customer->getShippingAddress()) {
return false;
}

View file

@ -12,6 +12,7 @@
namespace Sylius\Bundle\CoreBundle\Checkout\Step;
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\SyliusCheckoutEvents;
@ -32,7 +33,7 @@ class AddressingStep extends CheckoutStep
{
$order = $this->getCurrentCart();
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_INITIALIZE, $order);
//TODO replace getUser with getCustomer
$form = $this->createCheckoutAddressingForm($order, $this->getUser());
return $this->renderStep($context, $order, $form);
@ -47,7 +48,7 @@ class AddressingStep extends CheckoutStep
$order = $this->getCurrentCart();
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_INITIALIZE, $order);
//TODO replace getUser with getCustomer
$form = $this->createCheckoutAddressingForm($order, $this->getUser());
if ($form->handleRequest($request)->isValid()) {
@ -73,8 +74,8 @@ class AddressingStep extends CheckoutStep
));
}
protected function createCheckoutAddressingForm(OrderInterface $order, UserInterface $user = null)
protected function createCheckoutAddressingForm(OrderInterface $order, CustomerInterface $customer = null)
{
return $this->createForm('sylius_checkout_addressing', $order, array('user' => $user));
return $this->createForm('sylius_checkout_addressing', $order, array('customer' => $customer));
}
}

View file

@ -16,6 +16,7 @@ use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Currency\Context\CurrencyContext as BaseCurrencyContext;
use Sylius\Component\Storage\StorageInterface;
use Sylius\Component\User\Context\CustomerContextInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
@ -29,26 +30,25 @@ class CurrencyContext extends BaseCurrencyContext
protected $securityContext;
protected $settingsManager;
protected $userManager;
protected $customerManager;
protected $channelContext;
/**
* @param StorageInterface $storage
* @param SecurityContextInterface $securityContext
* @param SettingsManagerInterface $settingsManager
* @param ObjectManager $userManager
* @param ObjectManager $customerManager
* @param ChannelContextInterface $channelContext
*/
public function __construct(
StorageInterface $storage,
SecurityContextInterface $securityContext,
CustomerContextInterface $customerContext,
SettingsManagerInterface $settingsManager,
ObjectManager $userManager,
ObjectManager $customerManager,
ChannelContextInterface $channelContext
) {
$this->securityContext = $securityContext;
$this->customerContext = $customerContext;
$this->settingsManager = $settingsManager;
$this->userManager = $userManager;
$this->customerManager = $customerManager;
$this->channelContext = $channelContext;
parent::__construct($storage, $this->getDefaultCurrency());
@ -67,8 +67,8 @@ class CurrencyContext extends BaseCurrencyContext
*/
public function getCurrency()
{
if ((null !== $user = $this->getUser()) && null !== $user->getCurrency()) {
return $user->getCurrency();
if ((null !== $customer = $this->customerContext->getCustomer()) && null !== $customer->getCurrency()) {
return $customer->getCurrency();
}
$channel = $this->channelContext->getChannel();
@ -84,32 +84,21 @@ class CurrencyContext extends BaseCurrencyContext
$channel = $this->channelContext->getChannel();
$this->storage->setData($this->getStorageKey($channel->getCode()), $currency);
if (null === $user = $this->getUser()) {
return;
if (null === $customer = $this->customerContext->getCustomer()) {
return parent::setCurrency($currency);
}
$user->setCurrency($currency);
$customer->setCurrency($currency);
$this->userManager->persist($user);
$this->userManager->flush();
}
/**
* Get currently logged in user.
*
* @return null|UserInterface
*/
protected function getUser()
{
if ($this->securityContext->getToken() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
return $this->securityContext->getToken()->getUser();
}
$this->customerManager->persist($customer);
$this->customerManager->flush();
}
/**
* Get storage key for channel with given code.
*
* @param string $channelCode
* @return string
*/
private function getStorageKey($channelCode)
{

View file

@ -11,10 +11,10 @@
namespace Sylius\Bundle\CoreBundle\Controller;
use Sylius\Bundle\UserBundle\Controller\UserController as BaseController;
use Sylius\Bundle\UserBundle\Controller\UserController as BaseUserController;
use Symfony\Component\HttpFoundation\Request;
class UserController extends BaseController
class UserController extends BaseUserController
{
/**
* Render user filter form.

View file

@ -14,38 +14,38 @@ namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
use Pagerfanta\PagerfantaInterface;
use Sylius\Bundle\CartBundle\Doctrine\ORM\CartRepository;
use Sylius\Component\Core\Model\CouponInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
class OrderRepository extends CartRepository implements OrderRepositoryInterface
{
/**
* Create user orders paginator.
* Create customer orders paginator.
*
* @param UserInterface $user
* @param CustomerInterface $customer
* @param array $sorting
*
* @return PagerfantaInterface
*/
public function createByUserPaginator(UserInterface $user, array $sorting = array())
public function createByCustomerPaginator(CustomerInterface $customer, array $sorting = array())
{
$queryBuilder = $this->getCollectionQueryBuilderByUser($user, $sorting);
$queryBuilder = $this->getCollectionQueryBuilderByCustomer($customer, $sorting);
return $this->getPaginator($queryBuilder);
}
/**
* Gets orders for user.
* Gets orders for customer.
*
* @param UserInterface $user
* @param CustomerInterface $customer
* @param array $sorting
*
* @return array
*/
public function findByUser(UserInterface $user, array $sorting = array())
public function findByCustomer(CustomerInterface $customer, array $sorting = array())
{
$queryBuilder = $this->getCollectionQueryBuilderByUser($user, $sorting);
$queryBuilder = $this->getCollectionQueryBuilderByCustomer($customer, $sorting);
return $queryBuilder
->getQuery()
@ -67,7 +67,7 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
$queryBuilder = $this->getQueryBuilder();
$queryBuilder
->leftJoin('o.adjustments', 'adjustment')
->leftJoin('o.user', 'user')
->leftJoin('o.customer', 'customer')
->leftJoin('item.inventoryUnits', 'inventoryUnit')
->leftJoin('o.shipments', 'shipment')
->leftJoin('shipment.method', 'shippingMethod')
@ -83,7 +83,7 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
->leftJoin('o.shippingAddress', 'shippingAddress')
->leftJoin('shippingAddress.country', 'shippingCountry')
->addSelect('adjustment')
->addSelect('user')
->addSelect('customer')
->addSelect('inventoryUnit')
->addSelect('shipment')
->addSelect('shippingMethod')
@ -122,8 +122,8 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
$queryBuilder = parent::getCollectionQueryBuilder();
$queryBuilder
->andWhere($queryBuilder->expr()->isNotNull('o.completedAt'))
->leftJoin('o.user', 'user')
->addSelect('user')
->leftJoin('o.customer', 'customer')
->addSelect('customer')
;
if ($deleted) {
@ -188,7 +188,7 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
/**
* {@inheritdoc}
*/
public function countByUserAndCoupon(UserInterface $user, CouponInterface $coupon)
public function countByCustomerAndCoupon(CustomerInterface $customer, CouponInterface $coupon)
{
$this->_em->getFilters()->disable('softdeleteable');
@ -196,10 +196,10 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
$queryBuilder
->select('count(o.id)')
->innerJoin('o.promotionCoupons', 'coupons')
->andWhere('o.user = :user')
->andWhere('o.customer = :customer')
->andWhere('o.completedAt IS NOT NULL')
->andWhere($queryBuilder->expr()->in('coupons', ':coupons'))
->setParameter('user', $user)
->setParameter('customer', $customer)
->setParameter('coupons', (array) $coupon)
;
@ -265,16 +265,16 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
/**
* {@inheritdoc}
*/
public function countByUserAndPaymentState(UserInterface $user, $state)
public function countByCustomerAndPaymentState(CustomerInterface $customer, $state)
{
$queryBuilder = $this->createQueryBuilder('o');
$queryBuilder
->select('count(o.id)')
->andWhere('o.user = :user')
->andWhere('o.customer = :customer')
->andWhere('o.paymentState = :state')
->andWhere($queryBuilder->expr()->isNotNull('o.completedAt'))
->setParameter('user', $user)
->setParameter('customer', $customer)
->setParameter('state', $state)
;
@ -418,14 +418,14 @@ class OrderRepository extends CartRepository implements OrderRepositoryInterface
;
}
protected function getCollectionQueryBuilderByUser(UserInterface $user, array $sorting = array())
protected function getCollectionQueryBuilderByCustomer(CustomerInterface $customer, array $sorting = array())
{
$queryBuilder = $this->getCollectionQueryBuilder();
$queryBuilder
->innerJoin('o.user', 'user')
->andWhere('user = :user')
->setParameter('user', $user)
->innerJoin('o.customer', 'customer')
->andWhere('customer = :customer')
->setParameter('customer', $customer)
;
$this->applySorting($queryBuilder, $sorting);

View file

@ -16,13 +16,13 @@ use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Automatic set user's default addressing
* Automatic set customer's default addressing
*
* @author Liverbool <nukboon@gmail.com>
*/
class CheckoutAddressingListener
{
public function setUserAddressing(GenericEvent $event)
public function setCustomerAddressing(GenericEvent $event)
{
$order = $event->getSubject();
@ -33,16 +33,16 @@ class CheckoutAddressingListener
);
}
if (null === $user = $order->getUser()) {
if (null === $customer = $order->getCustomer()) {
return;
}
if (null === $user->getShippingAddress()) {
$user->setShippingAddress(clone $order->getShippingAddress());
if (null === $customer->getShippingAddress()) {
$customer->setShippingAddress(clone $order->getShippingAddress());
}
if (null === $user->getBillingAddress()) {
$user->setBillingAddress(clone $order->getBillingAddress());
if (null === $customer->getBillingAddress()) {
$customer->setBillingAddress(clone $order->getBillingAddress());
}
}
}

View file

@ -120,7 +120,7 @@ class MailerListener
if ($comment->getNotifyCustomer()) {
$order = $comment->getOrder();
$email = null === $order->getUser() ? $order->getEmail() : $order->getUser()->getEmail();
$email = $order->getCustomer()->getEmail();
$this->emailSender->send(Emails::ORDER_COMMENT, array($email), array(
'order' => $order,

View file

@ -54,9 +54,9 @@ class OrderPricingListener
}
$context = array();
if (null !== $user = $order->getUser()) {
$context['user'] = $user;
$context['groups'] = $user->getGroups()->toArray();
if (null !== $customer = $order->getCustomer()) {
$context['customer'] = $customer;
$context['groups'] = $customer->getGroups()->toArray();
}
if (null !== $order->getChannel()) {

View file

@ -12,6 +12,7 @@
namespace Sylius\Bundle\CoreBundle\Form\Type\Checkout;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\UserInterface;
use Symfony\Component\Form\FormBuilderInterface;
@ -42,23 +43,23 @@ class AddressingStepType extends AbstractResourceType
}
})
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
/* @var $user UserInterface */
$user = $options['user'];
if (null === $user || !$user instanceof UserInterface) {
/* @var CustomerInterface $customer */
$customer = $options['customer'];
if (null === $customer || !$customer instanceof CustomerInterface) {
return;
}
/* @var $order OrderInterface */
$order = $event->getData();
if ($order->getShippingAddress() === null && $user->getShippingAddress() !== null) {
$address = clone $user->getShippingAddress();
$address->setUser(null);
if ($order->getShippingAddress() === null && $customer->getShippingAddress() !== null) {
$address = clone $customer->getShippingAddress();
$address->setCustomer(null);
$order->setShippingAddress($address);
}
if ($order->getBillingAddress() === null && $user->getBillingAddress() !== null) {
$address = clone $user->getBillingAddress();
$address->setUser(null);
if ($order->getBillingAddress() === null && $customer->getBillingAddress() !== null) {
$address = clone $customer->getBillingAddress();
$address->setCustomer(null);
$order->setBillingAddress($address);
}
})

View file

@ -23,7 +23,7 @@ use Symfony\Component\Validator\Constraints\Type;
*
* @author Antonio Perić <antonio@locastic.com>
*/
class UserGroupType extends AbstractType
class CustomerGroupType extends AbstractType
{
protected $validationGroups;
@ -50,7 +50,7 @@ class UserGroupType extends AbstractType
'groups',
'sylius_entity_to_identifier',
array(
'label' => 'sylius.form.action.user_group',
'label' => 'sylius.form.action.customer_group',
'property' => 'name',
'class' => $groupRepository->getClassName(),
'query_builder' => function () use ($groupRepository) {
@ -82,6 +82,6 @@ class UserGroupType extends AbstractType
*/
public function getName()
{
return 'sylius_promotion_rule_user_group_configuration';
return 'sylius_promotion_rule_customer_group_configuration';
}
}

View file

@ -22,7 +22,7 @@ use Symfony\Component\Validator\Constraints\Type;
*
* @author Saša Stamenković <umpirsky@gmail.com>
*/
class UserLoyaltyConfigurationType extends AbstractType
class CustomerLoyaltyConfigurationType extends AbstractType
{
protected $validationGroups;
@ -38,26 +38,26 @@ class UserLoyaltyConfigurationType extends AbstractType
{
$builder
->add('time', 'integer', array(
'label' => 'sylius.form.rule.user_loyalty_configuration.time',
'label' => 'sylius.form.rule.customer_loyalty_configuration.time',
'constraints' => array(
new NotBlank(),
new Type(array('type' => 'numeric')),
)
))
->add('unit', 'choice', array(
'label' => 'sylius.form.rule.user_loyalty_configuration.unit.header',
'label' => 'sylius.form.rule.customer_loyalty_configuration.unit.header',
'choices' => array(
'days' => 'sylius.form.rule.user_loyalty_configuration.unit.days',
'weeks' => 'sylius.form.rule.user_loyalty_configuration.unit.weeks',
'months' => 'sylius.form.rule.user_loyalty_configuration.unit.months',
'years' => 'sylius.form.rule.user_loyalty_configuration.unit.years',
'days' => 'sylius.form.rule.customer_loyalty_configuration.unit.days',
'weeks' => 'sylius.form.rule.customer_loyalty_configuration.unit.weeks',
'months' => 'sylius.form.rule.customer_loyalty_configuration.unit.months',
'years' => 'sylius.form.rule.customer_loyalty_configuration.unit.years',
),
'constraints' => array(
new NotBlank(),
)
))
->add('after', 'checkbox', array(
'label' => 'sylius.form.rule.user_loyalty_configuration.after',
'label' => 'sylius.form.rule.customer_loyalty_configuration.after',
))
;
}
@ -79,6 +79,6 @@ class UserLoyaltyConfigurationType extends AbstractType
*/
public function getName()
{
return 'sylius_promotion_rule_user_loyalty_configuration';
return 'sylius_promotion_rule_customer_loyalty_configuration';
}
}

View file

@ -180,7 +180,7 @@ sylius_order:
sylius_sequence:
generators:
%sylius.model.order.class%: sylius.sequence.sequential_number_generator
sylius_pricing:
forms:
- sylius_product_variant
@ -714,3 +714,5 @@ sylius_user:
user:
model: Sylius\Component\Core\Model\User
controller: Sylius\Bundle\CoreBundle\Controller\UserController
customer:
model: Sylius\Component\Core\Model\Customer

View file

@ -14,12 +14,9 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
<mapped-superclass name="Sylius\Component\Core\Model\Address" table="sylius_address">
<many-to-one field="user" target-entity="Sylius\Component\User\Model\UserInterface" inversed-by="addresses">
<join-column name="user_id" referenced-column-name="id" nullable="true" on-delete="SET NULL"/>
<many-to-one field="customer" target-entity="Sylius\Component\User\Model\CustomerInterface" inversed-by="addresses">
<join-column name="customer_id" referenced-column-name="id" nullable="true" on-delete="SET NULL"/>
</many-to-one>
</mapped-superclass>
</doctrine-mapping>

View file

@ -17,7 +17,7 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Core\Model\Coupon" table="sylius_promotion_coupon">
<field type="integer" name="perUserUsageLimit" column="per_user_usage_limit" nullable="true" />
<field type="integer" name="perCustomerUsageLimit" column="per_customer_usage_limit" nullable="true" />
</mapped-superclass>
</doctrine-mapping>

View file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Core\Model\Customer" table="sylius_customer">
<field name="currency" length="3" nullable="true" />
<one-to-one field="billingAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="billing_address_id" on-delete="SET NULL" />
<cascade>
<cascade-persist />
</cascade>
</one-to-one>
<one-to-one field="shippingAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="shipping_address_id" on-delete="SET NULL" />
<cascade>
<cascade-persist />
</cascade>
</one-to-one>
<one-to-many field="orders" target-entity="Sylius\Component\Order\Model\OrderInterface" mapped-by="customer">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
<one-to-many field="addresses" target-entity="Sylius\Component\Addressing\Model\AddressInterface" mapped-by="customer">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
</mapped-superclass>
</doctrine-mapping>

View file

@ -60,8 +60,8 @@
</cascade>
</one-to-many>
<many-to-one field="user" target-entity="Sylius\Component\User\Model\UserInterface" inversed-by="orders">
<join-column name="user_id" referenced-column-name="id" nullable="true" />
<many-to-one field="customer" target-entity="Sylius\Component\User\Model\CustomerInterface" inversed-by="orders">
<join-column name="customer_id" referenced-column-name="id" nullable="true" />
</many-to-one>
<many-to-many field="promotions" target-entity="Sylius\Component\Promotion\Model\PromotionInterface">

View file

@ -18,51 +18,12 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Core\Model\User" table="sylius_user">
<field name="currency" length="3" nullable="true" />
<one-to-one field="billingAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="billing_address_id" on-delete="SET NULL" />
<cascade>
<cascade-persist />
</cascade>
</one-to-one>
<one-to-one field="shippingAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
<join-column name="shipping_address_id" on-delete="SET NULL" />
<cascade>
<cascade-persist />
</cascade>
</one-to-one>
<one-to-many field="orders" target-entity="Sylius\Component\Order\Model\OrderInterface" mapped-by="user">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
<one-to-many field="addresses" target-entity="Sylius\Component\Addressing\Model\AddressInterface" mapped-by="user">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
<one-to-many field="oauthAccounts" target-entity="Sylius\Component\Core\Model\UserOAuthInterface" mapped-by="user">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
<many-to-many field="groups" target-entity="Sylius\Component\Core\Model\GroupInterface">
<cascade>
<cascade-all />
</cascade>
<join-table name="sylius_user_group">
<join-columns>
<join-column name="user_id" referenced-column-name="id" on-delete="CASCADE"/>
</join-columns>
<inverse-join-columns>
<join-column name="group_id" referenced-column-name="id" on-delete="CASCADE"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="authorizationRoles" target-entity="Sylius\Component\Rbac\Model\RoleInterface">
<join-table name="sylius_user_role">
<join-columns>

View file

@ -41,11 +41,11 @@
<parameter key="sylius.form.type.price_calculator.zone_based.class">Sylius\Bundle\CoreBundle\Form\Type\Pricing\ZoneBasedConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.nth_order_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\NthOrderConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.user_loyalty_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\UserLoyaltyConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.customer_loyalty_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\CustomerLoyaltyConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.shipping_country_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\ShippingCountryConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.taxonomy_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\TaxonomyConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.contains_product_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\ContainsProductConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_rule.user_group_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\UserGroupType</parameter>
<parameter key="sylius.form.type.promotion_rule.customer_group_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Rule\CustomerGroupType</parameter>
<parameter key="sylius.form.type.promotion_action.shipping_discount_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Action\ShippingDiscountConfigurationType</parameter>
<parameter key="sylius.form.type.promotion_action.add_product_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Action\AddProductConfigurationType</parameter>
</parameters>
@ -124,9 +124,9 @@
<argument>%sylius.validation_group.promotion_rule_nth_order_configuration%</argument>
<tag name="form.type" alias="sylius_promotion_rule_nth_order_configuration" />
</service>
<service id="sylius.form.type.promotion_rule.user_loyalty_configuration" class="%sylius.form.type.promotion_rule.user_loyalty_configuration.class%">
<argument>%sylius.validation_group.promotion_rule_user_loyalty_configuration%</argument>
<tag name="form.type" alias="sylius_promotion_rule_user_loyalty_configuration" />
<service id="sylius.form.type.promotion_rule.customer_loyalty_configuration" class="%sylius.form.type.promotion_rule.customer_loyalty_configuration.class%">
<argument>%sylius.validation_group.promotion_rule_customer_loyalty_configuration%</argument>
<tag name="form.type" alias="sylius_promotion_rule_customer_loyalty_configuration" />
</service>
<service id="sylius.form.type.promotion_rule.shipping_country_configuration" class="%sylius.form.type.promotion_rule.shipping_country_configuration.class%">
<argument>%sylius.model.country.class%</argument>
@ -142,10 +142,10 @@
<argument type="service" id="sylius.repository.product_variant" />
<tag name="form.type" alias="sylius_promotion_rule_contains_product_configuration" />
</service>
<service id="sylius.form.type.promotion_rule.user_group_configuration" class="%sylius.form.type.promotion_rule.user_group_configuration.class%">
<argument>%sylius.validation_group.promotion_rule_user_group_configuration%</argument>
<service id="sylius.form.type.promotion_rule.customer_group_configuration" class="%sylius.form.type.promotion_rule.customer_group_configuration.class%">
<argument>%sylius.validation_group.promotion_rule_customer_group_configuration%</argument>
<argument type="service" id="sylius.repository.group" />
<tag name="form.type" alias="sylius_promotion_rule_user_group_configuration" />
<tag name="form.type" alias="sylius_promotion_rule_customer_group_configuration" />
</service>
<service id="sylius.form.type.promotion_action.shipping_discount_configuration" class="%sylius.form.type.promotion_action.shipping_discount_configuration.class%">
<argument>%sylius.validation_group.promotion_action_shipping_discount_configuration%</argument>

View file

@ -56,11 +56,11 @@
<parameter key="sylius.promotion_processor.class">Sylius\Bundle\CoreBundle\OrderProcessing\PromotionProcessor</parameter>
<parameter key="sylius.promotion_rule_checker.nth_order.class">Sylius\Component\Core\Promotion\Checker\NthOrderRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.user_loyalty.class">Sylius\Component\Core\Promotion\Checker\UserLoyaltyRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.customer_loyalty.class">Sylius\Component\Core\Promotion\Checker\CustomerLoyaltyRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.shipping_country.class">Sylius\Component\Core\Promotion\Checker\ShippingCountryRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.taxonomy.class">Sylius\Component\Core\Promotion\Checker\TaxonomyRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.contains_product.class">Sylius\Component\Core\Promotion\Checker\ContainsProductRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.user_group.class">Sylius\Component\Core\Promotion\Checker\UserGroupRuleChecker</parameter>
<parameter key="sylius.promotion_rule_checker.customer_group.class">Sylius\Component\Core\Promotion\Checker\CustomerGroupRuleChecker</parameter>
<parameter key="sylius.promotion_action.fixed_discount.class">Sylius\Component\Core\Promotion\Action\FixedDiscountAction</parameter>
<parameter key="sylius.promotion_action.percentage_discount.class">Sylius\Component\Core\Promotion\Action\PercentageDiscountAction</parameter>
<parameter key="sylius.promotion_action.shipping_discount.class">Sylius\Component\Core\Promotion\Action\ShippingDiscountAction</parameter>
@ -78,7 +78,6 @@
<parameter key="sylius.price_calculator.channel_based.class">Sylius\Component\Core\Pricing\ChannelBasedCalculator</parameter>
<parameter key="sylius.price_calculator.group_based.class">Sylius\Component\Core\Pricing\GroupBasedCalculator</parameter>
<parameter key="sylius.price_calculator.zone_based.class">Sylius\Component\Core\Pricing\ZoneBasedCalculator</parameter>
<parameter key="sylius.oauth.user_provider.class">Sylius\Bundle\UserBundle\OAuth\UserProvider</parameter>
<parameter key="sylius.data_collector.class">Sylius\Bundle\CoreBundle\DataCollector\SyliusDataCollector</parameter>
<parameter key="sylius.dynamic_router.class">Symfony\Cmf\Component\Routing\DynamicRouter</parameter>
<parameter key="sylius.generator.class">Sylius\Bundle\CoreBundle\Routing\SyliusAwareGenerator</parameter>
@ -128,7 +127,7 @@
<!-- checker -->
<service id="sylius.checker.restricted_zone" class="%sylius.checker.restricted_zone.class%">
<argument type="service" id="security.context" />
<argument type="service" id="sylius.context.customer" />
<argument type="service" id="sylius.zone_matcher" />
</service>
@ -287,10 +286,10 @@
<argument type="service" id="sylius.context.currency" />
<tag name="kernel.event_listener" event="sylius.cart.initialize" method="processOrderCurrency" />
</service>
<service id="sylius.listener.user_aware" class="%sylius.listener.user_aware.class%">
<argument type="service" id="security.context" />
<tag name="kernel.event_listener" event="sylius.checkout.security.pre_complete" method="setUser" priority="100" />
<tag name="kernel.event_listener" event="sylius.cart.initialize" method="setUser" />
<service id="sylius.listener.customer_aware" class="%sylius.listener.customer_aware.class%">
<argument type="service" id="sylius.context.customer" />
<tag name="kernel.event_listener" event="sylius.checkout.security.pre_complete" method="setCustomer" priority="100" />
<tag name="kernel.event_listener" event="sylius.cart.initialize" method="setCustomer" />
</service>
<service id="sylius.listener.restricted_zone" class="%sylius.listener.restricted_zone.class%">
<argument type="service" id="sylius.checker.restricted_zone" />
@ -311,7 +310,7 @@
<tag name="kernel.event_listener" event="sylius.checkout.purchase.complete" method="addFlash" />
</service>
<service id="sylius.listener.checkout_addressing" class="%sylius.listener.checkout_addressing.class%">
<tag name="kernel.event_listener" event="sylius.checkout.addressing.pre_complete" method="setUserAddressing" />
<tag name="kernel.event_listener" event="sylius.checkout.addressing.pre_complete" method="setCustomerAddressing" />
</service>
<service id="sylius.listener.insufficient_stock_exception" class="%sylius.listener.insufficient_stock_exception.class%">
<argument type="service" id="router" />
@ -351,8 +350,8 @@
<argument type="service" id="sylius.repository.order" />
<tag name="sylius.promotion_rule_checker" type="nth_order" label="Nth order" />
</service>
<service id="sylius.promotion_rule_checker.user_loyalty" class="%sylius.promotion_rule_checker.user_loyalty.class%">
<tag name="sylius.promotion_rule_checker" type="user_loyalty" label="User loyalty" />
<service id="sylius.promotion_rule_checker.customer_loyalty" class="%sylius.promotion_rule_checker.customer_loyalty.class%">
<tag name="sylius.promotion_rule_checker" type="customer_loyalty" label="Customer loyalty" />
</service>
<service id="sylius.promotion_rule_checker.shipping_country" class="%sylius.promotion_rule_checker.shipping_country.class%">
<tag name="sylius.promotion_rule_checker" type="shipping_country" label="Shipping country" />
@ -363,8 +362,8 @@
<service id="sylius.promotion_rule_checker.contains_product" class="%sylius.promotion_rule_checker.contains_product.class%">
<tag name="sylius.promotion_rule_checker" type="contains_product" label="Contains Product" />
</service>
<service id="sylius.promotion_rule_checker.user_group" class="%sylius.promotion_rule_checker.user_group.class%">
<tag name="sylius.promotion_rule_checker" type="user_group" label="User Group" />
<service id="sylius.promotion_rule_checker.customer_group" class="%sylius.promotion_rule_checker.customer_group.class%">
<tag name="sylius.promotion_rule_checker" type="customer_group" label="User Group" />
</service>
<service id="sylius.promotion_action.fixed_discount" class="%sylius.promotion_action.fixed_discount.class%">
<argument type="service" id="sylius.repository.adjustment" />
@ -408,9 +407,9 @@
<!-- money -->
<service id="sylius.context.currency" class="%sylius.context.currency.class%">
<argument /> <!-- Storage service name comes from config -->
<argument type="service" id="security.context" />
<argument type="service" id="sylius.context.customer" />
<argument type="service" id="sylius.settings.manager" />
<argument type="service" id="sylius.manager.user" />
<argument type="service" id="sylius.manager.customer" />
<argument type="service" id="sylius.context.channel" />
</service>

View file

@ -23,25 +23,6 @@
<property name="billingAddress">
<constraint name="Valid" />
</property>
<property name="email">
<constraint name="NotBlank">
<option name="groups">
<value>Guest</value>
</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="max">254</option>
<option name="groups">
<value>Guest</value>
</option>
</constraint>
<constraint name="Email">
<option name="groups">
<value>Guest</value>
</option>
</constraint>
</property>
</class>
<class name="Sylius\Component\Core\Model\ProductTranslation">

View file

@ -8,8 +8,8 @@ sylius:
price: Unit price
quantity: Quantity
variant: Variant
user_group:
User group
customer_group:
Customer group
block:
body: Body
id: ID

View file

@ -15,16 +15,15 @@ use PhpSpec\ObjectBehavior;
use Sylius\Component\Addressing\Matcher\ZoneMatcherInterface;
use Sylius\Component\Addressing\Model\AddressInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Sylius\Component\User\Context\CustomerContextInterface;
class RestrictedZoneCheckerSpec extends ObjectBehavior
{
function let(SecurityContextInterface $securityContext, ZoneMatcherInterface $zoneMatcher)
function let(CustomerContextInterface $customerContext, ZoneMatcherInterface $zoneMatcher)
{
$this->beConstructedWith($securityContext, $zoneMatcher);
$this->beConstructedWith($customerContext, $zoneMatcher);
}
function it_is_initializable()
@ -37,78 +36,66 @@ class RestrictedZoneCheckerSpec extends ObjectBehavior
$this->shouldImplement('Sylius\Component\Addressing\Checker\RestrictedZoneCheckerInterface');
}
function it_is_not_restricted_if_user_is_not_authenticated(ProductInterface $product, $securityContext)
function it_is_not_restricted_if_customer_is_not_authenticated(ProductInterface $product, $customerContext)
{
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->shouldBeCalled()->willReturn(false);
$customerContext->getCustomer()->shouldBeCalled()->willReturn(null);
$this->isRestricted($product)->shouldReturn(false);
}
function it_is_not_restricted_if_user_have_no_shipping_address(
function it_is_not_restricted_if_customer_have_no_shipping_address(
ProductInterface $product,
$securityContext,
TokenInterface $token,
UserInterface $user
$customerContext,
CustomerInterface $customer
) {
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->shouldBeCalled()->willReturn(true);
$securityContext->getToken()->shouldBeCalled()->willReturn($token);
$token->getUser()->shouldBeCalled()->willReturn($user);
$user->getShippingAddress()->shouldBeCalled()->willReturn(null);
$customerContext->getCustomer()->shouldBeCalled()->willReturn($customer);
$customer->getShippingAddress()->shouldBeCalled()->willReturn(null);
$this->isRestricted($product)->shouldReturn(false);
}
function it_is_not_restricted_if_product_have_no_restricted_zone(
ProductInterface $product,
$securityContext,
TokenInterface $token,
UserInterface $user,
$customerContext,
CustomerInterface $customer,
AddressInterface $address,
ProductInterface $product
) {
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->shouldBeCalled()->willReturn(true);
$securityContext->getToken()->shouldBeCalled()->willReturn($token);
$token->getUser()->shouldBeCalled()->willReturn($user);
$user->getShippingAddress()->shouldBeCalled()->willReturn($address);
$customerContext->getCustomer()->shouldBeCalled()->willReturn($customer);
$customer->getShippingAddress()->shouldBeCalled()->willReturn($address);
$product->getRestrictedZone()->shouldBeCalled()->willReturn(null);
$this->isRestricted($product)->shouldReturn(false);
}
function it_is_not_restricted_if_zone_matcher_does_not_match_users_shipping_address(
function it_is_not_restricted_if_zone_matcher_does_not_match_customers_shipping_address(
ProductInterface $product,
$securityContext,
$customerContext,
$zoneMatcher,
TokenInterface $token,
UserInterface $user,
CustomerInterface $customer,
AddressInterface $address,
ProductInterface $product,
ZoneInterface $zone
) {
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->shouldBeCalled()->willReturn(true);
$securityContext->getToken()->shouldBeCalled()->willReturn($token);
$token->getUser()->shouldBeCalled()->willReturn($user);
$user->getShippingAddress()->shouldBeCalled()->willReturn($address);
$customerContext->getCustomer()->shouldBeCalled()->willReturn($customer);
$customer->getShippingAddress()->shouldBeCalled()->willReturn($address);
$product->getRestrictedZone()->shouldBeCalled()->willReturn($zone);
$zoneMatcher->matchAll($address)->shouldBeCalled()->willReturn(array());
$this->isRestricted($product)->shouldReturn(false);
}
function it_is_restricted_if_zone_matcher_match_users_shipping_address(
function it_is_restricted_if_zone_matcher_match_customers_shipping_address(
ProductInterface $product,
$securityContext,
$customerContext,
$zoneMatcher,
TokenInterface $token,
UserInterface$user,
CustomerInterface $customer,
AddressInterface $address,
ProductInterface $product,
ZoneInterface $zone
) {
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->shouldBeCalled()->willReturn(true);
$securityContext->getToken()->shouldBeCalled()->willReturn($token);
$token->getUser()->shouldBeCalled()->willReturn($user);
$user->getShippingAddress()->shouldBeCalled()->willReturn($address);
$customerContext->getCustomer()->shouldBeCalled()->willReturn($customer);
$customer->getShippingAddress()->shouldBeCalled()->willReturn($address);
$product->getRestrictedZone()->shouldBeCalled()->willReturn($zone);
$zoneMatcher->matchAll($address)->shouldBeCalled()->willReturn(array($zone));

View file

@ -19,9 +19,11 @@ use Sylius\Bundle\SettingsBundle\Model\Settings;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Core\Model\Channel;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Currency\Context\CurrencyContextInterface;
use Sylius\Component\Storage\StorageInterface;
use Sylius\Component\User\Context\CustomerContextInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
@ -29,16 +31,16 @@ class CurrencyContextSpec extends ObjectBehavior
{
function let(
StorageInterface $storage,
SecurityContextInterface $securityContext,
CustomerContextInterface $customerContext,
SettingsManagerInterface $settingsManager,
ObjectManager $userManager,
ObjectManager $customerManager,
Settings $settings,
ChannelContextInterface $channelContext
) {
$settingsManager->loadSettings('general')->willReturn($settings);
$settings->get('currency')->willReturn('EUR');
$this->beConstructedWith($storage, $securityContext, $settingsManager, $userManager, $channelContext);
$this->beConstructedWith($storage, $customerContext, $settingsManager, $customerManager, $channelContext);
}
function it_is_initializable()
@ -56,74 +58,60 @@ class CurrencyContextSpec extends ObjectBehavior
$this->getDefaultCurrency()->shouldReturn('EUR');
}
function it_gets_currency_from_session_if_there_is_no_user(
TokenInterface $token,
$securityContext,
function it_gets_currency_from_session_if_there_is_no_customer(
$customerContext,
$storage,
ChannelInterface $channel,
$channelContext
) {
$securityContext->getToken()->willReturn($token);
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
$token->getUser()->willReturn(null);
$customerContext->getCustomer()->willReturn(null);
$channel->getCode()->willReturn("WEB");
$channel->getCode()->willReturn('WEB');
$channelContext->getChannel()->willReturn($channel);
$storage->getData(sprintf(CurrencyContext::STORAGE_KEY, "WEB"), 'EUR')->willReturn('RSD');
$storage->getData(sprintf(CurrencyContext::STORAGE_KEY, 'WEB'), 'EUR')->willReturn('RSD');
$this->getCurrency()->shouldReturn('RSD');
}
function it_gets_currency_from_user_if_authenticated(
UserInterface $user,
TokenInterface $token,
$securityContext
function it_gets_currency_from_customer(
CustomerInterface $customer,
$customerContext
) {
$securityContext->getToken()->willReturn($token);
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
$token->getUser()->willReturn($user);
$user->getCurrency()->willReturn('PLN');
$customerContext->getCustomer()->willReturn($customer);
$customer->getCurrency()->willReturn('PLN');
$this->getCurrency()->shouldReturn('PLN');
}
function it_sets_currency_to_session_if_there_is_no_user(
TokenInterface $token,
$securityContext,
function it_sets_currency_to_session_if_there_is_no_customer(
$customerContext,
$storage,
ChannelInterface $channel,
$channelContext
) {
$securityContext->getToken()->willReturn($token);
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
$token->getUser()->willReturn(null);
$customerContext->getCustomer()->willReturn(null);
$channel->getCode()->willReturn("WEB");
$channel->getCode()->willReturn('WEB');
$channelContext->getChannel()->willReturn($channel);
$storage->setData(sprintf(CurrencyContext::STORAGE_KEY, "WEB"), 'PLN')->shouldBeCalled();
$storage->setData(sprintf(CurrencyContext::STORAGE_KEY, 'WEB'), 'PLN')->shouldBeCalled();
$this->setCurrency('PLN');
}
function it_sets_currency_to_user_if_authenticated(
UserInterface $user,
TokenInterface $token,
$securityContext,
function it_sets_currency_to_customer(
CustomerInterface $customer,
$customerContext,
ChannelInterface $channel,
$channelContext
) {
$securityContext->getToken()->willReturn($token);
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
$token->getUser()->willReturn($user);
$customerContext->getCustomer()->willReturn($customer);
$customer->setCurrency('PLN')->shouldBeCalled();
$channel->getCode()->willReturn("WEB");
$channel->getCode()->willReturn('WEB');
$channelContext->getChannel()->willReturn($channel);
$user->setCurrency('PLN')->shouldBeCalled();
$this->setCurrency('PLN');
}
}

View file

@ -12,13 +12,13 @@
namespace spec\Sylius\Bundle\CoreBundle\EventListener;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\CustomerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\Model\AddressInterface;
/**
* Automatic set user's default addressing
* Automatic set customer's default addressing
*
* @author Liverbool <nukboon@gmail.com>
*/
@ -35,50 +35,50 @@ class CheckoutAddressingListenerSpec extends ObjectBehavior
$this
->shouldThrow('InvalidArgumentException')
->duringSetUserAddressing($event)
->duringSetCustomerAddressing($event)
;
}
function it_does_nothing_when_context_doesnt_have_user(GenericEvent $event, OrderInterface $order)
function it_does_nothing_when_context_doesnt_have_customer(GenericEvent $event, OrderInterface $order)
{
$event->getSubject()->willReturn($order);
$order->getUser()->willReturn(null);
$order->getCustomer()->willReturn(null);
$this->setUserAddressing($event);
$this->setCustomerAddressing($event);
}
function it_sets_user_default_addressing_from_order(GenericEvent $event, OrderInterface $order, UserInterface $user, AddressInterface $address)
function it_sets_customer_default_addressing_from_order(GenericEvent $event, OrderInterface $order, CustomerInterface $customer, AddressInterface $address)
{
$event->getSubject()->willReturn($order);
$order->getUser()->willReturn($user);
$order->getCustomer()->willReturn($customer);
$order->getShippingAddress()->willReturn($address);
$user->getShippingAddress()->willReturn(null);
$user->setShippingAddress($address)->shouldBeCalled();
$customer->getShippingAddress()->willReturn(null);
$customer->setShippingAddress($address)->shouldBeCalled();
$order->getBillingAddress()->willReturn($address);
$user->getBillingAddress()->willReturn(null);
$user->setBillingAddress($address)->shouldBeCalled();
$customer->getBillingAddress()->willReturn(null);
$customer->setBillingAddress($address)->shouldBeCalled();
$this->setUserAddressing($event);
$this->setCustomerAddressing($event);
}
function it_does_not_sets_user_addressing_when_user_already_have_default_addresses(GenericEvent $event, OrderInterface $order, UserInterface $user, AddressInterface $address)
function it_does_not_set_customer_addressing_when_customer_already_have_default_addresses(GenericEvent $event, OrderInterface $order, CustomerInterface $customer, AddressInterface $address)
{
$event->getSubject()->willReturn($order);
$order->getUser()->willReturn($user);
$order->getCustomer()->willReturn($customer);
$order->getShippingAddress()->willReturn($address);
$user->getShippingAddress()->willReturn($address);
$user->setShippingAddress($address)->shouldNotBeCalled();
$customer->getShippingAddress()->willReturn($address);
$customer->setShippingAddress($address)->shouldNotBeCalled();
$order->getBillingAddress()->willReturn($address);
$user->getBillingAddress()->willReturn($address);
$user->setBillingAddress($address)->shouldNotBeCalled();
$customer->getBillingAddress()->willReturn($address);
$customer->setBillingAddress($address)->shouldNotBeCalled();
$this->setUserAddressing($event);
$this->setCustomerAddressing($event);
}
}

View file

@ -74,15 +74,16 @@ class LoadApiData extends DataFixture
/* @var $user UserInterface */
$user = $this->getUserRepository()->createNew();
$user->setFirstname($this->faker->firstName);
$user->setLastname($this->faker->lastName);
$customer = $user->getCustomer();
$customer->setFirstname($this->faker->firstName);
$customer->setLastname($this->faker->lastName);
$customer->setCurrency($currency);
$user->setUsername($email);
$user->setEmail($email);
$user->setUsernameCanonical($canonicalizer->canonicalize($user->getUsername()));
$user->setEmailCanonical($canonicalizer->canonicalize($user->getEmail()));
$user->setPlainPassword($password);
$user->setRoles($roles);
$user->setCurrency($currency);
$user->setEnabled($enabled);
$this->get('sylius.user.password_updater')->updatePassword($user);

View file

@ -56,7 +56,6 @@ class LoadGroupsData extends DataFixture
/* @var $group GroupInterface */
$group = $this->getGroupRepository()->createNew();
$group->setName($name);
$group->setRoles($roles);
$this->setReference('Sylius.Group.'.$name, $group);

View file

@ -70,15 +70,12 @@ class LoadOrdersData extends DataFixture
$order->calculateTotal();
$order->complete();
if ($i < 4) {
$order->setUser($this->getReference('Sylius.User-Administrator'));
$this->createPayment($order, PaymentInterface::STATE_COMPLETED);
} else {
$order->setUser($this->getReference('Sylius.User-'.rand(1, 15)));
$this->createPayment($order);
$paymentState = PaymentInterface::STATE_COMPLETED;
if (rand(1, 10) < 5) {
$paymentState = PaymentInterface::STATE_NEW;
}
$order->setCustomer($this->getReference('Sylius.Customer-'.rand(1, 15)));
$this->createPayment($order, $paymentState);
$order->setCompletedAt($this->faker->dateTimeThisDecade);
$this->setReference('Sylius.Order-'.$i, $order);

View file

@ -36,7 +36,7 @@ class LoadUsersData extends DataFixture
'sylius@example.com',
'sylius',
true,
array('ROLE_SYLIUS_ADMIN')
array('ROLE_USER', 'ROLE_SYLIUS_ADMIN', 'ROLE_ADMINISTRATION_ACCESS')
);
$user->addAuthorizationRole($this->get('sylius.repository.role')->findOneBy(array('code' => 'administrator')));
@ -64,6 +64,7 @@ class LoadUsersData extends DataFixture
$this->usernames[$username] = true;
$this->setReference('Sylius.User-'.$i, $user);
$this->setReference('Sylius.Customer-'.$i, $user->getCustomer());
}
$manager->flush();
@ -92,15 +93,16 @@ class LoadUsersData extends DataFixture
/* @var $user UserInterface */
$user = $this->getUserRepository()->createNew();
$user->setFirstname($this->faker->firstName);
$user->setLastname($this->faker->lastName);
$customer = $user->getCustomer();
$customer->setFirstname($this->faker->firstName);
$customer->setLastname($this->faker->lastName);
$customer->setCurrency($currency);
$user->setUsername($email);
$user->setEmail($email);
$user->setUsernameCanonical($canonicalizer->canonicalize($user->getUsername()));
$user->setEmailCanonical($canonicalizer->canonicalize($user->getEmail()));
$user->setPlainPassword($password);
$user->setRoles($roles);
$user->setCurrency($currency);
$user->setEnabled($enabled);
$this->get('sylius.user.password_updater')->updatePassword($user);

View file

@ -23,7 +23,6 @@
</id>
<field name="number" column="number" type="string" unique="true" nullable="true" />
<field type="string" name="email" column="email" nullable="true"/>
<field name="state" column="state" type="string" />
<field name="completedAt" column="completed_at" type="datetime" nullable="true" />

View file

@ -15,7 +15,7 @@ use Payum\Core\Action\PaymentAwareAction;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Model\Order;
use Payum\Core\Request\Capture;
use Sylius\Component\Payment\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentInterface;
class GenericCapturePaymentAction extends PaymentAwareAction
{
@ -36,8 +36,8 @@ class GenericCapturePaymentAction extends PaymentAwareAction
$payumOrder->setNumber($order->getNumber());
$payumOrder->setTotalAmount($order->getTotal());
$payumOrder->setCurrencyCode($order->getCurrency());
$payumOrder->setClientEmail($order->getEmail());
$payumOrder->setClientId($order->getUser() ? $order->getUser()->getId() : $order->getEmail());
$payumOrder->setClientEmail($order->getCustomer()->getEmail());
$payumOrder->setClientId($order->getCustomer()->getId());
$payumOrder->setDescription(sprintf(
'Order containing %d items for a total of %01.2f',
$order->getItems()->count(), $order->getTotal() / 100

View file

@ -61,16 +61,15 @@ class CapturePaymentUsingBe2billFormAction extends AbstractCapturePaymentAction
}
$this->payment->execute($httpRequest = new GetHttpRequest());
$order = $payment->getOrder();
$details = array();
$details['AMOUNT'] = $order->getTotal();
$details['CLIENTEMAIL'] = $order->getEmail();
$details['CLIENTEMAIL'] = $order->getCustomer()->getEmail();
$details['HIDECLIENTEMAIL'] = 'yes';
$details['CLIENTUSERAGENT'] = $httpRequest->userAgent ?: 'Unknown';
$details['CLIENTIP'] = $httpRequest->clientIp;
$details['CLIENTIDENT'] = $order->getUser() ? $order->getUser()->getId() : $order->getEmail();
$details['CLIENTIDENT'] = $order->getCustomer()->getId();
$details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100);
$details['ORDERID'] = $payment->getId();

View file

@ -38,10 +38,10 @@ class CapturePaymentUsingCreditCardAction extends AbstractCapturePaymentAction
$details = array();
$details['AMOUNT'] = $order->getTotal();
$details['CLIENTEMAIL'] = $order->getEmail();
$details['CLIENTEMAIL'] = $order->getCustomer()->getEmail();
$details['CLIENTUSERAGENT'] = $httpRequest->userAgent ?: 'Unknown';
$details['CLIENTIP'] = $httpRequest->clientIp;
$details['CLIENTIDENT'] = $order->getUser() ? $order->getUser()->getId() : $order->getEmail();
$details['CLIENTIDENT'] = $order->getCustomer()->getId();
$details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100);
$details['ORDERID'] = $payment->getId();

View file

@ -75,7 +75,7 @@ class Configuration implements ConfigurationInterface
->prototype('scalar')->end()
->defaultValue(array('sylius'))
->end()
->arrayNode('promotion_rule_user_loyalty_configuration')
->arrayNode('promotion_rule_customer_loyalty_configuration')
->prototype('scalar')->end()
->defaultValue(array('sylius'))
->end()
@ -95,7 +95,7 @@ class Configuration implements ConfigurationInterface
->prototype('scalar')->end()
->defaultValue(array('sylius'))
->end()
->arrayNode('promotion_rule_user_group_configuration')
->arrayNode('promotion_rule_customer_group_configuration')
->prototype('scalar')->end()
->defaultValue(array('sylius'))
->end()

View file

@ -26,7 +26,7 @@ sylius:
equal: Equal
nth_order_configuration:
nth: Nth
user_loyalty_configuration:
customer_loyalty_configuration:
time: Time
unit:
days: Days

View file

@ -401,7 +401,7 @@ class ResourceController extends FOSRestController
if ($this->config->isApiRequest()) {
return $this->container->get('form.factory')->createNamed('', $type, $resource, array('csrf_protection' => false));
}
return $this->createForm($type, $resource);
}

View file

@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\UserBundle\Context;
use Sylius\Component\User\Context\CustomerContextInterface;
use Sylius\Component\User\Model\CustomerInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
*
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
class CustomerContext implements CustomerContextInterface
{
private $securityContext;
public function __construct(SecurityContextInterface $securityContext)
{
$this->securityContext = $securityContext;
}
/**
* Gets customer based on currently logged user.
*
* @return CustomerInterface|null
*/
public function getCustomer()
{
if ($this->securityContext->getToken() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')
&& $this->securityContext->getToken()->getUser()
) {
return $this->securityContext->getToken()->getUser()->getCustomer();
}
return null;
}
}

View file

@ -0,0 +1,58 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\UserBundle\Controller;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
class CustomerController extends ResourceController
{
public function updateProfileAction(Request $request)
{
$resource = $this->getCustomer();
$form = $this->getForm($resource);
if (in_array($request->getMethod(), array('POST', 'PUT', 'PATCH')) && $form->submit($request, !$request->isMethod('PATCH'))->isValid()) {
$this->domainManager->update($resource);
if ($this->config->isApiRequest()) {
return $this->handleView($this->view($resource, 204));
}
return $this->redirectHandler->redirectTo($resource);
}
if ($this->config->isApiRequest()) {
return $this->handleView($this->view($form, 400));
}
$view = $this
->view()
->setTemplate($this->config->getTemplate('updateProfile.html'))
->setData(array(
$this->config->getResourceName() => $resource,
'form' => $form->createView(),
))
;
return $this->handleView($view);
}
protected function getCustomer()
{
return $this->get('sylius.context.customer')->getCustomer();
}
}

View file

@ -29,37 +29,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*/
class UserController extends ResourceController
{
public function updateProfileAction(Request $request)
{
$resource = $this->getUser();
$form = $this->getForm($resource);
if (in_array($request->getMethod(), array('POST', 'PUT', 'PATCH')) && $form->submit($request, !$request->isMethod('PATCH'))->isValid()) {
$this->domainManager->update($resource);
if ($this->config->isApiRequest()) {
return $this->handleView($this->view($resource, 204));
}
return $this->redirectHandler->redirectTo($resource);
}
if ($this->config->isApiRequest()) {
return $this->handleView($this->view($form, 400));
}
$view = $this
->view()
->setTemplate($this->config->getTemplate('updateProfile.html'))
->setData(array(
$this->config->getResourceName() => $resource,
'form' => $form->createView(),
))
;
return $this->handleView($view);
}
public function changePasswordAction(Request $request)
{
$user = $this->getUser();

View file

@ -115,7 +115,7 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue('Sylius\Component\User\Model\Customer')->end()
->scalarNode('controller')->defaultValue('Sylius\Bundle\ResourceBundle\Controller\ResourceController')->end()
->scalarNode('controller')->defaultValue('Sylius\Bundle\UserBundle\Controller\CustomerController')->end()
->scalarNode('repository')->end()
->arrayNode('form')
->addDefaultsIfNotSet()

View file

@ -16,9 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Locale extension.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class SyliusUserExtension extends AbstractResourceExtension
{

View file

@ -12,21 +12,23 @@
namespace Sylius\Bundle\UserBundle\EventListener;
use Sylius\Component\Cart\Event\CartEvent;
use Sylius\Component\User\Context\CustomerContextInterface;
use Sylius\Component\User\Model\CustomerAwareInterface;
use Sylius\Component\User\Model\UserAwareInterface;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Security\Core\SecurityContextInterface;
class UserAwareListener
class CustomerAwareListener
{
protected $securityContext;
protected $customerContext;
public function __construct(SecurityContextInterface $securityContext)
public function __construct(CustomerContextInterface $securityContext)
{
$this->securityContext = $securityContext;
$this->customerContext = $securityContext;
}
public function setUser(GenericEvent $event)
public function setCustomer(GenericEvent $event)
{
if ($event instanceof CartEvent) {
$resource = $event->getCart();
@ -34,23 +36,14 @@ class UserAwareListener
$resource = $event->getSubject();
}
if (!$resource instanceof UserAwareInterface) {
throw new UnexpectedTypeException($resource, 'Sylius\Component\User\Model\UserAwareInterface');
if (!$resource instanceof CustomerAwareInterface) {
throw new UnexpectedTypeException($resource, 'Sylius\Component\User\Model\CustomerAwareInterface');
}
if (null === $user = $this->getUser()) {
if (null === $customer = $this->customerContext->getCustomer()) {
return;
}
$resource->setUser($user);
}
protected function getUser()
{
if ($this->securityContext->getToken() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
return $this->securityContext->getToken()->getUser();
}
return null;
$resource->setCustomer($customer);
}
}

View file

@ -17,8 +17,6 @@ use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* User register listener.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class UserLoginListener

View file

@ -17,8 +17,6 @@ use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* User update listener.
*
* @author Łukasz CHruściel <lukasz.chrusciel@lakion.com>
*/
class UserReloaderListener

View file

@ -22,15 +22,13 @@ use Sylius\Bundle\UserBundle\Form\EventListener\CanonicalizerFormListener;
class UserRegistrationType extends AbstractResourceType
{
/**
* DataFetcher registry.
*
* @var CanonicalizerInterface
*/
protected $canonicalizer;
/**
* Constructor.
*
* @param string $dataClass
* @param string[] $validationGroups
* @param CanonicalizerInterface $canonicalizer
*/
public function __construct($dataClass, array $validationGroups, CanonicalizerInterface $canonicalizer)

View file

@ -22,15 +22,13 @@ use Symfony\Component\Form\FormBuilderInterface;
class UserType extends AbstractResourceType
{
/**
* DataFetcher registry.
*
* @var CanonicalizerInterface
*/
protected $canonicalizer;
/**
* Constructor.
*
* @param string $dataClass
* @param string[] $validationGroups
* @param CanonicalizerInterface $canonicalizer
*/
public function __construct($dataClass, array $validationGroups, CanonicalizerInterface $canonicalizer)
@ -53,12 +51,6 @@ class UserType extends AbstractResourceType
->add('enabled', 'checkbox', array(
'label' => 'sylius.form.user.enabled',
))
->add('groups', 'sylius_group_choice', array(
'label' => 'sylius.form.user.groups',
'multiple' => true,
'required' => false,
))
->remove('username')
;
}

View file

@ -77,7 +77,7 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface
}
if (null !== $response->getEmail()) {
$user = $this->userRepository->findOneBy(array('email' => $response->getEmail()));
$user = $this->userRepository->findOneByEmail($response->getEmail());
if (null !== $user) {
return $this->updateUserByOAuthUserResponse($user, $response);
}

View file

@ -44,6 +44,20 @@
</cascade>
</one-to-one>
<many-to-many field="groups" target-entity="Sylius\Component\User\Model\GroupInterface">
<cascade>
<cascade-all />
</cascade>
<join-table name="sylius_customer_group">
<join-columns>
<join-column name="customer_id" referenced-column-name="id" on-delete="CASCADE"/>
</join-columns>
<inverse-join-columns>
<join-column name="group_id" referenced-column-name="id" on-delete="CASCADE"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<gedmo:soft-deleteable field-name="deletedAt" />
</mapped-superclass>

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
<mapped-superclass name="Sylius\Component\User\Model\User" collection="sylius_user">
<field name="id" id="true" strategy="AUTO" />
<field fieldName="enabled" name="enabled" type="boolean" />
<field fieldName="createdAt" name="createdAt" type="date">
<gedmo:timestampable on="create"/>
</field>
<field fieldName="updatedAt" name="updatedAt" type="date">
<gedmo:timestampable on="update"/>
</field>
</mapped-superclass>
</doctrine-mongo-mapping>

View file

@ -22,8 +22,8 @@
<generator strategy="AUTO" />
</id>
<field name="username" column="username" type="string" nullable="false" />
<field name="usernameCanonical" column="username_canonical" type="string" nullable="false" />
<field name="username" column="username" type="string" nullable="true" />
<field name="usernameCanonical" column="username_canonical" type="string" nullable="true" />
<field name="enabled" column="enabled" type="boolean" nullable="false" />
<field name="salt" column="salt" type="string" nullable="false" />
<field name="password" column="password" type="string" nullable="false" />
@ -58,20 +58,6 @@
</cascade>
</one-to-many>
<many-to-many field="groups" target-entity="Sylius\Component\User\Model\GroupInterface">
<cascade>
<cascade-all />
</cascade>
<join-table name="sylius_user_group">
<join-columns>
<join-column name="user_id" referenced-column-name="id" on-delete="CASCADE"/>
</join-columns>
<inverse-join-columns>
<join-column name="group_id" referenced-column-name="id" on-delete="CASCADE"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<gedmo:soft-deleteable field-name="deletedAt" />
</mapped-superclass>

View file

@ -17,6 +17,8 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius.context.customer.class">Sylius\Bundle\UserBundle\Context\CustomerContext</parameter>
<parameter key="sylius.user.canonicalizer.class">Sylius\Component\User\Canonicalizer\Canonicalizer</parameter>
<parameter key="sylius.user.password_updater.class">Sylius\Component\User\Security\PasswordUpdater</parameter>
<parameter key="sylius.user.code_provider.class">Sylius\Component\User\Security\TokenProvider</parameter>
@ -38,8 +40,8 @@
<parameter key="sylius.form.type.user_reset_password.class">Sylius\Bundle\UserBundle\Form\Type\UserResetPasswordType</parameter>
<parameter key="sylius.form.type.user_change_password.class">Sylius\Bundle\UserBundle\Form\Type\UserChangePasswordType</parameter>
<parameter key="sylius.listener.customer_aware.class">Sylius\Bundle\UserBundle\EventListener\CustomerAwareListener</parameter>
<parameter key="sylius.listener.user_delete.class">Sylius\Bundle\UserBundle\EventListener\UserDeleteListener</parameter>
<parameter key="sylius.listener.user_aware.class">Sylius\Bundle\UserBundle\EventListener\UserAwareListener</parameter>
<parameter key="sylius.listener.canonicalizer.class">Sylius\Bundle\UserBundle\EventListener\CanonicalizerListener</parameter>
<parameter key="sylius.listener.password_updater.class">Sylius\Bundle\UserBundle\EventListener\PasswordUpdaterListener</parameter>
<parameter key="sylius.listener.user_login.class">Sylius\Bundle\UserBundle\EventListener\UserLoginListener</parameter>
@ -50,6 +52,11 @@
</parameters>
<services>
<!-- Customer context -->
<service id="sylius.context.customer" class="%sylius.context.customer.class%">
<argument type="service" id="security.context" />
</service>
<!-- Controllers -->
<service id="sylius.controller.security" class="%sylius.controller.security.class%">
<call method="setContainer">
@ -89,6 +96,9 @@
</service>
<!-- Listeners -->
<service id="sylius.listener.customer_aware" class="%sylius.listener.customer_aware.class%">
<argument type="service" id="sylius.context.customer" />
</service>
<service id="sylius.listener.user_login" class="%sylius.listener.user_login.class%">
<argument type="service" id="sylius.security.user_login" />
<tag name="kernel.event_listener" event="sylius.user.post_register" method="login" />
@ -115,9 +125,6 @@
<tag name="kernel.event_listener" event="sylius.user.password_reset.request.pin" method="sendResetPasswordPinEmail" />
<tag name="kernel.event_listener" event="sylius.user.password_reset.request.token" method="sendResetPasswordTokenEmail" />
</service>
<service id="sylius.listener.user_aware" class="%sylius.listener.user_aware.class%">
<argument type="service" id="security.context" />
</service>
<service id="sylius.listener.user_delete" class="%sylius.listener.user_delete.class%">
<argument type="service" id="security.context" />
<argument type="service" id="session" />

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius.twig.extension.user.class">Sylius\Bundle\UserBundle\Twig\UserExtension</parameter>
</parameters>
<services>
<service id="sylius.twig.extension.locale" class="%sylius.twig.extension.locale.class%" public="false">
<argument type="service" id="sylius.templating.helper.locale" />
<tag name="twig.extension" />
</service>
</services>
</container>

View file

@ -17,43 +17,69 @@
http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
<class name="Sylius\Component\User\Model\Customer">
<property name="firstName">
<constraint name="NotBlank">
<option name="message">sylius.customer.first_name.not_blank</option>
<option name="groups"><value>sylius</value></option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.customer.first_name.min</option>
<option name="max">255</option>
<option name="maxMessage">sylius.customer.first_name.max</option>
<option name="groups"><value>sylius</value></option>
</constraint>
</property>
<property name="lastName">
<constraint name="NotBlank">
<option name="message">sylius.customer.last_name.not_blank</option>
<option name="groups"><value>sylius</value></option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.customer.last_name.min</option>
<option name="max">255</option>
<option name="maxMessage">sylius.customer.last_name.max</option>
<option name="groups"><value>sylius</value></option>
</constraint>
</property>
<property name="email">
<constraint name="NotBlank">
<option name="message">sylius.user.email.not_blank</option>
<option name="message">sylius.customer.email.not_blank</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.user.email.min</option>
<option name="minMessage">sylius.customer.email.min</option>
<option name="max">254</option>
<option name="maxMessage">sylius.user.email.max</option>
<option name="maxMessage">sylius.customer.email.max</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Email">
<option name="message">sylius.user.email.invalid</option>
<option name="message">sylius.customer.email.invalid</option>
<option name="groups">sylius</option>
</constraint>
</property>
</class>
<class name="Sylius\Component\User\Model\User">
<property name="email">
<constraint name="NotBlank">
<option name="message">sylius.user.email.not_blank</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="minMessage">sylius.user.email.min</option>
<option name="max">254</option>
<option name="maxMessage">sylius.user.email.max</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Email">
<option name="message">sylius.user.email.invalid</option>
<option name="groups">sylius</option>
</constraint>
</property>
<!--<property name="email">-->
<!--<constraint name="NotBlank">-->
<!--<option name="message">sylius.user.email.not_blank</option>-->
<!--<option name="groups">sylius</option>-->
<!--</constraint>-->
<!--<constraint name="Length">-->
<!--<option name="min">2</option>-->
<!--<option name="minMessage">sylius.user.email.min</option>-->
<!--<option name="max">254</option>-->
<!--<option name="maxMessage">sylius.user.email.max</option>-->
<!--<option name="groups">sylius</option>-->
<!--</constraint>-->
<!--<constraint name="Email">-->
<!--<option name="message">sylius.user.email.invalid</option>-->
<!--<option name="groups">sylius</option>-->
<!--</constraint>-->
<!--</property>-->
<property name="plainPassword">
<constraint name="NotBlank">
<option name="groups">sylius</option>

View file

@ -4,16 +4,18 @@ sylius:
name: Name
roles: Roles
user:
billing_address: Billing address
different_billing_address: Use different address for billing?
email: Email
enabled: Enabled
first_name: First name
groups: Groups
last_name: Last name
password:
label: Password
confirmation: Verification
shipping_address: Shipping address
customer:
first_name: First name
groups: Groups
last_name: Last name
email: Email
billing_address: Billing address
different_billing_address: Use different address for billing?
user_filter:
query: Search

View file

@ -6,6 +6,17 @@ sylius:
not_blank: Please enter group name.
user:
email:
already_used: The email is already used
max: Email must not be longer than {{ limit }} characters.
min: Email must be at least {{ limit }} characters long.
not_blank: Please enter your email.
invalid: This email is invalid.
plainPassword:
not_blank: Please enter your password.
mismatch: The entered passwords don't match
customer:
first_name:
max: First name must not be longer than {{ limit }} characters.
min: First name must be at least {{ limit }} characters long.
@ -19,7 +30,4 @@ sylius:
max: Email must not be longer than {{ limit }} characters.
min: Email must be at least {{ limit }} characters long.
not_blank: Please enter your email.
invalid: This email is invalid.
plainPassword:
not_blank: Please enter your password.
mismatch: The entered passwords don't match
invalid: This email is invalid.

View file

@ -10,6 +10,14 @@
"name": "Paweł Jędrzejewski",
"homepage": "http://pjedrzejewski.com"
},
{
"name": "Michał Marcinkowski",
"email": "michal.marcinkowski@lakion.com"
},
{
"name": "Łukasz Chruściel",
"email": "lukasz.chrusciel@lakion.com"
},
{
"name": "Bartosz Siejka",
"homepage": "http://bsiejka.com"
@ -33,8 +41,7 @@
},
"require-dev": {
"phpspec/phpspec": "~2.1",
"symfony/form": "~2.3",
"twig/twig": "~1.0"
"symfony/form": "~2.3"
},
"config": {
"bin-dir": "bin"

View file

@ -0,0 +1,51 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\UserBundle\Context;
use PhpSpec\ObjectBehavior;
use Sylius\Component\User\Model\CustomerInterface;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
class CustomerContextSpec extends ObjectBehavior
{
function let(SecurityContextInterface $securityContext)
{
$this->beConstructedWith($securityContext);
}
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\UserBundle\Context\CustomerContext');
}
function it_gets_customer_from_currently_logged_user($securityContext, TokenInterface $token, UserInterface $user, CustomerInterface $customer)
{
$securityContext->getToken()->willReturn($token);
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
$token->getUser()->willReturn($user);
$user->getCustomer()->willReturn($customer);
$this->getCustomer()->shouldReturn($customer);
}
function it_returns_null_if_user_is_not_logged_in($securityContext)
{
$securityContext->getToken()->willReturn(null);
$this->getCustomer()->shouldReturn(null);
}
}

View file

@ -19,8 +19,6 @@ use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
use Sylius\Component\User\Model\UserInterface;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class CanonicalizerListenerSpec extends ObjectBehavior
@ -67,9 +65,9 @@ class CanonicalizerListenerSpec extends ObjectBehavior
$this->preUpdate($event);
}
function it_canonicalize_only_user_interface_implementation($canonicalizer, LifecycleEventArgs $event, UserInterface $user)
function it_canonicalize_only_user_interface_implementation($canonicalizer, LifecycleEventArgs $event)
{
$user='';
$user = '';
$event->getEntity()->willReturn($user);
$canonicalizer->canonicalize('testUser')->shouldNotBeCalled();

View file

@ -0,0 +1,88 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\UserBundle\EventListener;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Cart\Event\CartEvent;
use Sylius\Component\User\Context\CustomerContextInterface;
use Sylius\Component\User\Model\CustomerAwareInterface;
use Sylius\Component\User\Model\CustomerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* @author Michał Marcinkowski <michal.marcinkowski@lakion.com>
*/
class CustomerAwareListenerSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\UserBundle\EventListener\CustomerAwareListener');
}
function let(CustomerContextInterface $customerContext)
{
$this->beConstructedWith($customerContext);
}
function it_throws_exception_when_object_is_not_customer(GenericEvent $event, \stdClass $object)
{
$event->getSubject()->willReturn($object);
$this
->shouldThrow('InvalidArgumentException')
->duringSetCustomer($event)
;
}
function it_does_nothing_when_context_doesnt_have_customer(
$customerContext,
GenericEvent $event,
CustomerAwareInterface $resource
) {
$event->getSubject()->willReturn($resource);
$customerContext->getCustomer()->willReturn(null);
$resource->setCustomer(Argument::any())->shouldNotBeCalled();
$this->setCustomer($event);
}
function it_sets_customer_on_a_resource(
$customerContext,
GenericEvent $event,
CustomerAwareInterface $resource,
CustomerInterface $customer
) {
$event->getSubject()->willReturn($resource);
$customerContext->getCustomer()->willReturn($customer);
$resource->setCustomer($customer)->shouldBeCalled();
$this->setCustomer($event);
}
function it_sets_customer_on_a_cart(
$customerContext,
CartEvent $event,
CustomerAwareInterface $cart,
CustomerInterface $customer
) {
$event->getCart()->willReturn($cart);
$customerContext->getCustomer()->willReturn($customer);
$cart->setCustomer($customer)->shouldBeCalled();
$this->setCustomer($event);
}
}

View file

@ -18,8 +18,6 @@ use Symfony\Component\EventDispatcher\GenericEvent;
use Sylius\Component\Mailer\Sender\SenderInterface;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class MailerListenerSpec extends ObjectBehavior

View file

@ -20,8 +20,6 @@ use Sylius\Component\User\Security\PasswordUpdaterInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class PasswordUpdaterListenerSpec extends ObjectBehavior

View file

@ -1,76 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\UserBundle\EventListener;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\User\Model\UserAwareInterface;
use Sylius\Component\Core\Model\UserInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
class UserAwareListenerSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\UserBundle\EventListener\UserAwareListener');
}
function let(SecurityContextInterface $securityContext)
{
$this->beConstructedWith($securityContext);
}
function it_throws_exception_when_object_is_not_user(GenericEvent $event, \stdClass $object)
{
$event->getSubject()->willReturn($object);
$this
->shouldThrow('InvalidArgumentException')
->duringSetUser($event)
;
}
function it_does_nothing_when_context_doesnt_have_user(
SecurityContextInterface $securityContext,
GenericEvent $event,
UserAwareInterface $resource
) {
$event->getSubject()->willReturn($resource);
$securityContext->getToken()->willReturn(null);
$resource->setUser(Argument::any())->shouldNotBeCalled();
$this->setUser($event);
}
function it_sets_user_on_order(
SecurityContextInterface $securityContext,
GenericEvent $event,
UserAwareInterface $resource,
TokenInterface $token,
UserInterface $user
) {
$event->getSubject()->willReturn($resource);
$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
$securityContext->getToken()->willReturn($token);
$token->getUser()->willReturn($user);
$resource->setUser($user)->shouldBeCalled();
$this->setUser($event);
}
}

View file

@ -19,8 +19,6 @@ use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class UserLoginListenerSpec extends ObjectBehavior

View file

@ -19,8 +19,6 @@ use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class UserReloaderListenerSpec extends ObjectBehavior

View file

@ -18,8 +18,6 @@ use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\Form\FormEvent;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class CanonicalizerFormListenerSpec extends ObjectBehavior

View file

@ -14,8 +14,6 @@ namespace spec\Sylius\Bundle\UserBundle\Form\Model;
use PhpSpec\ObjectBehavior;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class ChangePasswordSpec extends ObjectBehavior

View file

@ -14,8 +14,6 @@ namespace spec\Sylius\Bundle\UserBundle\Form\Model;
use PhpSpec\ObjectBehavior;
/**
* User register listener spec.
*
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class PasswordResetSpec extends ObjectBehavior

View file

@ -47,9 +47,6 @@ class UserTypeSpec extends ObjectBehavior
$builder->add('customer', 'sylius_customer')->shouldBeCalled()->willReturn($builder);
$builder->add('plainPassword', 'password', Argument::any())->shouldBeCalled()->willReturn($builder);
$builder->add('enabled', 'checkbox', Argument::any())->shouldBeCalled()->willReturn($builder);
$builder->add('groups', 'sylius_group_choice', Argument::any())->shouldBeCalled()->willReturn($builder);
$builder->add('authorizationRoles', 'sylius_role_choice', Argument::any())->shouldBeCalled()->willReturn($builder);
$builder->remove('username')->shouldBeCalled()->willReturn($builder);
$this->buildForm($builder, array());
}

View file

@ -45,7 +45,6 @@ class UserProviderSpec extends ObjectBehavior
$this->shouldImplement('HWI\Bundle\OAuthBundle\Connect\AccountConnectorInterface');
}
function it_should_connect_oauth_account_with_given_user(
$userManager,
$oauthRepository,
@ -112,7 +111,7 @@ class UserProviderSpec extends ObjectBehavior
$oauthRepository->findOneBy(array('provider' => 'google', 'identifier' => 'username'))->willReturn(null);
$oauthRepository->createNew()->willReturn($oauth);
$userRepository->findOneBy(array('email' => 'username@email'))->willReturn($user);
$userRepository->findOneByEmail('username@email')->willReturn($user);
$oauth->setIdentifier('username');
$oauth->setProvider('google');

View file

@ -15,15 +15,18 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
class UserLoginSpec extends ObjectBehavior
{
function let(Container $container)
function let(ContainerInterface $container)
{
$this->beConstructedWith($container);
}
@ -38,17 +41,17 @@ class UserLoginSpec extends ObjectBehavior
$this->shouldImplement('Sylius\Bundle\UserBundle\Security\UserLoginInterface');
}
// function it_logs_user_in($container, UserInterface $user, SecurityContext $context, Session $session)
// {
// $user->getRoles()->willReturn(array('ROLE_TEST'));
// $this->serialize(Argument::any())->willBeCalled();
function it_logs_user_in($container, UserInterface $user, SecurityContextInterface $context, SessionInterface $session)
{
$user->getRoles()->willReturn(array('ROLE_TEST'));
$user->serialize(Argument::any())->shouldBeCalled();
// $container->get('security.context')->willReturn($context);
// $container->get('session')->willReturn($session);
$container->get('security.context')->willReturn($context);
$container->get('session')->willReturn($session);
// $context->setToken(Argument::type('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'))->shouldBeCalled();
// $session->set('_security_main', Argument::any())->shouldBeCalled();
$context->setToken(Argument::type('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'))->shouldBeCalled();
$session->set('_security_main', Argument::any())->shouldBeCalled();
// $this->login($user);
// }
$this->login($user);
}
}

View file

@ -15,6 +15,7 @@ use Doctrine\Common\Persistence\ObjectManager;
use FOS\RestBundle\Controller\FOSRestController;
use Sylius\Component\Addressing\Model\AddressInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@ -22,14 +23,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* User account address controller.
* Customer account address controller.
*
* @author Julien Janvier <j.janvier@gmail.com>
*/
class AddressController extends FOSRestController
{
/**
* Get collection of user's addresses.
* Get collection of customer's addresses.
*/
public function indexAction()
{
@ -37,8 +38,8 @@ class AddressController extends FOSRestController
->view()
->setTemplate('SyliusWebBundle:Frontend/Account:Address/index.html.twig')
->setData(array(
'user' => $this->getUser(),
'addresses' => $this->getUser()->getAddresses(),
'customer' => $this->getCustomer(),
'addresses' => $this->getCustomer()->getAddresses(),
))
;
@ -46,19 +47,19 @@ class AddressController extends FOSRestController
}
/**
* Create new user address.
* Create new customer address.
*/
public function createAction(Request $request)
{
$user = $this->getUser();
$customer = $this->getCustomer();
$address = $this->getAddressRepository()->createNew();
$form = $this->getAddressForm($address);
if ($form->handleRequest($request)->isValid()) {
$user->addAddress($address);
$customer->addAddress($address);
$manager = $this->getUserManager();
$manager->persist($user);
$manager = $this->getCustomerManager();
$manager->persist($customer);
$manager->flush();
$this->addFlash('success', 'sylius.account.address.create');
@ -70,7 +71,7 @@ class AddressController extends FOSRestController
->view()
->setTemplate('SyliusWebBundle:Frontend/Account:Address/create.html.twig')
->setData(array(
'user' => $this->getUser(),
'customer' => $this->getCustomer(),
'form' => $form->createView()
))
;
@ -83,13 +84,13 @@ class AddressController extends FOSRestController
*/
public function updateAction(Request $request, $id)
{
$user = $this->getUser();
$customer = $this->getCustomer();
$address = $this->findUserAddressOr404($id);
$form = $this->getAddressForm($address);
if ($form->handleRequest($request)->isValid()) {
$manager = $this->getUserManager();
$manager->persist($user);
$manager = $this->getCustomerManager();
$manager->persist($customer);
$manager->flush();
$this->addFlash('success', 'sylius.account.address.update');
@ -101,7 +102,7 @@ class AddressController extends FOSRestController
->view()
->setTemplate('SyliusWebBundle:Frontend/Account:Address/update.html.twig')
->setData(array(
'user' => $this->getUser(),
'customer' => $this->getCustomer(),
'address' => $address,
'form' => $form->createView()
))
@ -115,13 +116,13 @@ class AddressController extends FOSRestController
*/
public function deleteAction($id)
{
$user = $this->getUser();
$customer = $this->getCustomer();
$address = $this->findUserAddressOr404($id);
$user->removeAddress($address);
$customer->removeAddress($address);
$manager = $this->getUserManager();
$manager->persist($user);
$manager = $this->getCustomerManager();
$manager->persist($customer);
$manager->flush();
$this->addFlash('success', 'sylius.account.address.delete');
@ -143,22 +144,22 @@ class AddressController extends FOSRestController
{
$address = $this->findUserAddressOr404($id);
$user = $this->getUser();
$customer = $this->getCustomer();
if ('billing' === $type) {
$user->setBillingAddress($address);
$customer->setBillingAddress($address);
$this->addFlash('success', 'sylius.account.address.set_as_billing');
} elseif ('shipping' === $type) {
$user->setShippingAddress($address);
$customer->setShippingAddress($address);
$this->addFlash('success', 'sylius.account.address.set_as_shipping');
} else {
throw new NotFoundHttpException();
}
$manager = $this->getUserManager();
$manager->persist($user);
$manager = $this->getCustomerManager();
$manager->persist($customer);
$manager->flush();
return $this->redirectToIndex();
@ -183,9 +184,9 @@ class AddressController extends FOSRestController
/**
* @return ObjectManager
*/
protected function getUserManager()
private function getCustomerManager()
{
return $this->get('sylius.manager.user');
return $this->get('sylius.manager.customer');
}
/**
@ -217,10 +218,18 @@ class AddressController extends FOSRestController
throw new NotFoundHttpException('Requested address does not exist.');
}
if (!$this->getUser()->hasAddress($address)) {
if (!$this->getCustomer()->hasAddress($address)) {
throw new AccessDeniedException();
}
return $address;
}
/**
* @return CustomerInterface
*/
protected function getCustomer()
{
return $this->get('sylius.context.customer')->getCustomer();
}
}

View file

@ -27,14 +27,14 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class OrderController extends FOSRestController
{
/**
* List orders of the current user.
* List orders of the current customer.
*
* @return Response
*/
public function indexAction()
{
$orders = $this->getOrderRepository()->findBy(array('user' => $this->getUser()), array('updatedAt' => 'desc'));
$orders = $this->getOrderRepository()->findBy(array('customer' => $this->getCustomer()), array('updatedAt' => 'desc'));
$view = $this
->view()
->setTemplate('SyliusWebBundle:Frontend/Account:Order/index.html.twig')
@ -47,7 +47,7 @@ class OrderController extends FOSRestController
}
/**
* Get single order of the current user.
* Get single order of the current customer.
*
* @param string $number
*
@ -140,10 +140,17 @@ class OrderController extends FOSRestController
throw $this->createNotFoundException('The order does not exist.');
}
if (!$this->get('security.context')->isGranted('ROLE_SYLIUS_ADMIN') && $this->getUser()->getCustomer()->getId() !== $order->getCustomer()->getId()) {
if (!$this->get('security.context')->isGranted('ROLE_SYLIUS_ADMIN')
&& (!$this->getCustomer() || $this->getCustomer()->getId() !== $order->getCustomer()->getId())
) {
throw new AccessDeniedException();
}
return $order;
}
protected function getCustomer()
{
return $this->get('sylius.context.customer')->getCustomer();
}
}

View file

@ -25,15 +25,15 @@ class ProfileController extends FOSRestController
*/
public function indexAction()
{
$user = $this->getUser();
$customer = $this->getCustomer();
$orderRepository = $this->get('sylius.repository.order');
$orders = $orderRepository->findBy(array('user' => $this->getUser()), array('updatedAt' => 'desc'), 5);
$orders = $orderRepository->findBy(array('customer' => $customer), array('updatedAt' => 'desc'), 5);
$view = $this
->view()
->setTemplate('SyliusWebBundle:Frontend/Account:Profile/index.html.twig')
->setData(array(
'user' => $user,
'customer' => $customer,
'orders' => $orders,
))
;
@ -145,4 +145,8 @@ class ProfileController extends FOSRestController
));
}
protected function getCustomer()
{
return $this->get('sylius.context.customer')->getCustomer();
}
}

View file

@ -11,9 +11,8 @@ sylius_user_profile_update:
path: /profile/edit
methods: [GET, POST]
defaults:
_controller: sylius.controller.user:updateProfileAction
_controller: sylius.controller.customer:updateProfileAction
_sylius:
form: sylius_user_profile
template: SyliusWebBundle:Frontend/Account:profileUpdate.html.twig
redirect: sylius_account_homepage

View file

@ -9,7 +9,6 @@
<tr>
<th>{{ sylius_resource_sort('id', 'sylius.group.id'|trans) }}</th>
<th>{{ sylius_resource_sort('name', 'sylius.group.name'|trans) }}</th>
<th>{{ 'sylius.group.roles'|trans }}</th>
<th></th>
</tr>
</thead>
@ -18,11 +17,6 @@
<tr id="{{ group.id }}">
<td>{{ group.id }}</td>
<td>{{ group.name }}</td>
<td>
{% for role in group.roles %}
<span class="label label-primary">{{ role }}</span>
{% endfor %}
</td>
<td>
<div class="pull-right">
{{ buttons.edit(path('sylius_backend_group_update', {'id': group.id})) }}

View file

@ -1,10 +1,10 @@
{% macro list(orders, user) %}
{% macro list(orders, customer) %}
{% import 'SyliusResourceBundle:Macros:buttons.html.twig' as buttons %}
{% import 'SyliusWebBundle:Backend/Macros:alerts.html.twig' as alerts %}
{% import 'SyliusWebBundle:Backend/Macros:misc.html.twig' as misc %}
{% set router_paramters = user is not null ? {'id' : user.id} : {} %}
{% set router_paramters = customer is not null ? {'id' : customer.user.id} : {} %}
{% if orders|length > 0 %}
<table id="orders" class="table">
@ -16,7 +16,7 @@
<th>{{ sylius_resource_sort('number', 'sylius.order.number'|trans, null, {'route_params' : router_paramters}) }}</th>
<th>{{ sylius_resource_sort('paymentState', 'sylius.order.payment_state'|trans, null, {'route_params' : router_paramters}) }}</th>
<th>{{ sylius_resource_sort('shippingState', 'sylius.order.shipment_state'|trans, null, {'route_params' : router_paramters}) }}</th>
<th>{{ sylius_resource_sort('user.lastName', 'sylius.order.user'|trans, null, {'route_params' : router_paramters}) }}</th>
<th>{{ sylius_resource_sort('customer.lastName', 'sylius.order.customer'|trans, null, {'route_params' : router_paramters}) }}</th>
<th>{{ sylius_resource_sort('total', 'sylius.order.total'|trans, null, {'route_params' : router_paramters}) }}</th>
<th></th>
</tr>
@ -41,8 +41,8 @@
{% include 'SyliusWebBundle:Backend/Order:_shippingState.html.twig' %}
</td>
<td>
{% if order.user %}
<p>{{ order.user.fullName }} <br><a href="{{ path('sylius_backend_user_show', {'id': order.user.id}) }}">{{ order.user.email }}</a></p>
{% if order.customer %}
<p>{{ order.customer.fullName }} <br><a href="{{ path('sylius_backend_user_show', {'id': order.customer.user.id}) }}">{{ order.customer.email }}</a></p>
{% else %}
<p>
{{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }}<br>
@ -67,8 +67,8 @@
</tbody>
</table>
{% else %}
{% if user is not null %}
{{ alerts.info('sylius.user.order.no_results'|trans) }}
{% if customer is not null %}
{{ alerts.info('sylius.customer.order.no_results'|trans) }}
{% else %}
{{ alerts.info('sylius.order.no_results'|trans) }}
{% endif %}
@ -104,10 +104,10 @@
{% include 'SyliusWebBundle:Backend/Order:_paymentState.html.twig' %}
</td>
<td style="width: 20%">
{% if order.user %}
{{ order.user.fullname }}<br>
<a href="{{ path('sylius_backend_user_show', {'id': order.user.id}) }}">
{{ order.user.email }}
{% if order.customer %}
{{ order.customer.fullname }}<br>
<a href="{{ path('sylius_backend_user_show', {'id': order.customer.user.id}) }}">
{{ order.customer.email }}
</a>
{% else %}
{{ order.billingAddress.firstName }} {{ order.billingAddress.lastName }}

View file

@ -3,12 +3,11 @@
<div class="row">
<div class="col-md-12">
<fieldset>
{{ form_row(form.email) }}
{{ form_row(form.firstName) }}
{{ form_row(form.lastName) }}
{{ form_row(form.customer.email) }}
{{ form_row(form.customer.firstName) }}
{{ form_row(form.customer.lastName) }}
{{ form_row(form.plainPassword) }}
{{ form_row(form.enabled) }}
{{ form_row(form.groups) }}
<div class="form-group">
{{ form_label(form.authorizationRoles) }}

View file

@ -19,11 +19,11 @@
</thead>
<tbody>
{% for user in users %}
<tr id="{{ user.id }}" data-user="{{ user.email }}" {% if user.deleted %} class="danger"{% endif %}>
<tr id="{{ user.id }}" data-user="{{ user.customer.email }}" {% if user.deleted %} class="danger"{% endif %}>
<td>{{ user.id }}</td>
<td>{{ user.firstName }}</td>
<td>{{ user.lastName }}</td>
<td><a href="{{ path('sylius_backend_user_show', {'id': user.id}) }}">{{ user.email }}</a></td>
<td>{{ user.customer.firstName }}</td>
<td>{{ user.customer.lastName }}</td>
<td><a href="{{ path('sylius_backend_user_show', {'id': user.id}) }}">{{ user.customer.email }}</a></td>
<td>{{ user.createdAt|date('d-m-Y H:i') }}</td>
<td>
{{ misc.state_label(user.enabled) }}
@ -70,11 +70,11 @@
</thead>
<tbody>
{% for user in users %}
<tr id="{{ user.id }}" data-user="{{ user.email }}" {% if user.deleted %} class="danger"{% endif %}>
<tr id="{{ user.id }}" data-user="{{ user.customer.email }}" {% if user.deleted %} class="danger"{% endif %}>
<td>
{{ user.fullname }}<br>
{{ user.customer.fullname }}<br>
<a href="{{ path('sylius_backend_user_show', {'id': user.id}) }}">
{{ user.email }}
{{ user.customer.email }}
</a>
</td>
<td>

View file

@ -6,7 +6,7 @@
<ol class="breadcrumb">
<li>{{ 'sylius.breadcrumb.customers'|trans }}</li>
<li><a href="{{ path('sylius_backend_user_index') }}">{{ 'sylius.breadcrumb.user.index'|trans }}</a></li>
<li><a href="{{ path('sylius_backend_user_show', {'id': user.id}) }}">{{ user.fullName }}</a></li>
<li><a href="{{ path('sylius_backend_user_show', {'id': user.id}) }}">{{ user.customer.fullName }}</a></li>
<li>{{ 'sylius.breadcrumb.edit'|trans }}</li>
</ol>
{% endblock %}

View file

@ -13,7 +13,7 @@
</div>
</div>
<div class="hidden-xs hidden-sm pull-right">
<p class="navbar-text">{{ 'sylius.backend_welcome'|trans({'%name%': app.user.fullname})|raw }}</p>
<p class="navbar-text">{{ 'sylius.backend_welcome'|trans({'%name%': app.user.customer.fullname})|raw }}</p>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">

View file

@ -4,12 +4,12 @@
{% block content %}
<h4>{{ 'sylius.account.address.list'|trans }}</h4>
{% if user.billingAddress is empty or user.shippingAddress is empty %}
{% if customer.billingAddress is empty or customer.shippingAddress is empty %}
<p>
{% if user.billingAddress is empty %}
{% if customer.billingAddress is empty %}
<span class="label label-success">{{ 'sylius.account.address.default.no_billing'|trans }}</span>
{% endif %}
{% if user.shippingAddress is empty %}
{% if customer.shippingAddress is empty %}
<span class="label label-primary">{{ 'sylius.account.address.default.no_shipping'|trans }}</span>
{% endif %}
</p>
@ -25,20 +25,20 @@
{{ include('SyliusWebBundle:Frontend/Address:_show.html.twig') }}
</td>
<td>
{% if address == user.billingAddress %}
{% if address == customer.billingAddress %}
<span id="defaultBillingAddress" class="label label-success">{{ 'sylius.account.address.default.billing'|trans }}</span><br><br>
{% endif %}
{% if address == user.shippingAddress %}
{% if address == customer.shippingAddress %}
<span id="defaultShippingAddress" class="label label-info">{{ 'sylius.account.address.default.shipping'|trans }}</span><br><br>
{% endif %}
{% if address != user.billingAddress %}
{% if address != customer.billingAddress %}
{{ buttons.patch(
path('sylius_account_address_set_default_billing', {'id': address.id}),
'sylius.account.address.action.billing', 'star-empty') }}
<br>
{% endif %}
{% if address != user.shippingAddress %}
{% if address != customer.shippingAddress %}
{{ buttons.patch(
path('sylius_account_address_set_default_shipping', {'id': address.id}),
'sylius.account.address.action.shipping', 'star') }}

View file

@ -11,7 +11,6 @@
<fieldset>
{{ form_widget(form) }}
</fieldset>
{{ form_rest(form) }}
{{ update() }}
</form>

View file

@ -12,10 +12,10 @@
<div class="row">
<div class="col-md-7">{{ 'sylius.account.home.outline'|trans }} </div>
<div class="col-md-5">
<strong>{{ user.lastName|upper }} {{ user.firstName }}</strong><br><br>
{{ 'sylius.account.home.id'|trans }} {{ user.id }} <br>
{{ 'sylius.account.home.email'|trans }} {{ user.email }}<br>
{{ 'sylius.account.home.since'|trans }} {{ user.createdAt|date() }}
<strong>{{ customer.lastName|upper }} {{ customer.firstName }}</strong><br><br>
{{ 'sylius.account.home.id'|trans }} {{ app.user.id }} <br>
{{ 'sylius.account.home.email'|trans }} {{ customer.email }}<br>
{{ 'sylius.account.home.since'|trans }} {{ app.user.createdAt|date() }}
</div>
</div>

View file

@ -9,9 +9,9 @@
<div class="row">
<div class="col-md-7">{{ 'sylius.account.home.outline'|trans }} </div>
<div class="col-md-5">
<strong>{{ app.user.lastName|upper }} {{ app.user.firstName }}</strong><br><br>
<strong>{{ user.customer.lastName|upper }} {{ user.customer.firstName }}</strong><br><br>
{{ 'sylius.account.home.id'|trans }} {{ app.user.id }} <br>
{{ 'sylius.account.home.email'|trans }} {{ app.user.email }}<br>
{{ 'sylius.account.home.email'|trans }} {{ app.user.customer.email }}<br>
{{ 'sylius.account.home.since'|trans }} {{ app.user.createdAt|date() }}
</div>
</div>

View file

@ -9,9 +9,9 @@
<fieldset class="well">
{{ form_errors(form) }}
{{ form_row(form.firstName) }}
{{ form_row(form.lastName) }}
{{ form_row(form.email) }}
{{ form_row(form.customer.firstName) }}
{{ form_row(form.customer.lastName) }}
{{ form_row(form.customer.email) }}
{{ form_row(form.plainPassword) }}

View file

@ -12,7 +12,7 @@
namespace Sylius\Component\Core\Model;
use Sylius\Component\Addressing\Model\Address as BaseAddress;
use Sylius\Component\User\Model\CustomerInterface;
use Sylius\Component\User\Model\CustomerInterface as BaseCustomerInterface;
/**
* Address entity.
@ -37,7 +37,7 @@ class Address extends BaseAddress implements AddressInterface
/**
* {@inheritdoc}
*/
public function setCustomer(CustomerInterface $customer = null)
public function setCustomer(BaseCustomerInterface $customer = null)
{
$this->customer = $customer;

View file

@ -16,26 +16,26 @@ use Sylius\Component\Promotion\Model\Coupon as BaseCoupon;
class Coupon extends BaseCoupon implements CouponInterface
{
/**
* The per user usage limit
* The per customer usage limit
*
* @var int
*/
protected $perUserUsageLimit = 0;
protected $perCustomerUsageLimit = 0;
/**
* {@inheritdoc}
*/
public function getPerUserUsageLimit()
public function getPerCustomerUsageLimit()
{
return $this->perUserUsageLimit;
return $this->perCustomerUsageLimit;
}
/**
* {@inheritdoc}
*/
public function setPerUserUsageLimit($perUserUsageLimit = 0)
public function setPerCustomerUsageLimit($perCustomerUsageLimit = 0)
{
$this->perUserUsageLimit = $perUserUsageLimit;
$this->perCustomerUsageLimit = $perCustomerUsageLimit;
return $this;
}

View file

@ -21,18 +21,18 @@ use Sylius\Component\Promotion\Model\CouponInterface as BaseCouponInterface;
interface CouponInterface extends BaseCouponInterface
{
/**
* Get per user usage limit.
* Get per customer usage limit.
*
* @return null|int
*/
public function getPerUserUsageLimit();
public function getPerCustomerUsageLimit();
/**
* Set per user usage limit.
* Set per customer usage limit.
*
* @param int $perUserUsageLimit
* @param int $perCustomerUsageLimit
*
* @return self
*/
public function setPerUserUsageLimit($perUserUsageLimit = 0);
public function setPerCustomerUsageLimit($perCustomerUsageLimit = 0);
}

View file

@ -16,7 +16,7 @@ use Doctrine\Common\Collections\Collection;
use Sylius\Component\Cart\Model\Cart;
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\User\Model\CustomerInterface;
use Sylius\Component\User\Model\CustomerInterface as BaseCustomerInterface;
use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface;
use Sylius\Component\Promotion\Model\CouponInterface as BaseCouponInterface;
use Sylius\Component\Promotion\Model\PromotionInterface as BasePromotionInterface;
@ -33,7 +33,7 @@ class Order extends Cart implements OrderInterface
/**
* Customer.
*
* @var CustomerInterface
* @var BaseCustomerInterface
*/
protected $customer;
@ -98,7 +98,7 @@ class Order extends Cart implements OrderInterface
*
* @var string
*/
protected $checkoutState = OrderInterface::CHECKOUT_STATE_CART;
protected $checkoutState = OrderInterface::STATE_CART;
/**
* Order payment state.
@ -146,7 +146,7 @@ class Order extends Cart implements OrderInterface
/**
* {@inheritdoc}
*/
public function setCustomer(CustomerInterface $customer = null)
public function setCustomer(BaseCustomerInterface $customer = null)
{
$this->customer = $customer;

View file

@ -18,5 +18,5 @@ interface PromotionRuleInterface extends RuleInterface
const TYPE_NTH_ORDER = 'nth_order';
const TYPE_SHIPPING_COUNTRY = 'shipping_country';
const TYPE_TAXONOMY = 'taxonomy';
const TYPE_USER_GROUP = 'user_group';
const TYPE_CUSTOMER_GROUP = 'customer_group';
}

View file

@ -29,6 +29,7 @@ class User extends BaseUser implements UserInterface
public function __construct()
{
parent::__construct();
$this->customer = new Customer();
$this->authorizationRoles = new ArrayCollection();
}

View file

@ -20,8 +20,12 @@ use Sylius\Component\Pricing\Calculator\CalculatorInterface;
*/
class GroupBasedCalculator extends AbstractCalculator implements CalculatorInterface
{
protected $parameterName = 'groups';
protected $className = 'Sylius\Component\User\Model\GroupInterface';
public function __construct()
{
$this->parameterName = 'groups';
$this->className = 'Sylius\Component\User\Model\GroupInterface';
parent::__construct();
}
/**
* {@inheritdoc}

View file

@ -15,15 +15,15 @@ use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Promotion\Checker\RuleCheckerInterface;
use Sylius\Component\Promotion\Exception\UnsupportedTypeException;
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
use Sylius\Component\Core\Model\GroupInterface;
use FOS\UserBundle\Model\User;
use Sylius\Component\User\Model\GroupInterface;
use Sylius\Component\User\Model\CustomerInterface;
/**
* Checks if user is part of Group.
*
* @author Antonio Perić <antonio@locastic.com>
*/
class UserGroupRuleChecker implements RuleCheckerInterface
class CustomerGroupRuleChecker implements RuleCheckerInterface
{
/**
* {@inheritdoc}
@ -34,13 +34,13 @@ class UserGroupRuleChecker implements RuleCheckerInterface
throw new UnsupportedTypeException($subject, 'Sylius\Component\Core\Model\OrderInterface');
}
/* @var $user User */
if (null === $user = $subject->getUser()) {
/* @var CustomerInterface $customer */
if (null === $customer = $subject->getCustomer()) {
return false;
}
/* @var $group GroupInterface */
foreach ($user->getGroups() as $group) {
/* @var GroupInterface $group */
foreach ($customer->getGroups() as $group) {
if ($configuration['groups'] == $group->getId()) {
return true;
@ -55,6 +55,6 @@ class UserGroupRuleChecker implements RuleCheckerInterface
*/
public function getConfigurationFormType()
{
return 'sylius_promotion_rule_user_group_configuration';
return 'sylius_promotion_rule_customer_group_configuration';
}
}

View file

@ -21,7 +21,7 @@ use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
*
* @author Saša Stamenković <umpirsky@gmail.com>
*/
class UserLoyaltyRuleChecker implements RuleCheckerInterface
class CustomerLoyaltyRuleChecker implements RuleCheckerInterface
{
/**
* {@inheritdoc}
@ -32,17 +32,17 @@ class UserLoyaltyRuleChecker implements RuleCheckerInterface
throw new UnsupportedTypeException($subject, 'Sylius\Component\Core\Model\OrderInterface');
}
if (null === $user = $subject->getUser()) {
if (null === $customer = $subject->getCustomer()) {
return false;
}
$time = new \DateTime(sprintf('%d %s ago', $configuration['time'], $configuration['unit']));
if (isset($configuration['after']) && $configuration['after']) {
return $user->getCreatedAt() >= $time;
return $customer->getCreatedAt() >= $time;
}
return $user->getCreatedAt() < $time;
return $customer->getCreatedAt() < $time;
}
/**
@ -50,6 +50,6 @@ class UserLoyaltyRuleChecker implements RuleCheckerInterface
*/
public function getConfigurationFormType()
{
return 'sylius_promotion_rule_user_loyalty_configuration';
return 'sylius_promotion_rule_customer_loyalty_configuration';
}
}

View file

@ -19,7 +19,7 @@ use Sylius\Component\Promotion\Exception\UnsupportedTypeException;
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
/**
* Checks if users order is the nth one.
* Checks if customers order is the nth one.
*
* @author Saša Stamenković <umpirsky@gmail.com>
* @author Joseph Bielawski <stloyd@gmail.com>
@ -48,11 +48,11 @@ class NthOrderRuleChecker implements RuleCheckerInterface
throw new UnsupportedTypeException($subject, 'Sylius\Component\Core\Model\OrderInterface');
}
if (null === $user = $subject->getUser()) {
if (null === $customer = $subject->getCustomer()) {
return false;
}
return $this->orderRepository->countByUserAndPaymentState($user, PaymentInterface::STATE_COMPLETED) === ($configuration['nth'] - 1);
return $this->orderRepository->countByCustomerAndPaymentState($customer, PaymentInterface::STATE_COMPLETED) === ($configuration['nth'] - 1);
}
/**

Some files were not shown because too many files have changed in this diff Show more