Skip to content

Before plugin loses its input parameters #375

@cosmo-ecommerce

Description

@cosmo-ecommerce

Hello,
we found a bug in the snowdog_menu_get_category_tree_by_sore_view plugin.
Reference files:

  • vendor/snowdog/module-menu/etc/adminhtml/di.xml
  • vendor/snowdog/module-menu/Plugin/Model/ResourceModel/Category/TreePlugin.php
  • vendor/magento/module-catalog/Model/ResourceModel/Category/Tree.php

If you take a look at the Tree.php file, you can see that there are 5 input parameters:

$collection = null,
$sorted = false,
$exclude = [],
$toLoad = true,
$onlyActive = false

In the TreePlugin.php file, however, only the first parameter (in addition to the subject) is considered:

Tree $subject,
$collection = null

It is correct to keep the subject + the five parameters:

Tree $subject,
$collection = null,
$sorted = false,
$exclude = [],
$toLoad = true,
$onlyActive = false

The same applies when returning. Instead of:
return [$collection];
The following should be used:
return [$collection, $sorted, $exclude, $toLoad, $onlyActive];

Otherwise, information will be lost!

The plugin is also executed when creating a new store view, for example. It is used to generate URL rewrites. If this information is lost, rewrites of the Default Category and disabled categories are also generated, causing redirect errors that are difficult to debug!

We ask you to modify the plugin as follows:

public function beforeAddCollectionData(
    Tree $subject,
         $collection = null,
         $sorted = false,
         $exclude = [],
         $toLoad = true,
         $onlyActive = false)
 {
    $postData = $this->request->getPost();
    
$storeId = $postData[‘store_id’];

    if (!isset($postData[‘store_id’])) {
        return [$collection, $sorted, $exclude, $toLoad, $onlyActive];
    }
    
$collection->setProductStoreId(
        $storeId
    )->setStoreId(
        $storeId
    );

return [$collection, $sorted, $exclude, $toLoad, $onlyActive];
}

Magento version -> 2.4.6-p9
Plugin version (snowdog/module-menu) -> 2.28.0

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions