-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in vendor/magento/module-shipping/Model/Config/Source/Allmethods.php - public function toOptionArray #13136
Comments
To make it more complete.. Line 1148: public function getAllowedMethods() You see that the return of this function is an array. So the error is a logical result. |
Hi, @Tantuss, did you get the same error on the fresh installation of Magento without extensions? I've checked described case and I didn't get any errors. According to a described example with
So, $methodTitle is a string, not an array. |
Of course I do not try it on a fresh installation without any configurations. Set in the core_config_data table the path: (so basically nothing selected) Then you get back the array at the wrong variable. So probably the mistake is in the USPS extension. So here: |
It helps to understand if extensions could be a reason for this issue.
This behavior doesn't seem correct because you don't have a possibility to don't select at least one allowed method, also, by default, the So, the described case is artificial it might happen only if you manually set invalid data into the database. But agree, the code should validate such behavior. |
It might be possible in Magento 1 and it might be there because of migration from Magento 1 to 2. |
It might seem not correct, but it is definitely possible to do it from the user interface. Just set 1 as active, saved, checked db and it was there. Then unselected that 1 and there was again NULL in the database. So it is not only related to migration, it is also just easy possible from the UI. |
I have same error. Magento 2.2.2, IWD_Opc Extension, Migration from M1 to M2. To figure out the problem i've changed code of
possible fix is to check if the method is active or not, directly in the module. |
@Tantuss, thank you for your report. |
Hi @diazwatson. Thank you for working on this issue.
|
Hi @oroskodias. Thank you for working on this issue.
|
@magento-engcom-team give me 2.3-develop instance |
Hi @oroskodias. Thank you for your request. I'm working on Magento 2.3-develop instance for you |
Hi @oroskodias, here is your Magento instance. |
Hi @mrodespin. Thank you for working on this issue.
|
Hi @Tantuss. Thank you for your report.
The fix will be available with the upcoming 2.4.0 release. |
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
intocore_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.The text was updated successfully, but these errors were encountered: