Description
Preconditions
Magento 2.2.2 but also 2.2.1
Steps to reproduce
This code is used by an external extension, but this should just work.
See also: magmodules/magento2-channable#28
But this is actually not the extensions bug, it is a bug in Magento 2.2 code.
See below my explanation.
I have no idea where else this is used in Magento, but if it is, there should be also an error visible.
Expected result
Dropdown box with all carriers, active and inactive.
Actual result
1 exception(s):
Exception #0 (Exception): Notice: Array to string conversion in vendor/magento/module-shipping/Model/Config/Source/Allmethods.php on line 61
Exception #0 (Exception): Notice: Array to string conversion in vendor/magento/module-shipping/Model/Config/Source/Allmethods.php on line 61
#0 vendor/magento/module-shipping/Model/Config/Source/Allmethods.php(61): Magento\Framework\App\ErrorHandler->handler(8, 'Array to string...', '/Users/jw/Proje...', 61, Array)
#1 vendor/magento/module-config/Model/Config/Structure/Element/Field.php(458): Magento\Shipping\Model\Config\Source\Allmethods->toOptionArray(false)
#2 vendor/magento/module-config/Model/Config/Structure/Element/Field.php(376): Magento\Config\Model\Config\Structure\Element\Field->_getOptionsFromSourceModel(Object(Magento\Shipping\Model\Config\Source\Allmethods))
Looking into this Magento code on this line:
'label' => '[' . $carrierCode . '] ' . $methodTitle,
At the $carrierCode = 'usps', I get an array returned.
This results in the error above.
So a simple quick fix is to change:
$methods[$carrierCode]['value'][] = [
'value' => $carrierCode . '_' . $methodCode,
'label' => '[' . $carrierCode . '] ' . $methodTitle,
];
into:
if(!is_array($methodTitle))
$methods[$carrierCode]['value'][] = [
'value' => $carrierCode . '_' . $methodCode,
'label' => '[' . $carrierCode . '] ' . $methodTitle,
];
But this is not the complete correct solution, but it makes my page working.
UPD from @joni-jones
To reproduce this issue you need to manually insert carries/usps/allowed_methods
NULL
into core_config_data
table and call \Magento\Shipping\Model\Config\Source\Allmethods::toOptionArray
method.
The issue not in the \Magento\Shipping\Model\Config\Source\Allmethods::toOptionArray
but how \Magento\Usps\Model\Carrier::getAllowedMethods
(and other similar methods) processes invalid configuration.