diff --git a/composer.json b/composer.json index 4ff9632aa1..9a32ade3ad 100644 --- a/composer.json +++ b/composer.json @@ -122,6 +122,7 @@ "sylius/currency": "self.version", "sylius/currency-bundle": "self.version", "sylius/customer": "self.version", + "sylius/customer-bundle": "self.version", "sylius/fixtures-bundle": "self.version", "sylius/flow-bundle": "self.version", "sylius/installer-bundle": "self.version", diff --git a/phpspec.yml.dist b/phpspec.yml.dist index 9c6e6be247..3ac947ac03 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -44,6 +44,7 @@ suites: ContentBundle: { namespace: Sylius\Bundle\ContentBundle, psr4_prefix: Sylius\Bundle\ContentBundle, spec_path: src/Sylius/Bundle/ContentBundle, src_path: src/Sylius/Bundle/ContentBundle } CoreBundle: { namespace: Sylius\Bundle\CoreBundle, psr4_prefix: Sylius\Bundle\CoreBundle, spec_path: src/Sylius/Bundle/CoreBundle, src_path: src/Sylius/Bundle/CoreBundle } CurrencyBundle: { namespace: Sylius\Bundle\CurrencyBundle, psr4_prefix: Sylius\Bundle\CurrencyBundle, spec_path: src/Sylius/Bundle/CurrencyBundle, src_path: src/Sylius/Bundle/CurrencyBundle } + CustomerBundle: { namespace: Sylius\Bundle\CustomerBundle, psr4_prefix: Sylius\Bundle\CustomerBundle, spec_path: src/Sylius/Bundle/CustomerBundle, src_path: src/Sylius/Bundle/CustomerBundle } FlowBundle: { namespace: Sylius\Bundle\FlowBundle, psr4_prefix: Sylius\Bundle\FlowBundle, spec_path: src/Sylius/Bundle/FlowBundle, src_path: src/Sylius/Bundle/FlowBundle } FixturesBundle: { namespace: Sylius\Bundle\FixturesBundle, psr4_prefix: Sylius\Bundle\FixturesBundle, spec_path: src/Sylius/Bundle/FixturesBundle, src_path: src/Sylius/Bundle/FixturesBundle } GridBundle: { namespace: Sylius\Bundle\GridBundle, psr4_prefix: Sylius\Bundle\GridBundle, spec_path: src/Sylius/Bundle/GridBundle, src_path: src/Sylius/Bundle/GridBundle } diff --git a/src/Sylius/Bundle/UserBundle/Resources/public/js/sylius-user.js b/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-user.js similarity index 100% rename from src/Sylius/Bundle/UserBundle/Resources/public/js/sylius-user.js rename to src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-user.js diff --git a/src/Sylius/Bundle/CoreBundle/Application/Kernel.php b/src/Sylius/Bundle/CoreBundle/Application/Kernel.php index e3b7418871..78f8a98a04 100644 --- a/src/Sylius/Bundle/CoreBundle/Application/Kernel.php +++ b/src/Sylius/Bundle/CoreBundle/Application/Kernel.php @@ -61,6 +61,7 @@ class Kernel extends HttpKernel new \Sylius\Bundle\ContentBundle\SyliusContentBundle(), new \Sylius\Bundle\RbacBundle\SyliusRbacBundle(), new \Sylius\Bundle\UserBundle\SyliusUserBundle(), + new \Sylius\Bundle\CustomerBundle\SyliusCustomerBundle(), new \Sylius\Bundle\UiBundle\SyliusUiBundle(), new \Sylius\Bundle\AdminBundle\SyliusAdminBundle(), new \Sylius\Bundle\ShopBundle\SyliusShopBundle(), diff --git a/src/Sylius/Bundle/CoreBundle/Controller/CustomerController.php b/src/Sylius/Bundle/CoreBundle/Controller/CustomerController.php index dd7065ab03..8f0f7aaa17 100644 --- a/src/Sylius/Bundle/CoreBundle/Controller/CustomerController.php +++ b/src/Sylius/Bundle/CoreBundle/Controller/CustomerController.php @@ -11,7 +11,7 @@ namespace Sylius\Bundle\CoreBundle\Controller; -use Sylius\Bundle\UserBundle\Controller\CustomerController as BaseCustomerController; +use Sylius\Bundle\CustomerBundle\Controller\CustomerController as BaseCustomerController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; diff --git a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/CustomerRepository.php similarity index 55% rename from src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php rename to src/Sylius/Bundle/CoreBundle/Doctrine/ORM/CustomerRepository.php index 3a6ad572b1..38a33e0435 100644 --- a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/CustomerRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/CustomerRepository.php @@ -9,60 +9,16 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Doctrine\ORM; +namespace Sylius\Bundle\CoreBundle\Doctrine\ORM; -use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; -use Sylius\Component\Customer\Repository\CustomerRepositoryInterface; +use Sylius\Bundle\CustomerBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository; +use Sylius\Component\Core\Repository\CustomerRepositoryInterface; /** - * @author Michał Marcinkowski + * @author Anna Walasek */ -class CustomerRepository extends EntityRepository implements CustomerRepositoryInterface +class CustomerRepository extends BaseCustomerRepository implements CustomerRepositoryInterface { - /** - * {@inheritdoc} - */ - public function count() - { - return (int) $this->createQueryBuilder('o') - ->select('COUNT(o.id)') - ->getQuery() - ->getSingleScalarResult() - ; - } - - /** - * {@inheritdoc} - */ - public function findLatest($count) - { - return $this->createQueryBuilder('o') - ->addOrderBy('o.createdAt', 'desc') - ->setMaxResults($count) - ->getQuery() - ->getResult() - ; - } - - /** - * {@inheritdoc} - */ - public function findForDetailsPage($id) - { - $queryBuilder = $this->createQueryBuilder('o'); - $queryBuilder - ->andWhere($queryBuilder->expr()->eq('o.id', ':id')) - ->setParameter('id', $id) - ; - - $result = $queryBuilder - ->getQuery() - ->getOneOrNullResult() - ; - - return $result; - } - /** * {@inheritdoc} */ diff --git a/src/Sylius/Bundle/UserBundle/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriber.php b/src/Sylius/Bundle/CoreBundle/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriber.php similarity index 96% rename from src/Sylius/Bundle/UserBundle/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriber.php rename to src/Sylius/Bundle/CoreBundle/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriber.php index 3aa30507f1..3ffdd557bc 100644 --- a/src/Sylius/Bundle/UserBundle/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriber.php +++ b/src/Sylius/Bundle/CoreBundle/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriber.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\EventSubscriber; +namespace Sylius\Bundle\CoreBundle\Form\EventSubscriber; use Sylius\Component\Customer\Model\CustomerAwareInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingType.php index 41a88e137d..3faea92651 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/AddressingType.php @@ -14,7 +14,7 @@ namespace Sylius\Bundle\CoreBundle\Form\Type\Checkout; use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddDefaultBillingAddressOnOrderFormSubscriber; use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddEmailGuestFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\UserBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber; +use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Rule/CustomerGroupType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Rule/CustomerGroupType.php index 65998bb3fe..1a2754f678 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Rule/CustomerGroupType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Rule/CustomerGroupType.php @@ -11,7 +11,7 @@ namespace Sylius\Bundle\CoreBundle\Form\Type\Rule; -use Sylius\Bundle\UserBundle\Doctrine\ORM\GroupRepository; +use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\NotBlank; @@ -23,14 +23,14 @@ use Symfony\Component\Validator\Constraints\Type; class CustomerGroupType extends AbstractType { /** - * @var GroupRepository + * @var RepositoryInterface */ protected $groupRepository; /** - * @param GroupRepository $groupRepository + * @param RepositoryInterface $groupRepository */ - public function __construct(GroupRepository $groupRepository) + public function __construct(RepositoryInterface $groupRepository) { $this->groupRepository = $groupRepository; } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/config.yml index 41de060628..3ef989d8d1 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/config.yml @@ -8,6 +8,7 @@ imports: - { resource: "@SyliusContactBundle/Resources/config/app/config.yml" } - { resource: "@SyliusContentBundle/Resources/config/app/config.yml" } - { resource: "@SyliusCurrencyBundle/Resources/config/app/config.yml" } + - { resource: "@SyliusCustomerBundle/Resources/config/app/config.yml" } - { resource: "@SyliusInventoryBundle/Resources/config/app/config.yml" } - { resource: "@SyliusLocaleBundle/Resources/config/app/config.yml" } - { resource: "@SyliusOrderBundle/Resources/config/app/config.yml" } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml index b6aa2a63e8..2b1acdf217 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml @@ -743,6 +743,7 @@ sylius_user: customer: classes: model: Sylius\Component\Core\Model\Customer + repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository controller: Sylius\Bundle\CoreBundle\Controller\CustomerController sylius_variation: diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml index e4a1242377..e10eceb9c5 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml @@ -55,7 +55,10 @@ Sylius\Bundle\CoreBundle\Form\Type\Action\AddProductConfigurationType Sylius\Bundle\CoreBundle\Form\DataTransformer\TaxonsToCodesTransformer + Sylius\Bundle\CoreBundle\Form\Type\CustomerGuestType + Sylius\Bundle\CoreBundle\Form\Type\CustomerRegistrationType + Sylius\Bundle\CoreBundle\Form\Type\CustomerSimpleRegistrationType @@ -203,9 +206,31 @@ + + %sylius.model.customer.class% + + sylius + + + + + %sylius.model.customer.class% + + sylius + + + + + %sylius.model.customer.class% + + sylius + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index 81e79c5779..f1c435e631 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -67,6 +67,8 @@ Sylius\Bundle\CoreBundle\EventListener\CustomerReviewsDeleteListener Sylius\Bundle\CoreBundle\EventListener\OrderRecalculationListener Sylius\Bundle\CoreBundle\EventListener\UserCartRecalculationListener + Sylius\Bundle\CoreBundle\EventListener\DefaultUsernameORMListener + Sylius\Bundle\CoreBundle\EventListener\UserAutoLoginListener Sylius\Component\Core\Provider\ActivePromotionsByChannelProvider @@ -102,6 +104,8 @@ Sylius\Bundle\CoreBundle\Routing\RouteProvider Sylius\Bundle\CoreBundle\Validator\Constraints\HasEnabledEntityValidator + Sylius\Bundle\CoreBundle\Validator\Initializer\CustomerInitializer + Sylius\Bundle\CoreBundle\Validator\Constraints\RegisteredUserValidator Doctrine\Common\DataFixtures\Purger\ORMPurger::PURGE_MODE_DELETE Sylius\Bundle\CoreBundle\Purger\QueryLogger @@ -118,6 +122,10 @@ Sylius\Bundle\CoreBundle\Context\CustomerContext + + Sylius\Bundle\CoreBundle\Form\EventSubscriber\SetCustomerFormSubscriber + Sylius\Bundle\UserBundle\Form\EventSubscriber\CoreUserFormSubscriber + Sylius\Bundle\CoreBundle\Form\Type\DataFetcher\NumberOfOrdersType Sylius\Bundle\CoreBundle\Form\Type\DataFetcher\SalesTotalType @@ -359,6 +367,13 @@ + + + + + + + @@ -503,6 +518,7 @@ + @@ -526,6 +542,14 @@ + + + + + + + + diff --git a/src/Sylius/Bundle/UserBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php b/src/Sylius/Bundle/CoreBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php similarity index 74% rename from src/Sylius/Bundle/UserBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php rename to src/Sylius/Bundle/CoreBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php index a1a62bf4e5..8edda720b3 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Doctrine\ORM; +namespace spec\Sylius\Bundle\CoreBundle\Doctrine\ORM; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManager; @@ -31,7 +31,7 @@ final class CustomerRepositorySpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Doctrine\ORM\CustomerRepository'); + $this->shouldHaveType('Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository'); } function it_is_a_repository() @@ -39,22 +39,6 @@ final class CustomerRepositorySpec extends ObjectBehavior $this->shouldHaveType(EntityRepository::class); } - function it_finds_details($em, QueryBuilder $builder, Expr $expr, AbstractQuery $query) - { - $builder->expr()->shouldBeCalled()->willReturn($expr); - $expr->eq('o.id', ':id')->shouldBeCalled()->willReturn($expr); - - $em->createQueryBuilder()->shouldBeCalled()->willReturn($builder); - $builder->select('o')->shouldBeCalled()->willReturn($builder); - $builder->from(Argument::any(), 'o', Argument::cetera())->shouldBeCalled()->willReturn($builder); - $builder->andWhere($expr)->shouldBeCalled()->willReturn($builder); - $builder->setParameter('id', 1)->shouldBeCalled()->willReturn($builder); - $builder->getQuery()->shouldBeCalled()->willReturn($query); - $query->getOneOrNullResult()->shouldBeCalled(); - - $this->findForDetailsPage(1); - } - function it_creates_paginator( $em, QueryBuilder $builder, diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriberSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriberSpec.php similarity index 93% rename from src/Sylius/Bundle/UserBundle/spec/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriberSpec.php rename to src/Sylius/Bundle/CoreBundle/spec/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriberSpec.php index 877b745d79..61bfebba06 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriberSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/Form/EventSubscriber/AddCustomerGuestTypeFormSubscriberSpec.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Form\EventSubscriber; +namespace spec\Sylius\Bundle\CoreBundle\Form\EventSubscriber; use PhpSpec\ObjectBehavior; -use Sylius\Bundle\UserBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber; +use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber; use Sylius\Component\Resource\Model\ResourceInterface; use Sylius\Component\Customer\Model\CustomerAwareInterface; -use Sylius\Component\Customer\Model\CustomerInterface; +use Sylius\Component\Core\Model\CustomerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormConfigInterface; use Symfony\Component\Form\FormEvent; @@ -36,7 +36,7 @@ final class AddCustomerGuestTypeFormSubscriberSpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber'); + $this->shouldHaveType('Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber'); } function it_is_an_event_subscriber() diff --git a/src/Sylius/Bundle/CoreBundle/spec/Form/Type/Checkout/AddressingTypeSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Form/Type/Checkout/AddressingTypeSpec.php index cf7991219a..9803271f68 100644 --- a/src/Sylius/Bundle/CoreBundle/spec/Form/Type/Checkout/AddressingTypeSpec.php +++ b/src/Sylius/Bundle/CoreBundle/spec/Form/Type/Checkout/AddressingTypeSpec.php @@ -15,7 +15,7 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddDefaultBillingAddressOnOrderFormSubscriber; use Sylius\Bundle\CoreBundle\Form\Type\Checkout\AddressingType; -use Sylius\Bundle\UserBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber; +use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddCustomerGuestTypeFormSubscriber; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; diff --git a/src/Sylius/Bundle/CustomerBundle/.gitignore b/src/Sylius/Bundle/CustomerBundle/.gitignore new file mode 100644 index 0000000000..46aed33710 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/.gitignore @@ -0,0 +1,5 @@ +vendor/ +bin/ + +composer.phar +composer.lock diff --git a/src/Sylius/Bundle/CustomerBundle/CHANGELOG.md b/src/Sylius/Bundle/CustomerBundle/CHANGELOG.md new file mode 100644 index 0000000000..caa062a0f1 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/CHANGELOG.md @@ -0,0 +1,6 @@ +CHANGELOG +========= + +### v1.0.0-alpha.1 + +* Initial dev release. diff --git a/src/Sylius/Bundle/UserBundle/Controller/CustomerController.php b/src/Sylius/Bundle/CustomerBundle/Controller/CustomerController.php similarity index 98% rename from src/Sylius/Bundle/UserBundle/Controller/CustomerController.php rename to src/Sylius/Bundle/CustomerBundle/Controller/CustomerController.php index db327ccc65..48a811d800 100644 --- a/src/Sylius/Bundle/UserBundle/Controller/CustomerController.php +++ b/src/Sylius/Bundle/CustomerBundle/Controller/CustomerController.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Controller; +namespace Sylius\Bundle\CustomerBundle\Controller; use FOS\RestBundle\View\View; use Sylius\Bundle\ResourceBundle\Controller\ResourceController; diff --git a/src/Sylius/Bundle/CustomerBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/CustomerBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000000..c16204785a --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/DependencyInjection/Configuration.php @@ -0,0 +1,162 @@ + + * @author Łukasz Chruściel + */ +class Configuration implements ConfigurationInterface +{ + /** + * {@inheritdoc} + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('sylius_customer'); + + $rootNode + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end() + ; + + $this->addResourcesSection($rootNode); + + return $treeBuilder; + } + + /** + * @param ArrayNodeDefinition $node + */ + private function addResourcesSection(ArrayNodeDefinition $node) + { + $node + ->children() + ->arrayNode('resources') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('customer') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(Customer::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(CustomerInterface::class)->cannotBeEmpty()->end() + ->scalarNode('controller')->defaultValue(CustomerController::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->end() + ->arrayNode('form') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('default')->defaultValue(CustomerType::class)->cannotBeEmpty()->end() + ->scalarNode('profile')->defaultValue(CustomerProfileType::class)->cannotBeEmpty()->end() + ->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('validation_groups') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('default') + ->prototype('scalar')->end() + ->defaultValue(['sylius']) + ->end() + ->arrayNode('profile') + ->prototype('scalar')->end() + ->defaultValue(['sylius', 'sylius_customer_profile']) + ->end() + ->arrayNode('registration') + ->prototype('scalar')->end() + ->defaultValue(['sylius', 'sylius_customer_profile', 'sylius_user_registration']) + ->end() + ->arrayNode('simple_registration') + ->prototype('scalar')->end() + ->defaultValue(['sylius', 'sylius_user_registration']) + ->end() + ->arrayNode('guest') + ->prototype('scalar')->end() + ->defaultValue(['sylius_customer_guest']) + ->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('group') + ->addDefaultsIfNotSet() + ->children() + ->variableNode('options')->end() + ->arrayNode('classes') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model')->defaultValue(Group::class)->cannotBeEmpty()->end() + ->scalarNode('interface')->defaultValue(GroupInterface::class)->cannotBeEmpty()->end() + ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() + ->scalarNode('repository')->cannotBeEmpty()->end() + ->scalarNode('factory')->defaultValue(Factory::class)->end() + ->arrayNode('form') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('default')->defaultValue(GroupType::class)->cannotBeEmpty()->end() + ->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end() + ->scalarNode('from_identifier')->defaultValue(ResourceFromIdentifierType::class)->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('validation_groups') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('default') + ->prototype('scalar')->end() + ->defaultValue(['sylius']) + ->end() + ->arrayNode('from_identifier') + ->prototype('scalar')->end() + ->defaultValue(['sylius']) + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ; + } +} diff --git a/src/Sylius/Bundle/CustomerBundle/DependencyInjection/SyliusCustomerExtension.php b/src/Sylius/Bundle/CustomerBundle/DependencyInjection/SyliusCustomerExtension.php new file mode 100644 index 0000000000..20bd378b0d --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/DependencyInjection/SyliusCustomerExtension.php @@ -0,0 +1,41 @@ + + */ +class SyliusCustomerExtension extends AbstractResourceExtension +{ + /** + * {@inheritdoc} + */ + public function load(array $config, ContainerBuilder $container) + { + $config = $this->processConfiguration($this->getConfiguration($config, $container), $config); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + + $loader->load(sprintf('driver/%s.xml', $config['driver'])); + + $this->registerResources('sylius', $config['driver'], $config['resources'], $container); + + $loader->load('services.xml'); + } +} diff --git a/src/Sylius/Bundle/CustomerBundle/Doctrine/ORM/CustomerRepository.php b/src/Sylius/Bundle/CustomerBundle/Doctrine/ORM/CustomerRepository.php new file mode 100644 index 0000000000..33fe05043d --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Doctrine/ORM/CustomerRepository.php @@ -0,0 +1,65 @@ + + */ +class CustomerRepository extends EntityRepository implements CustomerRepositoryInterface +{ + /** + * {@inheritdoc} + */ + public function count() + { + return (int) $this->createQueryBuilder('o') + ->select('COUNT(o.id)') + ->getQuery() + ->getSingleScalarResult() + ; + } + + /** + * {@inheritdoc} + */ + public function findLatest($count) + { + return $this->createQueryBuilder('o') + ->addOrderBy('o.createdAt', 'desc') + ->setMaxResults($count) + ->getQuery() + ->getResult() + ; + } + + /** + * {@inheritdoc} + */ + public function findForDetailsPage($id) + { + $queryBuilder = $this->createQueryBuilder('o'); + $queryBuilder + ->andWhere($queryBuilder->expr()->eq('o.id', ':id')) + ->setParameter('id', $id) + ; + + $result = $queryBuilder + ->getQuery() + ->getOneOrNullResult() + ; + + return $result; + } +} diff --git a/src/Sylius/Bundle/UserBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php b/src/Sylius/Bundle/CustomerBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php similarity index 96% rename from src/Sylius/Bundle/UserBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php rename to src/Sylius/Bundle/CustomerBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php index 405080522f..ee4e4e924a 100644 --- a/src/Sylius/Bundle/UserBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\EventSubscriber; +namespace Sylius\Bundle\CustomerBundle\Form\EventSubscriber; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\Component\Customer\Model\CustomerInterface; diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerProfileType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerProfileType.php similarity index 96% rename from src/Sylius/Bundle/UserBundle/Form/Type/CustomerProfileType.php rename to src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerProfileType.php index 5a10e8a531..9b252a250f 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerProfileType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerProfileType.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\Type; +namespace Sylius\Bundle\CustomerBundle\Form\Type; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\FormBuilderInterface; diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerRegistrationType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerRegistrationType.php similarity index 95% rename from src/Sylius/Bundle/UserBundle/Form/Type/CustomerRegistrationType.php rename to src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerRegistrationType.php index 1006caad44..c2c7593752 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerRegistrationType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerRegistrationType.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\Type; +namespace Sylius\Bundle\CustomerBundle\Form\Type; use Symfony\Component\Form\FormBuilderInterface; diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerSimpleRegistrationType.php similarity index 93% rename from src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php rename to src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerSimpleRegistrationType.php index b5efb684ba..9622f0a9dc 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerSimpleRegistrationType.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\Type; +namespace Sylius\Bundle\CustomerBundle\Form\Type; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\UserBundle\Form\EventSubscriber\CustomerRegistrationFormSubscriber; +use Sylius\Bundle\CustomerBundle\Form\EventSubscriber\CustomerRegistrationFormSubscriber; use Sylius\Bundle\UserBundle\Form\EventSubscriber\UserRegistrationFormSubscriber; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\FormBuilderInterface; diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerType.php similarity index 97% rename from src/Sylius/Bundle/UserBundle/Form/Type/CustomerType.php rename to src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerType.php index 94c61e97f4..a6bfbfdd72 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/CustomerType.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\Type; +namespace Sylius\Bundle\CustomerBundle\Form\Type; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormBuilderInterface; diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/GenderType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/GenderType.php similarity index 95% rename from src/Sylius/Bundle/UserBundle/Form/Type/GenderType.php rename to src/Sylius/Bundle/CustomerBundle/Form/Type/GenderType.php index 891573a477..816ae2e5af 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/GenderType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/GenderType.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\Type; +namespace Sylius\Bundle\CustomerBundle\Form\Type; use Sylius\Component\Customer\Model\CustomerInterface; use Symfony\Component\Form\AbstractType; diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/GroupType.php b/src/Sylius/Bundle/CustomerBundle/Form/Type/GroupType.php similarity index 94% rename from src/Sylius/Bundle/UserBundle/Form/Type/GroupType.php rename to src/Sylius/Bundle/CustomerBundle/Form/Type/GroupType.php index a5840d06d5..6226917eaf 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/GroupType.php +++ b/src/Sylius/Bundle/CustomerBundle/Form/Type/GroupType.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Form\Type; +namespace Sylius\Bundle\CustomerBundle\Form\Type; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\FormBuilderInterface; diff --git a/src/Sylius/Bundle/CustomerBundle/README.md b/src/Sylius/Bundle/CustomerBundle/README.md new file mode 100644 index 0000000000..ddece8932d --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/README.md @@ -0,0 +1,64 @@ +SyliusCustomerBundle [![Build status...](https://secure.travis-ci.org/Sylius/SyliusCustomerBundle.png?branch=master)](http://travis-ci.org/Sylius/SyliusCustomerBundle) +================== + +[**Symfony2**](http://symfony.com) integration of Sylius Customer processing +component. + +Sylius +------ + +**Sylius** - Modern ecommerce for Symfony2. Visit [Sylius.org](http://sylius.org). + +[phpspec](http://phpspec.net) examples +-------------------------------------- + +```bash +$ composer install +$ bin/phpspec run -f pretty +``` + +Documentation +------------- + +Documentation is available on [**docs.sylius.org**](http://sylius.org/en/latest/bundles/SyliusCustomerBundle/index.html). + +Contributing +------------ + +All informations about contributing to Sylius can be found on [this page](http://docs.sylius.org/en/latest/contributing/index.html). + +Sylius twitter account +---------------------- + +If you want to keep up with updates, [follow the official Sylius account on twitter](http://twitter.com/Sylius). + +Bug tracking +------------ + +This bundle uses [GitHub issues](https://github.com/Sylius/SyliusCustomerBundle/issues). +If you have found bug, please create an issue. + +Versioning +---------- + +Releases will be numbered with the format `major.minor.patch`. + +And constructed with the following guidelines. + +* Breaking backwards compatibility bumps the major. +* New additions without breaking backwards compatibility bumps the minor. +* Bug fixes and misc changes bump the patch. + +For more information on SemVer, please visit [semver.org website](http://semver.org/)... +This versioning method is same for all **Sylius** bundles and applications. + +MIT License +----------- + +License can be found [here](https://github.com/Sylius/SyliusCustomerBundle/blob/master/Resources/meta/LICENSE). + +Authors +------- + +The bundle was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com). +See the list of [contributors](https://github.com/Sylius/SyliusCustomerBundle/contributors). diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/CustomerBundle/Resources/config/app/config.yml new file mode 100644 index 0000000000..caf8b78645 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/app/config.yml @@ -0,0 +1,9 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +jms_serializer: + metadata: + directories: + sylius-user: + namespace_prefix: "Sylius\\Component\\Customer" + path: "@SyliusCustomerBundle/Resources/config/serializer" diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/doctrine/model/Customer.orm.xml b/src/Sylius/Bundle/CustomerBundle/Resources/config/doctrine/model/Customer.orm.xml similarity index 100% rename from src/Sylius/Bundle/UserBundle/Resources/config/doctrine/model/Customer.orm.xml rename to src/Sylius/Bundle/CustomerBundle/Resources/config/doctrine/model/Customer.orm.xml diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/doctrine/model/Group.orm.xml b/src/Sylius/Bundle/CustomerBundle/Resources/config/doctrine/model/Group.orm.xml similarity index 87% rename from src/Sylius/Bundle/UserBundle/Resources/config/doctrine/model/Group.orm.xml rename to src/Sylius/Bundle/CustomerBundle/Resources/config/doctrine/model/Group.orm.xml index 10bdb016ee..1f16f2ef9f 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/doctrine/model/Group.orm.xml +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/doctrine/model/Group.orm.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/driver/doctrine/orm.xml b/src/Sylius/Bundle/CustomerBundle/Resources/config/driver/doctrine/orm.xml new file mode 100644 index 0000000000..07390d2796 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/driver/doctrine/orm.xml @@ -0,0 +1,23 @@ + + + + + + + + Sylius\Bundle\CustomerBundle\Doctrine\ORM\CustomerRepository + + + diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/routing.yml b/src/Sylius/Bundle/CustomerBundle/Resources/config/routing.yml new file mode 100644 index 0000000000..cef955ed70 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/routing.yml @@ -0,0 +1,6 @@ +sylius_register: + resource: @SyliusCustomerBundle/Resources/config/routing/registration.yml + +sylius_account: + resource: @SyliusCustomerBundle/Resources/config/routing/account.yml + prefix: /account diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/routing/account.yml b/src/Sylius/Bundle/CustomerBundle/Resources/config/routing/account.yml new file mode 100644 index 0000000000..c8a2bb79a7 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/routing/account.yml @@ -0,0 +1,23 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +sylius_account_profile_show: + path: / + methods: [GET] + defaults: + _controller: sylius.controller.customer:showProfileAction + +sylius_account_profile_update: + path: /profile/edit + methods: [GET, POST] + defaults: + _controller: sylius.controller.customer:updateProfileAction + _sylius: + form: sylius_customer_profile + redirect: sylius_account_profile_show + +sylius_account_change_password: + path: /change-password + methods: [GET, POST] + defaults: + _controller: sylius.controller.user:changePasswordAction diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/routing/registration.yml b/src/Sylius/Bundle/CustomerBundle/Resources/config/routing/registration.yml new file mode 100644 index 0000000000..4d8f3d87ed --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/routing/registration.yml @@ -0,0 +1,11 @@ +sylius_user_registration: + path: /register + methods: [GET, POST] + defaults: + _controller: sylius.controller.customer:createAction + _sylius: + form: sylius_customer_registration + event: register + template: SyliusCustomerBundle::register.html.twig + redirect: referer + permission: false diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/serializer/Model.Customer.yml b/src/Sylius/Bundle/CustomerBundle/Resources/config/serializer/Model.Customer.yml similarity index 100% rename from src/Sylius/Bundle/UserBundle/Resources/config/serializer/Model.Customer.yml rename to src/Sylius/Bundle/CustomerBundle/Resources/config/serializer/Model.Customer.yml diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/services.xml b/src/Sylius/Bundle/CustomerBundle/Resources/config/services.xml new file mode 100644 index 0000000000..0c0edc3884 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/services.xml @@ -0,0 +1,41 @@ + + + + + + + + Sylius\Bundle\UserBundle\Form\Type\GenderType + Sylius\Bundle\UserBundle\EventListener\CustomerAwareListener + Sylius\Bundle\UserBundle\Form\EventSubscriber\SetCustomerFormSubscriber + Sylius\Bundle\UserBundle\Validator\Initializer\CustomerInitializer + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/config/validation.xml b/src/Sylius/Bundle/CustomerBundle/Resources/config/validation.xml new file mode 100644 index 0000000000..272acb87ed --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/config/validation.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/meta/LICENSE b/src/Sylius/Bundle/CustomerBundle/Resources/meta/LICENSE new file mode 100644 index 0000000000..acd4c1958c --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/meta/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2011-2016 Paweł Jędrzejewski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/serializer/Model.Customer.yml b/src/Sylius/Bundle/CustomerBundle/Resources/serializer/Model.Customer.yml new file mode 100644 index 0000000000..70ddd88522 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/serializer/Model.Customer.yml @@ -0,0 +1,36 @@ +Sylius\Component\User\Model\Customer: + exclusion_policy: ALL + xml_root_name: sylius_customer + properties: + id: + expose: true + type: integer + groups: [Default, Detailed] + email: + expose: true + type: string + groups: [Default, Detailed] + emailCanonical: + expose: true + type: string + groups: [Detailed] + firstName: + expose: true + type: string + groups: [Default, Detailed] + lastName: + expose: true + type: string + groups: [Default, Detailed] + gender: + expose: true + type: string + groups: [Detailed] + birthday: + expose: true + type: DateTime + groups: [Detailed] + groups: + expose: true + type: array + groups: [Detailed] diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/CustomerBundle/Resources/translations/messages.en.yml new file mode 100644 index 0000000000..fe51f8ec7d --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/translations/messages.en.yml @@ -0,0 +1,37 @@ +sylius: + form: + group: + name: Name + roles: Roles + user: + email: Email + enabled: Enabled + password: + label: Password + confirmation: Verification + remember_me: Remember me + shipping_address: Shipping address + customer: + first_name: First name + groups: Groups + last_name: Last name + email: Email + phone_number: Phone number + gender: Gender + birthday: Birthday + billing_address: Billing address + different_billing_address: Use different address for billing? + only_customer_registration: Create account? + user_filter: + query: Search + user_change_password: + confirmation: Confirmation + current: Current password + new: New password + user_reset_password: + confirmation: Confirmation + new: New password + gender: + unknown: Unknown + male: Male + female: Female diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/translations/validators.en.yml b/src/Sylius/Bundle/CustomerBundle/Resources/translations/validators.en.yml new file mode 100644 index 0000000000..ba018b8335 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/translations/validators.en.yml @@ -0,0 +1,39 @@ +sylius: + group: + name: + max: Group name must not be longer than {{ limit }} characters. + min: Group name must be at least {{ limit }} characters long. + not_blank: Please enter group name. + + user: + email: + not_blank: Please enter your email. + invalid: This email is invalid. + not_registered: User with this email does not exist. Please register first. + plainPassword: + not_blank: Please enter your password. + mismatch: The entered passwords don't match + wrong_current: Provided password is different than the current one. + password: + min: Password must be at least {{ limit }} characters long. + max: Password must not be longer than {{ limit }} characters. + + customer: + first_name: + max: First name must not be longer than {{ limit }} characters. + min: First name must be at least {{ limit }} characters long. + not_blank: Please enter your first name. + last_name: + max: Last name must not be longer than {{ limit }} characters. + min: Last name must be at least {{ limit }} characters long. + not_blank: Please enter your last name. + gender: + not_blank: Please choose your gender. + email: + already_used: This email is already used, please login or use forgotten password. + 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. + unique: This email is already used. + registered: This email is already registered, please login or use forgotten password. diff --git a/src/Sylius/Bundle/UserBundle/Resources/views/Customer/showProfile.html.twig b/src/Sylius/Bundle/CustomerBundle/Resources/views/Customer/showProfile.html.twig similarity index 84% rename from src/Sylius/Bundle/UserBundle/Resources/views/Customer/showProfile.html.twig rename to src/Sylius/Bundle/CustomerBundle/Resources/views/Customer/showProfile.html.twig index c7c78c6a65..fdfc4f1e9a 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/views/Customer/showProfile.html.twig +++ b/src/Sylius/Bundle/CustomerBundle/Resources/views/Customer/showProfile.html.twig @@ -1,4 +1,4 @@ -{% extends 'SyliusUserBundle::layout.html.twig' %} +{% extends 'SyliusCustomerBundle::layout.html.twig' %} {% block content %} {{ customer.fullName|upper }}
diff --git a/src/Sylius/Bundle/UserBundle/Resources/views/Customer/updateProfile.html.twig b/src/Sylius/Bundle/CustomerBundle/Resources/views/Customer/updateProfile.html.twig similarity index 85% rename from src/Sylius/Bundle/UserBundle/Resources/views/Customer/updateProfile.html.twig rename to src/Sylius/Bundle/CustomerBundle/Resources/views/Customer/updateProfile.html.twig index 0d925dd9a6..de8040b804 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/views/Customer/updateProfile.html.twig +++ b/src/Sylius/Bundle/CustomerBundle/Resources/views/Customer/updateProfile.html.twig @@ -1,4 +1,4 @@ -{% extends 'SyliusUserBundle::layout.html.twig' %} +{% extends 'SyliusCustomerBundle::layout.html.twig' %} {% from 'SyliusResourceBundle:Macros:actions.html.twig' import update %} {% block content %} diff --git a/src/Sylius/Bundle/CustomerBundle/Resources/views/layout.html.twig b/src/Sylius/Bundle/CustomerBundle/Resources/views/layout.html.twig new file mode 100644 index 0000000000..5734b63a26 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/Resources/views/layout.html.twig @@ -0,0 +1,35 @@ + + + + + + +
+ {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %} + {{ 'sylius.ui.logged_in_as'|trans({'%username%': app.user.username}) }} + + {{ 'sylius.ui.logout'|trans }} + + {% else %} + {{ 'sylius.ui.login'|trans }} + {% endif %} +
+ + {% block flashes %} + {% if app.request.hasPreviousSession %} + {% for type, messages in app.session.flashbag.all() %} + {% for message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endfor %} + {% endif %} + {% endblock flashes %} + +
+ {% block content %} + {% endblock content %} +
+ + \ No newline at end of file diff --git a/src/Sylius/Bundle/CustomerBundle/SyliusCustomerBundle.php b/src/Sylius/Bundle/CustomerBundle/SyliusCustomerBundle.php new file mode 100644 index 0000000000..44c416ad41 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/SyliusCustomerBundle.php @@ -0,0 +1,39 @@ + + */ +class SyliusCustomerBundle extends AbstractResourceBundle +{ + /** + * {@inheritdoc} + */ + public function getSupportedDrivers() + { + return [ + SyliusResourceBundle::DRIVER_DOCTRINE_ORM, + ]; + } + + /** + * {@inheritdoc} + */ + protected function getModelNamespace() + { + return 'Sylius\Component\Customer\Model'; + } +} diff --git a/src/Sylius/Bundle/UserBundle/Validator/Initializer/CustomerInitializer.php b/src/Sylius/Bundle/CustomerBundle/Validator/Initializer/CustomerInitializer.php similarity index 94% rename from src/Sylius/Bundle/UserBundle/Validator/Initializer/CustomerInitializer.php rename to src/Sylius/Bundle/CustomerBundle/Validator/Initializer/CustomerInitializer.php index 631a5db4ed..61be3f297d 100644 --- a/src/Sylius/Bundle/UserBundle/Validator/Initializer/CustomerInitializer.php +++ b/src/Sylius/Bundle/CustomerBundle/Validator/Initializer/CustomerInitializer.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Sylius\Bundle\UserBundle\Validator\Initializer; +namespace Sylius\Bundle\CustomerBundle\Validator\Initializer; use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; use Sylius\Component\Customer\Model\CustomerInterface; diff --git a/src/Sylius/Bundle/CustomerBundle/composer.json b/src/Sylius/Bundle/CustomerBundle/composer.json new file mode 100644 index 0000000000..a990d267bb --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/composer.json @@ -0,0 +1,68 @@ +{ + "name": "sylius/customer-bundle", + "type": "symfony-bundle", + "description": "Customers management for Symfony2 projects.", + "keywords": ["customer", "groups"], + "homepage": "http://sylius.org", + "license": "MIT", + "authors": [ + { + "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" + }, + { + "name": "Sylius project", + "homepage": "http://sylius.org" + }, + { + "name": "Community contributions", + "homepage": "http://github.com/Sylius/Sylius/contributors" + } + ], + "require": { + "php": "^5.6|^7.0", + + "sylius/customer": "^1.0", + "sylius/resource-bundle": "^1.0", + "symfony/framework-bundle": "^2.8", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.4", + "symfony/form": "^2.8" + }, + "config": { + "bin-dir": "bin" + }, + "autoload": { + "psr-4": { "Sylius\\Bundle\\CustomerBundle\\": "" } + }, + "autoload-dev": { + "psr-4": { "Sylius\\Bundle\\CustomerBundle\\spec\\": "spec/" } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": [ + { + "type": "path", + "url": "../../*/*" + } + ], + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + } +} diff --git a/src/Sylius/Bundle/CustomerBundle/phpspec.yml.dist b/src/Sylius/Bundle/CustomerBundle/phpspec.yml.dist new file mode 100644 index 0000000000..0c211120d3 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/phpspec.yml.dist @@ -0,0 +1,5 @@ +suites: + main: + namespace: Sylius\Bundle\CustomerBundle + psr4_prefix: Sylius\Bundle\CustomerBundle + src_path: . diff --git a/src/Sylius/Bundle/UserBundle/spec/Doctrine/ORM/GroupRepositorySpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php similarity index 51% rename from src/Sylius/Bundle/UserBundle/spec/Doctrine/ORM/GroupRepositorySpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php index cafab1edd6..8da8f0cc02 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Doctrine/ORM/GroupRepositorySpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Doctrine/ORM/CustomerRepositorySpec.php @@ -9,16 +9,20 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Doctrine\ORM; +namespace spec\Sylius\Bundle\CustomerBundle\Doctrine\ORM; +use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query\FilterCollection; use Doctrine\ORM\QueryBuilder; +use Pagerfanta\Pagerfanta; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; -final class GroupRepositorySpec extends ObjectBehavior +class CustomerRepositorySpec extends ObjectBehavior { public function let(EntityManager $em, ClassMetadata $classMetadata) { @@ -27,7 +31,7 @@ final class GroupRepositorySpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Doctrine\ORM\GroupRepository'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Doctrine\ORM\CustomerRepository'); } function it_is_a_repository() @@ -35,12 +39,19 @@ final class GroupRepositorySpec extends ObjectBehavior $this->shouldHaveType(EntityRepository::class); } - function it_has_a_form_query_builder($em, QueryBuilder $builder) + function it_finds_details($em, QueryBuilder $builder, Expr $expr, AbstractQuery $query) { + $builder->expr()->shouldBeCalled()->willReturn($expr); + $expr->eq('o.id', ':id')->shouldBeCalled()->willReturn($expr); + $em->createQueryBuilder()->shouldBeCalled()->willReturn($builder); $builder->select('o')->shouldBeCalled()->willReturn($builder); - $builder->from(Argument::any(), 'o', Argument::cetera())->shouldBeCalled(); + $builder->from(Argument::any(), 'o', Argument::cetera())->shouldBeCalled()->willReturn($builder); + $builder->andWhere($expr)->shouldBeCalled()->willReturn($builder); + $builder->setParameter('id', 1)->shouldBeCalled()->willReturn($builder); + $builder->getQuery()->shouldBeCalled()->willReturn($query); + $query->getOneOrNullResult()->shouldBeCalled(); - $this->getFormQueryBuilder(); + $this->findForDetailsPage(1); } } diff --git a/src/Sylius/Bundle/CustomerBundle/spec/Form/EventSubscriber/AddUserFormSubscriberSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Form/EventSubscriber/AddUserFormSubscriberSpec.php new file mode 100644 index 0000000000..3e915e21d1 --- /dev/null +++ b/src/Sylius/Bundle/CustomerBundle/spec/Form/EventSubscriber/AddUserFormSubscriberSpec.php @@ -0,0 +1,126 @@ + + */ +class AddUserFormSubscriberSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Form\EventSubscriber\AddUserFormSubscriber'); + } + + function it_is_event_subscriber_instance() + { + $this->shouldImplement(EventSubscriberInterface::class); + } + + function it_adds_user_form_type_and_create_user_check( + FormEvent $event, + Form $form + ) { + $event->getForm()->willReturn($form); + + $form->add('user', 'sylius_user')->shouldBeCalled(); + + $this->preSetData($event); + } + + function it_removes_user_form_type_by_default( + FormEvent $event, + Form $form, + CustomerInterface $customer + ) { + $event->getData()->willReturn([], ['user' => ['plainPassword' => '']]); + $event->getForm()->willReturn($form); + $form->getNormData()->willReturn($customer); + $customer->getUser()->willReturn(null); + + $event->setData([])->shouldBeCalledTimes(1); + $form->remove('user')->shouldBeCalledTimes(2); + + $this->preSubmit($event); + $this->preSubmit($event); + } + + function it_does_not_remove_user_form_type_if_users_data_is_submitted_and_user_data_is_created( + FormEvent $event, + Form $form, + CustomerInterface $customer, + UserInterface $user + ) { + $event->getData()->willReturn(['user' => ['plainPassword' => 'test']]); + $event->getForm()->willReturn($form); + $form->getNormData()->willReturn($customer); + $customer->getUser()->willReturn($user); + + $form->remove('user')->shouldNotBeCalled(); + + $this->preSubmit($event); + } + + function it_remove_user_form_type_if_users_data_is_not_submitted_and_user_is_not_created( + FormEvent $event, + Form $form, + CustomerInterface $customer + ) { + $event->getData()->willReturn(['user' => ['plainPassword' => '']]); + $event->getForm()->willReturn($form); + $form->getNormData()->willReturn($customer); + $customer->getUser()->willReturn(null); + + $event->setData([])->shouldBeCalled(); + $form->remove('user')->shouldBeCalled(); + + $this->preSubmit($event); + } + + function it_does_not_remove_user_form_type_if_users_data_is_submitted_and_user_is_not_created( + FormEvent $event, + Form $form, + CustomerInterface $customer + ) { + $event->getData()->willReturn(['user' => ['plainPassword' => 'test']]); + $event->getForm()->willReturn($form); + $form->getNormData()->willReturn($customer); + $customer->getUser()->willReturn(null); + + $form->remove('user')->shouldNotBeCalled(); + + $this->preSubmit($event); + } + + function it_does_not_remove_user_form_type_if_users_data_is_not_submitted_and_user_is_created( + FormEvent $event, + Form $form, + CustomerInterface $customer, + UserInterface $user + ) { + $event->getData()->willReturn(['user' => ['plainPassword' => '']]); + $event->getForm()->willReturn($form); + $form->getNormData()->willReturn($customer); + $customer->getUser()->willReturn($user); + + $form->remove('user')->shouldNotBeCalled(); + + $this->preSubmit($event); + } +} diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerProfileTypeSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerProfileTypeSpec.php similarity index 91% rename from src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerProfileTypeSpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerProfileTypeSpec.php index 2f9745bee7..97ee76194d 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerProfileTypeSpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerProfileTypeSpec.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Form\Type; +namespace spec\Sylius\Bundle\CustomerBundle\Form\Type; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -25,7 +25,7 @@ final class CustomerProfileTypeSpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\Type\CustomerProfileType'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Form\Type\CustomerProfileType'); } function it_is_a_form() diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerRegistrationTypeSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerRegistrationTypeSpec.php similarity index 90% rename from src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerRegistrationTypeSpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerRegistrationTypeSpec.php index 1a30d014c8..dcc62ba7d0 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerRegistrationTypeSpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerRegistrationTypeSpec.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Form\Type; +namespace spec\Sylius\Bundle\CustomerBundle\Form\Type; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\UserBundle\Form\EventSubscriber\CustomerRegistrationFormSubscriber; +use Sylius\Bundle\CustomerBundle\Form\EventSubscriber\CustomerRegistrationFormSubscriber; use Sylius\Bundle\UserBundle\Form\EventSubscriber\UserRegistrationFormSubscriber; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\Test\FormBuilderInterface; @@ -29,7 +29,7 @@ final class CustomerRegistrationTypeSpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\Type\CustomerRegistrationType'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Form\Type\CustomerRegistrationType'); } function it_is_a_form() diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerTypeSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerTypeSpec.php similarity index 89% rename from src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerTypeSpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerTypeSpec.php index 17689df491..2ae1dac231 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/CustomerTypeSpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/CustomerTypeSpec.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Form\Type; +namespace spec\Sylius\Bundle\CustomerBundle\Form\Type; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -30,7 +30,7 @@ final class CustomerTypeSpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\Type\CustomerType'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Form\Type\CustomerType'); } function it_extends_abstract_resource_type() @@ -52,7 +52,6 @@ final class CustomerTypeSpec extends ObjectBehavior $builder->add('gender', 'sylius_gender', Argument::any())->shouldBeCalled()->willReturn($builder); $builder->add('phoneNumber', 'text', Argument::any())->shouldBeCalled()->willReturn($builder); $builder->add('groups', 'sylius_group_choice', Argument::any())->shouldBeCalled()->willReturn($builder); - $builder->addEventSubscriber($addUserTypeSubscriber)->shouldBeCalled()->willReturn($builder); $this->buildForm($builder, []); } diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/GenderTypeSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/GenderTypeSpec.php similarity index 89% rename from src/Sylius/Bundle/UserBundle/spec/Form/Type/GenderTypeSpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Form/Type/GenderTypeSpec.php index ef9cf11a20..9732ffcfc0 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/GenderTypeSpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/GenderTypeSpec.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Form\Type; +namespace spec\Sylius\Bundle\CustomerBundle\Form\Type; use PhpSpec\ObjectBehavior; use Sylius\Component\Customer\Model\CustomerInterface; @@ -20,7 +20,7 @@ final class GenderTypeSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\Type\GenderType'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Form\Type\GenderType'); } function it_is_a_form() diff --git a/src/Sylius/Bundle/UserBundle/spec/Form/Type/GroupTypeSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/GroupTypeSpec.php similarity index 87% rename from src/Sylius/Bundle/UserBundle/spec/Form/Type/GroupTypeSpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Form/Type/GroupTypeSpec.php index b1dcf1838c..82dfba9ce6 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Form/Type/GroupTypeSpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Form/Type/GroupTypeSpec.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Form\Type; +namespace spec\Sylius\Bundle\CustomerBundle\Form\Type; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -25,7 +25,7 @@ final class GroupTypeSpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\Type\GroupType'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Form\Type\GroupType'); } function it_is_a_form() diff --git a/src/Sylius/Bundle/UserBundle/spec/Validator/Initializer/CustomerInitializerSpec.php b/src/Sylius/Bundle/CustomerBundle/spec/Validator/Initializer/CustomerInitializerSpec.php similarity index 89% rename from src/Sylius/Bundle/UserBundle/spec/Validator/Initializer/CustomerInitializerSpec.php rename to src/Sylius/Bundle/CustomerBundle/spec/Validator/Initializer/CustomerInitializerSpec.php index 909a5d6677..ae4dc05f59 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Validator/Initializer/CustomerInitializerSpec.php +++ b/src/Sylius/Bundle/CustomerBundle/spec/Validator/Initializer/CustomerInitializerSpec.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace spec\Sylius\Bundle\UserBundle\Validator\Initializer; +namespace spec\Sylius\Bundle\CustomerBundle\Validator\Initializer; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -29,7 +29,7 @@ final class CustomerInitializerSpec extends ObjectBehavior function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\UserBundle\Validator\Initializer\CustomerInitializer'); + $this->shouldHaveType('Sylius\Bundle\CustomerBundle\Validator\Initializer\CustomerInitializer'); } function it_implements_symfony_validator_initializer_interface() diff --git a/src/Sylius/Bundle/UserBundle/CHANGELOG.md b/src/Sylius/Bundle/UserBundle/CHANGELOG.md index e9c097488d..71c385e54c 100644 --- a/src/Sylius/Bundle/UserBundle/CHANGELOG.md +++ b/src/Sylius/Bundle/UserBundle/CHANGELOG.md @@ -1,5 +1,8 @@ CHANGELOG ========= +### v1.0.0-alpha.1 + +* Separate logic about customer to new bundle. ### v0.15.0 diff --git a/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php index 3803ac6ac3..bccf0564d4 100644 --- a/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php @@ -14,21 +14,10 @@ namespace Sylius\Bundle\UserBundle\DependencyInjection; use Sylius\Bundle\ResourceBundle\Controller\ResourceController; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceChoiceType; use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; -use Sylius\Bundle\UserBundle\Controller\CustomerController; use Sylius\Bundle\UserBundle\Controller\UserController; -use Sylius\Bundle\ResourceBundle\Form\Type\ResourceFromIdentifierType; -use Sylius\Bundle\UserBundle\Form\Type\CustomerProfileType; -use Sylius\Bundle\UserBundle\Form\Type\CustomerRegistrationType; -use Sylius\Bundle\UserBundle\Form\Type\CustomerSimpleRegistrationType; -use Sylius\Bundle\UserBundle\Form\Type\CustomerType; -use Sylius\Bundle\UserBundle\Form\Type\GroupType; use Sylius\Bundle\UserBundle\Form\Type\UserRegistrationType; use Sylius\Bundle\UserBundle\Form\Type\UserType; use Sylius\Component\Resource\Factory\Factory; -use Sylius\Component\Customer\Model\Customer; -use Sylius\Component\Customer\Model\CustomerInterface; -use Sylius\Component\Customer\Model\Group; -use Sylius\Component\Customer\Model\GroupInterface; use Sylius\Component\User\Model\User; use Sylius\Component\User\Model\UserInterface; use Sylius\Component\User\Model\UserOAuth; @@ -116,58 +105,6 @@ class Configuration implements ConfigurationInterface ->arrayNode('resources') ->addDefaultsIfNotSet() ->children() - ->arrayNode('customer') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('templates')->defaultValue('SyliusUserBundle:Customer')->end() - ->variableNode('options')->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(Customer::class)->cannotBeEmpty()->end() - ->scalarNode('interface')->defaultValue(CustomerInterface::class)->cannotBeEmpty()->end() - ->scalarNode('controller')->defaultValue(CustomerController::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->cannotBeEmpty()->end() - ->scalarNode('factory')->defaultValue(Factory::class)->end() - ->arrayNode('form') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('default')->defaultValue(CustomerType::class)->cannotBeEmpty()->end() - ->scalarNode('profile')->defaultValue(CustomerProfileType::class)->cannotBeEmpty()->end() - ->scalarNode('registration')->defaultValue(CustomerRegistrationType::class)->cannotBeEmpty()->end() - ->scalarNode('simple_registration')->defaultValue(CustomerSimpleRegistrationType::class)->cannotBeEmpty()->end() - ->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('validation_groups') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('default') - ->prototype('scalar')->end() - ->defaultValue(['sylius']) - ->end() - ->arrayNode('profile') - ->prototype('scalar')->end() - ->defaultValue(['sylius', 'sylius_customer_profile']) - ->end() - ->arrayNode('registration') - ->prototype('scalar')->end() - ->defaultValue(['sylius', 'sylius_customer_profile', 'sylius_user_registration']) - ->end() - ->arrayNode('simple_registration') - ->prototype('scalar')->end() - ->defaultValue(['sylius', 'sylius_user_registration']) - ->end() - ->arrayNode('guest') - ->prototype('scalar')->end() - ->defaultValue(['sylius_customer_guest']) - ->end() - ->end() - ->end() - ->end() - ->end() ->arrayNode('user') ->addDefaultsIfNotSet() ->children() @@ -221,43 +158,6 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->end() - ->arrayNode('group') - ->addDefaultsIfNotSet() - ->children() - ->variableNode('options')->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(Group::class)->cannotBeEmpty()->end() - ->scalarNode('interface')->defaultValue(GroupInterface::class)->cannotBeEmpty()->end() - ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->cannotBeEmpty()->end() - ->scalarNode('factory')->defaultValue(Factory::class)->end() - ->arrayNode('form') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('default')->defaultValue(GroupType::class)->cannotBeEmpty()->end() - ->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end() - ->scalarNode('from_identifier')->defaultValue(ResourceFromIdentifierType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('validation_groups') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('default') - ->prototype('scalar')->end() - ->defaultValue(['sylius']) - ->end() - ->arrayNode('from_identifier') - ->prototype('scalar')->end() - ->defaultValue(['sylius']) - ->end() - ->end() - ->end() - ->end() - ->end() ->end() ->end() ->end() diff --git a/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php b/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php index 3f642831ef..8f3c7a8828 100644 --- a/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php +++ b/src/Sylius/Bundle/UserBundle/DependencyInjection/SyliusUserExtension.php @@ -22,7 +22,7 @@ use Symfony\Component\DependencyInjection\Reference; /** * @author Łukasz Chruściel */ -class SyliusUserExtension extends AbstractResourceExtension implements PrependExtensionInterface +class SyliusUserExtension extends AbstractResourceExtension { /** * {@inheritdoc} @@ -42,41 +42,5 @@ class SyliusUserExtension extends AbstractResourceExtension implements PrependEx $container->setParameter('sylius.user.resetting.token_length', $config['resetting']['token']['length']); $container->setParameter('sylius.user.resetting.pin_length', $config['resetting']['pin']['length']); $container->setParameter('sylius.user.verification.token_length', $config['verification']['token']['length']); - - $container - ->getDefinition('sylius.form.type.customer_registration') - ->addArgument(new Reference('sylius.repository.customer')) - ; - $container - ->getDefinition('sylius.form.type.customer_simple_registration') - ->addArgument(new Reference('sylius.repository.customer')) - ; - $container - ->getDefinition('sylius.form.type.customer') - ->addArgument(new Reference('sylius.form.event_subscriber.add_user_type')) - ; - } - - /** - * @param ContainerBuilder $container - */ - public function prepend(ContainerBuilder $container) - { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - - $this->prependHwiOauth($container, $loader); - } - - /** - * @param ContainerBuilder $container - * @param LoaderInterface $loader - */ - private function prependHwiOauth(ContainerBuilder $container, LoaderInterface $loader) - { - if (!$container->hasExtension('hwi_oauth')) { - return; - } - - $loader->load('integration/hwi_oauth.xml'); } } diff --git a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/GroupRepository.php b/src/Sylius/Bundle/UserBundle/Doctrine/ORM/GroupRepository.php deleted file mode 100644 index e51154b96c..0000000000 --- a/src/Sylius/Bundle/UserBundle/Doctrine/ORM/GroupRepository.php +++ /dev/null @@ -1,29 +0,0 @@ - - */ -class GroupRepository extends EntityRepository implements GroupRepositoryInterface -{ - /** - * {@inheritdoc} - */ - public function getFormQueryBuilder() - { - return $this->createQueryBuilder('o'); - } -} diff --git a/src/Sylius/Bundle/UserBundle/OAuth/UserProvider.php b/src/Sylius/Bundle/UserBundle/OAuth/UserProvider.php index 18a2d1922f..ba8450e616 100644 --- a/src/Sylius/Bundle/UserBundle/OAuth/UserProvider.php +++ b/src/Sylius/Bundle/UserBundle/OAuth/UserProvider.php @@ -48,12 +48,7 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface * @var FactoryInterface */ protected $customerFactory; - - /** - * @var RepositoryInterface - */ - protected $customerRepository; - + /** * @var FactoryInterface */ @@ -66,7 +61,6 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface /** * @param FactoryInterface $customerFactory - * @param RepositoryInterface $customerRepository * @param FactoryInterface $userFactory * @param UserRepositoryInterface $userRepository * @param FactoryInterface $oauthFactory @@ -76,7 +70,6 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface */ public function __construct( FactoryInterface $customerFactory, - RepositoryInterface $customerRepository, FactoryInterface $userFactory, UserRepositoryInterface $userRepository, FactoryInterface $oauthFactory, @@ -86,7 +79,6 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface ) { parent::__construct($userRepository, $canonicalizer); - $this->customerFactory = $customerFactory; $this->customerRepository = $customerRepository; $this->oauthFactory = $oauthFactory; $this->oauthRepository = $oauthRepository; diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml b/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml index 2feae2de23..825314bbcc 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/driver/doctrine/orm.xml @@ -17,9 +17,7 @@ http://symfony.com/schema/dic/services/services-1.0.xsd"> - Sylius\Bundle\UserBundle\Doctrine\ORM\GroupRepository Sylius\Bundle\UserBundle\Doctrine\ORM\UserRepository - Sylius\Bundle\UserBundle\Doctrine\ORM\CustomerRepository diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml index 11a3db6a64..edfe8adb99 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml @@ -40,27 +40,17 @@ Sylius\Bundle\UserBundle\Form\Type\UserRequestPasswordResetType Sylius\Bundle\UserBundle\Form\Type\UserResetPasswordType Sylius\Bundle\UserBundle\Form\Type\UserChangePasswordType - Sylius\Bundle\UserBundle\Form\Type\GenderType - Sylius\Bundle\UserBundle\EventListener\DefaultUsernameORMListener - Sylius\Bundle\UserBundle\EventListener\CustomerAwareListener Sylius\Bundle\UserBundle\EventListener\UserDeleteListener Sylius\Bundle\UserBundle\EventListener\CanonicalizerListener Sylius\Bundle\UserBundle\EventListener\PasswordUpdaterListener Sylius\Bundle\UserBundle\EventListener\UserLastLoginSubscriber - Sylius\Bundle\UserBundle\EventListener\UserAutoLoginListener Sylius\Bundle\UserBundle\EventListener\UserReloaderListener Sylius\Bundle\UserBundle\EventListener\MailerListener Sylius\Bundle\UserBundle\EventListener\UserRegistrationListener - Sylius\Bundle\UserBundle\Form\EventSubscriber\AddUserFormSubscriber - Sylius\Bundle\UserBundle\Form\EventSubscriber\SetCustomerFormSubscriber - Sylius\Bundle\UserBundle\Controller\SecurityController - Sylius\Bundle\UserBundle\Validator\Constraints\RegisteredUserValidator - Sylius\Bundle\UserBundle\Validator\Initializer\CustomerInitializer - Sylius\Bundle\UserBundle\Form\Model\ChangePassword @@ -120,13 +110,6 @@
- - - - - - - @@ -197,20 +180,6 @@ - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml b/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml index 88c567a337..cc55cf2e1a 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/validation.xml @@ -16,77 +16,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -172,20 +101,4 @@ - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/UserBundle/Resources/serializer/Model.User.yml b/src/Sylius/Bundle/UserBundle/Resources/serializer/Model.User.yml new file mode 100644 index 0000000000..d8cf69b9e3 --- /dev/null +++ b/src/Sylius/Bundle/UserBundle/Resources/serializer/Model.User.yml @@ -0,0 +1,24 @@ +Sylius\Component\User\Model\User: + exclusion_policy: ALL + xml_root_name: sylius_user + properties: + id: + expose: true + type: integer + groups: [Default, Detailed] + username: + expose: true + type: string + groups: [Default, Detailed, Secured] + usernameCanonical: + expose: true + type: string + groups: [Detailed] + enabled: + expose: true + type: boolean + groups: [Default, Detailed] + roles: + expose: true + type: array + groups: [Detailed] diff --git a/src/Sylius/Bundle/UserBundle/spec/OAuth/UserProviderSpec.php b/src/Sylius/Bundle/UserBundle/spec/OAuth/UserProviderSpec.php index ea323ef491..b2d5374a55 100644 --- a/src/Sylius/Bundle/UserBundle/spec/OAuth/UserProviderSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/OAuth/UserProviderSpec.php @@ -17,7 +17,6 @@ use HWI\Bundle\OAuthBundle\OAuth\ResourceOwnerInterface; use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface; use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface; use PhpSpec\ObjectBehavior; -use Sylius\Bundle\UserBundle\Doctrine\ORM\CustomerRepository; use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; @@ -30,7 +29,6 @@ final class UserProviderSpec extends ObjectBehavior { function let( FactoryInterface $customerFactory, - CustomerRepository $customerRepository, FactoryInterface $userFactory, UserRepositoryInterface $userRepository, FactoryInterface $oauthFactory, @@ -38,7 +36,7 @@ final class UserProviderSpec extends ObjectBehavior ObjectManager $userManager, CanonicalizerInterface $canonicalizer ) { - $this->beConstructedWith($customerFactory, $customerRepository, $userFactory, $userRepository, $oauthFactory, $oauthRepository, $userManager, $canonicalizer); + $this->beConstructedWith($customerFactory, $userFactory, $userRepository, $oauthFactory, $oauthRepository, $userManager, $canonicalizer); } function it_is_initializable() diff --git a/src/Sylius/Component/Core/Repository/CustomerRepositoryInterface.php b/src/Sylius/Component/Core/Repository/CustomerRepositoryInterface.php new file mode 100644 index 0000000000..86c5d79944 --- /dev/null +++ b/src/Sylius/Component/Core/Repository/CustomerRepositoryInterface.php @@ -0,0 +1,28 @@ + + */ +interface CustomerRepositoryInterface +{ + /** + * @param array $criteria + * @param array $sorting + * + * @return Pagerfanta + */ + public function createFilterPaginator(array $criteria = null, array $sorting = null); +} diff --git a/src/Sylius/Component/Customer/Repository/CustomerRepositoryInterface.php b/src/Sylius/Component/Customer/Repository/CustomerRepositoryInterface.php index 78df5c9691..d4aeb0bedd 100644 --- a/src/Sylius/Component/Customer/Repository/CustomerRepositoryInterface.php +++ b/src/Sylius/Component/Customer/Repository/CustomerRepositoryInterface.php @@ -11,7 +11,6 @@ namespace Sylius\Component\Customer\Repository; -use Pagerfanta\Pagerfanta; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; @@ -38,12 +37,4 @@ interface CustomerRepositoryInterface extends RepositoryInterface * @return null|CustomerInterface */ public function findForDetailsPage($id); - - /** - * @param array $criteria - * @param array $sorting - * - * @return Pagerfanta - */ - public function createFilterPaginator(array $criteria = null, array $sorting = null); } diff --git a/src/Sylius/Component/Customer/Repository/GroupRepositoryInterface.php b/src/Sylius/Component/Customer/Repository/GroupRepositoryInterface.php deleted file mode 100644 index cb47fa88c2..0000000000 --- a/src/Sylius/Component/Customer/Repository/GroupRepositoryInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -interface GroupRepositoryInterface extends RepositoryInterface -{ - /** - * @return QueryBuilder - */ - public function getFormQueryBuilder(); -}