coopTilleuls / CoopTilleulsSyliusClickNCollectPlugin

Sell and deliver securely during the COVID-19 pandemic!
https://click-n-collect.shop
GNU Affero General Public License v3.0
78 stars 34 forks source link

ShippingMethodTypeExtension doesn't reference to overrided Location entity #33

Open kbyjoel opened 4 years ago

kbyjoel commented 4 years ago

Hi ! Just found a bug:

When you override Location entity, the ShippingMethodTypeExtension still reference CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location

The form extension service should get the location class as argument in services.xml:

        <service id="coop_tilleuls_click_n_collect.form.extension.type.shipping_method" class="CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension\ShippingMethodTypeExtension">
            <argument>%coop_tilleuls_click_n_collect.model.location.class%</argument>
            <tag name="form.type_extension" />
        </service>

And the form extension should use it:


use Doctrine\ORM\EntityRepository;
use Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * @author Kévin Dunglas <dunglas@gmail.com>
 */
final class ShippingMethodTypeExtension extends AbstractTypeExtension
{
    /** @var string */
    private $className;

    /**
     * ShippingMethodTypeExtension constructor.
     * @param string $className
     */
    public function __construct(string $className)
    {
        $this->className = $className;
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('locations', EntityType::class, [
                'class' => $this->className,
                'required' => false,
                'multiple' => true,
                'expanded' => true,
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('p')
                        ->orderBy('p.name', 'ASC');
                },
                'choice_label' => 'name',
                'label' => 'coop_tilleuls_click_n_collect.form.shipping_method.locations',
            ]);
    }

    public static function getExtendedTypes(): iterable
    {
        return [ShippingMethodType::class];
    }
}

Tell me if you need me to open a PR, Have a good day !

thcolin commented 4 years ago

Hi ! Thanks for the feedback, could you open a PR please ?

veloxy commented 3 years ago

@thcolin I opened a PR that fixes this, and some other places where the entity is used instead of the interface https://github.com/coopTilleuls/CoopTilleulsSyliusClickNCollectPlugin/pull/54