0

I have added custom code in m3\vendor\magento\module-wishlist\CustomerData\Wishlist.php, and called inside the app\design\frontend\zero\my_theme\Magento_Wishlist\templates\sidebar.phtml, for testing i am directly edited in core files, how to properly Override by using custom module?

1 Answer 1

0

This is going to be the best option for you.

app/code/Vendor/Wishlist/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">
    <type name="Magento\Wishlist\CustomerData\Wishlist">
        <plugin disabled="false" name="Vendor_Wishlist_Plugin_Magento_Wishlist_CustomerData_Wishlist" sortOrder="10" type="Vendor\Wishlist\Plugin\Magento\Wishlist\CustomerData\Wishlist"/>
    </type>
</config>

app/Vendor/Wishlist/Plugin/Magento/Wishlist/CustomerData/Wishlist

    <?php
/**
 * Copyright ©  All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Vendor\Wishlist\Plugin\Magento\Wishlist\CustomerData;


class Wishlist
{

    protected $wishlistHelper;

    public function __construct(
        \Magento\Wishlist\Helper\Data $wishlistHelper
    )
    {
        $this->wishlistHelper = $wishlistHelper;
    }


    public function afterGetSectionData(
        \Magento\Wishlist\CustomerData\Wishlist $subject,
        $result
    ) {

        // Your code here

        return $result;
    }
}
8
  • I am getting an error when i try to add the function: snipboard.io/XOK5Av.jpg inside the module.
    – zus
    Apr 9, 2021 at 14:50
  • I am trying to add the wholee function what i edit inside the C:\xampp\htdocs\m3\vendor\magento\module-wishlist\CustomerData\Wishlist.php
    – zus
    Apr 9, 2021 at 14:54
  • Well you don't add it inside a function you would add it after the afterGetSectionData function Apr 9, 2021 at 14:54
  • Also you cannot overwrite a protected function you would need to do you modifications in the afterGetSectionData function Apr 9, 2021 at 14:56
  • I am getting confused, 1) should i add the function which i edit in the core wishlist.php after the afterGetSectionData right? ( code : codeshare.io/anxjMV )
    – zus
    Apr 9, 2021 at 15:08

Your Answer

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

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