1

I'm trying to create a plugin for DirectoryDataProcessor.php but I can't seem to get the di.xml to work. The LayoutProcessor in di.xml works.

I get the following error:

Plugin class BB\Checkout\Plugin\Block\DirectoryDataProcessorPlugin doesn't exist.

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\Checkout\Block\Checkout\LayoutProcessor">
    <plugin name="bb_checkout" type="BB\Checkout\Plugin\Block\LayoutProcessor" sortOrder="1"/>
 </type>

<type name="Magento\Checkout\Block\Checkout\DirectoryDataProcessor">
    <plugin name='bb_checkout_req' 
 type='BB\Checkout\Plugin\Block\DirectoryDataProcessorPlugin' 
 sortOrder='99'/>
</type>

/BB/Checkout/Plugin/Block/DirectoryDataProcessorPlugin.php

<?php

 namespace BB\Checkout\Plugin\Block\Checkout;

 class DirectoryDataProcessorPlugin
 {
/**
 * @param \Magento\Checkout\Block\Checkout\DirectoryDataProcessor $subject
 * @param array $jsLayout
 * @return array
 */
public function afterProcess(
    \Magento\Checkout\Block\Checkout\DirectoryDataProcessor $subject,
    array  $jsLayout
) {

    return $jsLayout;
}
}

I tried changing the name and folder structure many times and have no clue on how to fix this. I just started working with Magento 2.

I also tried putting DirectoryDataProcessorPlugin in plugin/block instead of plugin/block/checkout.

2

You are misplacing your file

In di.xml you have defined

type='BB\Checkout\Plugin\Block\DirectoryDataProcessorPlugin'

where as you have shown the directory path of your file as

/BB/Checkout/Plugin/Block/Checkout/DirectoryDataProcessorPlugin.php

Move your file out of Checkout directory and check.

  • You're right but sadly that doesn't fix the error :( – Sanne Apr 17 '18 at 9:46
  • 1
    You also need to change the namespace inside your plugin file. namespace BB\Checkout\Plugin\Block; – Priyank Apr 17 '18 at 9:49
  • Ah that was it Priyank! Thanks changed the namespace to namespace BigBridge\Checkout\Plugin\Block; and now it works. – Sanne Apr 17 '18 at 9:52
0

Replace your etc/di.xml code with following 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\Checkout\Block\Checkout\LayoutProcessor">
    <plugin name="bb_checkout" type="BB\Checkout\Plugin\Block\LayoutProcessor" sortOrder="1"/>
 </type>

<type name="Magento\Checkout\Block\Checkout\DirectoryDataProcessor">
    <plugin name='bb_checkout_req' 
 type='BB\Checkout\Plugin\Block\Checkout\DirectoryDataProcessorPlugin' 
 sortOrder='99'/>
</type>

You missed Checkout on above XML it should be like BB\Checkout\Plugin\Block\Checkout\DirectoryDataProcessorPlugin.

After replacing with above code if it's still not working that I'll suggest you to check the file permission.

Hope it'll help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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