<?php
namespace Boab\EcommerceBundle\Form;
use Boab\EcommerceBundle\Form\EventListener\ClearCartListener;
use Boab\EcommerceBundle\Form\EventListener\RemoveCartItemListener;
use Boab\EcommerceBundle\Entity\Cart;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CartType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('items', CollectionType::class, [
'entry_type' => CartItemType::class,
])
->add('save', SubmitType::class,[
'label'=>'Proceed to checkout'
])
->add('clear', SubmitType::class,[
'label' => 'Clear cart'
]);
$builder->addEventSubscriber(new RemoveCartItemListener());
$builder->addEventSubscriber(new ClearCartListener());
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Cart::class,
]);
}
}