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

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

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?