magento / meta-for-magento2

33 stars 19 forks source link

Error when setting up the extension in the admin panel #42

Closed lemaryn closed 7 months ago

lemaryn commented 8 months ago

Preconditions (*)

  1. Magento 2.4.5-p1
  2. Meta for Magento v1.2.1

Steps to reproduce (*)

  1. Create a store following the screenshot image
  2. Set a debugging breakpoint on this line https://github.com/magento/meta-for-magento2/blob/v1.2.1/app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php#L136
  3. Go to Setup image
  4. The store key does not match 0 image

Expected result (*)

  1. Correct page for setup image

Actual result (*)

  1. I see a blank page image In the log, I see this error
[2023-10-20T17:01:24.075689+00:00] report.CRITICAL: Exception: Warning: Undefined array key 0 in /project-magento/vendor/meta/module-business-extension/Block/Adminhtml/Setup.php on line 135 in /project-magento/vendor/magento/framework/App/ErrorHandler.php:62
Stack trace:
#0 /project-magento/vendor/meta/module-business-extension/Block/Adminhtml/Setup.php(135): Magento\Framework\App\ErrorHandler->handler(2, 'Undefined array...', '/project-magento/vendor...', 135)
#1 /project-magento/vendor/meta/module-business-extension/view/adminhtml/templates/store_picker.phtml(13): Meta\BusinessExtension\Block\Adminhtml\Setup->getSelectedStoreId()

I suggest 2 options:

  1. Replace this line https://github.com/magento/meta-for-magento2/blob/v1.2.1/app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php#L136

from

$firstStore = array_slice($stores, 0, 1)[0];

to

$firstStore = array_shift($stores);
  1. Replace this part of code https://github.com/magento/meta-for-magento2/blob/v1.2.1/app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php#L127-L135

from

        // Missing or invalid query param, look for a default.
        foreach ($stores as $store) {
            if ($store->isDefault() && $store->getWebsiteId() === $this->getFirstWebsiteId()) {
                return $store['store_id'];
            }
        }

        // No default found, return the first store.
        $firstStore = array_slice($stores, 0, 1)[0];

to

        $i=0;
        // Missing or invalid query param, look for a default.
        foreach ($stores as $store) {
            if ($store->isDefault() && $store->getWebsiteId() === $this->getFirstWebsiteId()) {
                return $store['store_id'];
            }
            if ($i === 0) {
                // No default found, return the first store.
                $firstStore = $store;
            }
            $i++;
        }
zlik commented 7 months ago

Thank you for flagging, @lemaryn! Fixed in https://github.com/magento/meta-for-magento2/releases/tag/v1.2.3, closing this issue.