-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an upload order request upon order completion
- Loading branch information
Showing
8 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/EventSubscriber/CreateUploadOrderRequestSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakWMSPlugin\EventSubscriber; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Setono\Doctrine\ORMTrait; | ||
use Setono\SyliusPeakWMSPlugin\Factory\UploadOrderRequestFactoryInterface; | ||
use Setono\SyliusPeakWMSPlugin\Model\OrderInterface; | ||
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CreateUploadOrderRequestSubscriber implements EventSubscriberInterface | ||
{ | ||
use ORMTrait; | ||
|
||
public function __construct( | ||
ManagerRegistry $managerRegistry, | ||
private readonly UploadOrderRequestFactoryInterface $uploadOrderRequestFactory, | ||
) { | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
'sylius.order.pre_complete' => 'createUploadOrderRequest', | ||
]; | ||
} | ||
|
||
public function createUploadOrderRequest(ResourceControllerEvent $event): void | ||
{ | ||
/** @var OrderInterface|mixed $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$order->setPeakWMSUploadOrderRequest($this->uploadOrderRequestFactory->createNew()); | ||
Check failure on line 39 in src/EventSubscriber/CreateUploadOrderRequestSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)MixedMethodCall
Check failure on line 39 in src/EventSubscriber/CreateUploadOrderRequestSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)MixedMethodCall
Check failure on line 39 in src/EventSubscriber/CreateUploadOrderRequestSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)MixedMethodCall
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakWMSPlugin\Factory; | ||
|
||
use Setono\SyliusPeakWMSPlugin\Model\UploadOrderRequestInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
|
||
final class UploadOrderRequestFactory implements UploadOrderRequestFactoryInterface | ||
{ | ||
public function __construct( | ||
/** @var FactoryInterface<UploadOrderRequestInterface> $decoratedFactory */ | ||
private readonly FactoryInterface $decoratedFactory, | ||
) { | ||
} | ||
|
||
public function createNew(): UploadOrderRequestInterface | ||
{ | ||
return $this->decoratedFactory->createNew(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakWMSPlugin\Factory; | ||
|
||
use Setono\SyliusPeakWMSPlugin\Model\UploadOrderRequestInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
|
||
/** | ||
* @extends FactoryInterface<UploadOrderRequestInterface> | ||
*/ | ||
interface UploadOrderRequestFactoryInterface extends FactoryInterface | ||
{ | ||
public function createNew(): UploadOrderRequestInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters