Skip to content

Commit

Permalink
Add a shipmondo id to the order and add the doctrine_transaction midd…
Browse files Browse the repository at this point in the history
…leware to the command bus
  • Loading branch information
loevgaard committed Apr 11, 2024
1 parent efb1e70 commit c038deb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/DependencyInjection/SetonoSyliusShipmondoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('setono_sylius_shipmondo.webhooks.key', $config['webhooks']['key']);
$container->setParameter('setono_sylius_shipmondo.webhooks.name_prefix', $config['webhooks']['name_prefix']);

$this->registerResources('setono_sylius_shipmondo', SyliusResourceBundle::DRIVER_DOCTRINE_ORM, $config['resources'], $container);
$this->registerResources(
'setono_sylius_shipmondo',
SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
$config['resources'],
$container,
);

$loader->load('services.xml');
}
Expand All @@ -39,7 +44,11 @@ public function prepend(ContainerBuilder $container): void
$container->prependExtensionConfig('framework', [
'messenger' => [
'buses' => [
'setono_sylius_shipmondo.command_bus' => null,
'setono_sylius_shipmondo.command_bus' => [
'middleware' => [
'doctrine_transaction',
],
],
],
],
'webhook' => [
Expand Down
4 changes: 3 additions & 1 deletion src/Message/CommandHandler/UploadOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function __invoke(UploadOrder $message): void

$salesOrder = $this->salesOrderDataMapper->map($order);

$this->shipmondoClient->salesOrders()->create($salesOrder);
$response = $this->shipmondoClient->salesOrders()->create($salesOrder);

$order->setShipmondoId($response->id);

$this->orderWorkflow->apply($order, OrderWorkflow::TRANSITION_COMPLETE_UPLOAD);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Model/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ interface OrderInterface extends BaseOrderInterface, VersionedInterface
public function getShipmondoState(): string;

public function setShipmondoState(string $shipmondoState): void;

/**
* Returns the Shipmondo id (if the order has been uploaded to Shipmondo)
*/
public function getShipmondoId(): ?int;

public function setShipmondoId(?int $shipmondoId): void;
}
14 changes: 14 additions & 0 deletions src/Model/OrderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ trait OrderTrait
#[ORM\Column(type: 'string')]
protected string $shipmondoState = OrderInterface::SHIPMONDO_STATE_PENDING;

/** @ORM\Column(type="integer") */
#[ORM\Column(type: 'integer', nullable: true)]
protected ?int $shipmondoId = null;

public function getVersion(): int
{
return $this->version;
Expand All @@ -44,4 +48,14 @@ public function setShipmondoState(string $shipmondoState): void
{
$this->shipmondoState = $shipmondoState;
}

public function getShipmondoId(): ?int
{
return $this->shipmondoId;
}

public function setShipmondoId(?int $shipmondoId): void
{
$this->shipmondoId = $shipmondoId;
}
}

0 comments on commit c038deb

Please sign in to comment.