Error “Cannot read property 'indexedOptions' ” when removing Company field (Remove checkout field)
题
I need to remove Company field from checkout page. I am trying to follow this tutorials "Remove a component". But I am getting next Error:
Uncaught TypeError: Cannot read property 'indexedOptions' of undefined(…) region.js:59
My Plugins file is:
public function aroundProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, \Closure $proceed, $jsLayout) {
unset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['company']);
return $jsLayout;
}
Can anyone explain me please what i am doing wrong?
解决方案
I found the solution in this page https://github.com/magento/magento2/issues/4425
And the working code is:
public function aroundProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, \Closure $proceed, $jsLayout) {
$ret = $proceed($jsLayout);
unset($ret['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['company']);
return $ret;
}
From this plugin documentation I found also the problem: "It is also worth noting that you are responsible for forwarding the arguments from the plugin to the proceed callable." I add the the plugin function signature from @Aaron Allen answer to my previous post so it would be more clearer to anyone who would be needing it.
function aroundMethod ($subject, \Closure $proceed, $arg1, $arg2, etc...)