<?php | |||||
namespace Lc\ShopBundle\Controller\Admin; | |||||
use App\Entity\OrderProduct; | |||||
use App\Entity\Product; | |||||
use Doctrine\DBAL\Types\FloatType; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||||
use Lc\ShopBundle\Context\AddressInterface; | |||||
use Lc\ShopBundle\Context\ProductCategoryInterface; | |||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||||
use Lc\ShopBundle\Context\ProductInterface; | |||||
use Lc\ShopBundle\Context\TaxRateInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | |||||
use Lc\ShopBundle\Form\OrderProductType; | |||||
use Lc\ShopBundle\Form\ProductFamilyCategoriesType; | |||||
use Lc\ShopBundle\Form\ProductType; | |||||
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\Response; | |||||
class OrderController extends AdminController | |||||
{ | |||||
public function updateEntity($entity) | |||||
{ | |||||
foreach($entity->getOrderProducts() as $orderProduct) { | |||||
$orderProduct->setCreatedBy($this->getUser()) ; | |||||
$orderProduct->setUpdatedBy($this->getUser()) ; | |||||
$orderProduct->setTaxRate($orderProduct->getProduct()->getProductFamily()->getTaxRate()) ; | |||||
$orderProduct->setOrderShop($entity) ; | |||||
$this->em->persist($orderProduct); | |||||
$entity->addOrderProduct($orderProduct) ; | |||||
} | |||||
$this->setUpdated($entity); | |||||
parent::updateEntity($entity); | |||||
} | |||||
public function persistEntity($entity) | |||||
{ | |||||
parent::persistEntity($entity) ; | |||||
} | |||||
public function createEntityFormBuilder($entity, $view) | |||||
{ | |||||
$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 | |||||
) | |||||
); | |||||
$userClass = $this->em->getClassMetadata(UserInterface::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, | |||||
'query_builder' => function (EntityRepository $er) use ($entity) { | |||||
return $er->createQueryBuilder('a') | |||||
->where('a.user = :user') | |||||
->setParameter('user', $entity->getUser()); | |||||
}, | |||||
)); | |||||
$formBuilder->add('deliveryAddress', EntityType::class, array( | |||||
'class' => $addressClass->name, | |||||
'query_builder' => function (EntityRepository $er) use ($entity) { | |||||
return $er->createQueryBuilder('a') | |||||
->where('a.user = :user') | |||||
->setParameter('user', $entity->getUser()); | |||||
}, | |||||
)); | |||||
return $formBuilder; | |||||
} | |||||
public function getUserViaFirstStepForm($entity) | |||||
{ | |||||
$userClass = $this->em->getClassMetadata(UserInterface::class); | |||||
$userChoiceForm = $this->createFormBuilder($entity) | |||||
->add('user', EntityType::class, array( | |||||
'class' => $userClass->name | |||||
)) | |||||
->add('nextStep', SubmitType::class) | |||||
->getForm(); | |||||
$userChoiceForm->handleRequest($this->request); | |||||
if ($userChoiceForm->isSubmitted() && $userChoiceForm->isValid()) { | |||||
return $userChoiceForm->get('user')->getData(); | |||||
} | |||||
$parameters = [ | |||||
'form' => $userChoiceForm->createView(), | |||||
'formView' => 'default', | |||||
'entity' => $entity, | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||||
} | |||||
protected function newAction() | |||||
{ | |||||
$this->dispatch(EasyAdminEvents::PRE_NEW); | |||||
$entity = $this->executeDynamicMethod('createNew<EntityName>Entity'); | |||||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||||
$easyadmin['item'] = $entity; | |||||
$this->request->attributes->set('easyadmin', $easyadmin); | |||||
$fields = $this->entity['new']['fields']; | |||||
$newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]); | |||||
$newForm->handleRequest($this->request); | |||||
//ETAPE 1 Choix de l'utilisateur | |||||
$user = $newForm->get('user')->getData(); | |||||
if($user == null){ | |||||
$user = $this->getUserViaFirstStepForm($entity); | |||||
} | |||||
if (!$user instanceof UserInterface) return $user; | |||||
else{ | |||||
$entity->setUser($user); | |||||
/* $newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]); | |||||
$newForm->handleRequest($this->request);*/ | |||||
//dump( $entity); | |||||
//dump( $entity); | |||||
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]); | |||||
return $this->redirectToReferrer(); | |||||
} | |||||
$this->dispatch(EasyAdminEvents::POST_NEW, [ | |||||
'entity_fields' => $fields, | |||||
'form' => $newForm, | |||||
'entity' => $entity | |||||
]); | |||||
$parameters = [ | |||||
'form' => $newForm->createView(), | |||||
'entity_fields' => $fields, | |||||
'entity' => $entity | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||||
} | |||||
} | |||||
} |
$productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class); | $productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class); | ||||
$categories = $productCategoryRepository->findAllParents(); | $categories = $productCategoryRepository->findAllParents(); | ||||
$parameters = [ | |||||
'form' => $newForm->createView(), | |||||
'entity_fields' => $fields, | |||||
'entity' => $entity, | |||||
'categories' => $categories, | |||||
'sortableProductsField' => array() | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||||
Method('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||||
} | } | ||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Controller; | |||||
use Doctrine\ORM\EntityManager; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\ProductInterface; | |||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||||
use Symfony\Component\HttpFoundation\JsonResponse; | |||||
use Symfony\Component\Security\Core\Security; | |||||
class ApiController extends AbstractController | |||||
{ | |||||
protected $security; | |||||
protected $userManager; | |||||
protected $em ; | |||||
protected $utils ; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->em = $entityManager; | |||||
} | |||||
public function getEntity($entity, $id) | |||||
{ | |||||
if($entity == 'product'){ | |||||
$repo = $this->em->getRepository(ProductInterface::class); | |||||
$data = $repo->find($id); | |||||
$data= array( | |||||
'id' => $data->getId(), | |||||
'title' => $data->getTitleInherited(), | |||||
'price' => $data->getPriceInherited(), | |||||
'unit' => $data->getUnitInherited(), | |||||
'availableQuantity' => $data->getAvailableQuantityInherited(), | |||||
'taxRate' => $data->getTaxRateInherited(), | |||||
); | |||||
} | |||||
return new JsonResponse($data); | |||||
} | |||||
} | |||||
<?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, | |||||
/* 'attr'=>array( | |||||
'data-widget'=> 'select2' | |||||
),*/ | |||||
'choice_label'=> function($product){ | |||||
return $product->getProductFamily()->getTitle() . ' - ' . $product->getTitle(); | |||||
} | |||||
)); | |||||
$builder->add('quantity', NumberType::class, array( | |||||
'label' => 'Quantité', | |||||
'required' => false, | |||||
'attr' => [ | |||||
'append_html' => 'g' | |||||
] | |||||
)); | |||||
$builder->add('unit', HiddenType::class,array( | |||||
'data'=>'L', | |||||
)); | |||||
$builder->add('title', HiddenType::class,array( | |||||
'data'=>'Mon litre de pont', | |||||
)); | |||||
$builder->add('price', NumberType::class,array( | |||||
'attr'=> array( | |||||
'readonly'=> 'readonly' | |||||
) | |||||
)); | |||||
//$builder->add('buyingPrice', NumberType::class); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'data_class' => $this->em->getClassMetadata(OrderProductInterface::class)->getName(), | |||||
]); | |||||
} | |||||
} |
public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
{ | { | ||||
/* $builder->add('titleInherited', CheckboxType::class, array( | |||||
'mapped'=>false, | |||||
'required'=>false | |||||
));*/ | |||||
$builder->add('title', TextType::class, array( | $builder->add('title', TextType::class, array( | ||||
"required" => false | "required" => false | ||||
)) ; | )) ; | ||||
/*$builder->add('unitInherited', CheckboxType::class, array( | |||||
'mapped'=>false, | |||||
'required'=>false | |||||
));*/ | |||||
/* $builder->add('quantityInherited', CheckboxType::class, array( | |||||
'mapped'=>false, | |||||
'required'=>false | |||||
));*/ | |||||
$builder->add('quantity', NumberType::class, array( | $builder->add('quantity', NumberType::class, array( | ||||
'label' => 'Quantité', | 'label' => 'Quantité', | ||||
'required'=>false, | 'required'=>false, | ||||
'choices' => $this->utils->getUnitsListFormatedForType() | 'choices' => $this->utils->getUnitsListFormatedForType() | ||||
)); | )); | ||||
/* $builder->add('priceInherited', CheckboxType::class, array( | |||||
'mapped'=>false, | |||||
'required'=>false | |||||
));*/ | |||||
$builder->add('price', NumberType::class, array( | $builder->add('price', NumberType::class, array( | ||||
'label' => 'Prix', | 'label' => 'Prix', | ||||
"required" => false | "required" => false |
<?php | |||||
namespace Lc\ShopBundle\Form; | |||||
use Lc\ShopBundle\Context\TaxRateInterface; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class TaxRateType extends AbstractType | |||||
{ | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder | |||||
->add('title') | |||||
->add('value') | |||||
->add('createdAt') | |||||
->add('updatedAt') | |||||
->add('createdBy') | |||||
->add('updatedBy') | |||||
; | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'data_class' => TaxRateInterface::class, | |||||
]); | |||||
} | |||||
} |
abstract class OrderProduct extends AbstractEntity | abstract class OrderProduct extends AbstractEntity | ||||
{ | { | ||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderProducts") | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderProducts", cascade={"persist"}) | |||||
* @ORM\JoinColumn(nullable=false) | * @ORM\JoinColumn(nullable=false) | ||||
*/ | */ | ||||
protected $orderShop; | protected $orderShop; | ||||
*/ | */ | ||||
protected $title; | protected $title; | ||||
public function __toString() | |||||
{ | |||||
if($this->getTitle()) { | |||||
return $this->getTitle(); | |||||
}else{ | |||||
return $this->getProduct()->getProductFamily()->getTitle(). ' - '.$this->getProduct()->getTitle(); | |||||
} | |||||
} | |||||
public function getOrderShop(): ?OrderShop | public function getOrderShop(): ?OrderShop | ||||
{ | { | ||||
return $this->orderShop; | return $this->orderShop; |
*/ | */ | ||||
abstract class OrderShop extends AbstractEntity | abstract class OrderShop extends AbstractEntity | ||||
{ | { | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $merchant; | |||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders") | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders") | ||||
* @ORM\JoinColumn(nullable=false) | * @ORM\JoinColumn(nullable=false) | ||||
protected $comment; | protected $comment; | ||||
/** | /** | ||||
* @ORM\Column(type="boolean") | |||||
* @ORM\Column(type="boolean", nullable=true) | |||||
*/ | */ | ||||
protected $autoPayment; | protected $autoPayment; | ||||
/** | /** | ||||
* @ORM\Column(type="string", length=31) | |||||
* @ORM\Column(type="string", length=31, nullable=true) | |||||
*/ | */ | ||||
protected $meanPayment; | protected $meanPayment; | ||||
$this->creditHistories = new ArrayCollection(); | $this->creditHistories = new ArrayCollection(); | ||||
} | } | ||||
public function getMerchant(): ?Merchant | |||||
{ | |||||
return $this->merchant; | |||||
} | |||||
public function setMerchant(?Merchant $merchant): self | |||||
{ | |||||
$this->merchant = $merchant; | |||||
return $this; | |||||
} | |||||
public function getUser(): ?User | public function getUser(): ?User | ||||
{ | { | ||||
return $this->user; | return $this->user; |
protected $title; | protected $title; | ||||
public function getPriceInherited(){ | |||||
if($this->price){ | |||||
return $this->price; | |||||
}else{ | |||||
return $this->productFamily->getPrice(); | |||||
} | |||||
} | |||||
public function getUnitInherited(){ | |||||
if($this->unit){ | |||||
return $this->unit; | |||||
}else{ | |||||
return $this->productFamily->getUnit(); | |||||
} | |||||
} | |||||
public function getTitleInherited(){ | |||||
if($this->title){ | |||||
return $this->title; | |||||
}else{ | |||||
return $this->productFamily->getTitle(); | |||||
} | |||||
} | |||||
public function getAvailableQuantityInherited(){ | |||||
if($this->productFamily->getBehaviorCountStock()){ | |||||
return $this->availableQuantity; | |||||
}else{ | |||||
return $this->productFamily->getAvailableQuantity(); | |||||
} | |||||
} | |||||
public function getTaxRateInherited(){ | |||||
if($this->productFamily->getTaxRate()){ | |||||
return $this->productFamily->getTaxRate()->getValue(); | |||||
}else{ | |||||
return $this->productFamily->getMerchant()->getTaxRate()->getValue(); | |||||
} | |||||
} | |||||
public function getProductFamily(): ?ProductFamily | public function getProductFamily(): ?ProductFamily | ||||
{ | { |
return $this->behaviorCountStock; | return $this->behaviorCountStock; | ||||
} | } | ||||
public function setBehaviorCountStock(string $behaviorCountStock): self | public function setBehaviorCountStock(string $behaviorCountStock): self | ||||
{ | { | ||||
$this->behaviorCountStock = $behaviorCountStock; | $this->behaviorCountStock = $behaviorCountStock; |
- '/bundles/lcshop/js/backend/script/setup-ckfinder.js' | - '/bundles/lcshop/js/backend/script/setup-ckfinder.js' | ||||
- '/bundles/lcshop/js/backend/script/utils.js' | - '/bundles/lcshop/js/backend/script/utils.js' | ||||
- '/bundles/lcshop/js/backend/script/custom.js' | - '/bundles/lcshop/js/backend/script/custom.js' | ||||
- '/bundles/lcshop/js/backend/script/vuejs-mixins.js' | |||||
- '/bundles/lcshop/js/backend/script/vuejs-product-family.js' | |||||
- '/bundles/lcshop/js/backend/script/productfamily/vuejs-mixins.js' | |||||
- '/bundles/lcshop/js/backend/script/productfamily/vuejs-product-family.js' | |||||
- '/bundles/lcshop/js/backend/script/order/vuejs-order.js' | |||||
css: | css: | ||||
- '/bundles/lcshop/css/backend/jquery-ui.min.css' | - '/bundles/lcshop/css/backend/jquery-ui.min.css' | ||||
- '/bundles/lcshop/css/backend/custom.css' | - '/bundles/lcshop/css/backend/custom.css' |
switch_merchant: | switch_merchant: | ||||
path: /switch-merchant | path: /switch-merchant | ||||
controller: Lc\ShopBundle\Controller\Admin\MerchantController::switchMerchantAction | |||||
controller: Lc\ShopBundle\Controller\Admin\MerchantController::switchMerchantAction | |||||
lc_api: | |||||
path: /api/{entity}/{id} | |||||
controller: Lc\ShopBundle\Controller\ApiController::getEntity |
text-align: right ; | text-align: right ; | ||||
} | } | ||||
/* ORDER */ | |||||
/*.select2-container--bootstrap .select2-selection{max-width: none;}*/ | |||||
/*.order-product-item{margin: 15px 0; padding: 0;}*/ | |||||
/* Product */ | /* Product */ | ||||
.product-form-modal{display: none;} | .product-form-modal{display: none;} | ||||
.product-form.modal .form-check-label{font-style: italic; color: #666; text-align: left;} | .product-form.modal .form-check-label{font-style: italic; color: #666; text-align: left;} |
// Reference array sent to dynamic staticRenderFns | |||||
var staticRenderFns = []; | |||||
/* | |||||
Vue.directive('selecttwo', { | |||||
twoWay: true, | |||||
bind: function (el, binding, vnode) { | |||||
log(el) | |||||
log(binding) | |||||
log(this) | |||||
$(el).select2({ | |||||
theme: 'bootstrap', | |||||
language: '{{ _select2_locale }}' | |||||
}); | |||||
$(el).select2().on("select2:select", function(e) { | |||||
this.set($(el).val()); | |||||
}.bind(binding)); | |||||
}, | |||||
update: function(el, ov) { | |||||
log(el) | |||||
; | |||||
$(el).trigger("change"); | |||||
} | |||||
}); | |||||
*/ | |||||
Vue.component('order-product-form', { | |||||
mixins: [mixinTemplate], | |||||
props: ['template', 'keyForm'], | |||||
computed: {}, | |||||
data() { | |||||
return Object.assign( | |||||
{ | |||||
title: null, | |||||
price: null, | |||||
priceWithTax: null, | |||||
totalWithoutTax: null, | |||||
totalWithTax: null, | |||||
buyingPrice: null, | |||||
quantity: 1, | |||||
unit: null, | |||||
product: null | |||||
}/*, window.productForm[this.keyForm]*/) | |||||
}, | |||||
mounted: function () { | |||||
this.setSelect2(); | |||||
}, | |||||
methods: { | |||||
updateLine: function (data) { | |||||
this.price = data.price; | |||||
this.priceWithTax = getPriceWithTax(this.price, data.taxRate); | |||||
this.updateQuantity(); | |||||
this.$parent.updateTotalPrice(); | |||||
}, | |||||
updateQuantity:function(){ | |||||
this.totalWithTax = this.priceWithTax * this.quantity; | |||||
this.totalWithoutTax = this.price * this.quantity; | |||||
this.$parent.updateTotalPrice(); | |||||
}, | |||||
setSelect2: function(){ | |||||
var monSelect = $(this.$el).find('select.form-control').select2({ | |||||
theme: 'bootstrap', | |||||
language: 'fr' | |||||
}); | |||||
var vue = this; | |||||
monSelect.on('select2:select', function () { | |||||
this.product = monSelect.val(); | |||||
$.ajax({ | |||||
url: "http://localhost:8000/api/product/" + this.product, | |||||
method: "GET", | |||||
dataType: "", | |||||
success: function (response) { | |||||
vue.updateLine(response); | |||||
} | |||||
}); | |||||
}) | |||||
} | |||||
}, | |||||
watch: {} | |||||
}); | |||||
appOrder = new Vue({ | |||||
el: '#lc-order-edit', | |||||
delimiters: ['${', '}'], | |||||
computed: {}, | |||||
data() { | |||||
return Object.assign( | |||||
{ | |||||
currentSection: 'cart', | |||||
formOrderProductArray: [], | |||||
indexOrderProductForm: 0, | |||||
invoiceAddress: null, | |||||
deliveryAddress: null, | |||||
totalWithTax:null, | |||||
totalWithoutTax:null, | |||||
sectionsArray: [ | |||||
{ | |||||
name: 'cart', | |||||
nameDisplay: 'Panier' | |||||
}, | |||||
{ | |||||
name: 'addresses', | |||||
nameDisplay: 'Livraisons & facturations' | |||||
} | |||||
] | |||||
})/*, 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 = this.totalWithoutTax + line.totalWithoutTax; | |||||
this.totalWithTax = this.totalWithTax + line.totalWithTax; | |||||
} | |||||
}, | |||||
changeSection: function (section) { | |||||
this.updateChild(); | |||||
this.currentSection = section.name; | |||||
}, | |||||
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() | |||||
}, | |||||
} | |||||
}); |
//staticRenderFns.push(res.staticRenderFns[i]); | //staticRenderFns.push(res.staticRenderFns[i]); | ||||
this.$options.staticRenderFns.push(res.staticRenderFns[i]) | this.$options.staticRenderFns.push(res.staticRenderFns[i]) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |
{% extends '@EasyAdmin/default/edit.html.twig' %} | |||||
{% block entity_form %} | |||||
{% include '@LcShop/backend/order/form.html.twig' %} | |||||
{% endblock entity_form %} |
{{ form_start(form, {"attr": {'@change' : 'formUpdated'}}) }} | |||||
<div class="lc-vue-js-container" id="lc-order-edit"> | |||||
<div id="nav-params"> | |||||
<button type="button" v-for="section in sectionsArray" | |||||
:class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')" | |||||
@click="changeSection(section)"> | |||||
${ section.nameDisplay } | |||||
<span class="glyphicon glyphicon-triangle-bottom"></span> | |||||
</button> | |||||
</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> | |||||
</div> | |||||
{{ form_end(form) }} | |||||
{% extends '@EasyAdmin/default/new.html.twig' %} | |||||
{% block entity_form %} | |||||
{% if formView is defined and formView == 'default'%} | |||||
{{ form(form) }} | |||||
{% else %} | |||||
{% include '@LcShop/backend/order/form.html.twig' %} | |||||
{% endif %} | |||||
{% endblock entity_form %} |
{{ form_row(form.deliveryAddress) }} | |||||
{{ form_row(form.invoiceAddress, {"attr": {'v-model' : 'invoiceAddress', 'v-selecttwo' : 'invoiceAddress'}}) }} |
<div class="row"> | |||||
<div class="field-group col-12"> | |||||
<fieldset> | |||||
<legend>Stock</legend> | |||||
<div class="row"> | |||||
<div class="col"> | |||||
{{ form_label(form.behaviorCountStock) }} | |||||
{% for field in form.behaviorCountStock %} | |||||
{% if field.vars.value == "by-product" %} | |||||
<div v-if="activeProducts == true"> | |||||
{{ form_widget(field, {"attr" : {"v-model" : 'behaviorCountStock'}}) }} | |||||
</div> | |||||
{% else %} | |||||
{{ form_widget(field, {"attr" : {"v-model" : 'behaviorCountStock'}}) }} | |||||
{% endif %} | |||||
{% endfor %} | |||||
</div> | |||||
<div class="col"> | |||||
<div v-show="behaviorCountStock == 'by-product-family' || behaviorCountStock == 'by-quantity'" | |||||
class="form-group"> | |||||
{{ form_label(form.availableQuantity) }} | |||||
<div class="form-widget"> | |||||
<div class="input-group"> | |||||
{{ form_widget(form.availableQuantity) }} | |||||
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append"> | |||||
<span class="input-group-text">${ getUnitReference() }</span> | |||||
</div> | |||||
</div> | |||||
{{ form_help(form.availableQuantity) }} | |||||
</div> | |||||
{{ form_label(form.availableQuantityDefault) }} | |||||
<div class="form-widget"> | |||||
<div class="input-group"> | |||||
{{ form_widget(form.availableQuantityDefault) }} | |||||
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append"> | |||||
<span class="input-group-text">${ getUnitReference() }</span> | |||||
</div> | |||||
</div> | |||||
{{ form_help(form.availableQuantityDefault) }} | |||||
</div> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
</fieldset> | |||||
</div> | |||||
</div> |
{% 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 %} | |||||
<table id="order-products-list" class="table datagrid" | |||||
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> | |||||
<tr> | |||||
<td colspan="4"></td> | |||||
<td colspan="2"> | |||||
<table> | |||||
<tr> | |||||
<th>Total without Tax</th> | |||||
<td>${totalWithoutTax}</td> | |||||
</tr> | |||||
<tr> | |||||
<th>Total</th> | |||||
<td>${totalWithTax}</td> | |||||
</tr> | |||||
</table> | |||||
</td> | |||||
<td ></td> | |||||
</tr> | |||||
</tbody> | |||||
</table> | |||||
<button type="button" class="add_tag_link btn-add-product btn btn-default" @click="addOrderProductForm"><span | |||||
class="fa fa-plus"></span> Ajouter un produit | |||||
</button> | |||||
<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 %} | |||||