diff --git a/src/Controller/LocationsController.php b/src/Controller/LocationsController.php index 9991fc5..02db333 100644 --- a/src/Controller/LocationsController.php +++ b/src/Controller/LocationsController.php @@ -13,7 +13,7 @@ namespace CoopTilleuls\SyliusClickNCollectPlugin\Controller; -use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location; +use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface; use Doctrine\Persistence\ObjectRepository; use JMS\Serializer\SerializerInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -42,7 +42,7 @@ public function __invoke(string $shippingMethodCode): JsonResponse } // TODO: do this at the SQL layer in a repository, at the same do a proper JOIN... - $locations = $shippingMethod->getLocations()->filter(function (Location $p) { + $locations = $shippingMethod->getLocations()->filter(function (LocationInterface $p) { return $p->isEnabled(); }); diff --git a/src/Form/Extension/ShipmentTypeExtension.php b/src/Form/Extension/ShipmentTypeExtension.php index ce7ce5b..c86f2d2 100644 --- a/src/Form/Extension/ShipmentTypeExtension.php +++ b/src/Form/Extension/ShipmentTypeExtension.php @@ -13,7 +13,7 @@ namespace CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension; -use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location; +use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface; use Doctrine\Persistence\ObjectRepository; use Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShipmentType; use Symfony\Component\Form\AbstractTypeExtension; @@ -41,9 +41,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->create('location', HiddenType::class, [ 'required' => false, 'attr' => ['class' => 'click_n_collect_location'], - ])->addModelTransformer(new CallbackTransformer(function (?Location $location): string { + ])->addModelTransformer(new CallbackTransformer(function (?LocationInterface $location): string { return $location ? (string) $location->getCode() : ''; - }, function (?string $code): ?Location { + }, function (?string $code): ?LocationInterface { if ('' === $code || null === $code) { return null; } diff --git a/src/Form/Extension/ShippingMethodTypeExtension.php b/src/Form/Extension/ShippingMethodTypeExtension.php index d937482..3fca372 100644 --- a/src/Form/Extension/ShippingMethodTypeExtension.php +++ b/src/Form/Extension/ShippingMethodTypeExtension.php @@ -13,7 +13,7 @@ namespace CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension; -use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location; +use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface; use Doctrine\ORM\EntityRepository; use Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodType; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -25,11 +25,21 @@ */ final class ShippingMethodTypeExtension extends AbstractTypeExtension { + /** + * @var class-string + */ + private string $locationDataClass; + + public function __construct(string $locationDataClass) + { + $this->locationDataClass = $locationDataClass; + } + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('locations', EntityType::class, [ - 'class' => Location::class, + 'class' => $this->locationDataClass, 'required' => false, 'multiple' => true, 'expanded' => true, diff --git a/src/Repository/CollectionTimeRepository.php b/src/Repository/CollectionTimeRepository.php index b7b686b..8fdbeb3 100644 --- a/src/Repository/CollectionTimeRepository.php +++ b/src/Repository/CollectionTimeRepository.php @@ -13,7 +13,6 @@ namespace CoopTilleuls\SyliusClickNCollectPlugin\Repository; -use CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location; use CoopTilleuls\SyliusClickNCollectPlugin\Entity\LocationInterface; use Doctrine\ORM\EntityManagerInterface; @@ -82,7 +81,7 @@ public function isSlotFull(LocationInterface $location, \DateTimeInterface $coll /** * {@inheritdoc} */ - public function findShipments(Location $location, \DateTimeInterface $start, \DateTimeInterface $end): array + public function findShipments(LocationInterface $location, \DateTimeInterface $start, \DateTimeInterface $end): array { return $this->entityManager->createQuery(<< + %coop_tilleuls_click_n_collect.model.location.class%