magento-2-seo icon indicating copy to clipboard operation
magento-2-seo copied to clipboard

Call to undefined function Mageplaza\Seo\Plugin\array_first()

Open KZNcode opened this issue 2 years ago • 5 comments

Preconditions (*)

  1. Magento 2.4.3-p2

Steps to reproduce (*)

  1. Viewing some products, some are fine, the error appears

Expected result (*)

  1. Product should load normally (this started happening after updating from Magento 2.4.3-p1 to 2.4.3-p2

Actual result (*)

  1. Error: Call to undefined function Mageplaza\Seo\Plugin\array_first() in /home/public_html/vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php:459 Stack trace: #0 /home/public_html/vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php(307): Mageplaza\Seo\Plugin\SeoRender->showProductStructuredData() #1 /home/public_html/vendor/magento/framework/Interception/Interceptor.php(146): Mageplaza\Seo\Plugin\SeoRender->afterRenderHeadContent() #2 /home/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Page\Config\Renderer\Interceptor->Magento\Framework\Interception{closure}() #3 /home/public_html/generated/code/Magento/Framework/View/Page/Config/Renderer/Interceptor.php(32): Magento\Framework\View\Page\Config\Renderer\Interceptor->___callPlugins() #4 /home/public_html/vendor/magento/framework/View/Result/Page.php(252): Magento\Framework\View\Page\Config\Renderer\Interceptor->renderHeadContent() #5 /home/public_html/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render() #6 /home/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult() #7 /home/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent() #8 /home/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception{closure}() #9 /home/public_html/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(95): Magento\Framework\View\Result\Page\Interceptor->___callPlugins() #10 /home/public_html/vendor/magento/framework/App/Http.php(120): Magento\Framework\View\Result\Page\Interceptor->renderResult() #11 /home/public_html/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http->launch() #12 /home/public_html/pub/index.php(29): Magento\Framework\App\Bootstrap->run() #13 {main}

KZNcode avatar Apr 19 '22 21:04 KZNcode

This is using the latest mageplaza release versions

Mageplaza_Core Mageplaza_Seo Mageplaza_Sitemap Mageplaza_Smtp

(This isn't relavant to this issue: https://github.com/mageplaza/module-core/issues/3 ... nor this https://www.mageplaza.com/blog/magento-site-down.html)

KZNcode avatar Apr 19 '22 22:04 KZNcode

Disabling the extension resolved the issue.

bin/magento module:disable Mageplaza_Sitemap --clear-static-content
bin/magento module:disable Mageplaza_Seo --clear-static-content

bin/magento setup:upgrade

KZNcode avatar Apr 19 '22 22:04 KZNcode

Disabling the extension resolved the issue.

bin/magento module:disable Mageplaza_Sitemap --clear-static-content
bin/magento module:disable Mageplaza_Seo --clear-static-content

bin/magento setup:upgrade

Shame. We'd love to use this extension on Magento 2.4.4

themew avatar May 02 '22 15:05 themew

I didn't quite understand where that function should come from but I think the ideia was to get the first value the array so it can get the percentage later, so I changed in /home/public_html/vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php line 459, as it says in the error, from

array_first($ratingVotes);

to

$ratingVotes[0];

Probably not the best solution but was what I used to fix it for the moment and all seems to be working just fine when getting the reviews

Hope it helps at least as a workaround for now

ruipns avatar Jun 08 '22 11:06 ruipns

Patch file dump for cweagans/composer-patches. Requires patch installed on server.

composer.json

  "extra": {
    "patches": {
      "mageplaza/magento-2-seo-extension": {
        "[patch description]": "[path to file].diff"
      }
    }
  }

Patch file

diff --git a/Plugin/SeoRender.php b/Plugin/SeoRender.php
index e6a3f31..b5b20d4 100644
--- a/Plugin/SeoRender.php
+++ b/Plugin/SeoRender.php
@@ -455,7 +455,7 @@ public function showProductStructuredData()
                         ];
                         if ($review->getRatingVotes()->getData()) {
                             $ratingVotes                = $review->getRatingVotes()->getData();
-                            $vote                       = array_first($ratingVotes);
+                            $vote                       = $ratingVotes[0];
                             $reviewData['reviewRating'] = [
                                 '@type'       => 'Rating',
                                 'ratingValue' => $vote['percent'],                             

kickDominic avatar Jun 13 '22 09:06 kickDominic