From 461d3d63d58159c18359a76ba74baf818455abb5 Mon Sep 17 00:00:00 2001 From: Diego Jaure Date: Tue, 16 Jul 2024 05:20:38 +0200 Subject: [PATCH 1/3] bugfixing Oro6 upgrading --- README.md | 4 +- .../Async/StockAlertNotificationProcessor.php | 42 +++++----- .../Topic/StockAlertNotificationTopic.php | 10 +-- .../Frontend/StockAlertController.php | 4 +- .../StockAlertBundle/Entity/StockAlert.php | 3 +- .../ProductListStockAlertListener.php | 10 +-- ...nventoryLevelNotificationEventListener.php | 32 ++----- .../StockAlertFrontendDatagridListener.php | 14 +--- .../Form/Type/StockAlertType.php | 5 +- .../Handler/StockAlertHandler.php | 14 +--- .../InventoryQuantityDataProvider.php | 9 +- .../DataProvider/StockAlertDataProvider.php | 9 +- .../Mailer/SimpleEmailMailer.php | 83 ------------------- .../Data/ORM/Email/LoadEmailTemplates.php | 4 +- .../synolia_stock_alert_email.html.twig | 6 +- .../SynoliaStockAlertBundleInstaller.php | 2 + .../Migrations/Schema/v1_1/AddEmailField.php | 2 + .../Schema/v1_2/DeleteEmailField.php | 34 ++++++++ .../Model/ExtendStockAlert.php | 19 ----- .../Resources/config/oro/datagrids.yml | 66 --------------- .../Resources/config/oro/navigation.yml | 6 ++ .../Resources/config/services.yml | 13 +-- .../Resources/translations/messages.de.yml | 14 ++++ .../Resources/translations/messages.en.yml | 7 ++ .../Resources/translations/messages.es.yml | 14 ++++ .../Resources/translations/messages.fr.yml | 14 ++++ .../Resources/translations/messages.it.yml | 14 ++++ .../Resources/translations/messages.pt.yml | 14 ++++ .../layouts/default/config/datagrids.yml | 62 ++++++++++++++ .../layout.html.twig | 2 - .../Twig/QuantityExtension.php | 13 +-- 31 files changed, 253 insertions(+), 292 deletions(-) delete mode 100644 src/Synolia/Bundle/StockAlertBundle/Mailer/SimpleEmailMailer.php create mode 100644 src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_2/DeleteEmailField.php delete mode 100644 src/Synolia/Bundle/StockAlertBundle/Model/ExtendStockAlert.php create mode 100644 src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.de.yml create mode 100644 src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.es.yml create mode 100644 src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.fr.yml create mode 100644 src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.it.yml create mode 100644 src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.pt.yml create mode 100644 src/Synolia/Bundle/StockAlertBundle/Resources/views/layouts/default/config/datagrids.yml diff --git a/README.md b/README.md index 5e83071..8fa8f36 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ This plugin allows the customer to subscribe to a product whose stock level is e | | Version | | :--- |:--------| -| PHP | 8.2 | -| OroCommerce | 5.1 | +| PHP | 8.3 | +| OroCommerce | 6.0 | ## Installation diff --git a/src/Synolia/Bundle/StockAlertBundle/Async/StockAlertNotificationProcessor.php b/src/Synolia/Bundle/StockAlertBundle/Async/StockAlertNotificationProcessor.php index 011878b..48d111e 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Async/StockAlertNotificationProcessor.php +++ b/src/Synolia/Bundle/StockAlertBundle/Async/StockAlertNotificationProcessor.php @@ -4,6 +4,10 @@ namespace Synolia\Bundle\StockAlertBundle\Async; +use Doctrine\ORM\EntityManagerInterface; +use Oro\Bundle\CustomerBundle\Entity\CustomerUser; +use Oro\Bundle\SecurityBundle\Authentication\TokenAccessorInterface; +use Oro\Bundle\UserBundle\Mailer\UserTemplateEmailSender; use Oro\Bundle\WebsiteBundle\Manager\WebsiteManager; use Oro\Component\MessageQueue\Client\TopicSubscriberInterface; use Oro\Component\MessageQueue\Consumption\MessageProcessorInterface; @@ -11,43 +15,43 @@ use Oro\Component\MessageQueue\Transport\SessionInterface; use Oro\Component\MessageQueue\Util\JSON; use Synolia\Bundle\StockAlertBundle\Async\Topic\StockAlertNotificationTopic; -use Synolia\Bundle\StockAlertBundle\Mailer\SimpleEmailMailer; class StockAlertNotificationProcessor implements MessageProcessorInterface, TopicSubscriberInterface { public function __construct( - protected WebsiteManager $websiteManager, - protected SimpleEmailMailer $simpleEmailMailer, + protected UserTemplateEmailSender $userTemplateEmailSender, + protected EntityManagerInterface $entityManager, ) { } /** * @throws \JsonException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function process(MessageInterface $message, SessionInterface $session): string { $body = JSON::decode($message->getBody()); - if (empty($body['customerEmail'])) { - return self::REJECT; - } - $website = $this->websiteManager->getCurrentWebsite(); - if (!$website) { - return self::REJECT; - } + $id = $body['customerUserId']; - $this->simpleEmailMailer->send( - [$body['customerEmail']], + $customerUserRepository = $this->entityManager->getRepository(CustomerUser::class); + /** @var CustomerUser $customerUser */ + $customerUser = $customerUserRepository->findOneBy(['id' => $id]); + + $emailTemplateParams = [ + 'customerFullName' => $customerUser->getFullName(), + 'productName' => $body['productName'], + 'productSKU' => $body['productSKU'], + 'websiteName' => $customerUser->getWebsite(), + ]; + + $this->userTemplateEmailSender->sendUserTemplateEmail( + $customerUser, 'synolia_stock_alert_email', - $website, - [ - 'customerFullName' => $body['customerFullName'], - 'productName' => $body['productName'], - 'productSKU' => $body['productSKU'], - 'websiteName' => $website->getName(), - ] + $emailTemplateParams ); return self::ACK; diff --git a/src/Synolia/Bundle/StockAlertBundle/Async/Topic/StockAlertNotificationTopic.php b/src/Synolia/Bundle/StockAlertBundle/Async/Topic/StockAlertNotificationTopic.php index 830f08c..6d5744e 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Async/Topic/StockAlertNotificationTopic.php +++ b/src/Synolia/Bundle/StockAlertBundle/Async/Topic/StockAlertNotificationTopic.php @@ -4,6 +4,7 @@ namespace Synolia\Bundle\StockAlertBundle\Async\Topic; +use Oro\Bundle\CustomerBundle\Entity\CustomerUser; use Oro\Component\MessageQueue\Topic\AbstractTopic; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -23,19 +24,16 @@ public function configureMessageBody(OptionsResolver $resolver): void { $resolver ->setDefined([ - 'customerEmail', - 'customerFullName', + 'customerUserId', 'productName', 'productSKU', ]) ->setRequired([ - 'customerEmail', - 'customerFullName', + 'customerUserId', 'productName', 'productSKU', ]) - ->addAllowedTypes('customerEmail', 'string') - ->addAllowedTypes('customerFullName', 'string') + ->addAllowedTypes('customerUserId', 'int') ->addAllowedTypes('productName', 'string') ->addAllowedTypes('productSKU', 'string') ; diff --git a/src/Synolia/Bundle/StockAlertBundle/Controller/Frontend/StockAlertController.php b/src/Synolia/Bundle/StockAlertBundle/Controller/Frontend/StockAlertController.php index bcb8b86..12d0376 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Controller/Frontend/StockAlertController.php +++ b/src/Synolia/Bundle/StockAlertBundle/Controller/Frontend/StockAlertController.php @@ -58,7 +58,7 @@ public function form(Request $request, int $productId): Response $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { try { - $this->handler->create($product, $form->getData()->get('recipient_email')); + $this->handler->create($product); $this->addFlash( 'success', @@ -128,7 +128,7 @@ public function deleteAction(Product $product): JsonResponse 'status' => 'success', 'message' => $this->translator->trans('synolia.stockalert.alert.unregister.confirmation_message'), ]); - } catch (\Exception $exception) { + } catch (\Exception $e) { } return new JsonResponse([ diff --git a/src/Synolia/Bundle/StockAlertBundle/Entity/StockAlert.php b/src/Synolia/Bundle/StockAlertBundle/Entity/StockAlert.php index 103447d..3c07f40 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Entity/StockAlert.php +++ b/src/Synolia/Bundle/StockAlertBundle/Entity/StockAlert.php @@ -18,7 +18,6 @@ use Oro\Bundle\ProductBundle\Entity\Product; use Oro\Bundle\UserBundle\Entity\Ownership\UserAwareTrait; use Synolia\Bundle\StockAlertBundle\Entity\Repository\StockAlertRepository; -use Synolia\Bundle\StockAlertBundle\Model\ExtendStockAlert; #[ORM\Entity(repositoryClass: StockAlertRepository::class)] #[ORM\Table(name: 'synolia_stock_alert')] @@ -40,7 +39,7 @@ ], ] )] -class StockAlert extends ExtendStockAlert implements +class StockAlert implements ExtendEntityInterface, OrganizationAwareInterface, CustomerOwnerAwareInterface, diff --git a/src/Synolia/Bundle/StockAlertBundle/EventListener/Frontend/ProductListStockAlertListener.php b/src/Synolia/Bundle/StockAlertBundle/EventListener/Frontend/ProductListStockAlertListener.php index 9dbcfa9..397f97f 100644 --- a/src/Synolia/Bundle/StockAlertBundle/EventListener/Frontend/ProductListStockAlertListener.php +++ b/src/Synolia/Bundle/StockAlertBundle/EventListener/Frontend/ProductListStockAlertListener.php @@ -14,16 +14,10 @@ class ProductListStockAlertListener { - private EntityManagerInterface $entityManager; - - private TokenAccessorInterface $tokenAccessor; - public function __construct( - EntityManagerInterface $entityManager, - TokenAccessorInterface $tokenAccessor + private EntityManagerInterface $entityManager, + private TokenAccessorInterface $tokenAccessor ) { - $this->entityManager = $entityManager; - $this->tokenAccessor = $tokenAccessor; } public function onBuildResult(BuildResultProductListEvent $event): void diff --git a/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php b/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php index 62b8124..186056f 100644 --- a/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php +++ b/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php @@ -17,6 +17,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; use Synolia\Bundle\StockAlertBundle\Async\Topic\StockAlertNotificationTopic; use Synolia\Bundle\StockAlertBundle\Entity\Repository\StockAlertRepository; +use Synolia\Bundle\StockAlertBundle\Entity\StockAlert; use Synolia\Bundle\StockAlertBundle\Handler\StockAlertHandler; class InventoryLevelNotificationEventListener @@ -42,14 +43,13 @@ public function preUpdate(InventoryLevel $inventoryLevel, LifecycleEventArgs $ar if (!$this->inventoryHasNewStock($args)) { return; } + /** @var StockAlert[] $alerts */ $alerts = $this->stockAlertRepository->findUnexpiredByProduct($inventoryLevel->getProduct()); foreach ($alerts as $alert) { $this->stockAlerts[] = $alert; - $accessor = PropertyAccess::createPropertyAccessor(); $this->sendStockAlertMessage( $inventoryLevel->getProduct(), - $alert->getCustomerUser(), - $accessor->getValue($alert, 'recipient_email') + $alert->getCustomerUser() ); } } @@ -78,26 +78,12 @@ protected function inventoryHasNewStock(LifecycleEventArgs $args): bool */ protected function sendStockAlertMessage( Product $product, - ?CustomerUser $customerUser = null, - ?string $recipientEmail = null + CustomerUser $customerUser ): void { - $email = null; - $fullName = $this->translator->trans('synolia.stockalert.customer.fullname'); - - if ($customerUser instanceof CustomerUser) { - $email = $customerUser->getEmail(); - $fullName = $customerUser->getFullName(); - } elseif (!empty($recipientEmail)) { - $email = $recipientEmail; - } - - if (!empty($email)) { - $this->messageProducer->send(StockAlertNotificationTopic::getName(), [ - 'customerEmail' => $email, - 'customerFullName' => $fullName, - 'productName' => $product->getName()->getString(), - 'productSKU' => $product->getSku(), - ]); - } + $this->messageProducer->send(StockAlertNotificationTopic::getName(), [ + 'customerUserId' => $customerUser->getId(), + 'productName' => $product->getName()->getString(), + 'productSKU' => $product->getSku(), + ]); } } diff --git a/src/Synolia/Bundle/StockAlertBundle/EventListener/StockAlertFrontendDatagridListener.php b/src/Synolia/Bundle/StockAlertBundle/EventListener/StockAlertFrontendDatagridListener.php index d4d2c0e..356506d 100644 --- a/src/Synolia/Bundle/StockAlertBundle/EventListener/StockAlertFrontendDatagridListener.php +++ b/src/Synolia/Bundle/StockAlertBundle/EventListener/StockAlertFrontendDatagridListener.php @@ -17,19 +17,13 @@ class StockAlertFrontendDatagridListener { - private EntityManagerInterface $entityManager; - - private TokenAccessorInterface $tokenAccessor; - public function __construct( - EntityManagerInterface $entityManager, - TokenAccessorInterface $tokenAccessor + private EntityManagerInterface $entityManager, + private TokenAccessorInterface $tokenAccessor ) { - $this->entityManager = $entityManager; - $this->tokenAccessor = $tokenAccessor; } - public function onResultAfter(SearchResultAfter $event) + public function onResultAfter(SearchResultAfter $event): void { /** @var ResultRecord[] $records */ $records = $event->getRecords(); @@ -61,7 +55,7 @@ public function onResultAfter(SearchResultAfter $event) } } - public function onBuildBefore(BuildBefore $event) + public function onBuildBefore(BuildBefore $event): void { $config = $event->getConfig(); $config->offsetAddToArrayByPath( diff --git a/src/Synolia/Bundle/StockAlertBundle/Form/Type/StockAlertType.php b/src/Synolia/Bundle/StockAlertBundle/Form/Type/StockAlertType.php index b835a9d..d499c60 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Form/Type/StockAlertType.php +++ b/src/Synolia/Bundle/StockAlertBundle/Form/Type/StockAlertType.php @@ -12,8 +12,11 @@ class StockAlertType extends AbstractType { - public const NAME = 'synolia_stock_alert_type'; + public const string NAME = 'synolia_stock_alert_type'; + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder diff --git a/src/Synolia/Bundle/StockAlertBundle/Handler/StockAlertHandler.php b/src/Synolia/Bundle/StockAlertBundle/Handler/StockAlertHandler.php index 6dec94e..3dc169a 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Handler/StockAlertHandler.php +++ b/src/Synolia/Bundle/StockAlertBundle/Handler/StockAlertHandler.php @@ -31,12 +31,12 @@ public function __construct( * @throws NotSupported * @throws ORMException */ - public function create(Product $product, ?string $recipientEmail = null): StockAlert|bool + public function create(Product $product): StockAlert|bool { $user = $this->tokenAccessor->getUser(); $organization = $this->tokenAccessor->getOrganization(); - $stockAlert = $this->getStockAlert($product, $user, $organization, $recipientEmail); + $stockAlert = $this->getStockAlert($product, $user, $organization); if ($stockAlert instanceof StockAlert) { return $stockAlert; } @@ -51,10 +51,6 @@ public function create(Product $product, ?string $recipientEmail = null): StockA if ($organization instanceof Organization) { $stockAlert->setOrganization($organization); } - if (!empty($recipientEmail)) { - $accessor = PropertyAccess::createPropertyAccessor(); - $accessor->setValue($stockAlert, 'recipient_email', $recipientEmail); - } $stockAlert->setExpirationDate($this->getExpirationDate()); $this->entityManager->persist($stockAlert); $this->entityManager->flush(); @@ -116,8 +112,7 @@ protected function getExpirationDate(): \DateTime protected function getStockAlert( Product $product, ?CustomerUser $user, - ?Organization $organization, - ?string $recipientEmail = null + ?Organization $organization ): ?StockAlert { $stockAlertRepository = $this->entityManager->getRepository(StockAlert::class); @@ -128,9 +123,6 @@ protected function getStockAlert( if ($organization instanceof Organization) { $params['organization'] = $organization; } - if (!empty($recipientEmail)) { - $params['recipient_email'] = $recipientEmail; - } return $stockAlertRepository->findOneBy($params); } diff --git a/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/InventoryQuantityDataProvider.php b/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/InventoryQuantityDataProvider.php index 334c28f..6a0bdcb 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/InventoryQuantityDataProvider.php +++ b/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/InventoryQuantityDataProvider.php @@ -10,15 +10,10 @@ class InventoryQuantityDataProvider { - /** - * @var InventoryQuantityProviderInterface - */ - protected $inventoryQuantityProvider; public function __construct( - InventoryQuantityProviderInterface $inventoryQuantityProvider + protected InventoryQuantityProviderInterface $inventoryQuantityProvider ) { - $this->inventoryQuantityProvider = $inventoryQuantityProvider; } public function getAvailableQuantity(Product $product): int @@ -29,6 +24,6 @@ public function getAvailableQuantity(Product $product): int return 0; } - return (int)$this->inventoryQuantityProvider->getAvailableQuantity($product, $unit); + return $this->inventoryQuantityProvider->getAvailableQuantity($product, $unit); } } diff --git a/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/StockAlertDataProvider.php b/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/StockAlertDataProvider.php index 214b648..494ca46 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/StockAlertDataProvider.php +++ b/src/Synolia/Bundle/StockAlertBundle/Layout/DataProvider/StockAlertDataProvider.php @@ -12,16 +12,11 @@ class StockAlertDataProvider { - protected EntityManager $entityManager; - - protected TokenAccessor $tokenAccessor; public function __construct( - EntityManager $entityManager, - TokenAccessor $tokenAccessor + protected EntityManager $entityManager, + protected TokenAccessor $tokenAccessor ) { - $this->entityManager = $entityManager; - $this->tokenAccessor = $tokenAccessor; } /** diff --git a/src/Synolia/Bundle/StockAlertBundle/Mailer/SimpleEmailMailer.php b/src/Synolia/Bundle/StockAlertBundle/Mailer/SimpleEmailMailer.php deleted file mode 100644 index 89d65e8..0000000 --- a/src/Synolia/Bundle/StockAlertBundle/Mailer/SimpleEmailMailer.php +++ /dev/null @@ -1,83 +0,0 @@ -findEmailTemplateByName($templateName); - - [$subjectRendered, $templateRendered] = $this->renderer->compileMessage($emailTemplate, $emailTemplateParams); - - foreach ($listEmails as $listEmail) { - $email = new Email(); - $email->setFrom($this->getSenderEmail($website)); - $email->setTo([$listEmail]); - $email->setTemplate($emailTemplate); - $email->setBody($templateRendered); - $email->setType($emailTemplate->getType()); - $email->setSubject($subjectRendered); - $email->setOrganization($emailTemplate->getOrganization()); - $this->mailer->send($email); - } - } - - public function getConfigByWebsite(Website $website, string $configName): string - { - $this->configManager->setScopeIdFromEntity($website); - - return $this->configManager->get($configName); - } - - protected function findEmailTemplateByName(string $emailTemplateName): EmailTemplate - { - $emailTemplate = $this->entityManager - ->getRepository(EmailTemplate::class) - ->findOneBy(['name' => $emailTemplateName]); - Assert::notNull($emailTemplate); - - return $emailTemplate; - } - - protected function getSenderEmail(Website $website): string - { - $senderEmail = $this->getConfigByWebsite($website, 'oro_notification.email_notification_sender_email'); - $senderName = $this->getConfigByWebsite($website, 'oro_notification.email_notification_sender_name'); - if ($senderEmail && $senderName) { - return From::emailAddress( - $senderEmail, - $senderName - )->toString(); - } - - return From::emailAddress( - $this->configManager->get('oro_notification.email_notification_sender_email'), - $this->configManager->get('oro_notification.email_notification_sender_name') - )->toString(); - } -} diff --git a/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/Email/LoadEmailTemplates.php b/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/Email/LoadEmailTemplates.php index 874ff44..700fede 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/Email/LoadEmailTemplates.php +++ b/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/Email/LoadEmailTemplates.php @@ -5,8 +5,8 @@ namespace Synolia\Bundle\StockAlertBundle\Migrations\Data\ORM\Email; use Doctrine\Persistence\ObjectManager; -use Oro\Bundle\EmailBundle\Migrations\Data\ORM\AbstractEmailFixture; use Oro\Bundle\EmailBundle\Entity\EmailTemplate; +use Oro\Bundle\EmailBundle\Migrations\Data\ORM\AbstractEmailFixture; use Oro\Bundle\MigrationBundle\Fixture\VersionedFixtureInterface; class LoadEmailTemplates extends AbstractEmailFixture implements VersionedFixtureInterface @@ -16,7 +16,7 @@ public function getEmailsDir(): string return $this->container ->get('kernel') ->locateResource('@SynoliaStockAlertBundle/Migrations/Data/ORM/data/emails') - ; + ; } public function getVersion(): string diff --git a/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/data/emails/synolia_stock_alert_email.html.twig b/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/data/emails/synolia_stock_alert_email.html.twig index 3ba3b97..1184727 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/data/emails/synolia_stock_alert_email.html.twig +++ b/src/Synolia/Bundle/StockAlertBundle/Migrations/Data/ORM/data/emails/synolia_stock_alert_email.html.twig @@ -1,9 +1,9 @@ @name = synolia_stock_alert_email @entityName = Synolia\Bundle\StockAlertBundle\Entity\StockAlert -@subject = {{ websiteName }}: product back in stock +@subject = {{ websiteName }}: {{ 'synolia.stockalert.email.subject'|trans }} @isSystem = 0 @isEditable = 1 -Dear {{ customerFullName }},
+{{ 'synolia.stockalert.email.greeting'|trans }} {{ customerFullName }},

