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

The magic money tree problem

What are these boxed doors outside store fronts in New York?

What do you call a Matrix-like slowdown and camera movement effect?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

My colleague's body is amazing

How can bays and straits be determined in a procedurally generated map?

Is there really no realistic way for a skeleton monster to move around without magic?

What Brexit solution does the DUP want?

I probably found a bug with the sudo apt install function

Simulate Bitwise Cyclic Tag

What defenses are there against being summoned by the Gate spell?

Can you lasso down a wizard who is using the Levitate spell?

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

What is the command to reset a PC without deleting any files

Why is an old chain unsafe?

Should I join an office cleaning event for free?

Non-Jewish family in an Orthodox Jewish Wedding

What typically incentivizes a professor to change jobs to a lower ranking university?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Example of a relative pronoun

The use of multiple foreign keys on same column in SQL Server

How old can references or sources in a thesis be?

How do I create uniquely male characters?



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)

if (!$orderItem->getQtyToShip()

$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
    Apr 4 at 15:48












  • I am using it in controller

    – Asim Ali
    Apr 4 at 16:06

















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)

if (!$orderItem->getQtyToShip()

$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
    Apr 4 at 15:48












  • I am using it in controller

    – Asim Ali
    Apr 4 at 16:06













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)

if (!$orderItem->getQtyToShip()

$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)

if (!$orderItem->getQtyToShip()

$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 Apr 4 at 15:39









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
    Apr 4 at 15:48












  • I am using it in controller

    – Asim Ali
    Apr 4 at 16:06

















  • 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
    Apr 4 at 15:48












  • I am using it in controller

    – Asim Ali
    Apr 4 at 16:06
















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
Apr 4 at 15:48






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
Apr 4 at 15:48














I am using it in controller

– Asim Ali
Apr 4 at 16:06





I am using it in controller

– Asim Ali
Apr 4 at 16:06










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)

if (! $orderItem->getQtyToShip()

$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
    Apr 4 at 16:06











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    Apr 4 at 16:36











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)

if (! $orderItem->getQtyToShip()

$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
    Apr 4 at 16:06











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    Apr 4 at 16:36















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)

if (! $orderItem->getQtyToShip()

$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
    Apr 4 at 16:06











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    Apr 4 at 16:36













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)

if (! $orderItem->getQtyToShip()

$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)

if (! $orderItem->getQtyToShip()

$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 Apr 4 at 15:49









Ronak RathodRonak Rathod

1,125213




1,125213












  • Thanks Ronak Rathod, will try this

    – Asim Ali
    Apr 4 at 16:06











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    Apr 4 at 16:36

















  • Thanks Ronak Rathod, will try this

    – Asim Ali
    Apr 4 at 16:06











  • Working Or Not ??? Most Welcome

    – Ronak Rathod
    Apr 4 at 16:36
















Thanks Ronak Rathod, will try this

– Asim Ali
Apr 4 at 16:06





Thanks Ronak Rathod, will try this

– Asim Ali
Apr 4 at 16:06













Working Or Not ??? Most Welcome

– Ronak Rathod
Apr 4 at 16:36





Working Or Not ??? Most Welcome

– Ronak Rathod
Apr 4 at 16:36

















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

Sum ergo cogito? 1 nng

419 nièngy_Soadمي 19bal1.5o_g

Queiggey Chernihivv 9NnOo i Zw X QqKk LpB