Skip to content

Commit

Permalink
Add service point data mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed May 29, 2024
1 parent 4eba63a commit d0d157c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"phpunit/phpunit": "^9.6",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.1",
"setono/code-quality-pack": "^2.6",
"setono/code-quality-pack": "^2.7.2",
"sylius/sylius": "~1.12.13",
"symfony/debug-bundle": "^6.4",
"symfony/dotenv": "^6.4",
Expand Down
46 changes: 46 additions & 0 deletions src/DataMapper/ServicePointDataMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusShipmondoPlugin\DataMapper;

use Setono\Shipmondo\Request\SalesOrders\SalesOrder;
use Setono\Shipmondo\Request\SalesOrders\ServicePoint;
use Setono\SyliusShipmondoPlugin\Model\OrderInterface;
use Setono\SyliusShipmondoPlugin\Model\ShipmentInterface;

/**
* Will map the pickup point data to the sales order
*/
final class ServicePointDataMapper implements SalesOrderDataMapperInterface
{
public function map(OrderInterface $order, SalesOrder $salesOrder): void
{
$shipment = $order->getShipments()->first();
if (!$shipment instanceof ShipmentInterface) {
return;
}

/**
* todo make the shipmondo pickup point a value object that's mapped in Doctrine
*
* The keys below match the properties from this class: \Setono\Shipmondo\Response\PickupPoints\PickupPoint
*
* @var array{id: string, name: string, address: string, zipcode: string, city: string, country: string, address2: string|null}|null $pickupPoint
*/
$pickupPoint = $shipment->getShipmondoPickupPoint();
if (null === $pickupPoint) {
return;
}

$salesOrder->servicePoint = new ServicePoint(
id: $pickupPoint['id'],
name: $pickupPoint['name'],
address1: $pickupPoint['address'],
zipCode: $pickupPoint['zipcode'],
city: $pickupPoint['city'],
countryCode: $pickupPoint['country'],
address2: $pickupPoint['address2'] ?? null,
);
}
}
5 changes: 5 additions & 0 deletions src/Resources/config/services/data_mapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@

<tag name="setono_sylius_shipmondo.sales_order_data_mapper" priority="50"/>
</service>

<service id="setono_sylius_shipmondo.data_mapper.sales_order.service_point"
class="Setono\SyliusShipmondoPlugin\DataMapper\ServicePointDataMapper">
<tag name="setono_sylius_shipmondo.sales_order_data_mapper" priority="60"/>
</service>
</services>
</container>

0 comments on commit d0d157c

Please sign in to comment.