Skip to content

Commit

Permalink
[NamedCarts] refactor, fix wishlist
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed May 21, 2024
1 parent dce40f5 commit b0a8d65
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 41 deletions.
2 changes: 1 addition & 1 deletion docs/01_Getting_Started/04_Tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ vendor/bin/bdi detect drivers
APP_ENV=test PIMCORE_TEST_DB_DSN=mysql://root:[email protected]:3306/coreshop4___behat symfony server:start --port=9080 --dir=public --no-tls
# Run Behat
CORESHOP_SKIP_DB_SETUP=1 PANTHER_EXTERNAL_BASE_URI=http://127.0.0.1:9080/index_test.php PANTHER_NO_HEADLESS=0 PIMCORE_TEST_DB_DSN=mysql://root:[email protected]:3306/coreshop4___behat php -d memory_limit=-1 vendor/bin/behat -c behat.yml.dist -p ui -vvv
CORESHOP_SKIP_DB_SETUP=1 PANTHER_EXTERNAL_BASE_URI=http://127.0.0.1:9080/index_test.php PANTHER_NO_HEADLESS=0 PIMCORE_TEST_DB_DSN=mysql://root:[email protected]:3306/coreshop4___behat php -d memory_limit=-1 vendor/bin/behat -c behat.yml.dist -p ui -vvv features/ui/frontend/wishlist/adding_product_to_wishlist.feature
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
use CoreShop\Bundle\OrderBundle\DTO\AddToCartInterface;
use CoreShop\Bundle\OrderBundle\Factory\AddToCartFactoryInterface;
use CoreShop\Bundle\OrderBundle\Form\Type\AddToCartType;
use CoreShop\Bundle\OrderBundle\Form\Type\CartListChoiceType;
use CoreShop\Bundle\OrderBundle\Form\Type\CartListType;
use CoreShop\Bundle\OrderBundle\Form\Type\CartType;
use CoreShop\Bundle\OrderBundle\Form\Type\CreatedNamedCartType;
use CoreShop\Bundle\OrderBundle\Form\Type\ShippingCalculatorType;
use CoreShop\Bundle\ResourceBundle\Pimcore\Repository\StackRepositoryInterface;
use CoreShop\Bundle\StorageListBundle\Form\Type\StorageListChoiceType;
use CoreShop\Bundle\WorkflowBundle\Manager\StateMachineManagerInterface;
use CoreShop\Component\Address\Model\AddressInterface;
use CoreShop\Component\Core\Context\ShopperContextInterface;
use CoreShop\Component\Core\Currency\CurrencyStorageInterface;
use CoreShop\Component\Core\Order\Modifier\CartItemQuantityModifier;
use CoreShop\Component\Order\Cart\CartModifierInterface;
use CoreShop\Component\Order\Cart\Rule\CartPriceRuleProcessorInterface;
Expand All @@ -52,17 +48,14 @@
use CoreShop\Component\StorageList\Provider\ContextProviderInterface;
use CoreShop\Component\StorageList\Storage\StorageListStorageInterface;
use CoreShop\Component\StorageList\StorageListItemQuantityModifierInterface;
use CoreShop\Component\Store\Context\StoreContextInterface;
use CoreShop\Component\Tracking\Tracker\TrackerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Service\Attribute\SubscribedService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
use CoreShop\Component\StorageList\Model\ShareableStorageListInterface;
use CoreShop\Component\StorageList\Model\StorageListInterface;
use CoreShop\Component\StorageList\Model\StorageListItemInterface;
use CoreShop\Component\StorageList\Provider\ContextProviderInterface;
use CoreShop\Component\StorageList\Repository\ShareableStorageListRepositoryInterface;
use CoreShop\Component\StorageList\Resolver\StorageListResolverInterface;
use CoreShop\Component\StorageList\StorageListManagerInterface;
use CoreShop\Component\StorageList\StorageListModifierInterface;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -66,8 +64,6 @@ public function __construct(
protected string $indexRoute,
protected string $templateAddToList,
protected string $templateSummary,
protected StorageListResolverInterface $listResolver,
protected ContextProviderInterface $contextProvider,
protected TranslatorInterface $translator,
) {
$this->setContainer($container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

namespace CoreShop\Bundle\StorageListBundle\Controller;

use CoreShop\Bundle\OrderBundle\Form\Type\CartListType;
use CoreShop\Bundle\OrderBundle\Form\Type\CreatedNamedCartType;
use CoreShop\Bundle\StorageListBundle\Form\Type\CreatedNamedStorageListType;
use CoreShop\Component\Customer\Model\CustomerAwareInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use CoreShop\Component\StorageList\Context\StorageListContextInterface;
use CoreShop\Component\StorageList\Factory\StorageListFactoryInterface;
use CoreShop\Component\StorageList\Provider\ContextProviderInterface;
use CoreShop\Component\StorageList\Resolver\StorageListResolverInterface;
use CoreShop\Component\StorageList\Storage\StorageListStorageInterface;
use CoreShop\Component\StorageList\StorageListManagerInterface;
use Pimcore\Model\DataObject\Concrete;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\ClickableInterface;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function createNamedStorageListAction(Request $request): Response
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->denyAccessUnlessGranted(sprintf('CORESHOP_STORAGE_LIST_CREATED_%s', strtoupper($this->identifier)));

$form = $this->formFactory->createNamed('coreshop', CreatedNamedCartType::class);
$form = $this->formFactory->createNamed('coreshop', CreatedNamedStorageListType::class);

if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'])) {
$form->handleRequest($request);
Expand All @@ -75,11 +76,14 @@ public function createNamedStorageListAction(Request $request): Response

$this->contextProvider->provideContextForStorageList($storageList);

$this->manager->persistCart($storageList);
$this->manager->persist($storageList);

$this->storage->setForContext($this->contextProvider->getCurrentContext(), $storageList);

$this->addFlash('success', $this->translator->trans(sprintf('coreshop.ui.%s.created', $this->identifier)));
$this->addFlash(
'success',
$this->translator->trans(sprintf('coreshop.ui.%s.created', $this->identifier))
);

if ($request->isXmlHttpRequest()) {
return new JsonResponse([
Expand All @@ -104,14 +108,14 @@ public function createNamedStorageListAction(Request $request): Response
public function listStorageListAction(Request $request): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->denyAccessUnlessGranted('CORESHOP_STORAGE_LIST_MULTI_LIST_' . $this->identifier);
$this->denyAccessUnlessGranted('CORESHOP_STORAGE_LIST_MULTI_LIST_'.$this->identifier);

$storageLists = $this->listResolver->getStorageLists($this->contextProvider->getCurrentContext());
$storageList = $this->context->getStorageList();

$params = [
'lists' => $storageLists,
'list' => $storageList
'list' => $storageList,
];

if (null !== $this->listFormType) {
Expand All @@ -130,25 +134,34 @@ public function listStorageListAction(Request $request): Response
if ($form->isSubmitted() && $form->isValid()) {
$list = $form->getData()['list'];

if ($list->getCustomer()?->getId() !== $this->contextProvider->getCurrentContext()['customer']->getId()) {
if ($list instanceof CustomerAwareInterface &&
$list->getCustomer()?->getId() !== $this->contextProvider->getCurrentContext()['customer']->getId()
) {
throw new AccessDeniedException();
}

if ($form->has('deleteList')) {
$deleteListButton = $form->get('deleteList');

$deleteCLicked = $deleteListButton instanceof ClickableInterface && $deleteListButton->isClicked();
$deleteClicked = $deleteListButton instanceof ClickableInterface &&
$deleteListButton->isClicked();

if ($deleteCLicked) {
$list->delete();
if ($deleteClicked) {
if ($list instanceof Concrete) {
$list->delete();
}

return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost()));
return new RedirectResponse(
$request->headers->get('referer', $request->getSchemeAndHttpHost())
);
}
}

$this->storage->setForContext($this->contextProvider->getCurrentContext(), $list);

return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost()));
return new RedirectResponse(
$request->headers->get('referer', $request->getSchemeAndHttpHost())
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ public function load(array $configs, ContainerBuilder $container): void
$controllerDefinition->setArgument('$indexRoute', $list['routes']['index']);
$controllerDefinition->setArgument('$templateSummary', $list['templates']['summary']);
$controllerDefinition->setArgument('$templateAddToList', $list['templates']['add_to_cart']);
$controllerDefinition->setArgument('$listResolver', new Reference($list['services']['list_resolver']));
$controllerDefinition->setArgument('$contextProvider', new Reference('coreshop.storage_list.context_provider.' . $name));
$controllerDefinition->setArgument('$translator', new Reference('translator'));
$controllerDefinition->addTag('controller.service_arguments');
$controllerDefinition->addTag('container.service_subscriber');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*
*/

namespace CoreShop\Bundle\OrderBundle\Form\Type;
namespace CoreShop\Bundle\StorageListBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

final class CreatedNamedCartType extends AbstractType
final class CreatedNamedStorageListType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
parameters:
coreshop.storage_list.add_to_list_class: 'CoreShop\Component\StorageList\DTO\AddToStorageList'
coreshop.storage_list.add_to_selectable_list_class: 'CoreShop\Component\StorageList\DTO\AddToSelectableStorageList'
coreshop.storage_list.add_to_new_list_class: 'CoreShop\Component\StorageList\DTO\AddToNewStorageList'

services:
_defaults:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
parameters:
coreshop.dto.add_to_wishlist.class: '%coreshop.storage_list.add_to_list_class%'
coreshop.dto.add_to_selectable_wishlist.class: '%coreshop.storage_list.add_to_selectable_list_class%'
coreshop.dto.add_to_new_wishlist.class: '%coreshop.storage_list.add_to_new_list_class%'
coreshop.form.type.wishlist.validation_groups: [coreshop]
coreshop.form.type.wishlist_item.validation_groups: [coreshop]
coreshop.form.type.add_to_wishlist.validation_groups: [coreshop]
Expand Down Expand Up @@ -32,13 +30,6 @@ services:
arguments:
- '@coreshop.factory.wishlist.storage_list.inner'

coreshop.wishlist.context.factory:
class: CoreShop\Component\StorageList\Context\StorageListFactoryContext
arguments:
- '@coreshop.factory.wishlist'
tags:
- { name: coreshop.context.wishlist, priority: -999 }

CoreShop\Bundle\WishlistBundle\Form\Type\WishlistType:
arguments:
- '%coreshop.model.wishlist.class%'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use CoreShop\Component\Resource\Factory\FactoryInterface;
use CoreShop\Component\Resource\Pimcore\Model\AbstractPimcoreModel;
use CoreShop\Component\StorageList\Model\NameableStorageListInterface;
use CoreShop\Component\StorageList\Model\StorageListInterface;

final class StorageListFactoryContext implements StorageListContextInterface
Expand Down

0 comments on commit b0a8d65

Please sign in to comment.