magento2: AlertProcessor - Argument #2 ($storeId) must be of type int, string given

Preconditions and environment

  • Magento version 2.4.4
  • PHP8.1

Steps to reproduce

  • Enable product alert stock in BO (Configuration > Catalog >Product Alerts > Allow Alert When Product Comes Back in Stock > Yes, Allow Alert When Product Price Changes - Yes)
  • Reindex and cache flush
  • Front end - Login as customer - Select a Product without stock - Register to a product stock alert (Notify me when the price drops, Notify me when this product is in stock)
  • Add stock to that product from admin
  • Launch consumers

Expected result

Alert stock email being sent

Actual result

Emails not triggered for Product Alerts

[2022-06-10T07:31:56.520650+00:00] .CRITICAL: Magento\ProductAlert\Model\Mailing\ErrorEmailSender::execute(): Argument #2 ($storeId) must be of type int, string given, called in /var/www/html/vendor/magento/module-product-alert/Model/Mailing/AlertProcessor.php on line 130 [] []

Additional information

I guess (not tested) that change could solve the issue

Magento\Store\Model\Store

ACTUAL CODE
   /**
     * Get store identifier
     *
     * @return  int
     */
    public function getId()
    {
        return $this->_getData(self::STORE_ID);
    }


PROPOSED FIX

   /**
     * Get store identifier
     *
     * @return  int
     */
    public function getId(): int
    {
        return (int) $this->_getData(self::STORE_ID);
    }

(of course, StoreInterface interface should be modified accordingly.)

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

In case anybody stumbles upon this issue, the store id type is only coming up when trying to send an error email caused by another error in the getFilteredContent function. The following patch applies a self-contained fix for both, is can be applied directly to magento/module-product-alert.

diff --git a/Block/Email/AbstractEmail.php b/Block/Email/AbstractEmail.php
index 5708180..d81a362 100644
--- a/Block/Email/AbstractEmail.php
+++ b/Block/Email/AbstractEmail.php
@@ -69,6 +69,10 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template
      */
     public function getFilteredContent($content)
     {
+        if (is_null($content)) {
+            return '';
+        }
+
         return $this->_maliciousCode->filter($content);
     }
 
diff --git a/Model/Mailing/AlertProcessor.php b/Model/Mailing/AlertProcessor.php
index 83ac4ab..754bb56 100644
--- a/Model/Mailing/AlertProcessor.php
+++ b/Model/Mailing/AlertProcessor.php
@@ -126,7 +126,7 @@ class AlertProcessor
         if (!empty($errors)) {
             /** @var Website $website */
             $website = $this->storeManager->getWebsite($websiteId);
-            $defaultStoreId = $website->getDefaultStore()->getId();
+            $defaultStoreId = (int)$website->getDefaultStore()->getId();
             $this->errorEmailSender->execute($errors, $defaultStoreId);
         }
     }

Hi @Nuranto

The issue is still reproducible. So reopening the ticket again.

Thanks.

Why did this issue got closed? @katmoon: do you have an explanation? Can you link to some commits that fixed it?