Browse Source

Pages commandes suppresion reduction

feature/export_comptable
Fab 4 years ago
parent
commit
dd24e157a9
20 changed files with 426 additions and 180 deletions
  1. +109
    -112
      ShopBundle/Controller/Backend/OrderController.php
  2. +4
    -4
      ShopBundle/Form/Backend/Order/AddOrderReductionCartType.php
  3. +4
    -4
      ShopBundle/Form/Backend/Order/AddOrderReductionCreditType.php
  4. +3
    -3
      ShopBundle/Form/Backend/Order/AddPoductToOrderType.php
  5. +43
    -0
      ShopBundle/Form/Backend/Order/DeleteOrderReductionCartType.php
  6. +43
    -0
      ShopBundle/Form/Backend/Order/DeleteOrderReductionCreditType.php
  7. +18
    -0
      ShopBundle/Resources/public/js/backend/script/default/utils.js
  8. +36
    -12
      ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js
  9. +35
    -15
      ShopBundle/Resources/translations/lcshop.fr.yaml
  10. +6
    -4
      ShopBundle/Resources/views/backend/order/edit-cart.html.twig
  11. +1
    -1
      ShopBundle/Resources/views/backend/order/form/modal_addproducttoorder.html.twig
  12. +6
    -6
      ShopBundle/Resources/views/backend/order/form/modal_addreductioncart.html.twig
  13. +6
    -6
      ShopBundle/Resources/views/backend/order/form/modal_addreductioncredit.html.twig
  14. +30
    -0
      ShopBundle/Resources/views/backend/order/form/modal_deletereductioncart.html.twig
  15. +30
    -0
      ShopBundle/Resources/views/backend/order/form/modal_deletereductioncredit.html.twig
  16. +14
    -4
      ShopBundle/Resources/views/backend/order/macros.html.twig
  17. +7
    -6
      ShopBundle/Services/Order/OrderUtils.php
  18. +3
    -0
      ShopBundle/Services/Order/OrderUtilsReductionTrait.php
  19. +3
    -2
      ShopBundle/Services/Price/OrderShopPriceUtils.php
  20. +25
    -1
      ShopBundle/Services/Utils.php

+ 109
- 112
ShopBundle/Controller/Backend/OrderController.php View File

use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use Lc\ShopBundle\Context\OrderPaymentInterface; use Lc\ShopBundle\Context\OrderPaymentInterface;
use Lc\ShopBundle\Context\OrderProductInterface; use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\UserInterface; use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType; use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType;
use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCartType;
use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCreditType;
use Lc\ShopBundle\Form\Backend\Order\OrderDeliveryAddressType; use Lc\ShopBundle\Form\Backend\Order\OrderDeliveryAddressType;
use Lc\ShopBundle\Form\Backend\Order\OrderInvoiceAddressType; use Lc\ShopBundle\Form\Backend\Order\OrderInvoiceAddressType;
use Lc\ShopBundle\Form\Backend\Order\OrderPaymentType; use Lc\ShopBundle\Form\Backend\Order\OrderPaymentType;
use Lc\ShopBundle\Form\Backend\Order\OrderProductsType; use Lc\ShopBundle\Form\Backend\Order\OrderProductsType;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCartType;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCartType;
use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCreditType;
use Lc\ShopBundle\Form\Backend\Order\OrderStatusType; use Lc\ShopBundle\Form\Backend\Order\OrderStatusType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;


