Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</service>
<service id="api.colissimo.pickup.point" class="ColissimoPickupPoint\Listener\APIListener" scope="request">
<argument type="service" id="service_container"/>
<argument type="service" id="open_api.image.service"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="colissimo.pickup.point.price.smarty.plugin" class="ColissimoPickupPoint\Smarty\Plugins\ColissimoPickupPointDeliveryPrice" scope="request">
Expand Down
23 changes: 19 additions & 4 deletions Listener/APIListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace ColissimoPickupPoint\Listener;


use ColissimoPickupPoint\ColissimoPickupPoint;
use ColissimoPickupPoint\WebService\FindByAddress;
use OpenApi\Events\DeliveryModuleOptionEvent;
Expand All @@ -26,14 +25,19 @@ class APIListener implements EventSubscriberInterface
/** @var ContainerInterface */
protected $container;

/** @var ImageService */
protected $imageService;

/**
* APIListener constructor.
* @param ContainerInterface $container We need the container because we use a service from another module
* which is not mandatory, and using its service without it being installed will crash
* @param ImageService $imageService
*/
public function __construct(ContainerInterface $container)
public function __construct(ContainerInterface $container, ImageService $imageService)
{
$this->container = $container;
$this->imageService = $imageService;
}

/**
Expand Down Expand Up @@ -209,13 +213,24 @@ public function getDeliveryModuleOptions(DeliveryModuleOptionEvent $deliveryModu
$minimumDeliveryDate = ''; // TODO (calculate delivery date from day of order)
$maximumDeliveryDate = ''; // TODO (calculate delivery date from day of order

$image = null;
$imageQuery = ModuleImageQuery::create()->findByModuleId($deliveryModuleOptionEvent->getModule()->getId())->getFirst();

if (null !== $imageQuery) {
try {
$image = $this->imageService->getImageUrl($imageQuery, 'module');
} catch (\Exception $e) {
Tlog::getInstance()->addError($e);
}
}

/** @var DeliveryModuleOption $deliveryModuleOption */
$deliveryModuleOption = ($this->container->get('open_api.model.factory'))->buildModel('DeliveryModuleOption');
$deliveryModuleOption
->setCode('ColissimoPickupPoint')
->setValid($isValid)
->setTitle('Colissimo Pickup Point')
->setImage('')
->setImage($image)
->setMinimumDeliveryDate($minimumDeliveryDate)
->setMaximumDeliveryDate($maximumDeliveryDate)
->setPostage($postage)
Expand All @@ -241,4 +256,4 @@ public static function getSubscribedEvents()

return $listenedEvents;
}
}
}