-The product {{ productName }} with SKU {{ productSKU }} is now back in stock. +{{ 'synolia.stockalert.email.body.the_product'|trans }} {{ productName }} {{ 'synolia.stockalert.email.body.with_sku'|trans }} {{ productSKU }} {{ 'synolia.stockalert.email.body.is_back'|trans }} diff --git a/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/SynoliaStockAlertBundleInstaller.php b/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/SynoliaStockAlertBundleInstaller.php index 009cbf8..fa0bac1 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/SynoliaStockAlertBundleInstaller.php +++ b/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/SynoliaStockAlertBundleInstaller.php @@ -20,6 +20,8 @@ public function getMigrationVersion(): string /** * @throws SchemaException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function up(Schema $schema, QueryBag $queries): void { diff --git a/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_1/AddEmailField.php b/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_1/AddEmailField.php index 462e780..a4f1ff6 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_1/AddEmailField.php +++ b/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_1/AddEmailField.php @@ -15,6 +15,8 @@ class AddEmailField implements Migration { /** * @throws SchemaException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function up(Schema $schema, QueryBag $queries): void { diff --git a/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_2/DeleteEmailField.php b/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_2/DeleteEmailField.php new file mode 100644 index 0000000..e5306b6 --- /dev/null +++ b/src/Synolia/Bundle/StockAlertBundle/Migrations/Schema/v1_2/DeleteEmailField.php @@ -0,0 +1,34 @@ +hasTable('synolia_stock_alert')) { + return; + } + + $table = $schema->getTable('synolia_stock_alert'); + if ($table->hasColumn('recipient_email')) { + $table->dropColumn( + 'recipient_email' + ); + return; + } + + } +} diff --git a/src/Synolia/Bundle/StockAlertBundle/Model/ExtendStockAlert.php b/src/Synolia/Bundle/StockAlertBundle/Model/ExtendStockAlert.php deleted file mode 100644 index 1a9dca1..0000000 --- a/src/Synolia/Bundle/StockAlertBundle/Model/ExtendStockAlert.php +++ /dev/null @@ -1,19 +0,0 @@ - - {% else %} - {{ render(controller('App\\Controller\\Frontend\\StockAlertController::form', {'productId': product.id})) }} {% endif %} {% endblock %} diff --git a/src/Synolia/Bundle/StockAlertBundle/Twig/QuantityExtension.php b/src/Synolia/Bundle/StockAlertBundle/Twig/QuantityExtension.php index dc2b652..49f757c 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Twig/QuantityExtension.php +++ b/src/Synolia/Bundle/StockAlertBundle/Twig/QuantityExtension.php @@ -16,18 +16,11 @@ class QuantityExtension extends AbstractExtension { - protected InventoryQuantityDataProvider $inventoryQuantityDataProvider; - protected EntityManager $entityManager; - protected StockAlertDataProvider $stockAlertDataProvider; - public function __construct( - InventoryQuantityDataProvider $inventoryQuantityDataProvider, - EntityManager $entityManager, - StockAlertDataProvider $stockAlertDataProvider + protected InventoryQuantityDataProvider $inventoryQuantityDataProvider, + protected EntityManager $entityManager, + protected StockAlertDataProvider $stockAlertDataProvider ) { - $this->inventoryQuantityDataProvider = $inventoryQuantityDataProvider; - $this->entityManager = $entityManager; - $this->stockAlertDataProvider = $stockAlertDataProvider; } public function getFunctions(): array From 7ed33906855f83c11c53a353ef5e5fdd9aa2a539 Mon Sep 17 00:00:00 2001 From: Diego Jaure Date: Tue, 16 Jul 2024 05:34:27 +0200 Subject: [PATCH 2/3] missing translations --- .../Resources/translations/messages.de.yml | 7 +++++++ .../Resources/translations/messages.es.yml | 7 +++++++ .../Resources/translations/messages.fr.yml | 7 +++++++ .../Resources/translations/messages.it.yml | 7 +++++++ .../Resources/translations/messages.pt.yml | 7 +++++++ 5 files changed, 35 insertions(+) diff --git a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.de.yml b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.de.yml index a6b7d04..850c471 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.de.yml +++ b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.de.yml @@ -12,3 +12,10 @@ synolia: confirmation_message: Die Warnung für den Lagerbestand dieses Produkts wurde erfolgreich gelöscht recipient_email.label: E-Mail customer.fullname: Kunde + email: + subject: "Produkt wieder auf Lager" + greeting: "Sehr geehrte(r)" + body: + the_product: "Das Produkt" + with_sku: "mit der SKU" + is_back: "ist jetzt wieder auf Lager." diff --git a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.es.yml b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.es.yml index aa09986..7d72dad 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.es.yml +++ b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.es.yml @@ -12,3 +12,10 @@ synolia: confirmation_message: La alerta sobre el nivel de stock de ese producto ha sido eliminada con éxito recipient_email.label: Correo electrónico customer.fullname: cliente + email: + subject: "producto de nuevo en stock" + greeting: "Estimado(a)" + body: + the_product: "El producto" + with_sku: "con SKU" + is_back: "está ahora de nuevo en stock." diff --git a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.fr.yml b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.fr.yml index fcbc2cd..5b0c141 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.fr.yml +++ b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.fr.yml @@ -12,3 +12,10 @@ synolia: confirmation_message: L'alerte sur le niveau de stock de ce produit a été supprimée avec succès recipient_email.label: E-mail customer.fullname: client + email: + subject: "produit de nouveau en stock" + greeting: "Cher/Chère" + body: + the_product: "Le produit" + with_sku: "avec SKU" + is_back: "est maintenant de nouveau en stock." diff --git a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.it.yml b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.it.yml index 91ffa18..995696d 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.it.yml +++ b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.it.yml @@ -12,3 +12,10 @@ synolia: confirmation_message: L'allerta sul livello di stock di quel prodotto è stata eliminata con successo recipient_email.label: Email customer.fullname: cliente + email: + subject: "prodotto di nuovo in stock" + greeting: "Caro/a" + body: + the_product: "Il prodotto" + with_sku: "con SKU" + is_back: "è ora di nuovo in stock." diff --git a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.pt.yml b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.pt.yml index 0577e18..1996ffe 100644 --- a/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.pt.yml +++ b/src/Synolia/Bundle/StockAlertBundle/Resources/translations/messages.pt.yml @@ -12,3 +12,10 @@ synolia: confirmation_message: O alerta sobre o nível de estoque desse produto foi excluído com sucesso recipient_email.label: Email customer.fullname: cliente + email: + subject: "produto de novo em stock" + greeting: "Prezado(a)" + body: + the_product: "O produto" + with_sku: "com SKU" + is_back: "está agora de novo em stock." From bcc59b35b5d58b4457cda68ce5427e81f0130081 Mon Sep 17 00:00:00 2001 From: Diego Jaure Date: Wed, 17 Jul 2024 16:38:06 +0200 Subject: [PATCH 3/3] updating deprecated classes --- .../InventoryLevelNotificationEventListener.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php b/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php index 186056f..7dbc59d 100644 --- a/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php +++ b/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php @@ -4,12 +4,10 @@ namespace Synolia\Bundle\StockAlertBundle\EventListener; -use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\OptimisticLockException; use Oro\Bundle\CustomerBundle\Entity\CustomerUser; -use Oro\Bundle\EntityExtendBundle\PropertyAccess; use Oro\Bundle\InventoryBundle\Entity\InventoryLevel; use Oro\Bundle\ProductBundle\Entity\Product; use Oro\Component\MessageQueue\Client\MessageProducerInterface; @@ -35,9 +33,9 @@ public function __construct( /** * @throws Exception */ - public function preUpdate(InventoryLevel $inventoryLevel, LifecycleEventArgs $args): void + public function preUpdate(InventoryLevel $inventoryLevel, PreUpdateEventArgs $args): void { - if (!$args->getEntity() instanceof InventoryLevel) { + if (!$args->getObject() instanceof InventoryLevel) { return; } if (!$this->inventoryHasNewStock($args)) { @@ -63,11 +61,9 @@ public function postUpdate(): void $this->stockAlertHandler->deleteStockAlerts($this->stockAlerts); } - protected function inventoryHasNewStock(LifecycleEventArgs $args): bool + protected function inventoryHasNewStock(PreUpdateEventArgs $args): bool { - /** @var PreUpdateEventArgs $args */ $oldQuantity = floatval($args->getOldValue('quantity')); - /** @var PreUpdateEventArgs $args */ $newQuantity = floatval($args->getNewValue('quantity')); return $oldQuantity <= 0 && $newQuantity > 0;