public function addProductToOrderAction() public function addProductToOrderAction()
{ {

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$orderProductClass = $this->em->getClassMetadata(OrderProductInterface::class); $orderProductClass = $this->em->getClassMetadata(OrderProductInterface::class);
$formAddProductToOrder = $this->createForm(AddPoductToOrderType::class); $formAddProductToOrder = $this->createForm(AddPoductToOrderType::class);

$formAddProductToOrder->handleRequest($this->request); $formAddProductToOrder->handleRequest($this->request);

if ($formAddProductToOrder->get('product')->getData() == null) { if ($formAddProductToOrder->get('product')->getData() == null) {
$response['status'] = 'error'; $response['status'] = 'error';
$response['message'] = 'Vous devez choisir un produit dans la liste'; $response['message'] = 'Vous devez choisir un produit dans la liste';
public function orderProductsAction() public function orderProductsAction()
{ {


$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$formOrderProducts = $this->createForm(OrderProductsType::class, $orderShop); $formOrderProducts = $this->createForm(OrderProductsType::class, $orderShop);

$formOrderProducts->handleRequest($this->request); $formOrderProducts->handleRequest($this->request);




$error = false; $error = false;
// dump($formOrderProducts->get('orderProducts')->getData()); // dump($formOrderProducts->get('orderProducts')->getData());
foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
if($this->orderUtils->isProductAvailable($orderProduct->getProduct(),$orderProduct->getQuantityOrder())) {
if ($this->orderUtils->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder())) {
if ($orderProduct->getQuantityOrder() <= 0) { if ($orderProduct->getQuantityOrder() <= 0) {
$this->em->remove($orderProduct); $this->em->remove($orderProduct);
} else { } else {
$this->em->persist($orderProduct); $this->em->persist($orderProduct);
} }
}else{
} else {
$error = true; $error = true;
$response['status'] = 'error'; $response['status'] = 'error';
$response['message'] = 'Le prduit n\'est pas disponible dans cette quantité'; $response['message'] = 'Le prduit n\'est pas disponible dans cette quantité';
} }
} }
if(!$error) {
if (!$error) {
$this->em->flush(); $this->em->flush();
$response['status'] = 'success'; $response['status'] = 'success';
$response['message'] = 'La commande a bien été modifié'; $response['message'] = 'La commande a bien été modifié';
public function orderInvoiceAddressAction() public function orderInvoiceAddressAction()
{ {


$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$formOrderInvoiceAddress = $this->createForm(OrderInvoiceAddressType::class, $orderShop); $formOrderInvoiceAddress = $this->createForm(OrderInvoiceAddressType::class, $orderShop);

$formOrderInvoiceAddress->handleRequest($this->request); $formOrderInvoiceAddress->handleRequest($this->request);


if ($formOrderInvoiceAddress->isSubmitted() && $formOrderInvoiceAddress->isValid()) { if ($formOrderInvoiceAddress->isSubmitted() && $formOrderInvoiceAddress->isValid()) {
//TODO si la commande est valide on hydrate le champ invoiceAddresText et on vide invoiceAddres //TODO si la commande est valide on hydrate le champ invoiceAddresText et on vide invoiceAddres
$this->em->persist($orderShop); $this->em->persist($orderShop);
$this->em->flush(); $this->em->flush();
$response['status'] = 'success';
$response['message'] = 'La commande a bien été modifié';
$this->utils->addFlash('success', 'success.order.changeInvoiceAddress');
} else { } else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('success', 'error.form.submitted');
} }
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return new Response(json_encode($response));
return $this->createOrderAjaxReponse($orderShop);
} }


public function orderStatusAction() public function orderStatusAction()
{ {

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$formOrderStatus = $this->createForm(OrderStatusType::class, $orderShop); $formOrderStatus = $this->createForm(OrderStatusType::class, $orderShop);

$formOrderStatus->handleRequest($this->request); $formOrderStatus->handleRequest($this->request);


if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) { if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) {


if ($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)) { if ($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)) {
$this->addFlash('success', 'La commande a bien été modifié.');
$this->utils->addFlash('success', 'success.order.changeStatus');
} }
} else { } else {
$this->addFlash('error', 'Une erreur s\'est produite');
$this->utils->addFlash('success', 'error.form.submitted');
} }


return $this->redirectToRoute('easyadmin', [ return $this->redirectToRoute('easyadmin', [
'action' => 'show', 'action' => 'show',
'entity' => $this->request->query->get('entity'), 'entity' => $this->request->query->get('entity'),
'id' => $id
'id' => $orderShop->getId()
]); ]);


} }






public function orderPaymentAction() public function orderPaymentAction()
{ {

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$orderPaymentClass = $this->em->getClassMetadata(OrderPaymentInterface::class); $orderPaymentClass = $this->em->getClassMetadata(OrderPaymentInterface::class);

$orderPayment = new $orderPaymentClass->name; $orderPayment = new $orderPaymentClass->name;

$formOrderPayment = $this->createForm(OrderPaymentType::class, $orderPayment); $formOrderPayment = $this->createForm(OrderPaymentType::class, $orderPayment);


$formOrderPayment->handleRequest($this->request); $formOrderPayment->handleRequest($this->request);
$orderPayment->setOrderShop($orderShop); $orderPayment->setOrderShop($orderShop);
$this->em->persist($orderPayment); $this->em->persist($orderPayment);
$this->em->flush(); $this->em->flush();
$response['status'] = 'success';
$response['message'] = 'La paiement a bien été ajouté';
$this->utils->addFlash('success', 'success.order.addPayment');
} else { } else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('success', 'error.form.submitted');
} }
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return new Response(json_encode($response));
return $this->createOrderAjaxReponse($orderShop);
} }



