yireo / Yireo_GoogleTagManager2

Open Software License 3.0
147 stars 76 forks source link

Fixes a TypeError for MultiSelect attribute values #184

Closed frqnck closed 1 year ago

frqnck commented 1 year ago

Prevent TypeError when value is already an array.

May provide some unit-tests if times permits it...

jissereitsma commented 1 year ago

I think a unit test is not necessary here, the code makes sense. However, I didn't bump into this issue myself. Could it be that some third party extension was an issue here?

frqnck commented 1 year ago

From the exception log, it doesn't looks like a third party module is involved...

[2023-08-12 08:46:47] magento.CRITICAL: TypeError: explode() expects parameter 2 to be string, array given in /kit-app/src/vendor/yireo/magento2-googletagmana
ger2/Util/Attribute/GetAttributeValue.php:165
Stack trace:
#0 /kit-app/src/vendor/yireo/magento2-googletagmanager2/Util/Attribute/GetAttributeValue.php(165): explode(',', Array)
#1 /kit-app/src/vendor/yireo/magento2-googletagmanager2/Util/Attribute/GetAttributeValue.php(125): Yireo\GoogleTagManager2\Util\Attribute\GetAttributeValue->g
etAttributeValueFromMultiSelect(Object(Magento\Catalog\Model\ResourceModel\Eav\Attribute\Interceptor), Array)
#2 /kit-app/src/vendor/yireo/magento2-googletagmanager2/Util/Attribute/GetAttributeValue.php(103): Yireo\GoogleTagManager2\Util\Attribute\GetAttributeValue->f
ilterAttributeValue(Object(Magento\Catalog\Model\ResourceModel\Eav\Attribute\Interceptor), Array)
#3 /kit-app/src/vendor/yireo/magento2-googletagmanager2/Util/Attribute/GetAttributeValue.php(61): Yireo\GoogleTagManager2\Util\Attribute\GetAttributeValue->ge
tAttributeValue(Object(Magento\Catalog\Model\Category\Interceptor), 'catalog_categor...', 'available_sort_...')
#4 /kit-app/src/vendor/yireo/magento2-googletagmanager2/DataLayer/Mapper/CategoryDataMapper.php(39): Yireo\GoogleTagManager2\Util\Attribute\GetAttributeValue-
>getCategoryAttributeValue(Object(Magento\Catalog\Model\Category\Interceptor), 'available_sort_...')
#5 /kit-app/src/vendor/yireo/magento2-googletagmanager2/DataLayer/Tag/Category/CurrentCategory.php(34): Yireo\GoogleTagManager2\DataLayer\Mapper\CategoryDataM
apper->mapByCategory(Object(Magento\Catalog\Model\Category\Interceptor))
#6 /kit-app/src/vendor/yireo/magento2-googletagmanager2/DataLayer/TagParser.php(42): Yireo\GoogleTagManager2\DataLayer\Tag\Category\CurrentCategory->merge()
#7 /kit-app/src/vendor/yireo/magento2-googletagmanager2/DataLayer/TagParser.php(22): Yireo\GoogleTagManager2\DataLayer\TagParser->convertTag('category', Object(Yireo\GoogleTagManager2\DataLayer\Tag\Category\CurrentCategory), Array)
#8 /kit-app/src/vendor/yireo/magento2-googletagmanager2/ViewModel/DataLayer.php(60): Yireo\GoogleTagManager2\DataLayer\TagParser->parse(Array, Array)
#9 /kit-app/src/vendor/yireo/magento2-googletagmanager2/ViewModel/DataLayer.php(68): Yireo\GoogleTagManager2\ViewModel\DataLayer->getDataLayer()
#10 /kit-app/src/var/view_preprocessed/pub/static/vendor/yireo/magento2-googletagmanager2/view/frontend/templates/luma/data-layer.phtml(1): Yireo\GoogleTagManager2\ViewModel\DataLayer->getDataLayerAsJson()
#11 /kit-app/src/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/kit-app/src/va...')
#12 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Framework\View\Element\Template\Interceptor), '/kit-app/src/va...', Array)
#13 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array)
#14 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\View\Element\Template\Interceptor), '/kit-app/src/va...', Array)
#15 /kit-app/src/generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php(23): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callPlugins('render', Array, Array)
#16 /kit-app/src/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php\Interceptor->render(Object(Magento\Framework\View\Element\Template\Interceptor), '/kit-app/src/va...', Array)
#17 /kit-app/src/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView('/kit-app/src/va...')
#18 /kit-app/src/vendor/magento/framework/View/Element/AbstractBlock.php(1114): Magento\Framework\View\Element\Template->_toHtml()
#19 /kit-app/src/vendor/magento/framework/View/Element/AbstractBlock.php(1118): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#20 /kit-app/src/vendor/magento/framework/View/Element/AbstractBlock.php(678): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#21 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Element\AbstractBlock->toHtml()
#22 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Element\Template\Interceptor->___callParent('toHtml', Array)
#23 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Element\Template\Interceptor->Magento\Framework\Interception\{closure}()
#24 /kit-app/src/generated/code/Magento/Framework/View/Element/Template/Interceptor.php(32): Magento\Framework\View\Element\Template\Interceptor->___callPlugins('toHtml', Array, Array)
#25 /kit-app/src/vendor/magento/framework/View/Layout.php(578): Magento\Framework\View\Element\Template\Interceptor->toHtml()
#26 /kit-app/src/vendor/magento/framework/View/Layout.php(555): Magento\Framework\View\Layout->_renderBlock('yireo_googletag...')
#27 /kit-app/src/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('yireo_googletag...')
#28 /kit-app/src/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('yireo_googletag...', false)
#29 /kit-app/src/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('yireo_googletag...', false)
#30 /kit-app/src/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('yireo_googletag...')
#31 /kit-app/src/vendor/magento/framework/View/Layout.php(975): Magento\Framework\View\Layout->renderElement('yireo_googletag...')
#32 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput()
#33 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array)
#34 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#35 /kit-app/src/generated/code/Magento/Framework/View/Layout/Interceptor.php(41): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#36 /kit-app/src/vendor/magento/framework/View/Result/Page.php(260): Magento\Framework\View\Layout\Interceptor->getOutput()
#37 /kit-app/src/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#38 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#39 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#40 /kit-app/src/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#41 /kit-app/src/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(23): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#42 /kit-app/src/vendor/magento/framework/App/Http.php(120): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#43 /kit-app/src/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http->launch()
#44 /kit-app/src/pub/index.php(45): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#45 {main} [] {"url":"..}