Error in “Remove a component” plugin tutorial
Domanda
I am trying to follow this tutorials "Remove a component" But getting next Error:
"Uncaught Error: Cannot use object of type Magento\Checkout\Block\Checkout\LayoutProcessor\Interceptor as array in".
The plugins code is:
class removeCheckoutComponent {
public function aroundProcess($jsLayout) {
unset($jsLayout['components']['checkout']['children']['steps']['%path_to_target_node%']);
return $jsLayout;
}
}
Why it is not working? The end result I am trying to achieve is to remove city selection from checkout page.
Soluzione
The problem is you're not use the correct signature. Around plugins follow this signature:
function aroundMethod ($subject, \Closure $proceed, $arg1, $arg2, etc...)
Where $subject
is the instance of the class whose method is being intercepted, $proceed
is a delegate for the method, and then the arguments to the method call follow.
For your use case, you should have:
function aroundProcess (\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, \Closure $proceed, $jsLayout)
{
unset($jsLayout['components']['checkout']['children']['steps']['%path_to_target_node%']);
return $proceed($jsLayout);
}
More info here: http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange