PHP code example of keirontw / sylius-relay-point-plugin
1. Go to this page and download the library: Download keirontw/sylius-relay-point-plugin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
keirontw / sylius-relay-point-plugin example snippets
use Keirontw\SyliusRelayPointPlugin\RelayPoint\RelayPointSessionStorage;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(event: 'sylius.order.pre_complete')]
final class ApplyRelayPointSubscriber
{
public function __construct(
private readonly RelayPointSessionStorage $storage,
) {}
public function __invoke(GenericEvent $event): void
{
$order = $event->getSubject();
$point = $this->storage->get($order->getTokenValue());
if (null === $point) {
return;
}
$address = $order->getShippingAddress();
$address->setStreet($point->street);
$address->setPostcode($point->postcode);
$address->setCity($point->city);
$address->setCountryCode($point->countryCode);
$address->setCompany($point->name);
// Your custom field:
$address->setRelayPointId($point->id);
$this->storage->clear($order->getTokenValue());
}
}
use Keirontw\SyliusRelayPointPlugin\RelayPoint\RelayPointProviderInterface;
use Keirontw\SyliusRelayPointPlugin\RelayPoint\Model\RelayPoint;
use Keirontw\SyliusRelayPointPlugin\RelayPoint\Model\RelayPointSearchCriteria;
final class MyCarrierProvider implements RelayPointProviderInterface
{
public function __construct(
private readonly string $apiKey,
/** @param list<string> $shippingMethodCodes */
private readonly array $shippingMethodCodes,
) {}
public function supports(string $shippingMethodCode): bool
{
return in_array($shippingMethodCode, $this->shippingMethodCodes, true);
}
/** @return RelayPoint[] */
public function search(RelayPointSearchCriteria $criteria): array
{
// Call your carrier's API and map results to RelayPoint DTOs
return [];
}
}
use Keirontw\SyliusRelayPointPlugin\Geocoding\GeocodingProviderInterface;
use Keirontw\SyliusRelayPointPlugin\Geocoding\Model\GeocodingResult;
final class MyGeocoder implements GeocodingProviderInterface
{
public function geocode(string $query): ?GeocodingResult
{
// ...
return new GeocodingResult(
latitude: 48.8,
longitude: 2.3,
postcode: '75001',
city: 'Paris',
countryCode: 'FR',
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.