Create shipment programmatically and facing errorGenerate invoice automatically when I create shipment?How to create a shipment pdf programmatically?Unable to create shipment programmaticallyShipment create not working programmaticallyMagento 2 : extensionpool, read handlers and save handlersWarning: Invalid argument supplied for foreach() when viewing shipmentmagento 2 cannot do shipment for the order 404Get Shipment Id while creating Shipment in Magento 1.9Magento 2 - How to create item wise shipment And add tracking number programmaticallyShipment view page 404 error

Was any UN Security Council vote triple-vetoed?

Arrow those variables!

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Is it legal for company to use my work email to pretend I still work there?

Replacing matching entries in one column of a file by another column from a different file

Rock identification in KY

Is it possible to do 50 km distance without any previous training?

How much RAM could one put in a typical 80386 setup?

Modeling an IP Address

What does "Puller Prush Person" mean?

Convert two switches to a dual stack, and add outlet - possible here?

What's the point of deactivating Num Lock on login screens?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Can a Cauchy sequence converge for one metric while not converging for another?

How do I deal with an unproductive colleague in a small company?

Perform and show arithmetic with LuaLaTeX

Intersection point of 2 lines defined by 2 points each

A case of the sniffles

Why can't we play rap on piano?

Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?

dbcc cleantable batch size explanation

How old can references or sources in a thesis be?

How much of data wrangling is a data scientist's job?

Why doesn't H₄O²⁺ exist?



Create shipment programmatically and facing error


Generate invoice automatically when I create shipment?How to create a shipment pdf programmatically?Unable to create shipment programmaticallyShipment create not working programmaticallyMagento 2 : extensionpool, read handlers and save handlersWarning: Invalid argument supplied for foreach() when viewing shipmentmagento 2 cannot do shipment for the order 404Get Shipment Id while creating Shipment in Magento 1.9Magento 2 - How to create item wise shipment And add tracking number programmaticallyShipment view page 404 error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am trying to create shipment programmatically. Following a tutorial, but facing error on save shipment.



Here is the code that I am using:



$orderId = 100002156;
$order = $this->_orderRepository->get($orderId);

if (!$order->canShip())
echo "Can't Ship";
die;


$orderShipment = $this->_convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;


$qty = $orderItem->getQtyToShip();
$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qty);

$orderShipment->addItem($shipmentItem);


$orderShipment->register();
$orderShipment->getOrder()->setIsInProcess(true);

$this->save();
$this->getOrder()->save();


Can anyone tell what is the issue?










share|improve this question






















  • what is the context of your code, in what class do you use this code? And what is the error on which save ($this->save() whatever object $this is or $this->getOrder()->save();?

    – HelgeB
    yesterday












  • I am using it in controller

    – Asim Ali
    yesterday

















1















I am trying to create shipment programmatically. Following a tutorial, but facing error on save shipment.



Here is the code that I am using:



$orderId = 100002156;
$order = $this->_orderRepository->get($orderId);

if (!$order->canShip())
echo "Can't Ship";
die;


$orderShipment = $this->_convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;


$qty = $orderItem->getQtyToShip();
$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qty);

$orderShipment->addItem($shipmentItem);


$orderShipment->register();
$orderShipment->getOrder()->setIsInProcess(true);

$this->save();
$this->getOrder()->save();


Can anyone tell what is the issue?










share|improve this question






















  • what is the context of your code, in what class do you use this code? And what is the error on which save ($this->save() whatever object $this is or $this->getOrder()->save();?

    – HelgeB
    yesterday












  • I am using it in controller

    – Asim Ali
    yesterday













1












1








1








I am trying to create shipment programmatically. Following a tutorial, but facing error on save shipment.



Here is the code that I am using:



$orderId = 100002156;
$order = $this->_orderRepository->get($orderId);

if (!$order->canShip())
echo "Can't Ship";
die;


$orderShipment = $this->_convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;


$qty = $orderItem->getQtyToShip();
$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qty);

$orderShipment->addItem($shipmentItem);


$orderShipment->register();
$orderShipment->getOrder()->setIsInProcess(true);

$this->save();
$this->getOrder()->save();


Can anyone tell what is the issue?










share|improve this question














I am trying to create shipment programmatically. Following a tutorial, but facing error on save shipment.



Here is the code that I am using:



$orderId = 100002156;
$order = $this->_orderRepository->get($orderId);

if (!$order->canShip())
echo "Can't Ship";
die;


$orderShipment = $this->_convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;


$qty = $orderItem->getQtyToShip();
$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qty);

$orderShipment->addItem($shipmentItem);


$orderShipment->register();
$orderShipment->getOrder()->setIsInProcess(true);

$this->save();
$this->getOrder()->save();


Can anyone tell what is the issue?







magento2 shipment






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Asim AliAsim Ali

8211




