Commit d8d2a470 authored by Mat's avatar Mat

form commande: ne persist que les légumes sélectionnés, calcule le prix total >>

note, by_reference = true
sinon, il compte 2x chaque entrée légume, et le total est 2x trop élévé !!
parent 079826f4
......@@ -101,10 +101,9 @@ class MembreController extends MasterController
foreach ($currentOffre['legumesSorted'] as $legume)
{
dump($legume->getNom());
$item = new CommandeLegumes();
$item
->setOffreLegume($legume)
->setPrixUnitaire($legume->getPrixUnitaire())
->setUnite($legume->getUnite())
->setQuantite(0.0)
......@@ -118,6 +117,21 @@ class MembreController extends MasterController
if ($form->isSubmitted() && $form->isValid())
{
dump($form);
$total = 0.0;
foreach ($commande->getCommandeLegumes() as $item)
{
if ($item->getQuantite() === 0.0) {
$commande->removeCommandeLegumes($item);
}
else {
$item->setPrix($item->getPrixUnitaire() * $item->getQuantite());
$total += $item->getPrix();
}
}
$commande->setPrixTotal($total);
dump($commande);
$em = $this->getDoctrine()->getManager();
$em->persist($commande);
$em->flush();
......
......@@ -262,10 +262,10 @@ class CommandeLegumes
}
/**
* @param int $offreLegume
* @param OffreLegumes $offreLegume
* @return CommandeLegumes
*/
public function setOffreLegume($offreLegume)
public function setOffreLegume(OffreLegumes $offreLegume)
{
$this->offreLegume = $offreLegume;
return $this;
......
......@@ -4,6 +4,8 @@ namespace PotageBundle\Form\Membre;
use PotageBundle\Entity\CommandeLegumes;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
......@@ -12,10 +14,19 @@ class CommandeLegumesType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('prixUnitaire')
->add('unite')
/*
->add('prixUnitaire', MoneyType::class, array(
'currency' => 'EUR',
'disabled' => true,
))
->add('unite', TextType::class, array(
'disabled' => true,
))
*/
->add('quantite')
->add('prix')
->add('prix', MoneyType::class, array(
'currency' => 'EUR'
))
;
}
......
......@@ -18,7 +18,7 @@ class CommandeType extends AbstractType
->add('commandeLegumes', CollectionType::class, array(
'entry_type' => CommandeLegumesType::class,
'entry_options' => array('label' => false),
'by_reference' => false,
'by_reference' => true,
'allow_add' => true,
'allow_delete' => true,
))
......
......@@ -45,8 +45,11 @@
<ul class="commandeLegumes" data-prototype="{{ form_widget(formCommande.commandeLegumes.vars.prototype)|e }}">
{% for legume in formCommande.commandeLegumes %}
<li>
{{ form_row(legume.prixUnitaire) }}
{{ form_row(legume.unite) }}
{#
{{ form_row(legume.prixUnitaire) }}
{{ form_row(legume.unite)
#}
{{ form_row(legume.quantite) }}
{{ form_row(legume.prix) }}
</li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment