Skip to content

Commit

Permalink
Fixes creating order through API by adding listener for exchange rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Amunak committed Sep 19, 2016
1 parent 5e9ded0 commit 69c26f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ public function cartInitialize(CartEvent $event)
$this->processOrderExchangeRate($event->getCart());
}

/**
* @param GenericEvent $event
*/
public function orderPreCreate(GenericEvent $event)
{
$order = $event->getSubject();
if (!$order instanceof OrderInterface) {
throw new UnexpectedTypeException(
$order,
'Sylius\Component\Core\Model\OrderInterface'
);
}

if ($order->getExchangeRate() === null) {
$this->processOrderExchangeRate($order);
}
}

/**
* @param GenericEvent $event
*/
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
<service id="sylius.listener.order_exchange_rate" class="Sylius\Bundle\CoreBundle\EventListener\OrderExchangeRateListener">
<argument type="service" id="sylius.repository.currency" />
<tag name="kernel.event_listener" event="sylius.cart.initialize" method="cartInitialize" />
<tag name="kernel.event_listener" event="sylius.order.pre_create" method="orderPreCreate" />
<tag name="kernel.event_listener" event="sylius.checkout.finalize.pre_complete" method="checkoutFinalize" />
</service>
<service id="sylius.listener.restricted_zone" class="%sylius.listener.restricted_zone.class%">
Expand Down

0 comments on commit 69c26f6

Please sign in to comment.