-
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.
- Loading branch information
Showing
24 changed files
with
756 additions
and
46 deletions.
There are no files selected for viewing
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\Command; | ||
|
||
use Setono\SyliusPeakPlugin\Updater\InventoryUpdaterInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'setono:sylius-peak-wms:update-inventory', | ||
description: 'This will update the inventory for all product variants', | ||
)] | ||
final class UpdateInventoryCommand extends Command | ||
{ | ||
public function __construct(private readonly InventoryUpdaterInterface $inventoryUpdater) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
// todo allow the user to specify a product variant id to update | ||
// todo allow the user to force the update of _ALL_ product variants regardless of the last update time | ||
$this->inventoryUpdater->updateAll(); | ||
|
||
return 0; | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/EventSubscriber/Workflow/InventoryUpdate/CompleteSubscriber.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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\EventSubscriber\Workflow\InventoryUpdate; | ||
|
||
use Setono\SyliusPeakPlugin\Model\InventoryUpdateInterface; | ||
use Setono\SyliusPeakPlugin\Workflow\InventoryUpdateWorkflow; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CompleteSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
sprintf('workflow.%s.completed.%s', InventoryUpdateWorkflow::NAME, InventoryUpdateWorkflow::TRANSITION_COMPLETE) => 'set', | ||
]; | ||
} | ||
|
||
public function set(CompletedEvent $event): void | ||
{ | ||
/** @var InventoryUpdateInterface|object $inventoryUpdate */ | ||
$inventoryUpdate = $event->getSubject(); | ||
Assert::isInstanceOf($inventoryUpdate, InventoryUpdateInterface::class); | ||
|
||
$inventoryUpdate->setCompletedAt(new \DateTimeImmutable()); | ||
|
||
if (!$inventoryUpdate->hasErrors()) { | ||
$inventoryUpdate->setNextUpdateThreshold($inventoryUpdate->getProcessingStartedAt()); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/EventSubscriber/Workflow/InventoryUpdate/ProcessSubscriber.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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\EventSubscriber\Workflow\InventoryUpdate; | ||
|
||
use Setono\SyliusPeakPlugin\Model\InventoryUpdateInterface; | ||
use Setono\SyliusPeakPlugin\Workflow\InventoryUpdateWorkflow; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ProcessSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
sprintf('workflow.%s.completed.%s', InventoryUpdateWorkflow::NAME, InventoryUpdateWorkflow::TRANSITION_PROCESS) => 'set', | ||
]; | ||
} | ||
|
||
public function set(CompletedEvent $event): void | ||
{ | ||
/** @var InventoryUpdateInterface|object $inventoryUpdate */ | ||
$inventoryUpdate = $event->getSubject(); | ||
Assert::isInstanceOf($inventoryUpdate, InventoryUpdateInterface::class); | ||
|
||
$inventoryUpdate->setProcessingStartedAt(new \DateTimeImmutable()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/EventSubscriber/Workflow/InventoryUpdate/ResetSubscriber.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\EventSubscriber\Workflow\InventoryUpdate; | ||
|
||
use Setono\SyliusPeakPlugin\Model\InventoryUpdateInterface; | ||
use Setono\SyliusPeakPlugin\Workflow\InventoryUpdateWorkflow; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ResetSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
sprintf('workflow.%s.completed.%s', InventoryUpdateWorkflow::NAME, InventoryUpdateWorkflow::TRANSITION_RESET) => 'reset', | ||
]; | ||
} | ||
|
||
public function reset(CompletedEvent $event): void | ||
{ | ||
/** @var InventoryUpdateInterface|object $inventoryUpdate */ | ||
$inventoryUpdate = $event->getSubject(); | ||
Assert::isInstanceOf($inventoryUpdate, InventoryUpdateInterface::class); | ||
|
||
$inventoryUpdate->setCompletedAt(null); | ||
$inventoryUpdate->setProcessingStartedAt(null); | ||
$inventoryUpdate->setWarnings(null); | ||
$inventoryUpdate->setErrors(null); | ||
} | ||
} |
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
Oops, something went wrong.