Skip to content

Commit

Permalink
Provider with Setono original PickUpPointCode
Browse files Browse the repository at this point in the history
  • Loading branch information
ehibes committed May 17, 2023
1 parent 5870191 commit 77fbd3c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 162 deletions.
10 changes: 2 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": "^8.0",
"bitbag/shipping-export-plugin": "^3.0",
"setono/sylius-pickup-point-plugin": "dev-point-interface",
"setono/sylius-pickup-point-plugin": "^1.1",
"sylius/sylius": "^1.11",
"winzou/tnt-express": "^1.1.1"
},
Expand Down Expand Up @@ -85,11 +85,5 @@
"post-create-project-cmd": [
"php bin/create_node_symlink.php"
]
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/StudioWaaz/SyliusPickupPointPlugin.git"
}
]
}
}
10 changes: 4 additions & 6 deletions spec/Provider/TntProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Waaz\SyliusTntPlugin\Provider\TntProvider;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Waaz\SyliusTntPlugin\Model\TntPickupPointCode;
use Setono\SyliusPickupPointPlugin\Model\PickupPoint;
use Setono\SyliusPickupPointPlugin\Model\PickupPointCode;
use Setono\SyliusPickupPointPlugin\Provider\ProviderInterface;

class TntProviderSpec extends ObjectBehavior
Expand Down Expand Up @@ -68,13 +68,11 @@ public function it_finds_pickup_by_code(
$client->getDropOffPoints('64200', 'Biarritz')->willReturn([
$dropOffPoint
]);
$pickupPointCode = new TntPickupPointCode('test', 'tnt', 'FR');
$pickupPointCode->setZipcode('64200');
$pickupPointCode->setCity('Biarritz');
$pickupPointCode = new PickupPointCode('test###64200###Biarritz', 'tnt', 'FR');
$point = $this->findPickupPoint($pickupPointCode);
$point->shouldReturnAnInstanceOf(PickupPoint::class);
$point->getCode()->shouldReturnAnInstanceOf(TntPickupPointCode::class);
$point->getCode()->getIdPart()->shouldReturn('test');
$point->getCode()->shouldReturnAnInstanceOf(PickupPointCode::class);
$point->getCode()->getIdPart()->shouldReturn('test###64200###Biarritz');
$point->getCode()->getProviderPart()->shouldReturn('tnt');
$point->getCode()->getCountryPart()->shouldReturn('FR');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ReceiverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface;
use Setono\SyliusPickupPointPlugin\Model\PickupPointAwareInterface;
use Setono\SyliusPickupPointPlugin\Model\PickupPointCode;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use TNTExpress\Model\Receiver;
use Waaz\SyliusTntPlugin\Model\TntPickupPointCode;

class ReceiverFactory implements ReceiverFactoryInterface
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public function createNew(ShippingGatewayInterface $shippingGateway, ShipmentInt
if ($shipment instanceof PickupPointAwareInterface && $shipment->hasPickupPointId()) {
/** @var string $pointId */
$pointId = $shipment->getPickupPointId();
$tntCode = TntPickupPointCode::createFromString($pointId);
$tntCode = PickupPointCode::createFromString($pointId);
$receiver->setType('DROPOFFPOINT')
->setTypeId($tntCode->getIdPart())
;
Expand Down
116 changes: 0 additions & 116 deletions src/Model/TntPickupPointCode.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Model/TntPickupPointCodeInterface.php

This file was deleted.

28 changes: 14 additions & 14 deletions src/Provider/TntProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

use Setono\SyliusPickupPointPlugin\Exception\TimeoutException;
use Setono\SyliusPickupPointPlugin\Model\PickupPoint;
use Setono\SyliusPickupPointPlugin\Model\PickupPointCodeInterface;
use Setono\SyliusPickupPointPlugin\Model\PickupPointCode;
use Setono\SyliusPickupPointPlugin\Model\PickupPointInterface;
use Setono\SyliusPickupPointPlugin\Provider\Provider;
use Sylius\Component\Core\Model\OrderInterface;
use TNTExpress\Client\TNTClientInterface;
use TNTExpress\Exception\ClientException;
use TNTExpress\Model\DropOffPoint;
use Waaz\SyliusTntPlugin\Model\TntPickupPointCode;
use Webmozart\Assert\Assert;

final class TntProvider extends Provider
Expand Down Expand Up @@ -47,20 +46,17 @@ public function findPickupPoints(OrderInterface $order): iterable
}
}

public function findPickupPoint(PickupPointCodeInterface $code): ?PickupPointInterface
public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface
{
Assert::isInstanceOf($code, TntPickupPointCode::class);

$zipcode = $code->getZipCodePart();
Assert::string($zipcode);

$city = $code->getCityPart();
Assert::string($city);
$pickupId = $code->getIdPart();
$data = \explode('###', $pickupId);
Assert::count($data, 3, 'TNT Pickup ID is not correct.');
[$xettCode, $zipcode, $city] = $data;

$result = $this->client->getDropOffPoints($zipcode, $city);

foreach ($result as $item) {
if ($item->getXETTCode() === $code->getIdPart()) {
if ($item->getXETTCode() === $xettCode) {
return $this->transform($item);
}
}
Expand All @@ -78,10 +74,14 @@ private function transform(DropOffPoint $dropOffPoint): PickupPoint
$countryCode = 'FR'; // TNT only operates in France

$pickupPoint = new PickupPoint();
$zipcode = $dropOffPoint->getZipCode();
Assert::notNull($zipcode);

$city = $dropOffPoint->getCity();
Assert::notNull($city);

$pickupPointCode = new TntPickupPointCode($dropOffPoint->getXETTCode(), $this->getCode(), $countryCode);
$pickupPointCode->setZipcode((string) $dropOffPoint->getZipCode());
$pickupPointCode->setCity((string) $dropOffPoint->getCity());
$pickupId = (string) $dropOffPoint->getXETTCode() . '###' . $zipcode . '###' . $city;
$pickupPointCode = new PickupPointCode($pickupId, $this->getCode(), $countryCode);

$pickupPoint->setCode($pickupPointCode);
$pickupPoint->setName((string) $dropOffPoint->getName());
Expand Down
4 changes: 2 additions & 2 deletions tests/Behat/Page/Shop/Checkout/AddressPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public function selectBillingPostcode(string $postcode): void

public function getAvailableBillingCities(): array
{
$this->waitForOption(3, 'billing_city_select');
$this->waitForOption(5, 'billing_city_select');
return $this->getOptionsFromSelect($this->getElement('billing_city_select'));
}

public function selectBillingCity(string $city): void
{
$this->waitForOption(3, 'billing_city_select');
$this->waitForOption(5, 'billing_city_select');
$this->getElement('billing_city_select')->selectOption($city);
}

Expand Down

0 comments on commit 77fbd3c

Please sign in to comment.