Magento2 Reorder using REST ApiMagento reorder misbehaveBest practice for returning errors in WebApiPerform reorder in magento 2 REST APIConvert MagentoQuoteModelQuote to MagentoSalesModelOrder: Magento 2Customize Reorder function Magento2Order is not create Magento 2 Rest APIMagento2 currency switcher using rest APIHow can i cancel an order of a customer and reorder in Magento2 using REST APIMagento2 need to throw 500 internal server error in webapi responseMagento2 remove columns from admin sales order view page items grid

How does noise-cancellation work in Mac laptops?

Do atomic orbitals "pulse" in time?

As programers say: Strive to be lazy

Make all the squares explode

Extrude the faces of a cube symmetrically along XYZ

What does i386 mean on macOS Mojave?

Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?

Why is this int array not passed as an object vararg array?

What is the best way for a skeleton to impersonate human without using magic?

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

Reaction of borax with NaOH

What food production methods would allow a metropolis like New York to become self sufficient

What does the expression "right on the tip of my tongue" mean?

What is the relation between semi-supervised self-supervised visual representation learning?

Exclude loop* snap devices from lsblk output?

Size of a folder with du

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?

What does "Ich wusste, dass aus dir mal was wird" mean?

How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?

Early arrival in Australia, early hotel check in not available

How to minimise the cost of guessing a number in a high/low guess game?

Can a tourist shoot a gun in the USA?

When a land becomes a creature, is it untapped?

Was this character’s old age look CGI or make-up?



Magento2 Reorder using REST Api


Magento reorder misbehaveBest practice for returning errors in WebApiPerform reorder in magento 2 REST APIConvert MagentoQuoteModelQuote to MagentoSalesModelOrder: Magento 2Customize Reorder function Magento2Order is not create Magento 2 Rest APIMagento2 currency switcher using rest APIHow can i cancel an order of a customer and reorder in Magento2 using REST APIMagento2 need to throw 500 internal server error in webapi responseMagento2 remove columns from admin sales order view page items grid






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








0















Can anyone let me know if we can Reorder in Magento2 using REST webapi? Actually i have made one api and used same code as magento default reorder does, here is my code in API function using order_id as parameter:



public function reOrder($orderId)

$order = $this->orderApiRepository->get($orderId);
$cart = $this->cart;
$items = $order->getItemsCollection();
foreach ($items as $item)
try
$cart->addOrderItem($item);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(__($e->getMessage()), $e);





The issue is when i am checking response in postman, it returns null instead cart data, please let me know if anyone has done same type of things. please check below screenshot of POSTMAN api:



POSTMAN API










share|improve this question






















  • Got any solution ?

    – Yann Martel
    Jan 2 at 10:43











  • have you got solution for this

    – Adarsh Shukla
    Feb 19 at 11:51











  • Nope didn't get any solution on it

    – bhargav shastri
    Feb 19 at 13:06

















0















Can anyone let me know if we can Reorder in Magento2 using REST webapi? Actually i have made one api and used same code as magento default reorder does, here is my code in API function using order_id as parameter:



public function reOrder($orderId)

$order = $this->orderApiRepository->get($orderId);
$cart = $this->cart;
$items = $order->getItemsCollection();
foreach ($items as $item)
try
$cart->addOrderItem($item);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(__($e->getMessage()), $e);





The issue is when i am checking response in postman, it returns null instead cart data, please let me know if anyone has done same type of things. please check below screenshot of POSTMAN api:



POSTMAN API










share|improve this question






















  • Got any solution ?

    – Yann Martel
    Jan 2 at 10:43











  • have you got solution for this

    – Adarsh Shukla
    Feb 19 at 11:51











  • Nope didn't get any solution on it

    – bhargav shastri
    Feb 19 at 13:06













0












0








0








Can anyone let me know if we can Reorder in Magento2 using REST webapi? Actually i have made one api and used same code as magento default reorder does, here is my code in API function using order_id as parameter:



