From 0f7b51b0d6052bcce845452ce66b58ed66c3b8d1 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 14 Nov 2024 10:50:56 +0100 Subject: [PATCH 1/4] fix: avoid error during remove expired cart if coupon used --- dist/src/Migrations/Version20241114094753.php | 44 +++++++++++++++++++ src/Entity/PromotionCouponsAwareTrait.php | 8 ++-- 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 dist/src/Migrations/Version20241114094753.php diff --git a/dist/src/Migrations/Version20241114094753.php b/dist/src/Migrations/Version20241114094753.php new file mode 100644 index 0000000..d6a7bef --- /dev/null +++ b/dist/src/Migrations/Version20241114094753.php @@ -0,0 +1,44 @@ + + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace App\Migrations; + +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Migrations\AbstractMigration; + +/** + * Auto-generated Migration: Please modify to your needs! + */ +final class Version20241114094753 extends AbstractMigration +{ + public function getDescription(): string + { + return ''; + } + + public function up(Schema $schema): void + { + // this up() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon DROP FOREIGN KEY FK_5C4132AF17B24436'); + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon DROP FOREIGN KEY FK_5C4132AF8D9F6D38'); + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon ADD CONSTRAINT FK_5C4132AF17B24436 FOREIGN KEY (promotion_coupon_id) REFERENCES sylius_promotion_coupon (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon ADD CONSTRAINT FK_5C4132AF8D9F6D38 FOREIGN KEY (order_id) REFERENCES sylius_order (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon DROP FOREIGN KEY FK_5C4132AF8D9F6D38'); + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon DROP FOREIGN KEY FK_5C4132AF17B24436'); + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon ADD CONSTRAINT FK_5C4132AF8D9F6D38 FOREIGN KEY (order_id) REFERENCES sylius_order (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); + $this->addSql('ALTER TABLE monsieurbiz_advanced_promotion_order_promotion_coupon ADD CONSTRAINT FK_5C4132AF17B24436 FOREIGN KEY (promotion_coupon_id) REFERENCES sylius_promotion_coupon (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); + } +} diff --git a/src/Entity/PromotionCouponsAwareTrait.php b/src/Entity/PromotionCouponsAwareTrait.php index 634a4e5..deaee58 100644 --- a/src/Entity/PromotionCouponsAwareTrait.php +++ b/src/Entity/PromotionCouponsAwareTrait.php @@ -21,16 +21,16 @@ trait PromotionCouponsAwareTrait /** * @ORM\ManyToMany(targetEntity=PromotionCouponInterface::class) * @ORM\JoinTable(name="monsieurbiz_advanced_promotion_order_promotion_coupon", - * joinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id")}, - * inverseJoinColumns={@ORM\JoinColumn(name="promotion_coupon_id", referencedColumnName="id")} + * joinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")}, + * inverseJoinColumns={@ORM\JoinColumn(name="promotion_coupon_id", referencedColumnName="id", onDelete="CASCADE")} * ) * * @var Collection */ #[ORM\ManyToMany(targetEntity: PromotionCouponInterface::class)] #[ORM\JoinTable(name: 'monsieurbiz_advanced_promotion_order_promotion_coupon')] - #[ORM\JoinColumn(name: 'order_id', referencedColumnName: 'id')] - #[ORM\InverseJoinColumn(name: 'promotion_coupon_id', referencedColumnName: 'id')] + #[ORM\JoinColumn(name: 'order_id', referencedColumnName: 'id', onDelete: 'CASCADE')] + #[ORM\InverseJoinColumn(name: 'promotion_coupon_id', referencedColumnName: 'id', onDelete: 'CASCADE')] private $promotionCoupons; private function initializePromotionCoupons(): void From 281bb6f7ce15d43a6c672cd6f161a984bd846cc0 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 14 Nov 2024 11:01:48 +0100 Subject: [PATCH 2/4] chore(docker): avoid CI error use new docker compose syntax --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dd21e64..1962ca0 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ COMPOSER=symfony composer CONSOLE=${SYMFONY} console export COMPOSE_PROJECT_NAME=advanced-promotion PLUGIN_NAME=sylius-${COMPOSE_PROJECT_NAME}-plugin -COMPOSE=docker-compose +COMPOSE=docker compose YARN=yarn DOCTRINE_MIGRATIONS_NAMESPACE=MonsieurBiz\SyliusAdvancedPromotionPlugin\Migrations From a4df9a9731e2a4bf8408d303f2a39de98ab9b7c7 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 14 Nov 2024 11:21:32 +0100 Subject: [PATCH 3/4] chore(docker): remove compose files from sylius standard to use our file --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 1962ca0..250165a 100644 --- a/Makefile +++ b/Makefile @@ -85,6 +85,8 @@ setup_application: ${APP_DIR}/docker-compose.yaml: rm -f ${APP_DIR}/docker-compose.yml rm -f ${APP_DIR}/docker-compose.yaml + rm -f ${APP_DIR}/compose.yml # Remove Sylius file about Docker + rm -f ${APP_DIR}/compose.override.dist.yml # Remove Sylius file about Docker ln -s ../../docker-compose.yaml.dist ${APP_DIR}/docker-compose.yaml .PHONY: ${APP_DIR}/docker-compose.yaml From 4f44b64e75d136779bb4639ff717be7b206ce0e6 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 14 Nov 2024 11:58:50 +0100 Subject: [PATCH 4/4] chore: fix phpstan error in fixture class --- src/Fixture/AdvancedPromotionFixture.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Fixture/AdvancedPromotionFixture.php b/src/Fixture/AdvancedPromotionFixture.php index 82bc044..77d3559 100644 --- a/src/Fixture/AdvancedPromotionFixture.php +++ b/src/Fixture/AdvancedPromotionFixture.php @@ -12,6 +12,7 @@ namespace MonsieurBiz\SyliusAdvancedPromotionPlugin\Fixture; use Doctrine\ORM\EntityManagerInterface; +use InvalidArgumentException; use MonsieurBiz\SyliusAdvancedPromotionPlugin\Entity\AfterTaxAwareInterface; use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; @@ -31,14 +32,25 @@ public function getName(): string return 'monsieurbiz_advanced_promotion'; } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ public function load(array $options): void { - foreach ($options['promotion_advanced_configuration'] as $data) { + $config = $options['promotion_advanced_configuration'] ?? []; + if (!\is_array($config)) { + throw new InvalidArgumentException('The "promotion_advanced_configuration" option must be an array.'); + } + /** @var array $data */ + foreach ($config as $data) { + if (!isset($data['code'])) { + continue; + } $promotion = $this->promotionRepository->findOneBy(['code' => $data['code']]); if (null === $promotion || !$promotion instanceof AfterTaxAwareInterface) { continue; } - $promotion->setAfterTax($data['after_tax']); + $promotion->setAfterTax($data['after_tax'] ?? false); $this->entityManager->persist($promotion); }