@@ -2,36 +2,37 @@ | |||
namespace Lc\ShopBundle\Controller\Admin; | |||
use App\Entity\OrderProduct; | |||
use App\Entity\Product; | |||
use Doctrine\DBAL\Types\FloatType; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Doctrine\ORM\EntityRepository; | |||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||
use FOS\UserBundle\Model\UserManagerInterface; | |||
use Lc\ShopBundle\Context\AddressInterface; | |||
use Lc\ShopBundle\Context\PointSaleInterface; | |||
use Lc\ShopBundle\Context\ProductCategoryInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Context\TaxRateInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\OrderUtilsInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Form\Order\AddPoductToOrderType; | |||
use Lc\ShopBundle\Form\Order\OrderProductsType; | |||
use Lc\ShopBundle\Form\OrderProductType; | |||
use Lc\ShopBundle\Form\ProductFamilyCategoriesType; | |||
use Lc\ShopBundle\Form\ProductType; | |||
use Lc\ShopBundle\Model\PointSale; | |||
use Lc\ShopBundle\Services\Utils; | |||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | |||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||
use Symfony\Component\Form\Extension\Core\Type\DateType; | |||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||
use Symfony\Component\Form\Extension\Core\Type\MoneyType; | |||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | |||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |||
use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\HttpFoundation\Response; | |||
use Symfony\Component\Security\Core\Security; | |||
class OrderController extends AdminController | |||
{ | |||
protected $orderUtils; | |||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport, OrderUtilsInterface $orderUtils) | |||
{ | |||
$this->orderUtils = $orderUtils; | |||
parent::__construct($security, $userManager, $em, $utils, $merchantUtils, $mailjetTransport); | |||
} | |||
public function updateEntity($entity) | |||
{ | |||
@@ -77,28 +78,19 @@ class OrderController extends AdminController | |||
parent::persistEntity($entity); | |||
} | |||
public function createEntityFormBuilder($entity, $view, $override=true) | |||
public function createEntityFormBuilder($entity, $view, $override = true) | |||
{ | |||
$formBuilder = parent::createEntityFormBuilder($entity, $view); | |||
$formBuilder->add('orderProducts', CollectionType::class, array( | |||
'label' => 'Déclinaisons', | |||
'entry_type' => OrderProductType::class, | |||
'entry_options' => ['label' => false], | |||
'allow_add' => true, | |||
'allow_delete' => true, | |||
'required' => true | |||
) | |||
); | |||
$formBuilder = parent::createEntityFormBuilder($entity, $view, false); | |||
$userClass = $this->em->getClassMetadata(UserInterface::class); | |||
$addressClass = $this->em->getClassMetadata(AddressInterface::class); | |||
$formBuilder->add('user', EntityType::class, array( | |||
'class' => $userClass->name | |||
)); | |||
$addressClass = $this->em->getClassMetadata(AddressInterface::class); | |||
$formBuilder->add('invoiceAddress', EntityType::class, array( | |||
'class' => $addressClass->name, | |||
'placeholder' => '', | |||
@@ -109,6 +101,9 @@ class OrderController extends AdminController | |||
}, | |||
)); | |||
$formBuilder = $this->overrideFormBuilder($formBuilder, $entity, $view); | |||
return $formBuilder; | |||
} | |||
@@ -137,6 +132,109 @@ class OrderController extends AdminController | |||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||
} | |||
public function addProductToOrderAction() | |||
{ | |||
$id = $this->request->query->get('id'); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$orderShop = $easyadmin['item']; | |||
$orderProductClass = $this->em->getClassMetadata(OrderProductInterface::class); | |||
$formAddProductToOrder = $this->createForm(AddPoductToOrderType::class); | |||
$formAddProductToOrder->handleRequest($this->request); | |||
if($formAddProductToOrder->get('product')->getData() == null) { | |||
$response['status'] = 'error'; | |||
$response['message'] = 'Vous devez choisir un produit dans la liste'; | |||
}else if($formAddProductToOrder->get('quantity')->getData() == null){ | |||
$response['status'] = 'error'; | |||
$response['message'] = 'Vous devez entrer une quantité'; | |||
} else if ($formAddProductToOrder->isSubmitted() && $formAddProductToOrder->isValid()) { | |||
$orderProduct = new $orderProductClass->name; | |||
$orderProduct->setQuantityOrder($formAddProductToOrder->get('quantity')->getData()); | |||
$orderProduct->setProduct($formAddProductToOrder->get('product')->getData()); | |||
$this->orderUtils->addOrderProduct($orderShop, $orderProduct); | |||
$response['status'] = 'success'; | |||
$response['message'] = 'Le produit a bien été ajouté à la commande'; | |||
}else{ | |||
$response['status'] = 'error'; | |||
$response['message'] = 'Une erreur est survenue'; | |||
} | |||
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; | |||
return new Response(json_encode($response)); | |||
} | |||
public function orderProductsAction() | |||
{ | |||
$id = $this->request->query->get('id'); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$orderShop = $easyadmin['item']; | |||
$formOrderProducts = $this->createForm(OrderProductsType::class, $orderShop); | |||
$formOrderProducts->handleRequest($this->request); | |||
if ($formOrderProducts->isSubmitted() && $formOrderProducts->isValid()) { | |||
// dump($formOrderProducts->get('orderProducts')->getData()); | |||
foreach($orderShop->getOrderProducts() as $orderProduct){ | |||
if($orderProduct->getQuantityOrder() <= 0) { | |||
$response['niche'] = $orderProduct->getQuantityOrder() ; | |||
$this->em->remove($orderProduct); | |||
}else{ | |||
//dump($orderProduct); | |||
$this->em->persist($orderProduct); | |||
} | |||
} | |||
//$this->em->persist($orderShop); | |||
$this->em->flush(); | |||
$response['status'] = 'success'; | |||
$response['message'] = 'La commande a bien été modifié'; | |||
}else{ | |||
$response['status'] = 'error'; | |||
$response['message'] = 'Une erreur est survenue'; | |||
} | |||
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; | |||
//die('nicicici'); | |||
return new Response(json_encode($response)); | |||
} | |||
public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = []) | |||
{ | |||
if ($actionName == 'show') { | |||
$formAddProductToOrder = $this->createForm(AddPoductToOrderType::class, null, array( | |||
'action' => $this->generateUrl('easyadmin', [ | |||
'action' => 'addProductToOrder', | |||
'entity' => $this->entity['name'], | |||
'id' => $parameters['entity']->getId() | |||
]) | |||
)); | |||
$formOrderProducts = $this->createForm(OrderProductsType::class, null, array( | |||
'action' => $this->generateUrl('easyadmin', [ | |||
'action' => 'orderProducts', | |||
'entity' => $this->entity['name'], | |||
'id' => $parameters['entity']->getId() | |||
]) | |||
)); | |||
$parameters['form_add_product_to_order'] = $formAddProductToOrder->createView(); | |||
$parameters['form_order_products'] = $formOrderProducts->createView(); | |||
} | |||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||
} | |||
protected function newAction() | |||
{ | |||
$this->dispatch(EasyAdminEvents::PRE_NEW); | |||
@@ -162,40 +260,65 @@ class OrderController extends AdminController | |||
if (!$user instanceof UserInterface) return $user; | |||
else { | |||
$entity->setUser($user); | |||
//réinitialise le formulaire pour charger les adresses en fonction de l'utilisateur sélectionné | |||
$newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]); | |||
$newForm->handleRequest($this->request); | |||
$orderShop = $this->orderUtils->createOrderShop(array( | |||
'user' => $user, | |||
'merchant' => $this->merchantUtils->getMerchantUser() | |||
)); | |||
return $this->redirectToRoute('easyadmin', [ | |||
'action' => 'edit', | |||
'entity' => $this->entity['name'], | |||
'id' => $orderShop->getId() | |||
]); | |||
} | |||
} | |||
/** | |||
* The method that is executed when the user performs a 'show' action on an entity. | |||
* | |||
* @return Response | |||
*/ | |||
public function showAction() | |||
{ | |||
$this->dispatch(EasyAdminEvents::PRE_SHOW); | |||
//dump( $entity); | |||
//dump( $entity); | |||
$id = $this->request->query->get('id'); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$entity = $easyadmin['item']; | |||
if ($newForm->isSubmitted() && $newForm->isValid()) { | |||
/*dump($entity); | |||
die();*/ | |||
//$this->dispatch(EasyAdminEvents::PRE_PERSIST, ['entity' => $entity]); | |||
$this->executeDynamicMethod('persist<EntityName>Entity', [$entity, $newForm]); | |||
$this->dispatch(EasyAdminEvents::POST_PERSIST, ['entity' => $entity]); | |||
$fields = $this->entity['show']['fields']; | |||
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); | |||
return $this->redirectToReferrer(); | |||
} | |||
$this->dispatch(EasyAdminEvents::POST_SHOW, [ | |||
'deleteForm' => $deleteForm, | |||
'fields' => $fields, | |||
'entity' => $entity, | |||
]); | |||
$this->dispatch(EasyAdminEvents::POST_NEW, [ | |||
'entity_fields' => $fields, | |||
'form' => $newForm, | |||
'entity' => $entity | |||
]); | |||
$parameters = [ | |||
'entity' => $entity, | |||
'fields' => $fields, | |||
'delete_form' => $deleteForm->createView(), | |||
'order'=> $this->orderUtils->getOrderAsJsonObject($entity) | |||
$parameters = [ | |||
'form' => $newForm->createView(), | |||
'entity_fields' => $fields, | |||
'entity' => $entity | |||
]; | |||
]; | |||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||
} | |||
return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]); | |||
} | |||
/** | |||
* Réécriture de edit action pr rediriger vers le show */ | |||
public function editAction() | |||
{ | |||
$id = $this->request->query->get('id'); | |||
$entity = $this->request->query->get('entity'); | |||
return $this->redirectToRoute('easyadmin', [ | |||
'action' => 'show', | |||
'entity' => $entity, | |||
'id' => $id | |||
]); | |||
} | |||
} |
@@ -6,6 +6,8 @@ use Doctrine\ORM\EntityManager; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\ProductCategoryInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Services\PriceUtils; | |||
use Lc\ShopBundle\Services\ProductFamilyUtils; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
use Symfony\Component\HttpFoundation\JsonResponse; | |||
use Symfony\Component\HttpFoundation\Response; | |||
@@ -17,10 +19,14 @@ class ApiController extends AbstractController | |||
protected $userManager; | |||
protected $em ; | |||
protected $utils ; | |||
protected $priceUtils ; | |||
protected $productFamilyUtils; | |||
public function __construct(EntityManagerInterface $entityManager) | |||
public function __construct(EntityManagerInterface $entityManager, PriceUtils $priceUtils, ProductFamilyUtils $productFamilyUtils) | |||
{ | |||
$this->em = $entityManager; | |||
$this->priceUtils = $priceUtils; | |||
$this->productFamilyUtils = $productFamilyUtils; | |||
} | |||
public function getEntity($entity, $id) | |||
@@ -28,9 +34,6 @@ class ApiController extends AbstractController | |||
$repo = $this->em->getRepository(ProductCategoryInterface::class); | |||
$data = $repo->findBy(array()); | |||
dump($data); | |||
if($entity == 'product'){ | |||
$repo = $this->em->getRepository(ProductInterface::class); | |||
@@ -38,14 +41,16 @@ class ApiController extends AbstractController | |||
$data= array( | |||
'id' => $data->getId(), | |||
'title' => $data->getTitleInherited(), | |||
'price' => $data->getPriceInherited(), | |||
'price' => $this->priceUtils->getPrice($data), | |||
'priceWithTax' => $this->priceUtils->getPriceWithTax($data), | |||
'priceWithTaxAndReduction' => $this->priceUtils->getPriceWithTaxAndReduction($data), | |||
'unit' => $data->getUnitInherited(), | |||
'availableQuantity' => $data->getAvailableQuantityInherited(), | |||
'taxRate' => $data->getTaxRateInherited(), | |||
); | |||
} | |||
return new Response('<html><body>NICHE</body></html>'); | |||
return new Response(json_encode($data)); | |||
} | |||
} |
@@ -0,0 +1,63 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\Order; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Doctrine\ORM\EntityRepository; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
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\IntegerType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class AddPoductToOrderType extends AbstractType | |||
{ | |||
protected $em; | |||
protected $merchantUtils; | |||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) | |||
{ | |||
$this->em = $em; | |||
$this->merchantUtils = $merchantUtils; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
//$data = $options['data'] ; | |||
$productClass = $this->em->getClassMetadata(ProductInterface::class); | |||
$currentMerchant = $this->merchantUtils->getMerchantUser(); | |||
$builder | |||
->add('product', EntityType::class, array( | |||
'class' => $productClass->name, | |||
'placeholder' => '', | |||
'mapped' => false, | |||
'required' => false, | |||
'query_builder' => function (EntityRepository $er) use ($currentMerchant) { | |||
return $er->createQueryBuilder('p') | |||
->join('p.productFamily', 'pFamily') | |||
->where('pFamily.merchant = :currentMerchant') | |||
->setParameter('currentMerchant', $currentMerchant); | |||
}, | |||
'choice_label' => function ($product) { | |||
return $product->getProductFamily()->getTitle() . ' - ' . $product->getTitle(); | |||
} | |||
)) | |||
->add('quantity', IntegerType::class, array( | |||
'mapped' => false | |||
)) | |||
->add('addProductToOrder', ButtonType::class, array( | |||
'label'=> 'field.OrderShop.addOrderToProduct' | |||
)); | |||
} | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults([ | |||
'translation_domain'=>'lcshop' | |||
]); | |||
} | |||
} |
@@ -0,0 +1,46 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\Order; | |||
use App\Entity\Product; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
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\HiddenType; | |||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class OrderProductType extends AbstractType | |||
{ | |||
protected $em ; | |||
protected $productTransformer ; | |||
public function __construct(EntityManagerInterface $em, ProductToIdTransformer $productTransformer) | |||
{ | |||
$this->em = $em ; | |||
$this->productTransformer = $productTransformer ; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$builder | |||
->add('quantityOrder', NumberType::class,array( | |||
'html5'=>true | |||
)) | |||
->add('product', HiddenType::class); | |||
/* ->add('id', HiddenType::class);*/ | |||
$builder->get('product')->addModelTransformer($this->productTransformer); | |||
} | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults([ | |||
'data_class' => $this->em->getClassMetadata(OrderProductInterface::class)->getName(), | |||
]); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\Order; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
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 | |||
{ | |||
protected $em; | |||
protected $merchantUtils; | |||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) | |||
{ | |||
$this->em = $em; | |||
$this->merchantUtils = $merchantUtils; | |||
} | |||
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([ | |||
]); | |||
} | |||
} |
@@ -1,65 +0,0 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form; | |||
use CKSource\Bundle\CKFinderBundle\Form\Type\CKFinderFileChooserType; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use FOS\CKEditorBundle\Form\Type\CKEditorType; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Context\TaxRateInterface; | |||
use Lc\ShopBundle\Services\Utils; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | |||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||
use Symfony\Component\Form\Extension\Core\Type\DateType; | |||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | |||
use function PHPSTORM_META\type; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class OrderProductType extends AbstractType | |||
{ | |||
protected $em; | |||
protected $utils; | |||
public function __construct(EntityManagerInterface $entityManager, Utils $utils) | |||
{ | |||
$this->em = $entityManager; | |||
$this->utils = $utils; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$productClass = $this->em->getClassMetadata(ProductInterface::class); | |||
$builder->add('product', EntityType::class, array( | |||
'class' => $productClass->name, | |||
'placeholder'=> '', | |||
'choice_label'=> function($product){ | |||
return $product->getProductFamily()->getTitle() . ' - ' . $product->getTitle(); | |||
} | |||
)); | |||
$builder->add('quantity', NumberType::class, array( | |||
'label' => 'Quantité', | |||
'attr' => [ | |||
'append_html' => 'g' | |||
] | |||
)); | |||
} | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults([ | |||
'data_class' => $this->em->getClassMetadata(OrderProductInterface::class)->getName(), | |||
]); | |||
} | |||
} |
@@ -61,7 +61,7 @@ abstract class OrderShop implements FilterMerchantInterface | |||
protected $orderStatusHistories; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", orphanRemoval=true) | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true) | |||
*/ | |||
protected $orderProducts; | |||
@@ -3,7 +3,7 @@ easy_admin: | |||
design: | |||
templates: | |||
list: '@LcShop/backend/default/list.html.twig' | |||
layout: '@LcShop/backend/default/layout.html.twig' | |||
layout: '@LcShop/backend/default/layout/layout.html.twig' | |||
menu: '@LcShop/backend/default/menu.html.twig' | |||
edit: '@LcShop/backend/default/edit.html.twig' | |||
new: '@LcShop/backend/default/new.html.twig' |
@@ -300,6 +300,7 @@ let mixinTemplate = { | |||
immediate: true, // makes the watcher fire on first render, too. | |||
handler() { | |||
if (this.template) { | |||
var res = Vue.compile(this.template); | |||
this.templateRender = res.render; |
@@ -0,0 +1,231 @@ | |||
// Reference array sent to dynamic staticRenderFns | |||
var staticRenderFns = []; | |||
Vue.component('order-product-form', { | |||
mixins: [mixinTemplate], | |||
props: ['template', 'keyForm'], | |||
computed: {}, | |||
data() { | |||
return Object.assign( | |||
{ | |||
title: null, | |||
price: null, | |||
priceWithTax: null, | |||
priceWithTaxAndReduction: null, | |||
totalWithoutTax: null, | |||
totalWithTax: null, | |||
buyingPrice: null, | |||
quantity: 1, | |||
unit: null, | |||
product: null | |||
}, window.orderProductForm[this.keyForm]) | |||
}, | |||
mounted: function () { | |||
this.setSelect2(); | |||
this.updateQuantity(); | |||
}, | |||
methods: { | |||
updateLine: function (data) { | |||
this.price = data.price; | |||
this.priceWithTax = data.priceWithTax; | |||
this.priceWithTaxAndReduction = data.priceWithTaxAndReduction; | |||
this.priceWithTax = data.priceWithTax; | |||
this.updateQuantity(); | |||
this.$parent.updateTotalPrice(); | |||
}, | |||
updateQuantity: function () { | |||
this.totalWithTax = parseFloat(this.priceWithTaxAndReduction * this.quantity).toFixed(2); | |||
this.totalWithoutTax = parseFloat(this.price * this.quantity).toFixed(2); | |||
this.$parent.updateTotalPrice(); | |||
}, | |||
setSelect2: function () { | |||
var selectProduct = $(this.$el).find('select.form-control'); | |||
var select2Product =setSelect2(selectProduct); | |||
var vue = this; | |||
select2Product.on('select2:select', function (e) { | |||
//dispatch event pour que le select soit "submitable" | |||
var event = new Event('change'); | |||
e.target.dispatchEvent(event); | |||
this.product = select2Product.val(); | |||
$.ajax({ | |||
url: DOMAIN + "/api/product/" + this.product, | |||
method: "GET", | |||
dataType: "json", | |||
success: function (response) { | |||
vue.updateLine(response); | |||
} | |||
}); | |||
}) | |||
}, | |||
deleteProductForm: function () { | |||
if (confirm('Êtes-vous sur de cette action ?')) { | |||
this.$parent.formOrderProductArray.splice(this.keyForm, 1); | |||
} | |||
} | |||
}, | |||
watch: {} | |||
}); | |||
Vue.component('delivery-availability-choice', { | |||
mixins: [mixinTemplate], | |||
props: ['template', 'key', 'name', 'id'], | |||
data() { | |||
return { | |||
id: -1, | |||
deliveryAvailability: null, // Have to assign to this variable** | |||
deliveryAvailabilities: null, // Have to assign to this variable** | |||
selected_category: "", | |||
value: null, | |||
label: null | |||
}; | |||
}, | |||
mounted() { | |||
}, | |||
methods: { | |||
updateDeliveryAvailability() { | |||
log(this.deliveryAvailability); | |||
/*log('bnfbf'); | |||
var self = this; | |||
$.ajax({ | |||
url: DOMAIN+"/admin/delivery-availaibility/14", | |||
method: "POST", | |||
dataType: "", | |||
success: function (response) { | |||
self.categories = response.categories; | |||
} | |||
});*/ | |||
} | |||
} | |||
}); | |||
appOrder = new Vue({ | |||
el: '#lc-order-edit', | |||
delimiters: ['${', '}'], | |||
computed: {}, | |||
data() { | |||
return Object.assign( | |||
{ | |||
currentSection: 'cart', | |||
formOrderProductArray: [], | |||
indexOrderProductForm: 0, | |||
formDeliveryAvailabilityLargeArray: [], | |||
formDeliveryAvailabilityShortArray: [], | |||
indexDeliveryAvailability: null, | |||
invoiceAddress: null, | |||
deliveryAddress: null, | |||
deliveryType: null, | |||
deliveryPointSale: null, | |||
deliveryAvailability: 'niche', | |||
totalWithTax: null, | |||
totalWithoutTax: null, | |||
sectionsArray: [ | |||
{ | |||
name: 'cart', | |||
nameDisplay: 'Panier' | |||
}, | |||
{ | |||
name: 'addresses', | |||
nameDisplay: 'Adresses' | |||
}, | |||
{ | |||
name: 'delivery', | |||
nameDisplay: 'Livraisons' | |||
} | |||
] | |||
})/*, window.appOrderProductFamilyValues)*/; | |||
}, | |||
mounted: function () { | |||
}, | |||
methods: { | |||
addProductToOrder:function(){ | |||
if(this.addProductId && this.addProductQuantity){ | |||
} | |||
}, | |||
updateTotalPrice: function () { | |||
this.totalWithoutTax = 0; | |||
this.totalWithTax = 0; | |||
for (var i = 0; i < this.$refs.orderProductForm.length; i++) { | |||
var line = this.$refs.orderProductForm[i]; | |||
this.totalWithoutTax = parseFloat(parseFloat(this.totalWithoutTax) + parseFloat(line.totalWithoutTax)).toFixed(2); | |||
this.totalWithTax = parseFloat(parseFloat(this.totalWithTax) + parseFloat(line.totalWithTax)).toFixed(2); | |||
} | |||
}, | |||
changeSection: function (section) { | |||
this.updateChild(); | |||
this.currentSection = section.name; | |||
this.addDeliveryAvailabilityChoice(); | |||
}, | |||
addDeliveryAvailabilityChoice: function () { | |||
$.ajax({ | |||
url: DOMAIN + "/admin/delivery-availaibility/" + this.deliveryAddress, | |||
method: "POST", | |||
dataType: "", | |||
success: function (response) { | |||
for (i = 0; i < response.large.length; i++) { | |||
slot = response.large[i]; | |||
var deliveryAvailabilityForm = $('#delivery-availability-short').data('prototype'); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__id__/g, "{{ form.deliveryAvailabilityZone.vars.id }}_"+slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__name__/g, "{{ form.deliveryAvailabilityZone.vars.full_name }}" ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__value__/g, slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__label__/g, slot.label ); | |||
appOrder.formDeliveryAvailabilityLargeArray.push(deliveryAvailabilityForm); | |||
appOrder.indexDeliveryAvailability++; | |||
} | |||
for (i = 0; i < response.short.length; i++) { | |||
slot = response.short[i]; | |||
var deliveryAvailabilityForm = $('#delivery-availability-short').data('prototype'); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__id__/g, "{{ form.deliveryAvailabilityZone.vars.id }}_"+slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__name__/g, "{{ form.deliveryAvailabilityZone.vars.full_name }}" ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__value__/g, slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__label__/g, slot.label ); | |||
appOrder.formDeliveryAvailabilityShortArray.push(deliveryAvailabilityForm); | |||
appOrder.indexDeliveryAvailability++; | |||
} | |||
} | |||
}); | |||
}, | |||
addOrderProductForm: function () { | |||
var $collectionHolder = $('#order-products-list'); | |||
var prototype = $collectionHolder.data('prototype'); | |||
var newForm = prototype; | |||
newForm = newForm.replace(/__name__/g, this.indexOrderProductForm); | |||
this.formOrderProductArray.push(newForm); | |||
this.indexOrderProductForm++; | |||
//updateSortableProducts(); | |||
}, | |||
updateChild: function () { | |||
if (typeof this.$refs.productForm !== 'undefined') { | |||
for (i = 0; i < this.$refs.productForm.length; i++) { | |||
this.$refs.productForm[i].updateProductForm(); | |||
this.$refs.productForm[i].updateProductView(); | |||
} | |||
} | |||
}, | |||
getUnitReference: function () { | |||
if (typeof this.$refs.productUnitPrice !== 'undefined') { | |||
return this.$refs.productUnitPrice.unitReference; | |||
} | |||
} | |||
}, | |||
watch: { | |||
title: function () { | |||
this.updateChild() | |||
}, | |||
} | |||
}); | |||
@@ -1,109 +1,71 @@ | |||
// Reference array sent to dynamic staticRenderFns | |||
var staticRenderFns = []; | |||
Vue.component('order-product-form', { | |||
Vue.component('order-product', { | |||
mixins: [mixinTemplate], | |||
props: ['template', 'keyForm'], | |||
props: ['template', 'keyItem', 'orderProduct'], | |||
computed: {}, | |||
data() { | |||
return Object.assign( | |||
/* data:function() { | |||
return{ | |||
product:null | |||
}; | |||
/!* return Object.assign( | |||
{ | |||
title: null, | |||
/!*title: null, | |||
price: null, | |||
priceWithTax: null, | |||
priceWithTaxAndReduction: null, | |||
totalWithoutTax: null, | |||
totalWithTax: null, | |||
buyingPrice: null, | |||
quantity: 1, | |||
unit: null, | |||
product: null | |||
}, window.orderProductForm[this.keyForm]) | |||
}, | |||
mounted: function () { | |||
this.setSelect2(); | |||
this.updateQuantity(); | |||
product: null*!/ | |||
}, window.orderProducts[this.key])*!/ | |||
},*/ | |||
mounted:function () { | |||
log(this.keyItem); | |||
this.setFields() | |||
//this.$el.replace(/__name__/g, this.key); | |||
}, | |||
methods: { | |||
updateLine: function (data) { | |||
this.price = data.price; | |||
this.priceWithTax = getPriceWithTax(this.price, data.taxRate); | |||
this.updateQuantity(); | |||
this.$parent.updateTotalPrice(); | |||
}, | |||
updateQuantity: function () { | |||
this.totalWithTax = parseFloat(this.priceWithTax * this.quantity).toFixed(3); | |||
this.totalWithoutTax = parseFloat(this.price * this.quantity).toFixed(3); | |||
this.$parent.updateTotalPrice(); | |||
methods:{ | |||
init:function(){ | |||
//log(this.$els); | |||
//log(this.$element); | |||
}, | |||
setSelect2: function () { | |||
var select = $(this.$el).find('select.form-control'); | |||
var monSelect = $(this.$el).find('select.form-control').select2({ | |||
//theme: 'bootstrap', | |||
debug: true, | |||
placeholder: "Select an option" | |||
setFields:function(){ | |||
var app = this; | |||
fields = ['fieldQuantity', 'fieldProduct']; | |||
fields.forEach(function (field) { | |||
var name = $(app.$refs[field]).prop('name'); | |||
var id = $(app.$refs[field]).prop('id'); | |||
name = name.replace(/__name__/g, app.keyItem); | |||
id = id.replace(/__name__/g, app.keyItem); | |||
$(app.$refs[field]).prop('name', name); | |||
$(app.$refs[field]).prop('id', id); | |||
//log(app.$refs[field]); | |||
}); | |||
var vue = this; | |||
monSelect.on('select2:select', function (e) { | |||
//dispatch event pour que le select soit "submitable" | |||
var event = new Event('change'); | |||
e.target.dispatchEvent(event); | |||
this.product = monSelect.val(); | |||
$.ajax({ | |||
url: DOMAIN + "/api/product/" + this.product, | |||
method: "GET", | |||
dataType: "", | |||
success: function (response) { | |||
vue.updateLine(response); | |||
} | |||
}); | |||
}) | |||
}, | |||
deleteProductForm: function () { | |||
if (confirm('Êtes-vous sur de cette action ?')) { | |||
this.$parent.formOrderProductArray.splice(this.keyForm, 1); | |||
} | |||
updateOrderProducts:function () { | |||
this.$parent.updateOrderProducts(); | |||
}, | |||
deleteOrderProduct:function(){ | |||
$(this.$refs.fieldQuantity).val(0); | |||
this.$parent.updateOrderProducts(); | |||
} | |||
}, | |||
watch: {} | |||
}); | |||
/*log($('#order-products-list').data('prototype')); | |||
var prototype = $('#order-products-list').data('prototype'); | |||
Vue.component('delivery-availability-choice', { | |||
mixins: [mixinTemplate], | |||
props: ['template', 'key', 'name', 'id'], | |||
data() { | |||
return { | |||
id: -1, | |||
deliveryAvailability: null, // Have to assign to this variable** | |||
deliveryAvailabilities: null, // Have to assign to this variable** | |||
selected_category: "", | |||
value: null, | |||
label: null | |||
}; | |||
}, | |||
mounted() { | |||
}, | |||
methods: { | |||
updateDeliveryAvailability() { | |||
log(this.deliveryAvailability); | |||
/*log('bnfbf'); | |||
var self = this; | |||
$.ajax({ | |||
url: DOMAIN+"/admin/delivery-availaibility/14", | |||
method: "POST", | |||
dataType: "", | |||
success: function (response) { | |||
self.categories = response.categories; | |||
} | |||
});*/ | |||
var newForm = prototype; | |||
newForm = newForm.replace(/__name__/g, key); | |||
} | |||
*/ | |||
} | |||
}); | |||
appOrder = new Vue({ | |||
@@ -113,19 +75,14 @@ appOrder = new Vue({ | |||
data() { | |||
return Object.assign( | |||
{ | |||
currentSection: 'cart', | |||
formOrderProductArray: [], | |||
indexOrderProductForm: 0, | |||
formDeliveryAvailabilityLargeArray: [], | |||
formDeliveryAvailabilityShortArray: [], | |||
indexDeliveryAvailability: null, | |||
invoiceAddress: null, | |||
deliveryAddress: null, | |||
deliveryType: null, | |||
deliveryPointSale: null, | |||
deliveryAvailability: 'niche', | |||
totalWithTax: null, | |||
totalWithoutTax: null, | |||
templateTest: window.templateTest, | |||
orderProducts:[], | |||
order:[], | |||
isLoading:true, | |||
addProductId:null, | |||
addProductQuantity:null, | |||
sectionsArray: [ | |||
{ | |||
name: 'cart', | |||
@@ -143,85 +100,54 @@ appOrder = new Vue({ | |||
})/*, window.appOrderProductFamilyValues)*/; | |||
}, | |||
mounted: function () { | |||
}, | |||
methods: { | |||
updateTotalPrice: function () { | |||
this.totalWithoutTax = 0; | |||
this.totalWithTax = 0; | |||
for (var i = 0; i < this.$refs.orderProductForm.length; i++) { | |||
var line = this.$refs.orderProductForm[i]; | |||
this.totalWithoutTax = parseFloat(parseFloat(this.totalWithoutTax) + parseFloat(line.totalWithoutTax)).toFixed(2); | |||
this.totalWithTax = parseFloat(parseFloat(this.totalWithTax) + parseFloat(line.totalWithTax)).toFixed(2); | |||
} | |||
log('ncnnc'); | |||
log(window.templateTest); | |||
this.updateOrder(window.orderObject); | |||
//log($(this.$el).find('#orderProductsForm').replace(/__name__/g, 0)); | |||
}, | |||
changeSection: function (section) { | |||
this.updateChild(); | |||
this.currentSection = section.name; | |||
this.addDeliveryAvailabilityChoice(); | |||
}, | |||
addDeliveryAvailabilityChoice: function () { | |||
methods: { | |||
updateOrderProducts:function(){ | |||
var app = this; | |||
this.isLoading=true; | |||
//$('#orderProductsForm').submit(); | |||
$.ajax({ | |||
url: DOMAIN + "/admin/delivery-availaibility/" + this.deliveryAddress, | |||
url: $('#orderProductsForm').prop('action'), | |||
method: "POST", | |||
dataType: "", | |||
data: $('#orderProductsForm').serialize(), | |||
dataType:"json", | |||
success: function (response) { | |||
for (i = 0; i < response.large.length; i++) { | |||
slot = response.large[i]; | |||
var deliveryAvailabilityForm = $('#delivery-availability-short').data('prototype'); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__id__/g, "{{ form.deliveryAvailabilityZone.vars.id }}_"+slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__name__/g, "{{ form.deliveryAvailabilityZone.vars.full_name }}" ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__value__/g, slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__label__/g, slot.label ); | |||
appOrder.formDeliveryAvailabilityLargeArray.push(deliveryAvailabilityForm); | |||
appOrder.indexDeliveryAvailability++; | |||
} | |||
for (i = 0; i < response.short.length; i++) { | |||
slot = response.short[i]; | |||
var deliveryAvailabilityForm = $('#delivery-availability-short').data('prototype'); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__id__/g, "{{ form.deliveryAvailabilityZone.vars.id }}_"+slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__name__/g, "{{ form.deliveryAvailabilityZone.vars.full_name }}" ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__value__/g, slot.id ); | |||
deliveryAvailabilityForm = deliveryAvailabilityForm.replace(/__label__/g, slot.label ); | |||
appOrder.formDeliveryAvailabilityShortArray.push(deliveryAvailabilityForm); | |||
appOrder.indexDeliveryAvailability++; | |||
generateNotice(response.status, response.message); | |||
if (response.status == 'success') { | |||
app.updateOrder(response.data); | |||
} | |||
} | |||
}); | |||
}, | |||
addOrderProductForm: function () { | |||
var $collectionHolder = $('#order-products-list'); | |||
var prototype = $collectionHolder.data('prototype'); | |||
var newForm = prototype; | |||
newForm = newForm.replace(/__name__/g, this.indexOrderProductForm); | |||
this.formOrderProductArray.push(newForm); | |||
this.indexOrderProductForm++; | |||
//updateSortableProducts(); | |||
updateOrder:function (orderObject){ | |||
this.orderProducts = orderObject.orderProducts; | |||
this.order = orderObject; | |||
this.isLoading=false; | |||
}, | |||
updateChild: function () { | |||
if (typeof this.$refs.productForm !== 'undefined') { | |||
for (i = 0; i < this.$refs.productForm.length; i++) { | |||
this.$refs.productForm[i].updateProductForm(); | |||
this.$refs.productForm[i].updateProductView(); | |||
addProductToOrder:function(){ | |||
var app = this; | |||
this.isLoading=true; | |||
$.ajax({ | |||
url: $('#addProductToOrderForm').prop('action'), | |||
method: "POST", | |||
data: $('#addProductToOrderForm').serialize(), | |||
dataType:"json", | |||
success: function (response) { | |||
generateNotice(response.status, response.message); | |||
if (response.status == 'success') { | |||
app.updateOrder(response.data); | |||
} | |||
} | |||
} | |||
}); | |||
}, | |||
getUnitReference: function () { | |||
if (typeof this.$refs.productUnitPrice !== 'undefined') { | |||
return this.$refs.productUnitPrice.unitReference; | |||
} | |||
} | |||
}, | |||
watch: { | |||
title: function () { | |||
this.updateChild() | |||
}, | |||
} | |||
}); | |||
@@ -39,7 +39,9 @@ group: | |||
ReductionCatalog: | |||
info: Informations principal | |||
conditions: Condictions d'application | |||
OrderShop: | |||
resume: Résumé de commande | |||
addProduct: Ajout de produit à la commande | |||
None: Aucune valeur | |||
label.form.empty_value: Choisissez une option | |||
form.label.delete: Supprimer l'image | |||
@@ -207,6 +209,10 @@ field: | |||
Address: | |||
city: Commune | |||
OrderShop: | |||
product: Produit | |||
quantity: Quantité | |||
addOrderToProduct: Ajouter le produit | |||
action: | |||
new: Créer %entity_label% |
@@ -12,7 +12,13 @@ | |||
{% endmacro %} | |||
{% macro endCard(noCol = false) %} | |||
{% macro cardOverlay(attr) %} | |||
</div> | |||
<div v-if="{{ attr }}==true" class="overlay"> | |||
<i class="fas fa-2x fa-sync-alt"></i> | |||
</div> | |||
{% endmacro %} | |||
{% macro endCard(noCol = false) %} | |||
</div> | |||
</div> | |||
{% if noCol == false %}</div>{% endif %} |
@@ -50,91 +50,4 @@ | |||
{% block script_javascript %} | |||
{{ parent() }} | |||
<script src="{{ asset('bundles/lcshop/js/backend/script/default/init-edit.js') }}"></script> | |||
{#<script type="text/javascript"> | |||
$(function() { | |||
$('.edit-form').areYouSure({ 'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}' }); | |||
const entityForm = document.querySelector('form.edit-form'); | |||
const formSubmitButton = entityForm.querySelector('button[type="submit"]'); | |||
const inputFieldsSelector = 'input,select,textarea'; | |||
// Adding visual feedback for invalid fields: any ".form-group" with invalid fields | |||
// receives "has-error" class. The class is removed on click on the ".form-group" | |||
// itself to support custom/complex fields. | |||
formSubmitButton.addEventListener('click', function() { | |||
entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) { | |||
if (!input.validity.valid) { | |||
const formGroup = input.closest('div.form-group'); | |||
formGroup.classList.add('has-error'); | |||
formGroup.addEventListener('click', function onFormGroupClick() { | |||
formGroup.classList.remove('has-error'); | |||
formGroup.removeEventListener('click', onFormGroupClick); | |||
}); | |||
} | |||
}); | |||
}); | |||
// forms with tabs require some special treatment for errors. The problem | |||
// is when the field with errors is included in a tab not currently visible. | |||
// Browser shows this error "An invalid form control with name='...' is not focusable." | |||
// So, the user clicks on Submit button, the form is not submitted and the error | |||
// is not displayed. This JavaScript code ensures that each tab shows a badge with | |||
// the number of errors in it. | |||
formSubmitButton.addEventListener('click', function() { | |||
const formTabPanes = entityForm.querySelectorAll('.tab-pane'); | |||
if (0 === formTabPanes.length) { | |||
return; | |||
} | |||
let firstNavTabItemWithError = null; | |||
formTabPanes.forEach(function (tabPane) { | |||
let tabPaneNumErrors = 0; | |||
tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) { | |||
if (!input.validity.valid) { | |||
tabPaneNumErrors++; | |||
} | |||
}); | |||
let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]'); | |||
let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger'); | |||
if (null !== existingErrorBadge) { | |||
navTabItem.removeChild(existingErrorBadge); | |||
} | |||
if (tabPaneNumErrors > 0) { | |||
let newErrorBadge = document.createElement('span'); | |||
newErrorBadge.classList.add('badge', 'badge-danger'); | |||
newErrorBadge.title = 'form.tab.error_badge_title'; | |||
newErrorBadge.textContent = tabPaneNumErrors; | |||
navTabItem.appendChild(newErrorBadge); | |||
if (null === firstNavTabItemWithError) { | |||
firstNavTabItemWithError = navTabItem; | |||
} | |||
} | |||
}); | |||
if (firstNavTabItemWithError) { | |||
firstNavTabItemWithError.click(); | |||
} | |||
}); | |||
$('a.action-delete').on('click', function(e) { | |||
e.preventDefault(); | |||
$('#modal-delete').modal({ backdrop: true, keyboard: true }) | |||
.off('click', '#modal-delete-button') | |||
.on('click', '#modal-delete-button', function () { | |||
$('#delete-form').trigger('submit'); | |||
}); | |||
}); | |||
}); | |||
</script>#} | |||
{% endblock %} |
@@ -0,0 +1,5 @@ | |||
{% trans_default_domain "lcshop" %} | |||
{% block ajax %} | |||
{% endblock %} |
@@ -0,0 +1,76 @@ | |||
{% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %} | |||
{# the empty string concatenation is needed when the primary key is an object (e.g. an Uuid object) #} | |||
{% set _entity_id = '' ~ attribute(entity, _entity_config.primary_key_field_name) %} | |||
{% trans_default_domain _entity_config.translation_domain %} | |||
{% set _trans_parameters = { '%entity_name%': _entity_config.name|trans, '%entity_label%': _entity_config.label|trans, '%entity_id%': _entity_id } %} | |||
{% extends _entity_config.templates.layout %} | |||
{% block body_id 'easyadmin-show-' ~ _entity_config.name ~ '-' ~ _entity_id %} | |||
{% block content_title %} | |||
{% apply spaceless %} | |||
{% set _default_title = 'show.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %} | |||
{{ _entity_config.show.title is defined ? _entity_config.show.title|trans(_trans_parameters) : _default_title }} | |||
{% endapply %} | |||
{% endblock %} | |||
{% block content_footer_wrapper '' %} | |||
{% block main %} | |||
<div class="form-horizontal"> | |||
{% block show_fields %} | |||
{% set _fields_visible_by_user = fields|filter((metadata, field) => easyadmin_is_granted(metadata.permission)) %} | |||
{% for field, metadata in _fields_visible_by_user %} | |||
{% block show_field %} | |||
<div class="form-group field-{{ metadata.type|default('default')|lower }} {{ metadata.css_class|default('') }}"> | |||
<label class="control-label"> | |||
{{ metadata.label|trans(_trans_parameters)|raw }} | |||
</label> | |||
<div class="form-widget"> | |||
<div class="form-control"> | |||
{{ easyadmin_render_field_for_show_view(_entity_config.name, entity, metadata) }} | |||
</div> | |||
{% if metadata.help|default('') != '' %} | |||
<small class="form-help"><i class="fa fa-fw fa-info-circle"></i> {{ metadata.help|trans|raw }}</small> | |||
{% endif %} | |||
</div> | |||
</div> | |||
{% endblock %} | |||
{% endfor %} | |||
{% endblock %} | |||
</div> | |||
<section class="content-footer"> | |||
<div class="form-actions"> | |||
{% block item_actions %} | |||
{% set _show_actions = easyadmin_get_actions_for_show_item(_entity_config.name) %} | |||
{% set _request_parameters = app.request.query.all %} | |||
{{ include('@EasyAdmin/default/includes/_actions.html.twig', { | |||
actions: _show_actions, | |||
entity_config: _entity_config, | |||
request_parameters: _request_parameters, | |||
translation_domain: _entity_config.translation_domain, | |||
trans_parameters: _trans_parameters, | |||
item_id: _entity_id, | |||
item: entity | |||
}, with_context = false) }} | |||
{% endblock item_actions %} | |||
</div> | |||
</section> | |||
{% block delete_form %} | |||
{{ include('@EasyAdmin/default/includes/_delete_form.html.twig', { | |||
view: 'show', | |||
referer: app.request.query.get('referer', ''), | |||
delete_form: delete_form, | |||
_translation_domain: _entity_config.translation_domain, | |||
_trans_parameters: _trans_parameters, | |||
_entity_config: _entity_config, | |||
}, with_context = false) }} | |||
{% endblock delete_form %} | |||
{% endblock %} |
@@ -0,0 +1,14 @@ | |||
{{ form_start(form_add_product_to_order, {'attr': {"class" : 'row', 'id' : 'addProductToOrderForm'}}) }} | |||
{% form_theme form_add_product_to_order '@LcShop/backend/form/custom_bootstrap_4.html.twig' %} | |||
<div class="col-12"> | |||
{{ form_row(form_add_product_to_order.product, {'attr': {"v-model" : 'addProductId'}}) }} | |||
</div> | |||
<div class="col-12"> | |||
{{ form_row(form_add_product_to_order.quantity, {'attr': {"v-model" : 'addProductQuantity'}}) }} | |||
</div> | |||
<div class="col-12"> | |||
{{ form_row(form_add_product_to_order.addProductToOrder, {'attr': {"class": "btn-success float-right", "@click" : 'addProductToOrder'}}) }} | |||
</div> | |||
{{ form_end(form_add_product_to_order) }} | |||
@@ -0,0 +1,24 @@ | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{% import '@LcShop/backend/order/macros.html.twig' as orderMacros %} | |||
{{ macros.startCard(9, 'OrderShop.resume') }} | |||
<div class="col-12"> | |||
{{ form_start(form_order_products, {'attr': {'id' : 'orderProductsForm'}}) }} | |||
<script> | |||
window.templateTest = '{{ orderMacros.productsTemplate(form_order_products)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | |||
</script> | |||
{{ orderMacros.tableHead() }} | |||
{{ orderMacros.products(form_order_products) }} | |||
{{ orderMacros.tableTotal() }} | |||
{{ form_end(form_order_products) }} | |||
<div class="clearfix"></div> | |||
<script> | |||
window.orderObject = {{ order|json_encode|raw }}; | |||
</script> | |||
</div> | |||
{{ macros.cardOverlay('isLoading') }} | |||
{{ macros.endCard(9) }} |
@@ -1,23 +1,24 @@ | |||
{% extends app.request.query.get('action') == 'edit' ? '@LcShop/backend/default/edit.html.twig' : '@LcShop/backend/default/new.html.twig' %} | |||
{% extends '@LcShop/backend/default/show.html.twig' %} | |||
{% block entity_form %} | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{% block main %} | |||
{% if formView is defined and formView == 'default'%} | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{{ macros.startCard(8, 'OrderShop.selectUser') }} | |||
<div class="col-12"> | |||
{{ form(form) }} | |||
</div> | |||
{{ macros.endCard() }} | |||
{% else %} | |||
{% include '@LcShop/backend/order/form.html.twig' %} | |||
{% endif %} | |||
<div class="lc-vue-js-container" id="lc-order-edit"> | |||
<div class="row"> | |||
{% include '@LcShop/backend/order/form.html.twig' %} | |||
{% endblock entity_form %} | |||
{{ macros.startCard(3, 'OrderShop.addProduct', 'success') }} | |||
{% include '@LcShop/backend/order/card_addproducttoorder.html.twig' %} | |||
{{ macros.endCard }} | |||
</div> | |||
</div> | |||
{% endblock %} | |||
{% block body_javascript %} | |||
{% block script_javascript %} | |||
{{ parent() }} | |||
{% include '@LcShop/backend/default/block/script-vuejs.html.twig' %} | |||
<script src="{{ asset('bundles/lcshop/js/backend/script/order/vuejs-order.js') }}"></script> |
@@ -1,49 +1,12 @@ | |||
{{ form_start(form, {"attr": {'@change' : 'formUpdated'}}) }} | |||
<div class="lc-vue-js-container" id="lc-order-edit"> | |||
{#{{ form_start(form, {"attr": {'class' : "col-9"}}) }}#} | |||
<div id="lc-product-family-edit"> | |||
<div class="card card-light"> | |||
<div class="lc-vue-js-container card-header p-0 border-bottom-0"> | |||
<ul class="nav nav-tabs" id="nav-params"> | |||
<li class="nav-item" v-for="section in sectionsArray"> | |||
<button type="button" | |||
v-if="(section.name == 'delivery' && deliveryType == 'at-home' && deliveryAddress>0) || (section.name != 'delivery')" | |||
:class="'btn '+((currentSection == section.name) ? 'btn btn-primary' : 'btn')" | |||
@click="changeSection(section)"> | |||
${ section.nameDisplay } | |||
<span class="glyphicon glyphicon-triangle-bottom"></span> | |||
</button> | |||
</li> | |||
</ul> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="form"> | |||
<script>// rendered by server | |||
/*window.appProductFamilyValues = { | |||
{#{% if form.vars.value.title %}title: "{{ form.vars.value.title }}",{% endif %}#} | |||
};*/ | |||
</script> | |||
<div v-show="currentSection == 'cart'" class="panel panel-default"> | |||
{% include '@LcShop/backend/order/panel_orderproducts.html.twig' %} | |||
</div> | |||
<div v-show="currentSection == 'addresses'" class="panel panel-default"> | |||
{% include '@LcShop/backend/order/panel_addresses.html.twig' %} | |||
</div> | |||
<div v-show="currentSection == 'delivery'" class="panel panel-default"> | |||
{% include '@LcShop/backend/order/panel_delivery.html.twig' %} | |||
</div> | |||
</div> | |||
</div> | |||
{% include '@LcShop/backend/order/card_orderproducts.html.twig' %} | |||
{#{% include '@LcShop/backend/order/card_adresses.html.twig' %}#} | |||
{# | |||
{{ form_end(form) }} | |||
#} | |||
@@ -0,0 +1,86 @@ | |||
{% macro tableHead() %} | |||
<table id="order-products-list" class="table table-striped"> | |||
<thead> | |||
<tr> | |||
<th colspan="2"> | |||
<span>Produits / Producteurs</span> | |||
</th> | |||
<th> | |||
<span>Prix HT à l'unité</span> | |||
</th> | |||
<th> | |||
<span>Prix TTC à l'unité </span> | |||
</th> | |||
<th> | |||
<span>Disponibilité</span> | |||
</th> | |||
<th> | |||
<span>Quantité</span> | |||
</th> | |||
<th> | |||
<span>Total</span> | |||
</th> | |||
</tr> | |||
</thead> | |||
{% endmacro %} | |||
{% macro products(form_order_products) %} | |||
<tbody> | |||
<template v-for="(orderProduct, key) in orderProducts"> | |||
<order-product ref="orderProductBLOP" :order-product="orderProduct" :template="templateTest" :key-item="key"></order-product> | |||
</template> | |||
</tbody> | |||
{% endmacro %} | |||
{% macro productsTemplate(form_order_products) %} | |||
<tr class="order-product-item"> | |||
<td colspan="2">{% verbatim %}{{orderProduct.title}}{% endverbatim %}</td> | |||
<td> | |||
{% verbatim %}{{orderProduct.price}}{% endverbatim %}€ | |||
</td> | |||
<td> | |||
{% verbatim %}{{orderProduct.priceWithTax}}{% endverbatim %}€ | |||
</td> | |||
<td></td> | |||
<td> | |||
{{ form_widget(form_order_products.orderProducts.vars.prototype.quantityOrder, {'attr' : {'ref': 'fieldQuantity', 'v-model' : 'orderProduct.quantityOrder', '@change' : 'updateOrderProducts'}}) }} | |||
{{ form_widget(form_order_products.orderProducts.vars.prototype.product, {'attr' : {'ref' : 'fieldProduct', 'v-model' : 'orderProduct.product'}}) }} | |||
{#{{ form_widget(form_order_products.orderProducts.vars.prototype.id, {'attr' : {'ref' : 'fieldId', 'v-model' : 'orderProduct.id'}}) }}#} | |||
<button type="button" class="btn-remove-product btn btn-default" @click="deleteOrderProduct()"> | |||
<i class="fa fa-trash"></i> | |||
</button> | |||
</td> | |||
<td> | |||
{% verbatim %}{{orderProduct.totalWithTaxAndReduction}}{% endverbatim %}€ | |||
</td> | |||
</tr> | |||
{% endmacro %} | |||
{% macro tableTotal() %} | |||
</table> | |||
<div class="clearfix"></div> | |||
<div class="row"> | |||
<div class="col-7"></div> | |||
<div class="col-5"> | |||
<div class="table-responsive"> | |||
<table class="table"> | |||
<tbody> | |||
<tr> | |||
<th>Total without Tax</th> | |||
<td>${order.total}€</td> | |||
</tr> | |||
<tr> | |||
<th>Total</th> | |||
<td>${order.totalWithTax}€</td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
</div> | |||
{% endmacro %} |
@@ -0,0 +1,12 @@ | |||
{% extends '@LcShop/backend/default/new.html.twig' %} | |||
{% block entity_form %} | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{{ macros.startCard(8, 'OrderShop.selectUser') }} | |||
<div class="col-12"> | |||
{{ form(form) }} | |||
</div> | |||
{{ macros.endCard() }} | |||
{% endblock entity_form %} | |||
@@ -4,12 +4,11 @@ | |||
<div class="card-header"> | |||
<h3>{{ "form.group.ProductFamily.addresses"|trans }}</h3> | |||
</div> | |||
<div class="row" > | |||
<div class="row"> | |||
<div class="col"> | |||
{{ form_label(form.deliveryType) }} | |||
{% for field in form.deliveryType %} | |||
{{ form_widget(field, {"attr" : {"v-model" : 'deliveryType'}}) }} | |||
{% endfor %} | |||
@@ -25,6 +24,6 @@ | |||
{{ form_row(form.invoiceAddress, {"attr": {'v-model' : 'invoiceAddress', 'v-selecttwo' : 'invoiceAddress'}}) }} | |||
</div> | |||
</div> | |||
</fieldset> | |||
</div> | |||
</div> | |||
</div> |
@@ -1,135 +0,0 @@ | |||
{% macro printOrderProductRow(orderProduct) %} | |||
<tr class="order-product-item"> | |||
<td colspan="2"> | |||
<div class="form-widget"> | |||
{{ form_widget(orderProduct.product, {'attr' : {'v-model' : 'product'}}) }} | |||
</div> | |||
</td> | |||
<td> | |||
<div class="form-widget"> | |||
{% verbatim %}{{ price }}{% endverbatim %}€ | |||
</div> | |||
</td> | |||
<td> | |||
<div class="form-widget"> | |||
{% verbatim %}{{ priceWithTax }}{% endverbatim %}€ | |||
</div> | |||
</td> | |||
<td> | |||
<div class="form-widget"> | |||
{{ form_widget(orderProduct.quantity, {'attr' : {'v-model' : 'quantity', '@change': 'updateQuantity'}}) }} | |||
</div> | |||
</td> | |||
<td> | |||
{% verbatim %}{{ totalWithTax }}{% endverbatim %}€ | |||
</td> | |||
<td> | |||
<button type="button" class="btn-remove-product btn btn-default" @click="deleteProductForm()"> | |||
<i class="fa fa-trash"></i> | |||
</button> | |||
</td> | |||
</tr> | |||
{% endmacro %} | |||
{% import _self as formMacros %} | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
<div class="row"> | |||
{{ macros.startCard(12, 'OrderShop.cart') }} | |||
<div class="col-12"> | |||
<table id="order-products-list" class="table table-striped" | |||
data-prototype="{{ formMacros.printOrderProductRow(form.orderProducts.vars.prototype)|e('html_attr') }}"> | |||
<thead> | |||
<tr> | |||
<th colspan="2"> | |||
<span>Produit</span> | |||
</th> | |||
<th> | |||
<span>Prix HT à l'unité</span> | |||
</th> | |||
<th> | |||
<span>Prix TTC à l'unité</span> | |||
</th> | |||
<th> | |||
<span>Quantité</span> | |||
</th> | |||
<th> | |||
<span>Total</span> | |||
</th> | |||
<th> | |||
<span>Action</span> | |||
</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<template v-for="(formProduct, key) in formOrderProductArray"> | |||
<order-product-form ref="orderProductForm" :template="formProduct" :key-form="key"></order-product-form> | |||
</template> | |||
</tbody> | |||
</table> | |||
<button type="button" class="add_tag_link btn-add-product btn btn-default float-right" @click="addOrderProductForm"> | |||
<span class="fa fa-plus"></span> Ajouter un produit | |||
</button> | |||
<div class="clearfix"></div> | |||
<div class="row"> | |||
<div class="col-6"></div> | |||
<div class="col-6"> | |||
<div class="table-responsive"> | |||
<table class="table"> | |||
<tbody> | |||
<tr> | |||
<td>Total without Tax</td> | |||
<td>${totalWithoutTax}€</td> | |||
</tr> | |||
<tr> | |||
<td>Total Tax</td> | |||
<td>${totalWithTax- totalWithoutTax}€</td> | |||
</tr> | |||
<tr> | |||
<td>Total</td> | |||
<td>${totalWithTax}€</td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="clearfix"></div> | |||
<script> | |||
window.orderProductForm = new Array(); | |||
</script> | |||
{% for keyForm, orderProduct in form.orderProducts %} | |||
<script> | |||
window.orderProductForm[{{ keyForm }}] = { | |||
{% if orderProduct.vars.value.title %}title: "{{ orderProduct.vars.value.title }}",{% endif %} | |||
{% if orderProduct.vars.value.quantity %}quantity: "{{ orderProduct.vars.value.quantity }}",{% endif %} | |||
{% if orderProduct.vars.value.unit %}unit: "{{ orderProduct.vars.value.unit }}",{% endif %} | |||
{#{% if orderProduct.vars.value.buyingPrice %}buyingPrice: "{{ orderProduct.vars.value.buyingPrice }}",{% endif %}#} | |||
{% if orderProduct.vars.value.price %}price: parseFloat({{ orderProduct.vars.value.price }}).toFixed(3),{% endif %} | |||
{% if orderProduct.vars.value.product %}product: {{ orderProduct.vars.value.product.id }}{% endif %} | |||
}; | |||
jQuery(window).on('load', function () { | |||
var orderProductForm = '{{ formMacros.printOrderProductRow(orderProduct)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | |||
appOrder.formOrderProductArray.push(orderProductForm); | |||
appOrder.indexOrderProductForm++; | |||
}); | |||
</script> | |||
{% endfor %} | |||
{% do form.orderProducts.setRendered %} | |||
</div> | |||
{{ macros.endCard() }} | |||
</div> |
@@ -4,35 +4,6 @@ | |||
<tr class="lc-draggable"> | |||
<td><i class="fa fa-fw fa-sort"></i></td> | |||
{#<td colspan="2" class="title" v-on:click="titleInherited = true"> | |||
<div v-show="titleInherited == false"> | |||
<div v-if="title" class="blop"> | |||
{% verbatim %}{{ title }}{% endverbatim %} | |||
</div> | |||
<div v-else class="inherited"> | |||
{% verbatim %}{{ productFamily.title }}{% endverbatim %} | |||
</div> | |||
</div> | |||
<div v-show="titleInherited == true"> | |||
{{ form_widget(product.title, {'attr' : {'v-model' : 'title', 'v-on:focusout': 'titleInherited = false'}}) }} | |||
</div> | |||
</td>#} | |||
{# | |||
<td colspan="2" class="unit" v-on:click="unitInherited = true"> | |||
<div v-show="unitInherited == false"> | |||
<div v-if="unit" class="blop"> | |||
{% verbatim %}{{ unitWording }}{% endverbatim %} | |||
</div> | |||
<div v-else class="inherited"> | |||
{% verbatim %}{{ unitWording }}{% endverbatim %} | |||
</div> | |||
</div> | |||
<div v-show="unitInherited == true"> | |||
{{ form_widget(product.unit, {'attr' : {'v-model' : 'unit', 'v-on:focusout': 'unitInherited = false', '@change' : 'updateLine'}}) }} | |||
</div> | |||
</td>#} | |||
{{ macros.productField(2, product.title, 'title') }} | |||
{{ macros.productField(1, product.quantity, 'quantity') }} | |||
{{ macros.productField(2, product.unit, 'unit', 'unitWording') }} |
@@ -1,72 +0,0 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Routing; | |||
use Lc\ShopBundle\Model\Address; | |||
use Symfony\Component\Config\Loader\Loader; | |||
use Symfony\Component\Routing\Route; | |||
use Symfony\Component\Routing\RouteCollection; | |||
class CrudLoader extends Loader | |||
{ | |||
private $isLoaded = false; | |||
public function load($resource, $type = null) | |||
{ | |||
if (true === $this->isLoaded) { | |||
throw new \RuntimeException('Do not add the "extra" loader twice'); | |||
} | |||
$routes = new RouteCollection(); | |||
$lcShopRoutes = array( | |||
'address' => "Address", | |||
"cart" => "Cart", | |||
"credit_config" => "CreditConfig", | |||
"document_nelivery_note" => "DocumentDeliveryNote", | |||
"document_quotation" => "DocumentQuotation", | |||
"document_invoice" => "DocumentInvoice", | |||
"merchant" => "Merchant", | |||
"merchant_config" => "MerchantConfig", | |||
/*"order"=>"Order"*/ | |||
"point_sale" => "PointSale", | |||
"tax_rate" => "TaxRate", | |||
"product" => "Products" | |||
); | |||
$actions = [ | |||
'index' => 'indexAction', | |||
'edit' => 'editAction', | |||
'delete' => 'deleteAction', | |||
'show' => 'showAction' | |||
]; | |||
foreach ($lcShopRoutes as $entity => $controller) { | |||
foreach ($actions as $actionName => $action) { | |||
if ($actionName == 'edit' || $actionName == 'delete' || $actionName == "show") { | |||
$path = '/' . $entity . '/' . $actionName . '/{id}'; | |||
} else { | |||
$path = '/' . $entity . '/' . $actionName; | |||
} | |||
$defaults = [ | |||
'_controller' => 'Lc\ShopBundle\Controller\\' . $controller . 'Controller::' . $action | |||
]; | |||
$requirements = [ | |||
'parameter' => '\d+', | |||
]; | |||
$route = new Route($path, $defaults, $requirements); | |||
$routeName = 'lc_shop_' . $entity . '_' . $actionName; | |||
$routes->add($routeName, $route); | |||
} | |||
} | |||
$this->isLoaded = true; | |||
return $routes; | |||
} | |||
public function supports($resource, $type = null) | |||
{ | |||
return 'crud' === $type; | |||
} | |||
} |
@@ -6,6 +6,7 @@ use App\Entity\OrderProductReductionCatalog; | |||
use App\Entity\OrderShop; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | |||
use Symfony\Component\Security\Core\Security; | |||
@@ -31,6 +32,7 @@ class OrderUtils | |||
$this->productFamilyUtils = $productFamilyUtils ; | |||
} | |||
public function getOrderShopCurrent() | |||
{ | |||
$paramsSearchOrderShop = []; | |||
@@ -136,6 +138,7 @@ class OrderUtils | |||
$this->em->flush(); | |||
} | |||
} | |||
public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2) | |||
@@ -193,6 +196,35 @@ class OrderUtils | |||
return $data ; | |||
} | |||
public function getOrderAsJsonObject(OrderShopInterface $order) | |||
{ | |||
$data['id'] = $order->getId(); | |||
$data['total'] = $this->priceUtils->getTotal($order); | |||
$data['totalWithTax'] = $this->priceUtils->getTotalWithTax($order); | |||
$data['totalWithTaxAndReduction'] = $this->priceUtils->getTotalWithTax($order); | |||
$data['deliveryAddress'] = $order->getDeliveryAddress($order); | |||
$i=0; | |||
foreach ($this->getOrderProductsByParentCategory($order) as $labelCategory => $orderProducts) { | |||
foreach ($orderProducts as $orderProduct) { | |||
$data['orderProducts'][$i]['id'] = $orderProduct->getId(); | |||
$data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId(); | |||
$data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder(); | |||
$data['orderProducts'][$i]['labelCategory'] = $labelCategory; | |||
$data['orderProducts'][$i]['title'] = $orderProduct->getTitle(); | |||
$data['orderProducts'][$i]['price'] = $this->priceUtils->getPrice($orderProduct); | |||
$data['orderProducts'][$i]['priceWithTax'] = $this->priceUtils->getPriceWithTax($orderProduct); | |||
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceUtils->getPriceWithTaxAndReduction($orderProduct); | |||
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder(); | |||
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceUtils->getTotalWithTaxAndReductionByOrderProducts(array($orderProduct)); | |||
$i++; | |||
} | |||
} | |||
return $data; | |||
} | |||
public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog) | |||
{ | |||
$text = '' ; |