public function orderReductionCartAction()
public function addOrderReductionCartAction()
{ {
$orderShop = $this->getOrderShopEntity();
$formAddOrderReductionCart = $this->createForm(AddOrderReductionCartType::class, $orderShop);
$formAddOrderReductionCart->handleRequest($this->request);


$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$formOrderReductionCart = $this->createForm(OrderReductionCartType::class, $orderShop);
if ($formAddOrderReductionCart->isSubmitted() && $formAddOrderReductionCart->isValid()) {


$formOrderReductionCart->handleRequest($this->request);

if ($formOrderReductionCart->isSubmitted() && $formOrderReductionCart->isValid()) {
$reductionCart = $formOrderReductionCart->get('reductionCart')->getData();
$reductionCart = $formAddOrderReductionCart->get('reductionCart')->getData();
$orderShop->reductionError = array(); $orderShop->reductionError = array();
if ($this->orderUtils->isReductionCartAllowAddToOrder($orderShop, $reductionCart)) { if ($this->orderUtils->isReductionCartAllowAddToOrder($orderShop, $reductionCart)) {
$orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart); $orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart);
$this->em->persist($orderReductionCart); $this->em->persist($orderReductionCart);
$this->em->flush(); $this->em->flush();


$this->utils->addFlash('success', 'success.order.addReductionCart');
}
} else {
$this->utils->addFlash('error', $formAddOrderReductionCart->getErrors());
}
return $this->createOrderAjaxReponse($orderShop);
}

public function addOrderReductionCreditAction()
{
$orderShop = $this->getOrderShopEntity();
$formAddOrderReductionCredit = $this->createForm(AddOrderReductionCreditType::class, $orderShop);
$formAddOrderReductionCredit->handleRequest($this->request);


$response['status'] = 'success';
$response['message'] = 'La réduction a bien été ajouté';
if ($formAddOrderReductionCredit->isSubmitted() && $formAddOrderReductionCredit->isValid()) {
$reductionCredit = $formAddOrderReductionCredit->get('reductionCredit')->getData();
if ($this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)) {


} else {
$response['status'] = 'error';
$response['message'] = 'Cette réduction ne peut pas être appliqué sur cette commande';
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
$this->em->persist($orderReductionCredit);
$this->em->flush();


$response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
}
$response['message'] .= '</ul>';
$this->utils->addFlash('success', 'success.order.addReductionCredit');
} }


} else { } else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('error', $formAddOrderReductionCredit->getErrors());
} }
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return new Response(json_encode($response));
return $this->createOrderAjaxReponse($orderShop);
} }




public function orderReductionCreditAction()
public function deleteOrderReductionCartAction()
{ {

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$formOrderReductionCredit = $this->createForm(OrderReductionCreditType::class, $orderShop);

$formOrderReductionCredit->handleRequest($this->request);

if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) {
$reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData();
$orderShop->reductionError = array();
if ($this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)) {
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
$this->em->persist($orderReductionCredit);
$orderShop = $this->getOrderShopEntity();
$formDeleteOrderReductionCart = $this->createForm(DeleteOrderReductionCartType::class);
$formDeleteOrderReductionCart->handleRequest($this->request);

if ($formDeleteOrderReductionCart->isSubmitted() && $formDeleteOrderReductionCart->isValid()) {
$orderReductionCart = $this->em->getRepository(OrderReductionCartInterface::class)->find($formDeleteOrderReductionCart->get('id')->getData());
if($orderReductionCart && $orderShop->getOrderReductionCarts()->contains($orderReductionCart)){
$orderShop->removeOrderReductionCart($orderReductionCart);
$this->em->remove($orderReductionCart);
$this->em->flush(); $this->em->flush();


$this->utils->addFlash('warning', 'success.order.removeReductionCart');
}


$response['status'] = 'success';
$response['message'] = 'L\'avoir a bien été ajouté';
} else {
$this->utils->addFlash('error', $formDeleteOrderReductionCart->getErrors());
}
return $this->createOrderAjaxReponse($orderShop);
}


} else {
$response['status'] = 'error';
$response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande';
public function deleteOrderReductionCreditAction()
{
$orderShop = $this->getOrderShopEntity();
$formDeleteOrderReductionCredit = $this->createForm(DeleteOrderReductionCreditType::class);
$formDeleteOrderReductionCredit->handleRequest($this->request);

if ($formDeleteOrderReductionCredit->isSubmitted() && $formDeleteOrderReductionCredit->isValid()) {
$orderReductionCredit = $this->em->getRepository(OrderReductionCreditInterface::class)->find($formDeleteOrderReductionCredit->get('id')->getData());
if($formDeleteOrderReductionCredit && $orderShop->getOrderReductionCredits()->contains($orderReductionCredit)){
$orderShop->removeOrderReductionCredit($orderReductionCredit);
$this->em->remove($orderReductionCredit);
$this->em->flush();


$response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
}
$response['message'] .= '</ul>';
$this->utils->addFlash('warning', 'success.order.removeReductionCredit');
} }


} else { } else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('error', $formDeleteOrderReductionCredit->getErrors());
} }
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return $this->createOrderAjaxReponse($orderShop);
}

protected function createOrderAjaxReponse(OrderShopInterface $order)
{
$response['flashMessages'] = $this->utils->getFlashMessages();
$response['data'] = $this->orderUtils->getOrderAsJsonObject($order);
return new Response(json_encode($response)); return new Response(json_encode($response));
} }




