Skip to content

[Forwardport] Update shipment collection to unserialize packages attribute after load #18231

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

Merged
merged 1 commit into from
Oct 3, 2018
Merged

[Forwardport] Update shipment collection to unserialize packages attribute after load #18231

merged 1 commit into from
Oct 3, 2018

Conversation

mage2pratik
Copy link
Contributor

@mage2pratik mage2pratik commented Sep 25, 2018

Original Pull Request

#17679

Description

The column packages in sales_shipment is in its resource model \Magento\Sales\Model\ResourceModel\Order\Shipment characterized as a serializable field. But packages doesn't get unserialized when shipments are loaded with a collection. This pull request fixes the issue by unserializing the field after the collection is loaded.

Manual testing scenarios

  1. Create a shipment through the backend. packages is in my case set to [].
  2. Load this shipment with a collection. The attribute packages is a string, but should be an array.
class Shipment
{
    /**
     * @var \Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory
     */
    protected $shipmentCollectionFactory;

    /**
     * @var \Magento\Sales\Api\ShipmentRepositoryInterface
     */
    protected $shipmentRepository;

    public function __construct(
        \Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory $shipmentCollectionFactory,
        \Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepository
    ) {
        $this->shipmentCollectionFactory = $shipmentCollectionFactory;
        $this->shipmentRepository = $shipmentRepository;
    }

    public function execute()
    {
        /** @var \Magento\Sales\Model\Order\Shipment $shipment */
        $shipment = $this->shipmentRepository->get(1);
        echo gettype($shipment->getPackages()) . "\n";

        /** @var \Magento\Sales\Model\ResourceModel\Order\Shipment\Collection $shipmentCollection */
        $shipmentCollection = $this->shipmentCollectionFactory->create();
        $shipment = $shipmentCollection->addAttributeToFilter('entity_id', 1)
            ->getFirstItem();

        echo gettype($shipment->getPackages());
    }
}

In this example the same shipment is loaded with 1.) the shipment repository and 2.) the shipment collection. The output is:

array
string

This consequently causes further problems if the shipment loaded with the shipment collection is being updated, because packages gets saved as "[]" (the quotation marks are now a part of the string). packages now can't get unserialized when it's loaded with any method. Also an error is shown if this shipment is opened in the backend because an array is expected but a string is given:

Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /path/to/magento2/app/code/Magento/Shipping/view/adminhtml/templates/order/packaging/packed.phtml on line 12

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team magento-engcom-team added Partner: Krish TechnoLabs partners-contribution Pull Request is created by Magento Partner labels Sep 25, 2018
@magento-engcom-team
Copy link
Contributor

Hi @mage2pratik. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me $VERSION instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-3042 has been created to process this Pull Request

@magento-engcom-team magento-engcom-team merged commit fe27066 into magento:2.3-develop Oct 3, 2018
magento-engcom-team pushed a commit that referenced this pull request Oct 3, 2018
@magento-engcom-team
Copy link
Contributor

Hi @mage2pratik. Thank you for your contribution.
We will aim to release these changes as part of 2.3.1.
Please check the release notes for final confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants