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?

asked Apr 9, 2021 at 14:04

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;
 }
}
answered Apr 9, 2021 at 14:31
8
  • I am getting an error when i try to add the function: snipboard.io/XOK5Av.jpg inside the module. Commented 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 Commented Apr 9, 2021 at 14:54
  • Well you don't add it inside a function you would add it after the afterGetSectionData function Commented Apr 9, 2021 at 14:54
  • Also you cannot overwrite a protected function you would need to do you modifications in the afterGetSectionData function Commented 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 ) Commented Apr 9, 2021 at 15:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.