8211












  • what is the context of your code, in what class do you use this code? And what is the error on which save ($this->save() whatever object $this is or $this->getOrder()->save();?

    – HelgeB
    yesterday












  • I am using it in controller

    – Asim Ali
    yesterday

















  • what is the context of your code, in what class do you use this code? And what is the error on which save ($this->save() whatever object $this is or $this->getOrder()->save();?

    – HelgeB
    yesterday












  • I am using it in controller

    – Asim Ali
    yesterday
















what is the context of your code, in what class do you use this code? And what is the error on which save ($this->save() whatever object $this is or $this->getOrder()->save();?

– HelgeB
yesterday






what is the context of your code, in what class do you use this code? And what is the error on which save ($this->save() whatever object $this is or $this->getOrder()->save();?

– HelgeB
yesterday














I am using it in controller

– Asim Ali
yesterday





I am using it in controller

– Asim Ali
yesterday










1 Answer
1






active

oldest

votes


















0














Try This :-



$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orderInterface = $objectManager->get('MagentoSalesApiDataOrderInterface');



$incrementId = "000000165"; //Increment Id
$order = $objectManager->create('MagentoSalesModelOrder')
->loadByAttribute('increment_id', $incrementId);

if ($order->canShip())

$convertOrder = $objectManager->create('MagentoSalesModelConvertOrder');
$shipment = $convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;

$qtyShipped = $orderItem->getQtyToShip();

$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);

$shipment->addItem($shipmentItem);


$shipment->register();
$shipment->getOrder()->setIsInProcess(true);

try
// Save created shipment and order
$shipment->save();
$shipment->getOrder()->save();
catch (Exception $e)
echo "Shipment Not Created". $e->getMessage(); exit;


echo "Shipment Succesfully Generated for order: #".$incrementId;
else
echo "Shipment Not Created Becuase It's already created or something went wrong";






share|improve this answer























  • Thanks Ronak Rathod, will try this

    – Asim Ali
    yesterday











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    yesterday











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268820%2fcreate-shipment-programmatically-and-facing-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try This :-



$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orderInterface = $objectManager->get('MagentoSalesApiDataOrderInterface');



$incrementId = "000000165"; //Increment Id
$order = $objectManager->create('MagentoSalesModelOrder')
->loadByAttribute('increment_id', $incrementId);

if ($order->canShip())

$convertOrder = $objectManager->create('MagentoSalesModelConvertOrder');
$shipment = $convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;

$qtyShipped = $orderItem->getQtyToShip();

$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);

$shipment->addItem($shipmentItem);


$shipment->register();
$shipment->getOrder()->setIsInProcess(true);

try
// Save created shipment and order
$shipment->save();
$shipment->getOrder()->save();
catch (Exception $e)
echo "Shipment Not Created". $e->getMessage(); exit;


echo "Shipment Succesfully Generated for order: #".$incrementId;
else
echo "Shipment Not Created Becuase It's already created or something went wrong";






share|improve this answer























  • Thanks Ronak Rathod, will try this

    – Asim Ali
    yesterday











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    yesterday















0














Try This :-



$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orderInterface = $objectManager->get('MagentoSalesApiDataOrderInterface');



$incrementId = "000000165"; //Increment Id
$order = $objectManager->create('MagentoSalesModelOrder')
->loadByAttribute('increment_id', $incrementId);

if ($order->canShip())

$convertOrder = $objectManager->create('MagentoSalesModelConvertOrder');
$shipment = $convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;

$qtyShipped = $orderItem->getQtyToShip();

$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);

$shipment->addItem($shipmentItem);


$shipment->register();
$shipment->getOrder()->setIsInProcess(true);

try
// Save created shipment and order
$shipment->save();
$shipment->getOrder()->save();
catch (Exception $e)
echo "Shipment Not Created". $e->getMessage(); exit;


echo "Shipment Succesfully Generated for order: #".$incrementId;
else
echo "Shipment Not Created Becuase It's already created or something went wrong";






share|improve this answer























  • Thanks Ronak Rathod, will try this

    – Asim Ali
    yesterday











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    yesterday













0












0








0







Try This :-



$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orderInterface = $objectManager->get('MagentoSalesApiDataOrderInterface');



$incrementId = "000000165"; //Increment Id
$order = $objectManager->create('MagentoSalesModelOrder')
->loadByAttribute('increment_id', $incrementId);

if ($order->canShip())

$convertOrder = $objectManager->create('MagentoSalesModelConvertOrder');
$shipment = $convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;

$qtyShipped = $orderItem->getQtyToShip();

$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);

$shipment->addItem($shipmentItem);


$shipment->register();
$shipment->getOrder()->setIsInProcess(true);

try
// Save created shipment and order
$shipment->save();
$shipment->getOrder()->save();
catch (Exception $e)
echo "Shipment Not Created". $e->getMessage(); exit;


echo "Shipment Succesfully Generated for order: #".$incrementId;
else
echo "Shipment Not Created Becuase It's already created or something went wrong";






share|improve this answer













Try This :-



$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orderInterface = $objectManager->get('MagentoSalesApiDataOrderInterface');



$incrementId = "000000165"; //Increment Id
$order = $objectManager->create('MagentoSalesModelOrder')
->loadByAttribute('increment_id', $incrementId);

if ($order->canShip())

$convertOrder = $objectManager->create('MagentoSalesModelConvertOrder');
$shipment = $convertOrder->toShipment($order);

foreach ($order->getAllItems() AS $orderItem) $orderItem->getIsVirtual())
continue;

$qtyShipped = $orderItem->getQtyToShip();

$shipmentItem = $convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);

$shipment->addItem($shipmentItem);


$shipment->register();
$shipment->getOrder()->setIsInProcess(true);

try
// Save created shipment and order
$shipment->save();
$shipment->getOrder()->save();
catch (Exception $e)
echo "Shipment Not Created". $e->getMessage(); exit;


echo "Shipment Succesfully Generated for order: #".$incrementId;
else
echo "Shipment Not Created Becuase It's already created or something went wrong";







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Ronak RathodRonak Rathod

1,097213




1,097213












  • Thanks Ronak Rathod, will try this

    – Asim Ali
    yesterday











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    yesterday

















  • Thanks Ronak Rathod, will try this

    – Asim Ali
    yesterday











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    yesterday
















Thanks Ronak Rathod, will try this

– Asim Ali
yesterday





Thanks Ronak Rathod, will try this

– Asim Ali
yesterday













Working Or Not ??? Most Welcome

– Ronak Rathod
yesterday





Working Or Not ??? Most Welcome

– Ronak Rathod
yesterday

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268820%2fcreate-shipment-programmatically-and-facing-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form