Magento 2.0.7 - /sales/order/reorder Fatal Error
Steps to reproduce:
- Customer logs in, clicks on "Reorder" to re-order previous order.
- Returns with the following Fatal Error:
Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Framework\DataObject::__construct() must be of the type array, null given, called in /var/www/html/magento2/vendor/magento/module-checkout/Model/Cart.php on line 264 and defined in /var/www/html/magento2/vendor/magento/framework/DataObject.php:38 Stack trace: #0 /var/www/html/magento2/vendor/magento/module-checkout/Model/Cart.php(264): Magento\Framework\DataObject->__construct(NULL) #1 /var/www/html/magento2/var/generation/Magento/Checkout/Model/Cart/Interceptor.php(102): Magento\Checkout\Model\Cart->addOrderItem(Object(Magento\Sales\Model\Order\Item), NULL) #2 /var/www/html/magento2/vendor/magento/module-sales/Controller/AbstractController/Reorder.php(59): Magento\Checkout\Model\Cart\Interceptor->addOrderItem(Object(Magento\Sales\Model\Order\Item)) #3 /var/www/html/magento2/var/generation/Magento/Sales/Controller/Order/Reorder/Interceptor.php(24): Magento\Sales\Controller\AbstractController\Reorder->execute() #4 /var/www/html/magento2/vendor/magento/framework/ in /var/www/html/magento2/vendor/magento/framework/DataObject.php on line 38
System:
Magento 2.0.7 Ubuntu 14.04 LTS Apache 2.4.7 PHP 7.0.7-2+donate.sury.org~trusty+1 MySQL 5.6.30 Default mode.
Hi @longbeachjamie , thank you for reporting this issue. Pull request was already created with fix of this bug #4730. There are some problems with builds. Fix will be merged when builds are green.
What is the status of this? Is it part of the 2.0.8 release?
I'm interested too, hoping we don't need to update to 2.1
I think I should provide some updates as I have been able to find a work around, pending when the fix is merged into master and released.
Using Magento 2's dependency injection system, you can create a module that changes the preference for this class: Magento\Sales\Model\Order\Item to a class that extends Magento\Sales\Model\Order\Item.
An example di.xml file is this:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Model\Order\Item" type="Gloo\Sales\Model\Order\Item"/>
</config>
For mine, this is the file path I used: ModuleFolder/etc/frontend/di.xml.
Then within that class, you override the getProductOptionByCode method as mentioned by @NadiyaS above.
public function getProductOptionByCode($code = null)
{
$options = $this->getProductOptions();
if ($code === null) {
return $options;
}
if (isset($options[$code])) {
return $options[$code];
}
return [];
}
A better approach may be to use Magento 2's plugin system to change the return type.
Internal ticket MAGETWO-53595
We faced this issue after upgrade to M2.2.2. So we modified below lines in getProductOptions function. Now it is working fine. vendor/magento/module-sales/Model/Order/Item.php - if (is_string($data)) { - $data = $this->serializer->unserialize($data); - }
+ if (is_string($data['info_buyRequest'])) {
+ $data['info_buyRequest'] = unserialize($data['info_buyRequest']);
+ }