0

I run php bin/magento setup:upgrade command in magento2.4.6.

But I got error like this.

enter image description here

Ced\PwaNotifications\Ui\Component\Listing\Massaction\Templates.php

<?php

namespace Ced\PwaNotifications\Ui\Component\Listing\MassAction;

use Magento\Framework\UrlInterface; use Zend\Stdlib\JsonSerializable; use \Ced\PwaNotifications\Model\ResourceModel\Template\CollectionFactory;

/**

  • Class Options

/ class Templates implements JsonSerializable { /* * @var array */ protected $options;

/**
 * @var CollectionFactory
 */
protected $collectionFactory;

/**
 * Additional options params
 *
 * @var array
 */
protected $data;

/**
 * @var UrlInterface
 */
protected $urlBuilder;

/**
 * Base URL for subactions
 *
 * @var string
 */
protected $urlPath;

/**
 * Param name for subactions
 *
 * @var string
 */
protected $paramName;

/**
 * Additional params for subactions
 *
 * @var array
 */
protected $additionalData = [];

/**
 * Constructor
 *
 * @param CollectionFactory $collectionFactory
 * @param UrlInterface $urlBuilder
 * @param array $data
 */
public function __construct(
    CollectionFactory $collectionFactory,
    UrlInterface $urlBuilder,
    array $data = []
) {
    $this-&gt;collectionFactory = $collectionFactory;
    $this-&gt;data = $data;
    $this-&gt;urlBuilder = $urlBuilder;
}

/**
 * Get action options
 *
 * @return array
 */
public function jsonSerialize():mixed
{
    $i = 0;
    if ($this-&gt;options === null) {
        // get the massaction data from the database table
        $templateCollection = $this-&gt;collectionFactory-&gt;create();

        if (!count($templateCollection)) {
            return $this-&gt;options;
        }
        //make a array of massaction
        foreach ($templateCollection as $key =&gt; $value) {
            $options[$i]['value'] = $value-&gt;getId();
            $options[$i]['label'] = $value-&gt;getTitle();
            $i++;
        }
        $this-&gt;prepareData();
        foreach ($options as $optionCode) {
            $this-&gt;options[$optionCode['value']] = [
                'type' =&gt; $optionCode['value'],
                'label' =&gt; $optionCode['label'],
            ];

            if ($this-&gt;urlPath &amp;&amp; $this-&gt;paramName) {
                $this-&gt;options[$optionCode['value']]['url'] = $this-&gt;urlBuilder-&gt;getUrl(
                    $this-&gt;urlPath,
                    [$this-&gt;paramName =&gt; $optionCode['value']]
                );
            }

            $this-&gt;options[$optionCode['value']] = array_merge_recursive(
                $this-&gt;options[$optionCode['value']],
                $this-&gt;additionalData
            );
        }

        // return the massaction data
        $this-&gt;options = array_values($this-&gt;options);
    }
    return $this-&gt;options;
}

/**
 * Prepare addition data for subactions
 *
 * @return void
 */
protected function prepareData()
{

    foreach ($this-&gt;data as $key =&gt; $value) {
        switch ($key) {
            case 'urlPath':
                $this-&gt;urlPath = $value;
                break;
            case 'paramName':
                $this-&gt;paramName = $value;
                break;
            default:
                $this-&gt;additionalData[$key] = $value;
                break;
        }
    }
}

}

Bohdan V.
  • 37
  • 1
  • 6

1 Answers1

1

As the error message indicates, the Ced\PwaNotifications\Ui\Component\Listing\Massaction\Templates::jsonSerialize() method in your third-party module (Ced_PwaNotifications) has a different the return type compared to its parent's method, JsonSerializable::jsonSerialize.

To resolve this issue, you can try upgrading the Ced_PwaNotifications module to the latest version, remove the generated directory, and recompile code (bin/magento setup:di:compile.

If the issue persists, you'll need to override Ced\PwaNotifications\Ui\Component\Listing\Massaction\Templates::jsonSerialize() method or create a custom composer patch in order to change it's return type.

The code for that method should similar to this:

public function jsonSerialize(): mixed
{
...
}

Read more about how to apply composer patches here https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/patches/apply.html?lang=en#composer

You can take a look at this page to know how to create a custom composer patch: How to create a Magento 2 Patch?

Tu Van
  • 6,868
  • 2
  • 11
  • 22
  • How to upgrading the Ced_PwaNotifications module to the latest version? – Bohdan V. Aug 30 '23 at 03:00
  • Since you installed that module manually in app/code, follow these steps to upgrade that module to the latest version: 1. Download the latest version of the module from the module provider website. 2. Remove all files and directories in the Ced_PwaNotifications module located at app/code/Ced/PwaNotifications. 3. Extract the latest version of the module to the Ced_PwaNotifications module located at app/code/Ced/PwaNotifications. 4. Run the upgrade command and recompile code (and redeploy static content if you are not in the Developer mode). You're done! – Tu Van Aug 30 '23 at 04:15