Magento2: Serializable fields not unserialized when getting model from collection

Created on 28 Jul 2016  路  5Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.0.8
  2. MariaDB 10.0.24 & PHP 5.6.20

    Steps to reproduce

  3. Create an order (any way you want)

  4. Create a credit memo for that order
  5. Check DB for serialized field product_options in table sales_order_item

    Expected result

  6. Field product_options of the Magento\Sales\Model\Order\Item model should be unserialized on collection load (before it's serialized again when saving the model)

    Actual result

  7. Field product_options is re-serialized as string (see screenshot below)

screen_db_product_options

As you can see in the screenshot some of the item's product_options field is re-serialized into a string when the item is loaded through the collection and not through the model.

This happens every time I interact on an order after creation (credit memo, cancel, etc...).
I've noticed this after getting error when using $item->getBuyRequest().
After investigating I've noticed the items were loaded through the collection therefore not going through the $this->unserializeFields($object); from the ResourceModel's load function.
When creating the credit memo, it goes through the order's item to set the amount refunded and saves the item.
The save function of the ResourceModel automatically serialize the $_serializableFields creating this thousand character long entry as shown in the screenshot above.

Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

Hello,
Since the format of the product options have been changed (serialized to json) it would be great if you could think about this bug in the conversion script Magento\Sales\Setup\SerializedDataConverter::convert($value).

When I upgraded to Magento 2.2, the convertion from serialized to json went ok except for those doubly serialized entries. In those cases, the JSON object had a single string of PHP serialized data :/

Regards,

All 5 comments

Hi @LTC-fperrin!
In Magento 2 we created service layer for the most common entities. We imply you use repositories to work with products, attributes, orders, invoices, etc. You may find repositories and data models in "Api" folder of each module.
To check OrderItemRepositoryInterface works properly i sent GET request to /rest/V1/orders/items?searchCriteria[filter_groups][0][filters][0][field]=order_id& searchCriteria[filter_groups][0][filters][0][value]=4 where 4 is my order id. This request returned unserialized product options:
<product_option> <extension_attributes> <configurable_item_options> <item> <option_id>135</option_id> <option_value>4</option_value> </item> <item> <option_id>136</option_id> <option_value>6</option_value> </item> </configurable_item_options> </extension_attributes> </product_option>

Nevertheless the behavior you described is a bug. We created internal issue MAGETWO-58305. Thank you for reporting.

@LTC-fperrin, thank you for your report.
We've created internal ticket(s) MAGETWO-58305 to track progress on the issue.

Hello,
Since the format of the product options have been changed (serialized to json) it would be great if you could think about this bug in the conversion script Magento\Sales\Setup\SerializedDataConverter::convert($value).

When I upgraded to Magento 2.2, the convertion from serialized to json went ok except for those doubly serialized entries. In those cases, the JSON object had a single string of PHP serialized data :/

Regards,

The issue had been fixed in 2.2.2

Was this page helpful?
0 / 5 - 0 ratings