diff --git a/src/DependencyInjection/SetonoSyliusOrderEditExtension.php b/src/DependencyInjection/SetonoSyliusOrderEditExtension.php index c26d265..fa1f30f 100644 --- a/src/DependencyInjection/SetonoSyliusOrderEditExtension.php +++ b/src/DependencyInjection/SetonoSyliusOrderEditExtension.php @@ -4,7 +4,6 @@ namespace Setono\SyliusOrderEditPlugin\DependencyInjection; -use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -13,8 +12,6 @@ final class SetonoSyliusOrderEditExtension extends Extension implements PrependExtensionInterface { - use PrependDoctrineMigrationsTrait; - public function load(array $configs, ContainerBuilder $container): void { /** @@ -34,7 +31,10 @@ public function prepend(ContainerBuilder $container): void 'after' => [ 'setono_sylius_order_edit.set_initial_total' => [ 'on' => ['create'], - 'do' => ['@setono_sylius_order_edit.order_processing.order_initial_total_processor', 'process'], + 'do' => [ + '@setono_sylius_order_edit.order_processing.order_initial_total_processor', + 'process', + ], 'args' => ['object'], ], ], @@ -53,22 +53,5 @@ public function prepend(ContainerBuilder $container): void ], ], ]); - - $this->prependDoctrineMigrations($container); - } - - protected function getMigrationsNamespace(): string - { - return 'Setono\SyliusOrderEditPlugin\Migrations'; - } - - protected function getMigrationsDirectory(): string - { - return '@SetonoSyliusOrderEditPlugin/Migrations'; - } - - protected function getNamespacesOfMigrationsExecutedBefore(): array - { - return ['Sylius\Bundle\CoreBundle\Migrations']; } } diff --git a/src/Entity/EditableOrderInterface.php b/src/Entity/EditableOrderInterface.php new file mode 100644 index 0000000..9ca48ad --- /dev/null +++ b/src/Entity/EditableOrderInterface.php @@ -0,0 +1,11 @@ + false, ], 'getter' => function (OrderInterface &$order): array { - $adjustments = $order->getAdjustments(self::CUSTOM_ORDER_DISCOUNT)->toArray(); + $adjustments = $order->getAdjustments(OrderEditDiscountTypes::SETONO_ADMIN_ORDER_DISCOUNT)->toArray(); return array_map(function (AdjustmentInterface $adjustment): int { return -1 * $adjustment->getAmount(); }, $adjustments); }, 'setter' => function (OrderInterface &$order, array $discounts): void { - $order->removeAdjustments(self::CUSTOM_ORDER_DISCOUNT); + $order->removeAdjustments(OrderEditDiscountTypes::SETONO_ADMIN_ORDER_DISCOUNT); /** @var int $discount */ foreach ($discounts as $discount) { $adjustment = $this->adjustmentFactory->createWithData( - self::CUSTOM_ORDER_DISCOUNT, + OrderEditDiscountTypes::SETONO_ADMIN_ORDER_DISCOUNT, 'Custom discount: ' . number_format($discount, 2), -1 * $discount, ); diff --git a/src/Migrations/Version20240617131409.php b/src/Migrations/Version20240617131409.php deleted file mode 100644 index a1148ed..0000000 --- a/src/Migrations/Version20240617131409.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE sylius_order ADD initial_total INT DEFAULT 0 NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE sylius_order DROP initial_total'); - } -} diff --git a/src/Model/OrderEditDiscountTypes.php b/src/Model/OrderEditDiscountTypes.php new file mode 100644 index 0000000..09075b1 --- /dev/null +++ b/src/Model/OrderEditDiscountTypes.php @@ -0,0 +1,14 @@ +setInitialTotal($order->getTotal()); diff --git a/src/OrderProcessing/OrderInitialTotalProcessorInterface.php b/src/OrderProcessing/OrderInitialTotalProcessorInterface.php new file mode 100644 index 0000000..85bc4ea --- /dev/null +++ b/src/OrderProcessing/OrderInitialTotalProcessorInterface.php @@ -0,0 +1,12 @@ +prophesize(EntityManagerInterface::class); $processor = new OrderInitialTotalProcessor($entityManager->reveal()); - $order = new class() extends Order implements OrderInterface, InitialTotalAwareOrderInterface { - use InitialTotalAwareOrder; - - public function getTotal(): int - { - return 1000; - } - }; - $entityManager->flush()->shouldBeCalled(); + $order = $this->prophesize(EditableOrderInterface::class); + + $order->getTotal()->willReturn(1000); + $order->setInitialTotal(1000)->shouldBeCalled(); - $processor->process($order); + $entityManager->flush()->shouldBeCalled(); - self::assertSame(1000, $order->getInitialTotal()); + $processor->process($order->reveal()); } }