<?php

namespace Lc\ShopBundle\Form\Backend\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(),
                ]);
        }
}