public function reOrder($orderId)

$order = $this->orderApiRepository->get($orderId);
$cart = $this->cart;
$items = $order->getItemsCollection();
foreach ($items as $item)
try
$cart->addOrderItem($item);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(__($e->getMessage()), $e);





The issue is when i am checking response in postman, it returns null instead cart data, please let me know if anyone has done same type of things. please check below screenshot of POSTMAN api:



POSTMAN API










share|improve this question














Can anyone let me know if we can Reorder in Magento2 using REST webapi? Actually i have made one api and used same code as magento default reorder does, here is my code in API function using order_id as parameter:



public function reOrder($orderId)

$order = $this->orderApiRepository->get($orderId);
$cart = $this->cart;
$items = $order->getItemsCollection();
foreach ($items as $item)
try
$cart->addOrderItem($item);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(__($e->getMessage()), $e);





The issue is when i am checking response in postman, it returns null instead cart data, please let me know if anyone has done same type of things. please check below screenshot of POSTMAN api:



POSTMAN API







magento2 sales-order quote rest-api reorder






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 3 '18 at 7:49









bhargav shastribhargav shastri

15611




15611












  • Got any solution ?

    – Yann Martel
    Jan 2 at 10:43











  • have you got solution for this

    – Adarsh Shukla
    Feb 19 at 11:51











  • Nope didn't get any solution on it

    – bhargav shastri
    Feb 19 at 13:06

















  • Got any solution ?

    – Yann Martel
    Jan 2 at 10:43











  • have you got solution for this

    – Adarsh Shukla
    Feb 19 at 11:51











  • Nope didn't get any solution on it

    – bhargav shastri
    Feb 19 at 13:06
















Got any solution ?

– Yann Martel
Jan 2 at 10:43





Got any solution ?

– Yann Martel
Jan 2 at 10:43













have you got solution for this

– Adarsh Shukla
Feb 19 at 11:51





have you got solution for this

– Adarsh Shukla
Feb 19 at 11:51













Nope didn't get any solution on it

– bhargav shastri
Feb 19 at 13:06





Nope didn't get any solution on it

– bhargav shastri
Feb 19 at 13:06










1 Answer
1






active

oldest

votes


















0














Use below code for Reorder api



Create YourNameSpace/Module/etc/webapi.xml



<route url="/V1/reorder/:orderId" method="POST">
<service class="YourNameSpaceModuleApiReorderInterface" method="createReorder"/>
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="cartId" force="true">%cart_id%</parameter>
</data>
</route>


Create YourNameSpace/Module/Api/ReorderInterface.php



 <?php

namespace YourNameSpaceModuleApi;

interface ReorderInterface

/**
*
*
* @api
* @param int $cartId
* @param int $orderId
* @return boolean
*/
public function createReorder($cartId,$orderId);




Create YourNameSpaceModuleModelReorder.php



<?php

namespace YourNameSpaceModuleSalesModel;

use YourNameSpaceModuleApiReorderInterface;
use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoQuoteApiCartRepositoryInterface;
use MagentoSalesModelOrderRepository;
use MagentoQuoteModelQuote;
use MagentoCatalogApiProductRepositoryInterface;
use MagentoQuoteApiDataCartItemInterface;
use MagentoQuoteApiCartItemRepositoryInterface;

class Reorder implements ReorderInterface

protected $quoteRepository;

protected $orderRepository;

protected $quote;

protected $productRepository;

protected $cartItemInterface;

protected $cartItemRepository;

public function __construct(
CartRepositoryInterface $quoteRepository,
OrderRepository $orderRepository,
Quote $quote,
ProductRepositoryInterface $productRepository,
CartItemInterface $cartItemInterface,
CartItemRepositoryInterface $cartItemRepository
)

$this->quoteRepository = $quoteRepository;
$this->orderRepository = $orderRepository;
$this->quote = $quote;
$this->productRepository = $productRepository;
$this->cartItemInterface = $cartItemInterface;
$this->cartItemRepository = $cartItemRepository;



