I am using 'Dirty Playground' for external retrieve/update Magento products & order information. It's working fine.
Now, I am trying to update shipment from the same concept, but not able to achieve. It is showing a blank page.
I had tried updating shipment by programmatic, it's also working fine in Magento frontend.

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/../shoppersbay/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');

    // Load the order static ID for testing 
    $order = $obj->create('Magento\Sales\Model\Order')
        ->loadByAttribute('increment_id', '000000040');
// Check if order can be shipped or has already shipped
        if (! $order->canShip()) {
            throw new \Magento\Framework\Exception\LocalizedException(
                            __('You can\'t create an shipment.')

        // Initialize the order shipment object
    $convertOrder = $obj->create('Magento\Sales\Model\Convert\Order');
    $shipment = $convertOrder->toShipment($order);

    // Loop through order items
    foreach ($order->getAllItems() AS $orderItem) {
        // Check if order item has qty to ship or is virtual
        if (! $orderItem->getQtyToShip() || $orderItem->getIsVirtual()) {

        $qtyShipped = $orderItem->getQtyToShip();

        // Create shipment item with qty
        $shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);

        // Add shipment item to shipment

    // Register shipment


    try {
        // Save created shipment and order

        // Send email

    } catch (\Exception $e) {
        throw new \Magento\Framework\Exception\LocalizedException(

How can I achieve this? Am I missing something in the code?

Thanks in Advance.

1 Answer 1


Finally, We achieve this by below changes. I am using for getting order details. As per "dirty playground" ObjectManager has been already created, so we can't create again.

$order = $obj->create('Magento\Sales\Model\Order') ->loadByAttribute('increment_id', '000000040');

$order = $obj->get('Magento\Sales\Model\Order')

I replace all $obj->get with $obj->create, now it's working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.