public function renderOrderCartTemplate($actionName, $templatePath, array $parameters = []) public function renderOrderCartTemplate($actionName, $templatePath, array $parameters = [])
{ {
dump($actionName);
if ($actionName == 'show') { if ($actionName == 'show') {
if (!isset($parameters['form_order_delivery_address'])) { if (!isset($parameters['form_order_delivery_address'])) {
$parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); $parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView();
} }
$parameters['form_order_reduction_credit'] = $this->createOrderForm(OrderReductionCreditType::class, 'orderReductionCredit', $parameters)->createView();
$parameters['form_order_reduction_cart'] = $this->createOrderForm(OrderReductionCartType::class, 'orderReductionCart', $parameters)->createView();
$parameters['form_add_order_reduction_credit'] = $this->createOrderForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView();
$parameters['form_add_order_reduction_cart'] = $this->createOrderForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_cart'] = $this->createOrderForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_credit'] = $this->createOrderForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView();
$parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); $parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView();
$parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); $parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView();
$parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); $parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();


if ($actionName == 'show') { if ($actionName == 'show') {
if (!isset($parameters['form_order_delivery_address'])) { if (!isset($parameters['form_order_delivery_address'])) {

$parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); $parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView();
} }
$parameters['form_order_reduction_credit'] = $this->createOrderForm(OrderReductionCreditType::class, 'orderReductionCredit', $parameters)->createView();
$parameters['form_order_reduction_cart'] = $this->createOrderForm(OrderReductionCartType::class, 'orderReductionCart', $parameters)->createView();
$parameters['form_add_order_reduction_credit'] = $this->createOrderForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView();
$parameters['form_add_order_reduction_cart'] = $this->createOrderForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_cart'] = $this->createOrderForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_credit'] = $this->createOrderForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView();
$parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); $parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView();
$parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); $parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView();
$parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); $parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
'order' => $this->orderUtils->getOrderAsJsonObject($entity) 'order' => $this->orderUtils->getOrderAsJsonObject($entity)


]; ];
dump($this->entity['name']);
return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]); return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
} }


]); ]);
} }


protected function getOrderShopEntity()
{
$easyadmin = $this->request->attributes->get('easyadmin');
return $easyadmin['item'];
}

} }

ShopBundle/Form/Backend/Order/OrderReductionCartType.php → ShopBundle/Form/Backend/Order/AddOrderReductionCartType.php View File

use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;


class OrderReductionCartType extends AbstractType
class AddOrderReductionCartType extends AbstractType
{ {
protected $em; protected $em;


'required' => true, 'required' => true,
'mapped'=>false 'mapped'=>false
)); ));
$builder->add('saveOrderReductionCart', ButtonType::class, array(
'label' => 'field.OrderShop.saveOrderReductionCart'
$builder->add('add', ButtonType::class, array(
'label' => 'action.add'
)); ));




'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(), 'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(),
]); ]);
} }
}
}

ShopBundle/Form/Backend/Order/OrderReductionCreditType.php → ShopBundle/Form/Backend/Order/AddOrderReductionCreditType.php View File

use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;


class OrderReductionCreditType extends AbstractType
class AddOrderReductionCreditType extends AbstractType
{ {
protected $em; protected $em;
protected $orderUtils; protected $orderUtils;
'required' => true, 'required' => true,
'mapped'=>false 'mapped'=>false
)); ));
$builder->add('saveOrderReductionCredit', ButtonType::class, array(
'label' => 'field.OrderShop.saveOrderReductionCredit'
$builder->add('add', ButtonType::class, array(
'label' => 'action.add'
)); ));




'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(), 'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(),
]); ]);
} }
}
}

+ 3
- 3
ShopBundle/Form/Backend/Order/AddPoductToOrderType.php View File

->add('quantity', IntegerType::class, array( ->add('quantity', IntegerType::class, array(
'mapped' => false 'mapped' => false
)) ))
->add('addProductToOrder', ButtonType::class, array(
'label'=> 'field.OrderShop.addOrderToProduct'
->add('add', ButtonType::class, array(
'label'=> 'action.add'
)); ));
} }


'translation_domain'=>'lcshop' 'translation_domain'=>'lcshop'
]); ]);
} }
}
}

+ 43
- 0
ShopBundle/Form/Backend/Order/DeleteOrderReductionCartType.php View File

<?php

namespace Lc\ShopBundle\Form\Backend\Order;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
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 DeleteOrderReductionCartType extends AbstractType
{
protected $em ;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em ;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', HiddenType::class)
->add('delete', ButtonType::class);

/* ->add('id', HiddenType::class);*/
}

public function configureOptions(OptionsResolver $resolver)
{
/*$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(OrderReductionCartInterface::class)->getName(),
]);*/
}
}

+ 43
- 0
ShopBundle/Form/Backend/Order/DeleteOrderReductionCreditType.php View File

<?php

namespace Lc\ShopBundle\Form\Backend\Order;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
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 DeleteOrderReductionCreditType extends AbstractType
{
protected $em ;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em ;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', HiddenType::class)
->add('delete', ButtonType::class);

/* ->add('id', HiddenType::class);*/
}

public function configureOptions(OptionsResolver $resolver)
{
/*$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(OrderReductionCartInterface::class)->getName(),
]);*/
}
}

+ 18
- 0
ShopBundle/Resources/public/js/backend/script/default/utils.js View File







