Skip to content

Error in vendor/magento/module-shipping/Model/Config/Source/Allmethods.php - public function toOptionArray #13136

Closed
@Tantuss

Description

@Tantuss

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.

Metadata

Metadata

Assignees

Labels

Component: ShippingFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions