use Lc\CaracoleBundle\Factory\Product\ProductCategoryFactory; | use Lc\CaracoleBundle\Factory\Product\ProductCategoryFactory; | ||||
use Lc\CaracoleBundle\Repository\Product\ProductCategoryRepositoryQuery; | use Lc\CaracoleBundle\Repository\Product\ProductCategoryRepositoryQuery; | ||||
use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore; | use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore; | ||||
use Lc\CaracoleBundle\Solver\Product\ProductCategorySolver; | |||||
class ProductCategoryContainer | class ProductCategoryContainer | ||||
{ | { | ||||
protected ProductCategoryFactory $factory; | protected ProductCategoryFactory $factory; | ||||
protected ProductCategorySolver $solver; | |||||
protected ProductCategoryRepositoryQuery $repositoryQuery; | protected ProductCategoryRepositoryQuery $repositoryQuery; | ||||
protected ProductCategoryStore $store; | protected ProductCategoryStore $store; | ||||
public function __construct( | public function __construct( | ||||
ProductCategoryFactory $factory, | ProductCategoryFactory $factory, | ||||
ProductCategorySolver $solver, | |||||
ProductCategoryRepositoryQuery $repositoryQuery, | ProductCategoryRepositoryQuery $repositoryQuery, | ||||
ProductCategoryStore $store | ProductCategoryStore $store | ||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->solver = $solver; | |||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
$this->store = $store; | $this->store = $store; | ||||
} | } | ||||
return $this->factory; | return $this->factory; | ||||
} | } | ||||
public function getSolver(): ProductCategorySolver | |||||
{ | |||||
return $this->solver; | |||||
} | |||||
public function getRepositoryQuery(): ProductCategoryRepositoryQuery | public function getRepositoryQuery(): ProductCategoryRepositoryQuery | ||||
{ | { | ||||
return $this->repositoryQuery; | return $this->repositoryQuery; |
use Lc\CaracoleBundle\Factory\Product\ProductFactory; | use Lc\CaracoleBundle\Factory\Product\ProductFactory; | ||||
use Lc\CaracoleBundle\Repository\Product\ProductRepositoryQuery; | use Lc\CaracoleBundle\Repository\Product\ProductRepositoryQuery; | ||||
use Lc\CaracoleBundle\Repository\Product\ProductStore; | use Lc\CaracoleBundle\Repository\Product\ProductStore; | ||||
use Lc\CaracoleBundle\Solver\Product\ProductSolver; | |||||
class ProductContainer | class ProductContainer | ||||
{ | { | ||||
protected ProductFactory $factory; | protected ProductFactory $factory; | ||||
protected ProductSolver $solver; | |||||
protected ProductRepositoryQuery $repositoryQuery; | protected ProductRepositoryQuery $repositoryQuery; | ||||
protected ProductStore $store; | protected ProductStore $store; | ||||
public function __construct( | public function __construct( | ||||
ProductFactory $factory, | ProductFactory $factory, | ||||
ProductSolver $solver, | |||||
ProductRepositoryQuery $repositoryQuery, | ProductRepositoryQuery $repositoryQuery, | ||||
ProductStore $store | ProductStore $store | ||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->solver = $solver; | |||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
$this->store = $store; | $this->store = $store; | ||||
} | } | ||||
return $this->factory; | return $this->factory; | ||||
} | } | ||||
public function getSolver(): ProductSolver | |||||
{ | |||||
return $this->solver; | |||||
} | |||||
public function getRepositoryQuery(): ProductRepositoryQuery | public function getRepositoryQuery(): ProductRepositoryQuery | ||||
{ | { | ||||
return $this->repositoryQuery; | return $this->repositoryQuery; |
<?php | |||||
namespace Lc\CaracoleBundle\Controller; | |||||
use Lc\SovBundle\Controller\AbstractController as SovAbstractController; | |||||
class AbstractController extends SovAbstractController | |||||
{ | |||||
use ControllerTrait; | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Controller; | |||||
use Lc\CaracoleBundle\Container\Address\AddressContainer; | |||||
use Lc\CaracoleBundle\Container\Config\TaxRateContainer; | |||||
use Lc\CaracoleBundle\Container\Config\UnitContainer; | |||||
use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer; | |||||
use Lc\CaracoleBundle\Container\File\DocumentContainer; | |||||
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderPaymentContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderProductContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderProductReductionCatalogContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderProductRefundContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderReductionCartContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderReductionCreditContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderRefundContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderShopContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderStatusContainer; | |||||
use Lc\CaracoleBundle\Container\Order\OrderStatusHistoryContainer; | |||||
use Lc\CaracoleBundle\Container\PointSale\PointSaleContainer; | |||||
use Lc\CaracoleBundle\Container\Product\ProductCategoryContainer; | |||||
use Lc\CaracoleBundle\Container\Product\ProductContainer; | |||||
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; | |||||
use Lc\CaracoleBundle\Container\Reduction\ReductionCartContainer; | |||||
use Lc\CaracoleBundle\Container\Reduction\ReductionCatalogContainer; | |||||
use Lc\CaracoleBundle\Container\Reduction\ReductionCreditContainer; | |||||
use Lc\CaracoleBundle\Container\Section\OpeningContainer; | |||||
use Lc\CaracoleBundle\Container\Section\SectionContainer; | |||||
use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer; | |||||
use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer; | |||||
use Lc\CaracoleBundle\Container\User\UserMerchantContainer; | |||||
use Lc\CaracoleBundle\Container\User\UserPointSaleContainer; | |||||
use Lc\CaracoleBundle\Container\User\VisitorContainer; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | |||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||||
use Lc\CaracoleBundle\Resolver\SectionResolver; | |||||
use Lc\CaracoleBundle\Solver\Price\PriceSolver; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use Symfony\Component\Security\Core\Security; | |||||
trait ControllerTrait | |||||
{ | |||||
public static function getSubscribedServices() | |||||
{ | |||||
return array_merge( | |||||
parent::getSubscribedServices(), | |||||
[ | |||||
PriceSolver::class => PriceSolver::class, | |||||
MerchantResolver::class => MerchantResolver::class, | |||||
SectionResolver::class=> SectionResolver::class, | |||||
OrderShopContainer::class => OrderShopContainer::class, | |||||
AddressContainer::class => AddressContainer::class, | |||||
TaxRateContainer::class => TaxRateContainer::class, | |||||
UnitContainer::class => UnitContainer::class, | |||||
CreditHistoryContainer::class => CreditHistoryContainer::class, | |||||
DocumentContainer::class => DocumentContainer::class, | |||||
MerchantContainer::class => MerchantContainer::class, | |||||
OrderPaymentContainer::class => OrderPaymentContainer::class, | |||||
OrderProductContainer::class => OrderProductContainer::class, | |||||
OrderProductReductionCatalogContainer::class => OrderProductReductionCatalogContainer::class, | |||||
OrderProductRefundContainer::class => OrderProductRefundContainer::class, | |||||
OrderReductionCartContainer::class => OrderReductionCartContainer::class, | |||||
OrderReductionCreditContainer::class => OrderReductionCreditContainer::class, | |||||
OrderRefundContainer::class => OrderRefundContainer::class, | |||||
OrderStatusContainer::class => OrderStatusContainer::class, | |||||
OrderStatusHistoryContainer::class => OrderStatusHistoryContainer::class, | |||||
PointSaleContainer::class => PointSaleContainer::class, | |||||
ProductCategoryContainer::class => ProductCategoryContainer::class, | |||||
ProductContainer::class => ProductContainer::class, | |||||
ProductFamilyContainer::class => ProductFamilyContainer::class, | |||||
ReductionCartContainer::class => ReductionCartContainer::class, | |||||
ReductionCatalogContainer::class => ReductionCatalogContainer::class, | |||||
ReductionCreditContainer::class => ReductionCreditContainer::class, | |||||
OpeningContainer::class => OpeningContainer::class, | |||||
SectionContainer::class => SectionContainer::class, | |||||
MerchantSettingContainer::class => MerchantSettingContainer::class, | |||||
SectionSettingContainer::class => SectionSettingContainer::class, | |||||
UserMerchantContainer::class => UserMerchantContainer::class, | |||||
UserPointSaleContainer::class => UserPointSaleContainer::class, | |||||
VisitorContainer::class => VisitorContainer::class, | |||||
] | |||||
); | |||||
} | |||||
public function getMerchantSettingCurrent($settingName) | |||||
{ | |||||
return $this->getSettingValue($this->getCurrentMerchant(), $settingName); | |||||
} | |||||
public function getSectionSettingCurrent($settingName) | |||||
{ | |||||
return $this->getSettingValue($this->getCurrentSection(), $settingName); | |||||
} | |||||
public function getUserCurrent(): ?UserInterface | |||||
{ | |||||
return $this->get(Security::class)->getUser(); | |||||
} | |||||
public function getVisitorCurrent(): VisitorInterface | |||||
{ | |||||
} | |||||
public function getMerchantCurrent(): MerchantInterface | |||||
{ | |||||
return $this->get(MerchantResolver::class)->getCurrent(); | |||||
} | |||||
public function getUserMerchantCurrent(): UserMerchantInterface | |||||
{ | |||||
return $this->getUserMerchantContainer()->getBuilder()->createIfNotExist($this->getCurrentUser(), $this->getCurrentMerchant()); | |||||
} | |||||
public function getSectionCurrent(): SectionInterface | |||||
{ | |||||
return $this->get(SectionResolver::class)->getCurrent(); | |||||
} | |||||
public function getCartCurrent(): OrderShopInterface | |||||
{ | |||||
return $this->getOrderShopContainer()->getStore() | |||||
->setSection($this->getSectionCurrent()) | |||||
->getOneCartCurrent(); | |||||
} | |||||
public function getPriceSolver(): PriceSolver | |||||
{ | |||||
return $this->get(PriceSolver::class); | |||||
} | |||||
public function getOrderShopContainer(): OrderShopContainer | |||||
{ | |||||
return $this->get(OrderShopContainer::class); | |||||
} | |||||
public function getAddressContainer(): AddressContainer | |||||
{ | |||||
return $this->get(AddressContainer::class); | |||||
} | |||||
public function getTaxRateContainer(): TaxRateContainer | |||||
{ | |||||
return $this->get(TaxRateContainer::class); | |||||
} | |||||
public function getUnitContainer(): UnitContainer | |||||
{ | |||||
return $this->get(UnitContainer::class); | |||||
} | |||||
public function getCreditHistoryContainer(): CreditHistoryContainer | |||||
{ | |||||
return $this->get(CreditHistoryContainer::class); | |||||
} | |||||
public function getDocumentContainer(): DocumentContainer | |||||
{ | |||||
return $this->get(DocumentContainer::class); | |||||
} | |||||
public function getMerchantContainer(): MerchantContainer | |||||
{ | |||||
return $this->get(MerchantContainer::class); | |||||
} | |||||
public function getOrderPaymentContainer(): OrderPaymentContainer | |||||
{ | |||||
return $this->get(OrderPaymentContainer::class); | |||||
} | |||||
public function getOrderProductContainer(): OrderProductContainer | |||||
{ | |||||
return $this->get(OrderProductContainer::class); | |||||
} | |||||
public function getOrderProductReductionCatalogContainer(): OrderProductReductionCatalogContainer | |||||
{ | |||||
return $this->get(OrderProductReductionCatalogContainer::class); | |||||
} | |||||
public function getOrderProductRefundContainer(): OrderProductRefundContainer | |||||
{ | |||||
return $this->get(OrderProductRefundContainer::class); | |||||
} | |||||
public function getOrderReductionCartContainer(): OrderReductionCartContainer | |||||
{ | |||||
return $this->get(OrderReductionCartContainer::class); | |||||
} | |||||
public function getOrderReductionCreditContainer(): OrderReductionCreditContainer | |||||
{ | |||||
return $this->get(OrderReductionCreditContainer::class); | |||||
} | |||||
public function getOrderRefundContainer(): OrderRefundContainer | |||||
{ | |||||
return $this->get(OrderRefundContainer::class); | |||||
} | |||||
public function getOrderStatusContainer(): OrderStatusContainer | |||||
{ | |||||
return $this->get(OrderStatusContainer::class); | |||||
} | |||||
public function getOrderStatusHistoryContainer(): OrderStatusHistoryContainer | |||||
{ | |||||
return $this->get(OrderStatusHistoryContainer::class); | |||||
} | |||||
public function getPointSaleContainer(): PointSaleContainer | |||||
{ | |||||
return $this->get(PointSaleContainer::class); | |||||
} | |||||
public function getProductCategoryContainer(): ProductCategoryContainer | |||||
{ | |||||
return $this->get(ProductCategoryContainer::class); | |||||
} | |||||
public function getProductContainer(): ProductContainer | |||||
{ | |||||
return $this->get(ProductContainer::class); | |||||
} | |||||
public function getProductFamilyContainer(): ProductFamilyContainer | |||||
{ | |||||
return $this->get(ProductFamilyContainer::class); | |||||
} | |||||
public function getReductionCartContainer(): ReductionCartContainer | |||||
{ | |||||
return $this->get(ReductionCartContainer::class); | |||||
} | |||||
public function getReductionCatalogContainer(): ReductionCatalogContainer | |||||
{ | |||||
return $this->get(ReductionCatalogContainer::class); | |||||
} | |||||
public function getReductionCreditContainer(): ReductionCreditContainer | |||||
{ | |||||
return $this->get(ReductionCreditContainer::class); | |||||
} | |||||
public function getOpeningContainer(): OpeningContainer | |||||
{ | |||||
return $this->get(OpeningContainer::class); | |||||
} | |||||
public function getSectionContainer(): SectionContainer | |||||
{ | |||||
return $this->get(SectionContainer::class); | |||||
} | |||||
public function getMerchantSettingContainer(): MerchantSettingContainer | |||||
{ | |||||
return $this->get(MerchantSettingContainer::class); | |||||
} | |||||
public function getSectionSettingContainer(): SectionSettingContainer | |||||
{ | |||||
return $this->get(SectionSettingContainer::class); | |||||
} | |||||
public function getUserMerchantContainer(): UserMerchantContainer | |||||
{ | |||||
return $this->get(UserMerchantContainer::class); | |||||
} | |||||
public function getUserPointSaleContainer(): UserPointSaleContainer | |||||
{ | |||||
return $this->get(UserPointSaleContainer::class); | |||||
} | |||||
public function getVisitorContainer(): VisitorContainer | |||||
{ | |||||
return $this->get(VisitorContainer::class); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Controller\Order; | |||||
use Lc\CaracoleBundle\Controller\AbstractController; | |||||
use Lc\CaracoleBundle\Form\Order\OrderProductsType; | |||||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||||
use Symfony\Component\HttpFoundation\JsonResponse; | |||||
use Symfony\Component\HttpFoundation\RedirectResponse; | |||||
use Symfony\Component\HttpFoundation\Request; | |||||
use Symfony\Component\Routing\Annotation\Route; | |||||
class CartController extends AbstractController | |||||
{ | |||||
protected ProductFamilyInterface $productFamily; | |||||
protected array $orderProducts = []; | |||||
public function addProductFamily(Request $request): JsonResponse | |||||
{ | |||||
$user = $this->getUserCurrent(); | |||||
$visitor = $this->getVisitorCurrent(); | |||||
$return = []; | |||||
$data = $request->request->all(); | |||||
if (isset($data['order_products']['id_product_family'])) { | |||||
$idProductFamily = $data['order_products']['id_product_family']; | |||||
$this->productFamily = $this->getProductFamilyContainer()->getStore()->getOneById($idProductFamily); | |||||
// alerte si cookies non acceptés | |||||
if (!$user && !$visitor) { | |||||
$this->addFlash( | |||||
'error', | |||||
'Vous devez <a href="' . $this->getRouter()->generate( | |||||
'frontend_page', | |||||
['devAlias' => 'politique-de-confidentialite'] | |||||
) . '">accepter les cookies</a> ou vous <a href="' . $this->getRouter()->generate( | |||||
'fos_user_security_login' | |||||
) . '">connecter</a> pour ajouter un produit.' | |||||
); | |||||
return false; | |||||
} | |||||
if ($this->productFamily) { | |||||
$form = $this->createForm( | |||||
OrderProductsType::class, | |||||
['id_product_family' => $this->productFamily->getId()] | |||||
); | |||||
$form->handleRequest($request); | |||||
if ($form->isSubmitted() && $form->isValid()) { | |||||
$orderShop = $this->getOrderShopContainer()->getBuilder()->createIfNotExist( | |||||
$this->getSectionCurrent(), | |||||
$this->getUserCurrent(), | |||||
$this->getVisitorCurrent() | |||||
); | |||||
$data = $form->getData(); | |||||
foreach ($data as $orderProduct) { | |||||
if ($orderProduct instanceof OrderProductInterface) { | |||||
if ($orderProduct->getQuantityOrder() > 0) { | |||||
$addOrderProduct = $this->getOrderShopContainer()->getBuilder()->addOrderProduct( | |||||
$orderShop, | |||||
$orderProduct | |||||
); | |||||
} | |||||
if (isset($addOrderProduct) && $addOrderProduct && $orderProduct->getQuantityOrder() > 0) { | |||||
$this->orderProducts[] = $orderProduct; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return new JsonResponse($return); | |||||
} | |||||
/** | |||||
* @Route("/order-reduction-cart/delete/{id}", name="frontend_cart_delete_reduction_cart") | |||||
*/ | |||||
public function deleteReductionCart(Request $request): RedirectResponse | |||||
{ | |||||
$entityManager = $this->getEntityManager(); | |||||
$id = $request->get('id'); | |||||
$orderReductionCart = $this->getOrderReductionCartContainer()->getStore()->getOneById((int)$id); | |||||
$orderShop = $this->getCartCurrent(); | |||||
if ($orderReductionCart && $orderShop->getOrderReductionCarts() && $orderShop->getOrderReductionCarts( | |||||
)->contains($orderReductionCart)) { | |||||
$entityManager->remove($orderReductionCart); | |||||
$entityManager->flush(); | |||||
$this->addFlash('success', 'La réduction a bien été supprimée de votre panier.'); | |||||
} else { | |||||
$this->addFlash('error', 'Une erreur est survenue lors de la suppression de la réduction. '); | |||||
} | |||||
return $this->redirectToReferer($request); | |||||
} | |||||
/** | |||||
* @Route("/reduction-credit/add/{id}", name="frontend_order_cart_reduction_credit") | |||||
*/ | |||||
public function addReductionCredit(Request $request): RedirectResponse | |||||
{ | |||||
$id = $request->get('id'); | |||||
$orderShop = $this->getCartCurrent(); | |||||
$user = $this->getUserCurrent(); | |||||
$orderShopContainer = $this->getOrderShopContainer(); | |||||
$reductionCredit = $this->getReductionCreditContainer()->getStore()->getOneById($id); | |||||
if ($orderShop && $user && $reductionCredit | |||||
&& $orderShopContainer->getStore()->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) | |||||
&& !$orderShopContainer->getSolver()->isReductionCreditAddedToOrder($orderShop, $reductionCredit)) { | |||||
$return = $orderShopContainer->getBuilder()->addReductionCredit($orderShop, $reductionCredit); | |||||
if ($return) { | |||||
$this->addFlash('success', 'Votre avoir a bien été ajouté à votre panier.'); | |||||
} else { | |||||
$this->addFlash( | |||||
'error', | |||||
'Vous ne pouvez pas effectuer cette action. Le montant de la commande est insuffisant.' | |||||
); | |||||
} | |||||
} else { | |||||
$this->addFlash('error', "Impossible d'effectuer cette action"); | |||||
} | |||||
return $this->redirectToReferer($request); | |||||
} | |||||
/** | |||||
* @Route("/order-reduction-credit/delete/{id}", name="frontend_cart_delete_reduction_credit") | |||||
*/ | |||||
public function deleteReductionCredit(Request $request): RedirectResponse | |||||
{ | |||||
$entityManager = $this->getEntityManager(); | |||||
$id = $request->get('id'); | |||||
$orderReductionCredit = $this->getOrderReductionCreditContainer()->getStore()->getOneById((int)$id); | |||||
$orderShop = $this->getCartCurrent(); | |||||
if ($orderReductionCredit && $orderShop->getOrderReductionCredits() && $orderShop->getOrderReductionCredits( | |||||
)->contains($orderReductionCredit)) { | |||||
$entityManager->remove($orderReductionCredit); | |||||
$entityManager->flush(); | |||||
$this->addFlash('success', 'Votre avoir a bien été supprimé de votre panier.'); | |||||
} else { | |||||
$this->addFlash('error', 'Une erreur est survenue lors de la suppression de votre avoir. '); | |||||
} | |||||
$referer = $this->getReferer($request); | |||||
if ($referer) { | |||||
return $this->redirect($referer); | |||||
} else { | |||||
return $this->redirectToRoute('frontend_order_cart'); | |||||
} | |||||
} | |||||
protected function redirectToReferer(Request $request): RedirectResponse | |||||
{ | |||||
$referer = $this->getReferer($request); | |||||
if ($referer) { | |||||
return $this->redirect($referer); | |||||
} else { | |||||
return $this->redirectToRoute('frontend_order_cart'); | |||||
} | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Form\Order; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\CaracoleBundle\Form\Product\ProductToIdTransformer; | |||||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class OrderProductType extends AbstractType | |||||
{ | |||||
protected EntityManagerInterface $entityManager; | |||||
protected ProductToIdTransformer $productTransformer; | |||||
public function __construct(EntityManagerInterface $entityManager, ProductToIdTransformer $productTransformer) | |||||
{ | |||||
$this->entityManager = $entityManager; | |||||
$this->productTransformer = $productTransformer; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder | |||||
->add( | |||||
'quantityOrder', | |||||
NumberType::class, | |||||
array( | |||||
'html5' => true | |||||
) | |||||
) | |||||
->add('product', HiddenType::class); | |||||
$builder->get('product')->addModelTransformer($this->productTransformer); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults( | |||||
[ | |||||
'data_class' => $this->entityManager->getEntityName(OrderProductInterface::class), | |||||
] | |||||
); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Form\Order; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class OrderProductsType extends AbstractType | |||||
{ | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder->add( | |||||
'orderProducts', | |||||
CollectionType::class, | |||||
array( | |||||
'label' => false, | |||||
'entry_type' => OrderProductType::class, | |||||
'entry_options' => ['label' => false], | |||||
'allow_add' => true, | |||||
'allow_delete' => true, | |||||
'required' => true | |||||
) | |||||
); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults( | |||||
[ | |||||
] | |||||
); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Form\Product; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | |||||
use Symfony\Component\Form\DataTransformerInterface; | |||||
use Symfony\Component\Form\Exception\TransformationFailedException; | |||||
class ProductToIdTransformer implements DataTransformerInterface | |||||
{ | |||||
private EntityManagerInterface $entityManager; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->entityManager = $entityManager; | |||||
} | |||||
public function transform($product) | |||||
{ | |||||
if (null === $product) { | |||||
return ''; | |||||
} | |||||
return $product->getId(); | |||||
} | |||||
public function reverseTransform($productId) | |||||
{ | |||||
if (!$productId) { | |||||
return; | |||||
} | |||||
$product = $this->entityManager->getRepository( | |||||
$this->entityManager->getEntityName(ProductInterface::class) | |||||
)->find($productId); | |||||
if (null === $product) { | |||||
throw new TransformationFailedException( | |||||
sprintf( | |||||
'An issue with number "%s" does not exist!', | |||||
$productId | |||||
) | |||||
); | |||||
} | |||||
return $product; | |||||
} | |||||
} |
return $this->andWhere('.propertyOrganicLabel IS NOT NULL'); | return $this->andWhere('.propertyOrganicLabel IS NOT NULL'); | ||||
} | } | ||||
public function filterIsNovelty() | |||||
{ | |||||
return $this->andWhere(':now <= e.propertyNoveltyExpirationDate') | |||||
->setParameter('now', new \DateTime()) ; | |||||
} | |||||
public function filterByTerms($terms): self | public function filterByTerms($terms): self | ||||
{ | { | ||||
$this->andWhere('.title LIKE :terms OR cat.title LIKE :terms'); | $this->andWhere('.title LIKE :terms OR cat.title LIKE :terms'); |
return $query; | return $query; | ||||
} | } | ||||
//getProductFamiliesByCategory | |||||
// getProductFamiliesByCategory | |||||
public function getByCategory(ProductCategoryInterface $productCategory, $query = null) | public function getByCategory(ProductCategoryInterface $productCategory, $query = null) | ||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
//getProductFamiliesNovelties | |||||
public function getByNovelties($query = null) | |||||
// getProductFamiliesNovelties | |||||
public function getNovelty($query = null) | |||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
//getProductFamiliesOrganics | |||||
public function getOrganics($query = null) | |||||
// getProductFamiliesOrganics | |||||
public function getOrganic($query = null) | |||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
// getProductFamiliesOnDiscount | |||||
public function getDiscount($organizeByParentCategory = false, $user = null, $query = null) | |||||
{ | |||||
return $this->getWithReductions($this->getOnline($query), $user, $organizeByParentCategory, true); | |||||
} | |||||
// getProductFamiliesFavorites | |||||
public function getFavorite($user = null) | |||||
{ | |||||
if ($user) { | |||||
return $this->getWithReductions($user->getProductFamiliesFavorites(), $user, false, true); | |||||
} | |||||
return []; | |||||
} | |||||
//findByTerms | //findByTerms | ||||
public function getByTerms($terms, $maxResults = false, $query = null) | public function getByTerms($terms, $maxResults = false, $query = null) | ||||
{ | { |
$this->visitorStore = $visitorStore; | $this->visitorStore = $visitorStore; | ||||
} | } | ||||
// getVisitorCurrent | |||||
public function getCurrent() | public function getCurrent() | ||||
{ | { | ||||
$cookie = $this->requestStack->getCurrentRequest()->cookies->get( | $cookie = $this->requestStack->getCurrentRequest()->cookies->get( |
<?php | |||||
namespace Lc\CaracoleBundle\Solver\Product; | |||||
class ProductCategorySolver | |||||
{ | |||||
} | |||||