function setFlashMessages(flashMessages){
for (var type in flashMessages) {
for (var key in flashMessages[type]) {
generateNotice(type, flashMessages[type][key]);
}
}
}

function generateNotice(type, text) { function generateNotice(type, text) {
toastr.options.timeOut = 30000; toastr.options.timeOut = 30000;
toastr[type](text); toastr[type](text);
} }
});*/ });*/
} }


function checkFormValidity(formId){
if(!document.getElementById(formId.substr(1)).checkValidity()){
document.getElementById(formId.substr(1)).reportValidity()
return false;
}else{
return true;
}
}

+ 36
- 12
ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js View File

}, },
mounted: function () { mounted: function () {
this.updateOrder(window.orderObject); this.updateOrder(window.orderObject);
this.preventFormSubmit();
//log($(this.$el).find('#orderProductsForm').replace(/__name__/g, 0)); //log($(this.$el).find('#orderProductsForm').replace(/__name__/g, 0));
}, },
methods: { methods: {
preventFormSubmit: function (){
$(document).keypress(function(e) {
if (e.which == 13) {
e.preventDefault();
}
});
},
addProductToOrder: function () { addProductToOrder: function () {
this.postForm('#addProductToOrderForm', false); this.postForm('#addProductToOrderForm', false);
}, },
this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability'); this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability');
}, },
addOrderReductionCart: function () { addOrderReductionCart: function () {
this.postForm('#orderReductionCartForm', '#modal-reduction-cart');
this.postForm('#addOrderReductionCartForm', '#modal-add-reduction-cart');
},
modalOrderReductionCart: function (id) {
$('#modal-delete-reduction-cart').find('#delete_order_reduction_cart_id').val(id);
$('#modal-delete-reduction-cart').modal("show")
},
deleteOrderReductionCart: function () {
this.postForm('#deleteOrderReductionCartForm', '#modal-delete-reduction-cart');
},
modalOrderReductionCredit: function (id) {
$('#modal-delete-reduction-credit').find('#delete_order_reduction_credit_id').val(id);
$('#modal-delete-reduction-credit').modal("show")
},
deleteOrderReductionCredit: function () {
this.postForm('#deleteOrderReductionCreditForm', '#modal-delete-reduction-credit');
}, },
addOrderReductionCredit: function () { addOrderReductionCredit: function () {
this.postForm('#orderReductionCreditForm', '#modal-reduction-credit');
this.postForm('#addOrderReductionCreditForm', '#modal-add-reduction-credit');
}, },