/**
* @param $cartId
* @param $orderId
* @return bool
*/
public function createReorder($cartId,$orderId)

// $quoteRepo = $this->quoteRepository->getActive($cartId);
$order = $this->orderRepository->get($orderId);

$items = $order->getItemsCollection();
foreach ($items as $item)

try
$this->addOrderItem($item, $cartId);
catch (MagentoFrameworkExceptionLocalizedException $e)
return false;

catch (Exception $e)
return false;



return true;


public function addOrderItem($orderItem,$quoteId)

/* @var $orderItem MagentoSalesModelOrderItem */
if ($orderItem->getParentItem() === null)
//$storeId = $this->_storeManager->getStore()->getId();
try
/**
* We need to reload product in this place, because products
* with the same id may have different sets of order attributes.
*/
$product = $this->productRepository->getById($orderItem->getProductId());

catch (NoSuchEntityException $e)
return $this;


$this->cartItemInterface->setQuoteId($quoteId);
$this->cartItemInterface->setSku($product->getSku());
$this->cartItemInterface->setQty($orderItem->getQtyOrdered());

$this->cartItemRepository->save($this->cartItemInterface);







Pass order id in your api with customer authentication , so it will add your order items in customer cart and gives you true in return so later on you can get cart items by calling /V1/carts/mine/items api.



Hope it will solve your issue.






share|improve this answer























    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%2f252170%2fmagento2-reorder-using-rest-api%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














    Use below code for Reorder api



    Create YourNameSpace/Module/etc/webapi.xml



    <route url="/V1/reorder/:orderId" method="POST">
    <service class="YourNameSpaceModuleApiReorderInterface" method="createReorder"/>
    <resources>
    <resource ref="self" />
    </resources>
    <data>
    <parameter name="cartId" force="true">%cart_id%</parameter>
    </data>
    </route>


    Create YourNameSpace/Module/Api/ReorderInterface.php



     <?php

    namespace YourNameSpaceModuleApi;

    interface ReorderInterface

    /**
    *
    *
    * @api
    * @param int $cartId
    * @param int $orderId
    * @return boolean
    */
    public function createReorder($cartId,$orderId);




    Create YourNameSpaceModuleModelReorder.php



    <?php

    namespace YourNameSpaceModuleSalesModel;

    use YourNameSpaceModuleApiReorderInterface;
    use MagentoFrameworkExceptionNoSuchEntityException;
    use MagentoQuoteApiCartRepositoryInterface;
    use MagentoSalesModelOrderRepository;
    use MagentoQuoteModelQuote;
    use MagentoCatalogApiProductRepositoryInterface;
    use MagentoQuoteApiDataCartItemInterface;
    use MagentoQuoteApiCartItemRepositoryInterface;

    class Reorder implements ReorderInterface

    protected $quoteRepository;

    protected $orderRepository;

    protected $quote;

    protected $productRepository;

    protected $cartItemInterface;

    protected $cartItemRepository;

    public function __construct(
    CartRepositoryInterface $quoteRepository,
    OrderRepository $orderRepository,
    Quote $quote,
    ProductRepositoryInterface $productRepository,
    CartItemInterface $cartItemInterface,
    CartItemRepositoryInterface $cartItemRepository
    )

    $this->quoteRepository = $quoteRepository;
    $this->orderRepository = $orderRepository;
    $this->quote = $quote;
    $this->productRepository = $productRepository;
    $this->cartItemInterface = $cartItemInterface;
    $this->cartItemRepository = $cartItemRepository;



    /**
    * @param $cartId
    * @param $orderId
    * @return bool
    */
    public function createReorder($cartId,$orderId)

    // $quoteRepo = $this->quoteRepository->getActive($cartId);
    $order = $this->orderRepository->get($orderId);

    $items = $order->getItemsCollection();
    foreach ($items as $item)

    try
    $this->addOrderItem($item, $cartId);
    catch (MagentoFrameworkExceptionLocalizedException $e)
    return false;

    catch (Exception $e)
    return false;



    return true;


    public function addOrderItem($orderItem,$quoteId)

    /* @var $orderItem MagentoSalesModelOrderItem */
    if ($orderItem->getParentItem() === null)
    //$storeId = $this->_storeManager->getStore()->getId();
    try
    /**
    * We need to reload product in this place, because products
    * with the same id may have different sets of order attributes.
    */
    $product = $this->productRepository->getById($orderItem->getProductId());

    catch (NoSuchEntityException $e)
    return $this;


    $this->cartItemInterface->setQuoteId($quoteId);
    $this->cartItemInterface->setSku($product->getSku());
    $this->cartItemInterface->setQty($orderItem->getQtyOrdered());

    $this->cartItemRepository->save($this->cartItemInterface);







    Pass order id in your api with customer authentication , so it will add your order items in customer cart and gives you true in return so later on you can get cart items by calling /V1/carts/mine/items api.



    Hope it will solve your issue.






    share|improve this answer



























      0














      Use below code for Reorder api



      Create YourNameSpace/Module/etc/webapi.xml



      <route url="/V1/reorder/:orderId" method="POST">
      <service class="YourNameSpaceModuleApiReorderInterface" method="createReorder"/>
      <resources>
      <resource ref="self" />
      </resources>
      <data>
      <parameter name="cartId" force="true">%cart_id%</parameter>
      </data>
      </route>


      Create YourNameSpace/Module/Api/ReorderInterface.php



       <?php

      namespace YourNameSpaceModuleApi;

      interface ReorderInterface

      /**
      *
      *
      * @api
      * @param int $cartId
      * @param int $orderId
      * @return boolean
      */
      public function createReorder($cartId,$orderId);




      Create YourNameSpaceModuleModelReorder.php



      <?php

      namespace YourNameSpaceModuleSalesModel;

      use YourNameSpaceModuleApiReorderInterface;
      use MagentoFrameworkExceptionNoSuchEntityException;
      use MagentoQuoteApiCartRepositoryInterface;
      use MagentoSalesModelOrderRepository;
      use MagentoQuoteModelQuote;
      use MagentoCatalogApiProductRepositoryInterface;
      use MagentoQuoteApiDataCartItemInterface;
      use MagentoQuoteApiCartItemRepositoryInterface;

      class Reorder implements ReorderInterface

      protected $quoteRepository;

      protected $orderRepository;

      protected $quote;

      protected $productRepository;

      protected $cartItemInterface;

      protected $cartItemRepository;

      public function __construct(
      CartRepositoryInterface $quoteRepository,
      OrderRepository $orderRepository,
      Quote $quote,
      ProductRepositoryInterface $productRepository,
      CartItemInterface $cartItemInterface,
      CartItemRepositoryInterface $cartItemRepository
      )

      $this->quoteRepository = $quoteRepository;
      $this->orderRepository = $orderRepository;
      $this->quote = $quote;
      $this->productRepository = $productRepository;
      $this->cartItemInterface = $cartItemInterface;
      $this->cartItemRepository = $cartItemRepository;



      /**
      * @param $cartId
      * @param $orderId
      * @return bool
      */
      public function createReorder($cartId,$orderId)

      // $quoteRepo = $this->quoteRepository->getActive($cartId);
      $order = $this->orderRepository->get($orderId);

      $items = $order->getItemsCollection();
      foreach ($items as $item)

      try
      $this->addOrderItem($item, $cartId);
      catch (MagentoFrameworkExceptionLocalizedException $e)
      return false;

      catch (Exception $e)
      return false;



      return true;


      public function addOrderItem($orderItem,$quoteId)

      /* @var $orderItem MagentoSalesModelOrderItem */
      if ($orderItem->getParentItem() === null)
      //$storeId = $this->_storeManager->getStore()->getId();
      try
      /**
      * We need to reload product in this place, because products
      * with the same id may have different sets of order attributes.
      */
      $product = $this->productRepository->getById($orderItem->getProductId());

      catch (NoSuchEntityException $e)
      return $this;


      $this->cartItemInterface->setQuoteId($quoteId);
      $this->cartItemInterface->setSku($product->getSku());
      $this->cartItemInterface->setQty($orderItem->getQtyOrdered());

      $this->cartItemRepository->save($this->cartItemInterface);







      Pass order id in your api with customer authentication , so it will add your order items in customer cart and gives you true in return so later on you can get cart items by calling /V1/carts/mine/items api.



      Hope it will solve your issue.






      share|improve this answer

























        0












        0








        0







        Use below code for Reorder api



        Create YourNameSpace/Module/etc/webapi.xml



        <route url="/V1/reorder/:orderId" method="POST">
        <service class="YourNameSpaceModuleApiReorderInterface" method="createReorder"/>
        <resources>
        <resource ref="self" />
        </resources>
        <data>
        <parameter name="cartId" force="true">%cart_id%</parameter>
        </data>
        </route>


        Create YourNameSpace/Module/Api/ReorderInterface.php



         <?php

        namespace YourNameSpaceModuleApi;

        interface ReorderInterface

        /**
        *
        *
        * @api
        * @param int $cartId
        * @param int $orderId
        * @return boolean
        */
        public function createReorder($cartId,$orderId);




        Create YourNameSpaceModuleModelReorder.php



        <?php

        namespace YourNameSpaceModuleSalesModel;

        use YourNameSpaceModuleApiReorderInterface;
        use MagentoFrameworkExceptionNoSuchEntityException;
        use MagentoQuoteApiCartRepositoryInterface;
        use MagentoSalesModelOrderRepository;
        use MagentoQuoteModelQuote;
        use MagentoCatalogApiProductRepositoryInterface;
        use MagentoQuoteApiDataCartItemInterface;
        use MagentoQuoteApiCartItemRepositoryInterface;

        class Reorder implements ReorderInterface

        protected $quoteRepository;

        protected $orderRepository;

        protected $quote;

        protected $productRepository;

        protected $cartItemInterface;

        protected $cartItemRepository;

        public function __construct(
        CartRepositoryInterface $quoteRepository,
        OrderRepository $orderRepository,
        Quote $quote,
        ProductRepositoryInterface $productRepository,
        CartItemInterface $cartItemInterface,
        CartItemRepositoryInterface $cartItemRepository
        )

        $this->quoteRepository = $quoteRepository;
        $this->orderRepository = $orderRepository;
        $this->quote = $quote;
        $this->productRepository = $productRepository;
        $this->cartItemInterface = $cartItemInterface;
        $this->cartItemRepository = $cartItemRepository;



        /**
        * @param $cartId
        * @param $orderId
        * @return bool
        */
        public function createReorder($cartId,$orderId)

        // $quoteRepo = $this->quoteRepository->getActive($cartId);
        $order = $this->orderRepository->get($orderId);

        $items = $order->getItemsCollection();
        foreach ($items as $item)

        try
        $this->addOrderItem($item, $cartId);
        catch (MagentoFrameworkExceptionLocalizedException $e)
        return false;

        catch (Exception $e)
        return false;



        return true;


        public function addOrderItem($orderItem,$quoteId)

        /* @var $orderItem MagentoSalesModelOrderItem */
        if ($orderItem->getParentItem() === null)
        //$storeId = $this->_storeManager->getStore()->getId();
        try
        /**
        * We need to reload product in this place, because products
        * with the same id may have different sets of order attributes.
        */
        $product = $this->productRepository->getById($orderItem->getProductId());

        catch (NoSuchEntityException $e)
        return $this;


        $this->cartItemInterface->setQuoteId($quoteId);
        $this->cartItemInterface->setSku($product->getSku());
        $this->cartItemInterface->setQty($orderItem->getQtyOrdered());

        $this->cartItemRepository->save($this->cartItemInterface);







        Pass order id in your api with customer authentication , so it will add your order items in customer cart and gives you true in return so later on you can get cart items by calling /V1/carts/mine/items api.



        Hope it will solve your issue.






        share|improve this answer













        Use below code for Reorder api



        Create YourNameSpace/Module/etc/webapi.xml



        <route url="/V1/reorder/:orderId" method="POST">
        <service class="YourNameSpaceModuleApiReorderInterface" method="createReorder"/>
        <resources>
        <resource ref="self" />
        </resources>
        <data>
        <parameter name="cartId" force="true">%cart_id%</parameter>
        </data>
        </route>


        Create YourNameSpace/Module/Api/ReorderInterface.php



         <?php

        namespace YourNameSpaceModuleApi;

        interface ReorderInterface

        /**
        *
        *
        * @api
        * @param int $cartId
        * @param int $orderId
        * @return boolean
        */
        public function createReorder($cartId,$orderId);




        Create YourNameSpaceModuleModelReorder.php



        <?php

        namespace YourNameSpaceModuleSalesModel;

        use YourNameSpaceModuleApiReorderInterface;
        use MagentoFrameworkExceptionNoSuchEntityException;
        use MagentoQuoteApiCartRepositoryInterface;
        use MagentoSalesModelOrderRepository;
        use MagentoQuoteModelQuote;
        use MagentoCatalogApiProductRepositoryInterface;
        use MagentoQuoteApiDataCartItemInterface;
        use MagentoQuoteApiCartItemRepositoryInterface;

        class Reorder implements ReorderInterface

        protected $quoteRepository;

        protected $orderRepository;

        protected $quote;

        protected $productRepository;

        protected $cartItemInterface;

        protected $cartItemRepository;

        public function __construct(
        CartRepositoryInterface $quoteRepository,
        OrderRepository $orderRepository,
        Quote $quote,
        ProductRepositoryInterface $productRepository,
        CartItemInterface $cartItemInterface,
        CartItemRepositoryInterface $cartItemRepository
        )

        $this->quoteRepository = $quoteRepository;
        $this->orderRepository = $orderRepository;
        $this->quote = $quote;
        $this->productRepository = $productRepository;
        $this->cartItemInterface = $cartItemInterface;
        $this->cartItemRepository = $cartItemRepository;



        /**
        * @param $cartId
        * @param $orderId
        * @return bool
        */
        public function createReorder($cartId,$orderId)

        // $quoteRepo = $this->quoteRepository->getActive($cartId);
        $order = $this->orderRepository->get($orderId);

        $items = $order->getItemsCollection();
        foreach ($items as $item)

        try
        $this->addOrderItem($item, $cartId);
        catch (MagentoFrameworkExceptionLocalizedException $e)
        return false;

        catch (Exception $e)
        return false;



        return true;


        public function addOrderItem($orderItem,$quoteId)

        /* @var $orderItem MagentoSalesModelOrderItem */
        if ($orderItem->getParentItem() === null)
        //$storeId = $this->_storeManager->getStore()->getId();
        try
        /**
        * We need to reload product in this place, because products
        * with the same id may have different sets of order attributes.
        */
        $product = $this->productRepository->getById($orderItem->getProductId());

        catch (NoSuchEntityException $e)
        return $this;


        $this->cartItemInterface->setQuoteId($quoteId);
        $this->cartItemInterface->setSku($product->getSku());
        $this->cartItemInterface->setQty($orderItem->getQtyOrdered());

        $this->cartItemRepository->save($this->cartItemInterface);







        Pass order id in your api with customer authentication , so it will add your order items in customer cart and gives you true in return so later on you can get cart items by calling /V1/carts/mine/items api.



        Hope it will solve your issue.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 8 at 11:07









        Hitesh AgrawalHitesh Agrawal

        346




        346



























            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%2f252170%2fmagento2-reorder-using-rest-api%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