<?php | |||||
namespace Lc\ShopBundle\Form\Backend\Common; | |||||
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\FormBuilderInterface; | |||||
use Symfony\Component\Form\FormEvent; | |||||
use Symfony\Component\Form\FormEvents; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class ProductType extends AbstractType | |||||
{ | |||||
protected $em; | |||||
protected $merchantUtils; | |||||
public function __construct(EntityManagerInterface $entityManager, MerchantUtilsInterface $merchantUtils) | |||||
{ | |||||
$this->em = $entityManager; | |||||
$this->merchantUtils = $merchantUtils; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$productClass = $this->em->getClassMetadata(ProductInterface::class); | |||||
$currentMerchant = $this->merchantUtils->getMerchantUser(); | |||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($productClass, $options, $currentMerchant) { | |||||
$builder = $event->getForm()->getParent(); | |||||
$builder->add('product', EntityType::class, array_merge($options,[ | |||||
'class' => $productClass->name, | |||||
'query_builder' => function (EntityRepository $er) use ($currentMerchant) { | |||||
return $er->createQueryBuilder('p') | |||||
->join('p.productFamily', 'pFamily') | |||||
->where('pFamily.merchant = :currentMerchant') | |||||
->andWhere('pFamily.status = 1') | |||||
->setParameter('currentMerchant', $currentMerchant); | |||||
}, | |||||
'choice_label' => function ($product) { | |||||
return $product->getProductFamily()->getTitle() . ' - ' . $product->getTitle(); | |||||
} | |||||
])); | |||||
}); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'translation_domain' => 'lcshop', | |||||
]); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Form\Backend\Common; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use Lc\ShopBundle\Context\ReductionCatalogInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | |||||
use Lc\ShopBundle\Repository\GroupUserRepository; | |||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\Form\FormEvent; | |||||
use Symfony\Component\Form\FormEvents; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class UserType extends AbstractType | |||||
{ | |||||
protected $em; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->em = $entityManager; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$userClass = $this->em->getClassMetadata(UserInterface::class); | |||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($userClass, $options) { | |||||
$builder = $event->getForm()->getParent(); | |||||
$builder->add('user', EntityType::class, array_merge($options,[ | |||||
'class' => $userClass->name, | |||||
'query_builder'=> function (EntityRepository $er) { | |||||
$query = $er->findByMerchantQuery(); | |||||
return $query; | |||||
}, | |||||
'expanded' => false, | |||||
'translation_domain'=>'lcshop', | |||||
])); | |||||
}); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'translation_domain' => 'lcshop', | |||||
]); | |||||
} | |||||
} |
return $er->createQueryBuilder('p') | return $er->createQueryBuilder('p') | ||||
->join('p.productFamily', 'pFamily') | ->join('p.productFamily', 'pFamily') | ||||
->where('pFamily.merchant = :currentMerchant') | ->where('pFamily.merchant = :currentMerchant') | ||||
->andWhere('pFamily.status = 1') | |||||
->setParameter('currentMerchant', $currentMerchant); | ->setParameter('currentMerchant', $currentMerchant); | ||||
}, | }, | ||||
'choice_label' => function ($product) { | 'choice_label' => function ($product) { |
</span> | </span> | ||||
<span v-show="orderProduct.isRedelivery"> | <span v-show="orderProduct.isRedelivery"> | ||||
- <i class="fa fa-undo" data-toggle="tooltip" title="Ce produit fait l'objet d'une relivraison" ></i> | |||||
- <i class="fa fa-undo" data-toggle="tooltip" title="Ce produit est une relivraison" ></i> | |||||
</span> | </span> | ||||
</td> | </td> |