Skip to content

Commit

Permalink
extensible customer structure (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3tezsky authored Dec 19, 2019
2 parents d2d1da8 + 715175f commit 9a5b86f
Show file tree
Hide file tree
Showing 47 changed files with 1,115 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion config/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:

App\Form\Admin\UserFormTypeExtension:
tags:
- { name: form.type_extension, extended_type: Shopsys\FrameworkBundle\Form\Admin\Customer\UserFormType }
- { name: form.type_extension, extended_type: Shopsys\FrameworkBundle\Form\Admin\Customer\User\UserFormType }

App\Form\Admin\OrderFormTypeExtension:
tags:
Expand Down
2 changes: 1 addition & 1 deletion config/packages/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ security:
id: Shopsys\FrameworkBundle\Model\Administrator\Security\AdministratorUserProvider

user_identities:
id: Shopsys\FrameworkBundle\Model\Customer\FrontendUserProvider
id: Shopsys\FrameworkBundle\Model\Customer\User\FrontendCustomerUserProvider

firewalls:
# see Shopsys\FrameworkBundle\Model\Administrator\Security\AdministratorFrontSecurityFacade
Expand Down
2 changes: 1 addition & 1 deletion config/parameters_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parameters:
Shopsys\FrameworkBundle\Model\Article\Article: App\Model\Article\Article
Shopsys\FrameworkBundle\Model\Administrator\Administrator: App\Model\Administrator\Administrator
Shopsys\FrameworkBundle\Model\Category\Category: App\Model\Category\Category
Shopsys\FrameworkBundle\Model\Customer\User: App\Model\Customer\User
Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser: App\Model\Customer\User\CustomerUser
Shopsys\FrameworkBundle\Model\Order\Order: App\Model\Order\Order
Shopsys\FrameworkBundle\Model\Order\Item\OrderItem: App\Model\Order\Item\OrderItem
Shopsys\FrameworkBundle\Model\Transport\Transport: App\Model\Transport\Transport
Expand Down
4 changes: 2 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:

Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface: '@App\Model\Category\CategoryDataFactory'

Shopsys\FrameworkBundle\Model\Customer\UserDataFactoryInterface: '@App\Model\Customer\UserDataFactory'
Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserDataFactoryInterface: '@App\Model\Customer\User\CustomerUserDataFactory'

Shopsys\FrameworkBundle\Model\Order\OrderDataFactoryInterface: '@App\Model\Order\OrderDataFactory'

Expand Down Expand Up @@ -78,7 +78,7 @@ services:
arguments:
- "%shopsys.performance_data.product.total_count%"

App\DataFixtures\Performance\UserDataFixture:
App\DataFixtures\Performance\CustomerUserDataFixture:
arguments:
- "%shopsys.performance_data.user.count_per_domain%"

Expand Down
2 changes: 1 addition & 1 deletion config/services_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ services:

Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface: '@App\Model\Category\CategoryDataFactory'

Shopsys\FrameworkBundle\Model\Customer\UserDataFactoryInterface: '@App\Model\Customer\UserDataFactory'
Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserDataFactoryInterface: '@App\Model\Customer\User\CustomerUserDataFactory'

Shopsys\FrameworkBundle\Model\Order\Item\OrderItemDataFactoryInterface: '@App\Model\Order\Item\OrderItemDataFactory'

Expand Down
16 changes: 8 additions & 8 deletions src/Command/PerformanceDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace App\Command;

use App\DataFixtures\Performance\CategoryDataFixture;
use App\DataFixtures\Performance\CustomerUserDataFixture;
use App\DataFixtures\Performance\OrderDataFixture;
use App\DataFixtures\Performance\ProductDataFixture;
use App\DataFixtures\Performance\UserDataFixture;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -30,9 +30,9 @@ class PerformanceDataCommand extends Command
private $productDataFixture;

/**
* @var \App\DataFixtures\Performance\UserDataFixture
* @var \App\DataFixtures\Performance\CustomerUserDataFixture
*/
private $userDataFixture;
private $customerUserDataFixture;

/**
* @var \App\DataFixtures\Performance\OrderDataFixture
Expand All @@ -42,18 +42,18 @@ class PerformanceDataCommand extends Command
/**
* @param \App\DataFixtures\Performance\CategoryDataFixture $categoryDataFixture
* @param \App\DataFixtures\Performance\ProductDataFixture $productDataFixture
* @param \App\DataFixtures\Performance\UserDataFixture $userDataFixture
* @param \App\DataFixtures\Performance\CustomerUserDataFixture $customerUserDataFixture
* @param \App\DataFixtures\Performance\OrderDataFixture $orderDataFixture
*/
public function __construct(
CategoryDataFixture $categoryDataFixture,
ProductDataFixture $productDataFixture,
UserDataFixture $userDataFixture,
CustomerUserDataFixture $customerUserDataFixture,
OrderDataFixture $orderDataFixture
) {
$this->categoryDataFixture = $categoryDataFixture;
$this->productDataFixture = $productDataFixture;
$this->userDataFixture = $userDataFixture;
$this->customerUserDataFixture = $customerUserDataFixture;
$this->orderDataFixture = $orderDataFixture;

parent::__construct();
Expand All @@ -75,8 +75,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->categoryDataFixture->load($output);
$output->writeln('<fg=green>loading ' . ProductDataFixture::class . '</fg=green>');
$this->productDataFixture->load($output);
$output->writeln('<fg=green>loading ' . UserDataFixture::class . '</fg=green>');
$this->userDataFixture->load($output);
$output->writeln('<fg=green>loading ' . CustomerUserDataFixture::class . '</fg=green>');
$this->customerUserDataFixture->load($output);
$output->writeln('<fg=green>loading ' . OrderDataFixture::class . '</fg=green>');
$this->orderDataFixture->load($output);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Controller/Front/BestsellingProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\Category\Category;
use Shopsys\FrameworkBundle\Model\Customer\CurrentCustomer;
use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser;
use Shopsys\FrameworkBundle\Model\Product\BestsellingProduct\BestsellingProductFacade;
use Shopsys\FrameworkBundle\Model\Product\BestsellingProduct\CachedBestsellingProductFacade;

Expand All @@ -23,23 +23,23 @@ class BestsellingProductController extends FrontBaseController
private $domain;

/**
* @var \Shopsys\FrameworkBundle\Model\Customer\CurrentCustomer
* @var \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser
*/
private $currentCustomer;
private $currentCustomerUser;

/**
* @param \Shopsys\FrameworkBundle\Model\Product\BestsellingProduct\CachedBestsellingProductFacade $cachedBestsellingProductFacade
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\Customer\CurrentCustomer $currentCustomer
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser $currentCustomerUser
*/
public function __construct(
CachedBestsellingProductFacade $cachedBestsellingProductFacade,
Domain $domain,
CurrentCustomer $currentCustomer
CurrentCustomerUser $currentCustomerUser
) {
$this->cachedBestsellingProductFacade = $cachedBestsellingProductFacade;
$this->domain = $domain;
$this->currentCustomer = $currentCustomer;
$this->currentCustomerUser = $currentCustomerUser;
}

/**
Expand All @@ -50,7 +50,7 @@ public function listAction(Category $category)
$bestsellingProducts = $this->cachedBestsellingProductFacade->getAllOfferedBestsellingProducts(
$this->domain->getId(),
$category,
$this->currentCustomer->getPricingGroup()
$this->currentCustomerUser->getPricingGroup()
);

return $this->render('Front/Content/Product/bestsellingProductsList.html.twig', [
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Front/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct(
*/
public function indexAction(Request $request)
{
$cart = $this->cartFacade->findCartOfCurrentCustomer();
$cart = $this->cartFacade->findCartOfCurrentCustomerUser();
$cartItems = $cart === null ? [] : $cart->getItems();

$cartFormData = ['quantities' => []];
Expand Down Expand Up @@ -143,7 +143,7 @@ public function boxAction()
$orderPreview = $this->orderPreviewFactory->createForCurrentUser();

return $this->render('Front/Inline/Cart/cartBox.html.twig', [
'cart' => $this->cartFacade->findCartOfCurrentCustomer(),
'cart' => $this->cartFacade->findCartOfCurrentCustomerUser(),
'productsPrice' => $orderPreview->getProductsPrice(),
]);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Controller/Front/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\Category\CategoryFacade;
use Shopsys\FrameworkBundle\Model\Category\TopCategory\TopCategoryFacade;
use Shopsys\FrameworkBundle\Model\Customer\CurrentCustomer;
use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser;
use Symfony\Component\HttpFoundation\Request;

class CategoryController extends FrontBaseController
Expand All @@ -34,29 +34,29 @@ class CategoryController extends FrontBaseController
private $topCategoryFacade;

/**
* @var \Shopsys\FrameworkBundle\Model\Customer\CurrentCustomer
* @var \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser
*/
private $currentCustomer;
private $currentCustomerUser;

/**
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\Category\CategoryFacade $categoryFacade
* @param \App\Model\Category\CurrentCategoryResolver $currentCategoryResolver
* @param \Shopsys\FrameworkBundle\Model\Category\TopCategory\TopCategoryFacade $topCategoryFacade
* @param \Shopsys\FrameworkBundle\Model\Customer\CurrentCustomer $currentCustomer
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser $currentCustomerUser
*/
public function __construct(
Domain $domain,
CategoryFacade $categoryFacade,
CurrentCategoryResolver $currentCategoryResolver,
TopCategoryFacade $topCategoryFacade,
CurrentCustomer $currentCustomer
CurrentCustomerUser $currentCustomerUser
) {
$this->domain = $domain;
$this->categoryFacade = $categoryFacade;
$this->currentCategoryResolver = $currentCategoryResolver;
$this->topCategoryFacade = $topCategoryFacade;
$this->currentCustomer = $currentCustomer;
$this->currentCustomerUser = $currentCustomerUser;
}

/**
Expand Down Expand Up @@ -121,7 +121,7 @@ public function topAction()
public function categoryListAction(array $categories, $showProductsCountByCategory = true)
{
if ($showProductsCountByCategory === true) {
$pricingGroup = $this->currentCustomer->getPricingGroup();
$pricingGroup = $this->currentCustomerUser->getPricingGroup();
$domainId = $this->domain->getId();

$listableProductCountsIndexedByCategoryId = $this->categoryFacade
Expand Down
48 changes: 24 additions & 24 deletions src/Controller/Front/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Controller\Front;

use App\Form\Front\Customer\CustomerFormType;
use App\Form\Front\Customer\User\CustomerUserUpdateFormType;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\Customer\CustomerDataFactoryInterface;
use Shopsys\FrameworkBundle\Model\Customer\CustomerFacade;
use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserFacade;
use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserUpdateDataFactoryInterface;
use Shopsys\FrameworkBundle\Model\Order\Item\OrderItemPriceCalculation;
use Shopsys\FrameworkBundle\Model\Order\OrderFacade;
use Shopsys\FrameworkBundle\Model\Security\LoginAsUserFacade;
Expand All @@ -17,9 +17,9 @@
class CustomerController extends FrontBaseController
{
/**
* @var \Shopsys\FrameworkBundle\Model\Customer\CustomerFacade
* @var \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserFacade
*/
private $customerFacade;
private $customerUserFacade;

/**
* @var \Shopsys\FrameworkBundle\Component\Domain\Domain
Expand All @@ -42,32 +42,32 @@ class CustomerController extends FrontBaseController
private $loginAsUserFacade;

/**
* @var \Shopsys\FrameworkBundle\Model\Customer\CustomerDataFactoryInterface
* @var \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserUpdateDataFactoryInterface
*/
private $customerDataFactory;
private $customerUserUpdateDataFactory;

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\CustomerFacade $customerFacade
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserFacade $customerUserFacade
* @param \Shopsys\FrameworkBundle\Model\Order\OrderFacade $orderFacade
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\Order\Item\OrderItemPriceCalculation $orderItemPriceCalculation
* @param \Shopsys\FrameworkBundle\Model\Security\LoginAsUserFacade $loginAsUserFacade
* @param \Shopsys\FrameworkBundle\Model\Customer\CustomerDataFactoryInterface $customerDataFactory
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserUpdateDataFactoryInterface $customerUserUpdateDataFactory
*/
public function __construct(
CustomerFacade $customerFacade,
CustomerUserFacade $customerUserFacade,
OrderFacade $orderFacade,
Domain $domain,
OrderItemPriceCalculation $orderItemPriceCalculation,
LoginAsUserFacade $loginAsUserFacade,
CustomerDataFactoryInterface $customerDataFactory
CustomerUserUpdateDataFactoryInterface $customerUserUpdateDataFactory
) {
$this->customerFacade = $customerFacade;
$this->customerUserFacade = $customerUserFacade;
$this->orderFacade = $orderFacade;
$this->domain = $domain;
$this->orderItemPriceCalculation = $orderItemPriceCalculation;
$this->loginAsUserFacade = $loginAsUserFacade;
$this->customerDataFactory = $customerDataFactory;
$this->customerUserUpdateDataFactory = $customerUserUpdateDataFactory;
}

/**
Expand All @@ -80,18 +80,18 @@ public function editAction(Request $request)
return $this->redirectToRoute('front_login');
}

$user = $this->getUser();
$customerData = $this->customerDataFactory->createFromUser($user);
$customerUser = $this->getUser();
$customerUserUpdateData = $this->customerUserUpdateDataFactory->createFromCustomerUser($customerUser);

$form = $this->createForm(CustomerFormType::class, $customerData, [
$form = $this->createForm(CustomerUserUpdateFormType::class, $customerUserUpdateData, [
'domain_id' => $this->domain->getId(),
]);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$customerData = $form->getData();
$customerUserUpdateData = $form->getData();

$this->customerFacade->editByCustomer($user->getId(), $customerData);
$this->customerUserFacade->editByCustomer($customerUser->getId(), $customerUserUpdateData);

$this->getFlashMessageSender()->addSuccessFlash(t('Your data had been successfully updated'));
return $this->redirectToRoute('front_customer_edit');
Expand All @@ -113,10 +113,10 @@ public function ordersAction()
return $this->redirectToRoute('front_login');
}

/** @var \App\Model\Customer\User $user */
$user = $this->getUser();
/** @var \App\Model\Customer\User\CustomerUser $customerUser */
$customerUser = $this->getUser();

$orders = $this->orderFacade->getCustomerOrderList($user);
$orders = $this->orderFacade->getCustomerUserOrderList($customerUser);
return $this->render('Front/Content/Customer/orders.html.twig', [
'orders' => $orders,
]);
Expand Down Expand Up @@ -150,10 +150,10 @@ private function orderDetailAction($urlHash = null, $orderNumber = null)
return $this->redirectToRoute('front_login');
}

$user = $this->getUser();
$customerUser = $this->getUser();
try {
/** @var \App\Model\Order\Order $order */
$order = $this->orderFacade->getByOrderNumberAndUser($orderNumber, $user);
$order = $this->orderFacade->getByOrderNumberAndUser($orderNumber, $customerUser);
} catch (\Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException $ex) {
$this->getFlashMessageSender()->addErrorFlash(t('Order not found'));
return $this->redirectToRoute('front_customer_orders');
Expand All @@ -179,7 +179,7 @@ public function loginAsRememberedUserAction(Request $request)
{
try {
$this->loginAsUserFacade->loginAsRememberedUser($request);
} catch (\Shopsys\FrameworkBundle\Model\Customer\Exception\UserNotFoundException $e) {
} catch (\Shopsys\FrameworkBundle\Model\Customer\Exception\CustomerUserNotFoundException $e) {
/** @var \Shopsys\FrameworkBundle\Component\FlashMessage\FlashMessageSender $adminFlashMessageSender */
$adminFlashMessageSender = $this->get('shopsys.shop.component.flash_message.sender.admin');
$adminFlashMessageSender->addErrorFlash(t('User not found.'));
Expand Down
Loading

0 comments on commit 9a5b86f

Please sign in to comment.