0

I am trying to create after plugin for Magento\Framework\DataObject.php getData function but it seems not working also not getting sku value in it.

Please suggest

1 Answer 1

0
  1. Create a di.xml file in Vendor/Module/etc directory to configure the plugin and add the below code.

    <?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\Framework\DataObject">
     <plugin name="custom_dataobject_plugin" type="MageINIC\BundleSelectionImage\Plugin\DataObjectPlugin"
             sortOrder="10" disabled="false"/>
      </type>
    </config>
    
  2. Create a DataObjectPlugin.php file in Vendor/Module/Plugin directory and add the below code.

    <?php
    namespace Vendor\Module\Plugin;
    
    class DataObjectPlugin
    {
       public function afterGetData(\Magento\Framework\DataObject $subject, $result)
       {
         // Perform your custom logic here
    
         return $result;
       }
    }
    
  3. Run the below commands and check.
    php bin/magento s:d:c

I am trying to create after plugin for Magento\Framework\DataObject.php getData function in my local setup it working properly.

Please let me know still if you get issue.

5
  • Plugin i have created successfully but not getting sku value in plugin only sku key is coming. May 8, 2023 at 11:00
  • please share you code here May 8, 2023 at 11:11
  • namespace Vendor\Module\Plugin; class DataObjectPlugin { public function afterGetData(\Magento\Framework\DataObject $subject, $result) { print_r($result['sku']);die; return $result; } } May 8, 2023 at 11:23
  • Need to get sku value here May 8, 2023 at 11:23
  • please try this if (isset($result['sku'])) { $sku = $result['sku']; print_r($sku);exit; } May 8, 2023 at 11:42

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.