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->collectionFactory = $collectionFactory;
        $this->data = $data;
        $this->urlBuilder = $urlBuilder;
    }

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

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

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

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

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

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

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

1 Answer 1

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?

2
  • How to upgrading the Ced_PwaNotifications module to the latest version?
    – Bohdan V.
    Commented Aug 30, 2023 at 3: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
    Commented Aug 30, 2023 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.