1515use BitBag \SyliusUserComPlugin \Api \ProductApiInterface ;
1616use BitBag \SyliusUserComPlugin \Builder \Payload \OrderPayloadBuilderInterface ;
1717use BitBag \SyliusUserComPlugin \Builder \Payload \ProductEventPayloadBuilderInterface ;
18+ use BitBag \SyliusUserComPlugin \Provider \UserComApiAwareResourceProviderInterface ;
1819use BitBag \SyliusUserComPlugin \Trait \UserComApiAwareInterface ;
1920use Psr \Log \LoggerInterface ;
2021use Sylius \Component \Core \Model \OrderInterface ;
@@ -28,17 +29,14 @@ public function __construct(
2829 private readonly DealApiInterface $ dealApi ,
2930 private readonly ProductApiInterface $ productApi ,
3031 private readonly LoggerInterface $ logger ,
32+ private readonly UserComApiAwareResourceProviderInterface $ provider ,
3133 ) {
3234 }
3335
3436 public function handle (OrderInterface $ order ): void
3537 {
36- $ channel = $ order ->getChannel ();
37- if (false === $ channel instanceof UserComApiAwareInterface) {
38- throw new \InvalidArgumentException ('Channel must implement UserComApiAwareInterface ' );
39- }
40-
41- if (null === $ channel ->getUserComUrl () || null === $ channel ->getUserComApiKey ()) {
38+ $ resource = $ this ->provider ->getApiAwareResourceByOrder ($ order );
39+ if (null === $ resource || null === $ resource ->getUserComUrl () || null === $ resource ->getUserComApiKey ()) {
4240 return ;
4341 }
4442
@@ -51,10 +49,12 @@ public function handle(OrderInterface $order): void
5149
5250 $ email = $ customer ->getEmail ();
5351 Assert::notNull ($ email , 'Order customer email cannot be null while sending order data to User.com ' );
54- $ this ->createProductEvents ($ order , $ channel , $ email );
52+ $ email = strtolower ($ email );
53+
54+ $ this ->createProductEvents ($ order , $ resource , $ email );
5555
5656 if (OrderInterface::STATE_NEW === $ order ->getState ()) {
57- $ this ->dealApi ->createDeal ($ channel , $ this ->orderPayloadBuilder ->build ($ order ), $ email );
57+ $ this ->dealApi ->createDeal ($ resource , $ this ->orderPayloadBuilder ->build ($ order ), $ email );
5858
5959 return ;
6060 }
@@ -64,7 +64,7 @@ public function handle(OrderInterface $order): void
6464 Assert::notNull ($ orderNumber , 'Order number cannot be null while sending order data to User.com ' );
6565
6666 $ this ->dealApi ->updateDealByCustomId (
67- $ channel ,
67+ $ resource ,
6868 $ orderNumber ,
6969 $ this ->orderPayloadBuilder ->build ($ order ),
7070 );
0 commit comments