0

i have overwritten the Related.php file but nothing happen

app/code/Vendor/Module/etc/di.xml

<preference for="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related" type="Vendor\Module\Ui\DataProvider\Product\Form\Modifier\Related" />

app/code/Vendor/Module/Ui/DataProvider/Product/Form/Modifier/Related.php

namespace Vendor\Module\Ui\DataProvider\Product\Form\Modifier;

class Related extends \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related
    {

     public function modifyMeta(array $meta)
     { 
       echo "test"; die;
     }
  }
?>

Please help this issue.

1 Answer 1

0

app/code/Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <preference for="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related" type="Vendor\Module\Model\Related" />
</config>

app/code/Vendor/Module/Model/Related.php

<?php

namespace Vendor\Module\Model;

use Magento\Ui\Component\Form\Fieldset;

class Related extends \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related
{
    /**
     * @var string
     */
    private static $previousGroup = 'search-engine-optimization';
    /**
     * @var int
     */
    private static $sortOrder = 90;

    public function modifyMeta(array $meta)
    {
        $meta = array_replace_recursive(
            $meta,
            [
                static::GROUP_RELATED => [
                    'children' => [
                        $this->scopePrefix . static::DATA_SCOPE_RELATED => $this->getRelatedFieldset(),
                        $this->scopePrefix . static::DATA_SCOPE_UPSELL => $this->getUpSellFieldset(),
                        $this->scopePrefix . static::DATA_SCOPE_CROSSSELL => $this->getCrossSellFieldset(),
                    ],
                    'arguments' => [
                        'data' => [
                            'config' => [
                                'label' => __('Related Products, Up-Sells, and Cross-Sells'),
                                'collapsible' => true,
                                'componentType' => Fieldset::NAME,
                                'dataScope' => static::DATA_SCOPE,
                                'sortOrder' =>
                                    $this->getNextGroupSortOrder(
                                        $meta,
                                        self::$previousGroup,
                                        self::$sortOrder
                                    ),
                            ],
                        ],

                    ],
                ],
            ]
        );

        return $meta;
    }

    protected function getCrossSellFieldset()
    {
        $content = __(
            'These "impulse-buy" products appear next to the shopping cart' .
            ' as cross-sells to the items already in the shopping cart.'
        );

        return [
            'children' => [
                'button_set' => $this->getButtonSet(
                    $content,
                    __('Add Cross-Sell Products'),
                    $this->scopePrefix . static::DATA_SCOPE_CROSSSELL
                ),
                'modal' => $this->getGenericModal(
                    __('Add Cross-Sell Products'),
                    $this->scopePrefix . static::DATA_SCOPE_CROSSSELL
                ),
                static::DATA_SCOPE_CROSSSELL => $this->getGrid($this->scopePrefix . static::DATA_SCOPE_CROSSSELL),
            ],
            'arguments' => [
                'data' => [
                    'config' => [
                        'additionalClasses' => 'admin__fieldset-section',
                        'label' => __('Test Sell Products'),
                        'collapsible' => false,
                        'componentType' => Fieldset::NAME,
                        'dataScope' => '',
                        'sortOrder' => 30,
                    ],
                ],
            ]
        ];
    }
}

Thanks,

5
  • I followed as per your instruction nothing happened. still loading from vendor file. Is this working for you? Am using the enterprise version Commented Oct 29, 2020 at 5:52
  • ok. i will check in enterprise. Commented Oct 29, 2020 at 5:54
  • do we need to extend as like below mentioned? app/code/Vendor/Module/etc/adminhtmldi.xml <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool"> <arguments> <argument name="modifiers" xsi:type="array"> <item name="logotype" xsi:type="array"> <item name="class" xsi:type="string">vendor\Module\Ui\DataProvider\Product\Form\Modifier\Related</item> <item name="sortOrder" xsi:type="number">130</item> </item> </argument> </arguments> </virtualType> Commented Oct 29, 2020 at 6:31
  • i am not try using virtualtype.best way class override using preference. Commented Oct 29, 2020 at 6:44
  • okay, please check from your end and let me know what needs to be change in preference level. Thanks Commented Oct 29, 2020 at 7:19

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.