postForm: function (formId, modalId) { postForm: function (formId, modalId) {
var app = this; var app = this;
this.isLoading = true; this.isLoading = true;
if (modalId) $(modalId).modal('hide'); if (modalId) $(modalId).modal('hide');
$.ajax({
url: $(formId).prop('action'),
method: "POST",
data: $(formId).serialize(),
dataType: "json",
success: function (response) {
generateNotice(response.status, response.message);
app.updateOrder(response.data);
}
});
if(checkFormValidity(formId)) {
$.ajax({
url: $(formId).prop('action'),
method: "POST",
data: $(formId).serialize(),
dataType: "json",
success: function (response) {
setFlashMessages(response.flashMessages);
app.updateOrder(response.data);
}
});
}
}, },
updateOrder: function (orderObject) { updateOrder: function (orderObject) {
this.orderProducts = orderObject.orderProducts; this.orderProducts = orderObject.orderProducts;

+ 35
- 15
ShopBundle/Resources/translations/lcshop.fr.yaml View File

None: Aucune valeur None: Aucune valeur
label.form.empty_value: Choisissez une option label.form.empty_value: Choisissez une option
form.label.delete: Supprimer l'image form.label.delete: Supprimer l'image

success:
order:
addPayment: Le paiement a bien été ajouté
changeStatus: Le statut de la commande a été modifié
changeInvoiceAddress: L'adresse de facuration a bien été modifié
changeDeliveryAddress: L'adresse de livraison a bien été modifié
error:
form:
submitted: Une erreur est survenue à la soumission du formulaire
order:
closeSale: Les commandes sont actuellements fermés
invoiceAddressMissing: Vous n'avez pas d'adresse de facturation
deliveryAddressMissing: Vous n'avez pas d'adresse de livraison
deliverySlotMissing: Vous n'avez pas de créneau de livraison
productUnavailable: Certains produits ne sont plus disponibles
nextStatusNotAllow: La commande ne peut passer à ce statut
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité

reductionCart:
conditionsError: Cette réduction ne peut pas être appliqué sur cette commande
date: La réduction n'est plus active
pointSale: L'ambassade ne correspond pas
deliveryZone: La zone de livraison ne correspond pas
deliverySlot: La créneau de livraison ne correspond pas
groupUser: Le(s) groupe(s) utilisateurs ne correspondent pas
user: L'utilisateur ne correspond pas
combinable: La réduction n'est pas cumulable avec celle dejà appliqué
amountMin: Le montant minimum de commandes n'est pas respecté
qauntity: La réduction n'est plus disponible
quantityPerUser: La reduction n'est plus disponible pour cet utilisateur
reductionCredit:
userNotAllow: Cet avoir n'est pas disponible pour cet utilisateur
alreayUse: Cet avoir a déjà été utilisé
field: field:
error:
orderStatus:
nextStatusAllowed: La commande ne peut passer à ce statut
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité
reductionCart:
date: La réduction n'est plus active
pointSale: L'ambassade ne correspond pas
deliveryZone: La zone de livraison ne correspond pas
deliverySlot: La créneau de livraison ne correspond pas
groupUser: Le(s) groupe(s) utilisateurs ne correspondent pas
user: L'utilisateur ne correspond pas
combinable: La réduction n'est pas cumulable avec celle dejà appliqué
amountMin: Le montant minimum de commandes n'est pas respecté
qauntity: La réduction n'est plus disponible
quantityPerUser: La reduction n'est plus disponible pour cet utilisateur
default: default:
placeholder: Choisissez une option placeholder: Choisissez une option
deliveryPointSale: Lieu de livraison deliveryPointSale: Lieu de livraison
list: Retour à la liste list: Retour à la liste
deselect: Désélectionner deselect: Désélectionner
form.empty_value: Aucun(e) form.empty_value: Aucun(e)
add: Ajouter
user: user:
account: Mon compte account: Mon compte
logout: Me déconnecter logout: Me déconnecter

+ 6
- 4
ShopBundle/Resources/views/backend/order/edit-cart.html.twig View File

{% import '@LcShop/backend/order/macros.html.twig' as orderMacros %} {% import '@LcShop/backend/order/macros.html.twig' as orderMacros %}


{% block main %} {% block main %}
{% form_theme form_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{# {% form_theme form_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{% form_theme form_add_product_to_order '@LcShop/backend/form/custom_bootstrap_4.html.twig' %} {% form_theme form_add_product_to_order '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{% form_theme form_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{% form_theme form_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}#}
<div class="lc-vue-js-container" id="lc-order-edit"> <div class="lc-vue-js-container" id="lc-order-edit">




{% include '@LcShop/backend/order/form/modal_deliveryaddress.html.twig' %} {% include '@LcShop/backend/order/form/modal_deliveryaddress.html.twig' %}
{% include '@LcShop/backend/order/form/modal_deliveryavailability.html.twig' %} {% include '@LcShop/backend/order/form/modal_deliveryavailability.html.twig' %}
{% include '@LcShop/backend/order/form/modal_orderstatus.html.twig' %} {% include '@LcShop/backend/order/form/modal_orderstatus.html.twig' %}
{% include '@LcShop/backend/order/form/modal_reductioncredit.html.twig' %}
{% include '@LcShop/backend/order/form/modal_reductioncart.html.twig' %}
{% include '@LcShop/backend/order/form/modal_addreductioncredit.html.twig' %}
{% include '@LcShop/backend/order/form/modal_addreductioncart.html.twig' %}
{% include '@LcShop/backend/order/form/modal_deletereductioncart.html.twig' %}
{% include '@LcShop/backend/order/form/modal_deletereductioncredit.html.twig' %}
{% include '@LcShop/backend/order/form/modal_addproducttoorder.html.twig' %} {% include '@LcShop/backend/order/form/modal_addproducttoorder.html.twig' %}


{# {{ macros.startCard(3, 'OrderShop.addProduct', 'success') }} {# {{ macros.startCard(3, 'OrderShop.addProduct', 'success') }}

+ 1
- 1
ShopBundle/Resources/views/backend/order/form/modal_addproducttoorder.html.twig View File

</div> </div>
<div class="modal-footer justify-content-between"> <div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_widget(form_add_product_to_order.addProductToOrder, {"attr": {'class' : 'btn btn-primary', '@click' : 'addProductToOrder'}}) }}
{{ form_widget(form_add_product_to_order.add, {"attr": {'class' : 'btn btn-primary', '@click' : 'addProductToOrder'}}) }}
</div> </div>
</div> </div>
<!-- /.modal-content --> <!-- /.modal-content -->

ShopBundle/Resources/views/backend/order/form/modal_reductioncart.html.twig → ShopBundle/Resources/views/backend/order/form/modal_addreductioncart.html.twig View File

{% trans_default_domain 'lcshop' %} {% trans_default_domain 'lcshop' %}


<div class="modal fade show" id="modal-reduction-cart">
{{ form_start(form_order_reduction_cart, {'attr': { 'id' : 'orderReductionCartForm'}}) }}) }}
{% form_theme form_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal fade show" id="modal-add-reduction-cart">
{{ form_start(form_add_order_reduction_cart, {'attr': { 'id' : 'addOrderReductionCartForm'}}) }}
{% form_theme form_add_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog"> <div class="modal-dialog">


<div class="modal-content"> <div class="modal-content">
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="col"> <div class="col">
{{ form_row(form_order_reduction_cart.reductionCart) }}
{{ form_row(form_add_order_reduction_cart.reductionCart) }}
</div> </div>


</div> </div>
<div class="modal-footer justify-content-between"> <div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_order_reduction_cart.saveOrderReductionCart, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCart'}}) }}
{{ form_row(form_add_order_reduction_cart.add, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCart'}}) }}
</div> </div>
</div> </div>
<!-- /.modal-content --> <!-- /.modal-content -->
</div> </div>
{{ form_end(form_order_reduction_cart) }}
{{ form_end(form_add_order_reduction_cart) }}
</div> </div>

ShopBundle/Resources/views/backend/order/form/modal_reductioncredit.html.twig → ShopBundle/Resources/views/backend/order/form/modal_addreductioncredit.html.twig View File

{% trans_default_domain 'lcshop' %} {% trans_default_domain 'lcshop' %}


<div class="modal fade show" id="modal-reduction-credit">
{{ form_start(form_order_reduction_credit, {'attr': {'class': 'row', 'id' : 'orderReductionCreditForm'}}) }}) }}
{% form_theme form_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal fade show" id="modal-add-reduction-credit">
{{ form_start(form_add_order_reduction_credit, {'attr': {'class': 'row', 'id' : 'addOrderReductionCreditForm'}}) }}
{% form_theme form_add_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog"> <div class="modal-dialog">


<div class="modal-content"> <div class="modal-content">
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="col"> <div class="col">
{{ form_row(form_order_reduction_credit.reductionCredit) }}
{{ form_row(form_add_order_reduction_credit.reductionCredit) }}
</div> </div>


</div> </div>
<div class="modal-footer justify-content-between"> <div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_order_reduction_credit.saveOrderReductionCredit, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCredit'}}) }}
{{ form_row(form_add_order_reduction_credit.add, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCredit'}}) }}
</div> </div>
</div> </div>
<!-- /.modal-content --> <!-- /.modal-content -->
</div> </div>
{{ form_end(form_order_reduction_credit) }}
{{ form_end(form_add_order_reduction_credit) }}
</div> </div>

+ 30
- 0
ShopBundle/Resources/views/backend/order/form/modal_deletereductioncart.html.twig View File

{% trans_default_domain 'lcshop' %}

<div class="modal fade show" id="modal-delete-reduction-cart">
{{ form_start(form_delete_order_reduction_cart, {'attr': { 'id' : 'deleteOrderReductionCartForm'}}) }}
{% form_theme form_delete_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
<div class="modal-header">
<h4>{{ "action.order.deleteReductionCart"|trans }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col">
Est-vous sur de vouloir surppimer cette réduction
{{ form_row(form_delete_order_reduction_cart.id) }}
</div>

</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_delete_order_reduction_cart.delete, {"attr": {'class' : 'btn btn-primary', '@click': 'deleteOrderReductionCart'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>#}
{{ form_end(form_delete_order_reduction_cart) }}
</div>

+ 30
- 0
ShopBundle/Resources/views/backend/order/form/modal_deletereductioncredit.html.twig View File

{% trans_default_domain 'lcshop' %}

<div class="modal fade show" id="modal-delete-reduction-credit">
{{ form_start(form_delete_order_reduction_credit, {'attr': { 'id' : 'deleteOrderReductionCreditForm'}}) }}
{% form_theme form_delete_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
<div class="modal-header">
<h4>{{ "action.order.deleteReductionCredit"|trans }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col">
Est-vous sur de vouloir surppimer cette réduction
{{ form_row(form_delete_order_reduction_credit.id) }}
</div>

</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_delete_order_reduction_credit.delete, {"attr": {'class' : 'btn btn-primary', '@click': 'deleteOrderReductionCredit'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>#}
{{ form_end(form_delete_order_reduction_credit) }}
</div>

+ 14
- 4
ShopBundle/Resources/views/backend/order/macros.html.twig View File

<button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-add-product-to-order"> <button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-add-product-to-order">
<i class="fa fa-plus"></i> {{ "action.order.addOrderProduct"|trans }} <i class="fa fa-plus"></i> {{ "action.order.addOrderProduct"|trans }}
</button> </button>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-reduction-cart">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-add-reduction-cart">
<i class="fa fa-shopping-basket"></i> {{ "action.order.addReductionCart"|trans }} <i class="fa fa-shopping-basket"></i> {{ "action.order.addReductionCart"|trans }}
</button> </button>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-reduction-credit">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-add-reduction-credit">
<i class="fa fa-backspace"></i> {{ "action.order.addReductionCredit"|trans }} <i class="fa fa-backspace"></i> {{ "action.order.addReductionCredit"|trans }}
</button> </button>
</div> </div>
</tr> </tr>
<template v-for="(orderReductionCart, key) in order.orderReductionCarts"> <template v-for="(orderReductionCart, key) in order.orderReductionCarts">
<tr> <tr>
<th>${orderReductionCart.title}</th>
<th>
${orderReductionCart.title}
<button type="button" class="btn-sm btn-danger" @click="modalOrderReductionCart(orderReductionCart.id)">
<i class="fa fa-trash"></i>
</button>
</th>
<td>${orderReductionCart.amount}€</td> <td>${orderReductionCart.amount}€</td>
</tr> </tr>
</template> </template>
<template v-for="(orderReductionCredit, key) in order.orderReductionCredits"> <template v-for="(orderReductionCredit, key) in order.orderReductionCredits">
<tr> <tr>
<th>${orderReductionCredit.title}</th>
<th>${orderReductionCredit.title}

<button type="button" class="btn-sm btn-danger" @click="modalOrderReductionCredit(orderReductionCredit.id)">
<i class="fa fa-trash"></i>
</button>
</th>
<td>${orderReductionCredit.amount}€</td> <td>${orderReductionCredit.amount}€</td>
</tr> </tr>
</template> </template>

+ 7
- 6
ShopBundle/Services/Order/OrderUtils.php View File

use Lc\ShopBundle\Services\DocumentUtils; use Lc\ShopBundle\Services\DocumentUtils;
use Lc\ShopBundle\Services\Price\OrderShopPriceUtils; use Lc\ShopBundle\Services\Price\OrderShopPriceUtils;
use Lc\ShopBundle\Services\UserUtils; use Lc\ShopBundle\Services\UserUtils;
use Lc\ShopBundle\Services\Utils;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;


protected $priceUtils; protected $priceUtils;
protected $productFamilyUtils; protected $productFamilyUtils;
protected $documentUtils; protected $documentUtils;
protected $session;
protected $utils;


public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils, public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils, MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils, SessionInterface $session)
DocumentUtils $documentUtils, Utils $utils)
{ {
$this->em = $em; $this->em = $em;
$this->security = $security; $this->security = $security;
$this->priceUtils = $priceUtils; $this->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils; $this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils; $this->documentUtils = $documentUtils;
$this->session = $session;
$this->utils = $utils;
} }




if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) { && $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor); $orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
$this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else { } else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor; $orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
} }
$textError .= ' dans cette quantité ' ; $textError .= ' dans cette quantité ' ;
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ; $textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ;
} }
$this->session->getFlashBag()->add('error', $textError) ;
$this->utils->addFlash('error', $textError);
} }


return $return ; return $return ;
if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTax($order)) { if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTax($order)) {
return true; return true;
} else { } else {
$order->editError[] = 'field.error.orderStatus.noPayment';
$this->utils->addFlash('error', 'error.order.noPayment');
return false; return false;
} }
} }

+ 3
- 0
ShopBundle/Services/Order/OrderUtilsReductionTrait.php View File



// appartient à l'utilisateur // appartient à l'utilisateur
if(!$reductionCredit->getUsers()->contains($user)) { if(!$reductionCredit->getUsers()->contains($user)) {
$this->utils->addFlash('error', 'error.reductionCredit.userNotAllow');
return false ; return false ;
} }


// n'a pas été utilisé // n'a pas été utilisé
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) { if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) {
$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse');

return false; return false;
} }



+ 3
- 2
ShopBundle/Services/Price/OrderShopPriceUtils.php View File

foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
$total += $this->orderProductPriceUtils->getTotalWithTaxAndReduction($orderProduct); $total += $this->orderProductPriceUtils->getTotalWithTaxAndReduction($orderProduct);
} }

return $total; return $total;


} }
]; ];
} }


$orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) * $this->getReductionsCoef($orderShop);
$orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) * $this->getReductionsCoef($orderShop) ;
$orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) / $this->getReductionsCoef($orderShop);
$orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) / $this->getReductionsCoef($orderShop) ;
} }


return $orderProductsTaxes ; return $orderProductsTaxes ;

+ 25
- 1
ShopBundle/Services/Utils.php View File

use Lc\ShopBundle\Context\UserPointSaleInterface; use Lc\ShopBundle\Context\UserPointSaleInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;


class Utils class Utils
{ {
protected $em ; protected $em ;
protected $parameterBag ; protected $parameterBag ;
protected $merchantUtils ; protected $merchantUtils ;
protected $session;
protected $translator;


public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag)
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, SessionInterface $session, TranslatorInterface $translator)
{ {
$this->em = $em ; $this->em = $em ;
$this->parameterBag = $parameterBag ; $this->parameterBag = $parameterBag ;
$this->session = $session;
$this->translator = $translator;
} }




return '' ; return '' ;
} }


public function addFlash($success, $message, $extraMessages = array(), $params=array(), $domain='lcshop'){
$message = $this->translator->trans($message, $params,$domain);

if (count($extraMessages)) {
$message .= '<ul>';
foreach ($extraMessages as $extraMessage) {
$message .= '<li> <i>' . $this->translator->trans($extraMessage, array(), $domain) . '</i></li>';
}
$message .= '</ul>';
}

$this->session->getFlashBag()->add($success, $message);

}

public function getFlashMessages(){
return $this->session->getFlashBag()->all();
}
} }

Loading…
Cancel
Save