<?php

namespace Lc\ShopBundle\Controller\Backend;


use Doctrine\ORM\EntityManagerInterface;

use FOS\UserBundle\Model\UserManagerInterface;
use Lc\ShopBundle\Services\UtilsManager;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

class ReductionCartController extends AdminController
{


        public function updateReductionCartEntity($entity, $editForm = false)
        {
                $displayError =false;
                foreach ($entity->getCodes() as $code) {
                        $reductionCart = $this->orderUtils->getReductionCartByCode($code);
                        if ($reductionCart && $reductionCart->getId() != $entity->getId()) {
                                $this->addFlash('error', "Le code " . $code . " est déjà utilisé dans la réduction #" . $reductionCart->getId() . " " . $reductionCart->getTitle());
                                $displayError = true;
                        }
                }
                if ($displayError == false) parent::updateEntity($entity);
        }

        /* public function persistProductFamilyEntity($entity, $newForm)
         {
                 $entity = $this->productFamilyUtils->processBeforePersistProductFamily($entity, $newForm);

                 $this->em->persist($entity);
                 $this->em->flush();
         }*/
}

