How to add quote to customer in magento2Magento API customer.create -> cart_product.moveToCustomerQuoteProceeding to an exception page after save new categoryMagento Module creation gives errorUnable to create order from admin in magento 2Monolog Error After 2.2 UpgradeAdd configure product in Cart using Magento 2 API facing an issueMagento2 REST API - Cannot create cart/quote for customerMagento2 REST API get all customers detailswhen click on place order then paypal showing error in Magento2Magento Fatal Error on Running Installation

How to deal with apathetic co-worker?

Impedance ratio vs. SWR

Why is one of Madera Municipal's runways labelled with only "R" on both sides?

How do governments keep track of their issued currency?

Passing multiple files through stdin (over ssh)

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?

Arriving at the same result with the opposite hypotheses

Character descriptions

Did Milano or Benatar approve or comment on their namesake MCU ships?

Taxi Services at Didcot

How come the nude protesters were not arrested?

Does the spell Clone require any material components to cast on a Zealot barbarian?

Share calendar details request from manager's manager

Cycle through MeshStyle directives in ListLinePlot

Would the US government be able to hold control if all electronics were disabled for an indefinite amount of time?

English word for "product of tinkering"

Is the term 'open source' a trademark?

Should I avoid hard-packed crusher dust trails with my hybrid?

Using "subway" as name for London Underground?

Is open-sourcing the code of a webapp not recommended?

Logarithm of exponential

How can I tell the difference between unmarked sugar and stevia?

What language is software running on the ISS written in?

Prime Sieve and brute force



How to add quote to customer in magento2


Magento API customer.create -> cart_product.moveToCustomerQuoteProceeding to an exception page after save new categoryMagento Module creation gives errorUnable to create order from admin in magento 2Monolog Error After 2.2 UpgradeAdd configure product in Cart using Magento 2 API facing an issueMagento2 REST API - Cannot create cart/quote for customerMagento2 REST API get all customers detailswhen click on place order then paypal showing error in Magento2Magento Fatal Error on Running Installation






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








0















I want to set custom pricing for magento2 product through API . I googled for the same and tried to implement the solutions one by one. But no solution is worked out.



$cartId = $this->cartManagementInterface->createEmptyCartForCustomer($customer_id); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId);


I am getting error on creating empty cart for customer.



"Warning: Illegal offset type in isset or empty in /var/www/html/mypro/vendor/magento/module-quote/Model/QuoteRepository.php on line 133"


Can any one help me on this? I am adding complete code that i am trying. Please help me on this.



class PoApi implements PosApiInterface

public function __construct(
MagentoFrameworkAppRequestInterface $request,
MagentoFrameworkObjectManagerInterface $objectManager,
MyRequestToQuoteModelQuote $quote,
MyRequestToQuoteModelQuoteDetail $qdetails,
MyRequestToQuoteModelPo $po,
MyVincrequestModelVpo $vpo,
MyRequestToQuoteModelPoDetail $podetails,
MagentoQuoteApiCartRepositoryInterface $cartRepositoryInterface,
MagentoQuoteApiCartManagementInterface $cartManagementInterface,
MagentoFrameworkRegistry $registry,
MagentoFrameworkUrlInterface $urlinterface,
MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory
)
$this->_request = $request;
$this->_objectManager = $objectManager;
$this->_quote = $quote;
$this->_quotedetails = $qdetails;
$this->_po = $po;
$this->_vpo = $vpo;
$this->_podetails = $podetails;
$this->_coreRegistry = $registry;
$this->_urlBuilder = $urlinterface;
$this->_customerRepository = $customerRepositoryFactory;
$this->cartRepositoryInterface=$cartRepositoryInterface;
$this->cartManagementInterface=$cartManagementInterface;


public function poToCart($poid)

try $status == '0')
$poData->setData('status', '1');
$poData->save();

$podetail = $poData->getCollection()->addFieldToFilter('po_increment_id', $po_incId)->addFieldToFilter('status', '1')->getData();

if (sizeof($podetail)>0)
$poProd=$this->_objectManager->create('MyCrequestModelPoDetail')->getCollection()->addFieldToFilter('po_id', $po_incId)->getData();


$cartId = $this->cartManagementInterface->createEmptyCart(); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
$quote->setStore($store);
// if you have allready buyer id then you can load customer directly
$customer= $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer

//add items in quote
foreach ($poProd as $item)
$product=$this->_product->load($item['product_id']);
$product->setPrice($item['po_price']);
$quote->addProduct($product, intval($item['product_qty']));


$quote->save(); //Now Save quote and your quote is ready

return "Added Cart";


catch (Exception $ex)
return $ex->getMessage();





When i tried to call this API. I am getting below error message.



MagentoFrameworkExceptionCouldNotSaveException: Cannot create quote in /var/www/html/myproj/vendor/magento/module-quote/Model/QuoteManagement.php:239
Stack trace:
#0 /var/www/html/myproj/app/code/My/Crequest/Model/PoApi.php(316): MagentoQuoteModelQuoteManagement->createEmptyCart()
#1 [internal function]: MyCrequestModelPoApi->poToCart('PO000101')


I tried another code as well by hitting API programmatically.



$store=$this->_storeManager->getStore();
$repository = $this->_objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customer = $repository->getById(2);
$customerId = $customerObj->getId();

$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/customers/' . $customerId . '/carts',
'httpMethod' => MagentoFrameworkWebapiRestRequest::HTTP_METHOD_POST,
]
];

echo $quoteId = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);


But this is also giving an error like below.



 Uncaught Error: Call to undefined method MyCrequestModelPoApi::_webApiCall() in









share|improve this question
























  • Please specify cartManagementInterface and cartRepositoryInterface er class name

    – Amit Bera
    Mar 27 at 11:22











  • Please check updated edits , I mentioned total code in my post.

    – Dinesh
    Mar 28 at 5:30

















0















I want to set custom pricing for magento2 product through API . I googled for the same and tried to implement the solutions one by one. But no solution is worked out.



$cartId = $this->cartManagementInterface->createEmptyCartForCustomer($customer_id); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId);


I am getting error on creating empty cart for customer.



"Warning: Illegal offset type in isset or empty in /var/www/html/mypro/vendor/magento/module-quote/Model/QuoteRepository.php on line 133"


Can any one help me on this? I am adding complete code that i am trying. Please help me on this.



class PoApi implements PosApiInterface

public function __construct(
MagentoFrameworkAppRequestInterface $request,
MagentoFrameworkObjectManagerInterface $objectManager,
MyRequestToQuoteModelQuote $quote,
MyRequestToQuoteModelQuoteDetail $qdetails,
MyRequestToQuoteModelPo $po,
MyVincrequestModelVpo $vpo,
MyRequestToQuoteModelPoDetail $podetails,
MagentoQuoteApiCartRepositoryInterface $cartRepositoryInterface,
MagentoQuoteApiCartManagementInterface $cartManagementInterface,
MagentoFrameworkRegistry $registry,
MagentoFrameworkUrlInterface $urlinterface,
MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory
)
$this->_request = $request;
$this->_objectManager = $objectManager;
$this->_quote = $quote;
$this->_quotedetails = $qdetails;
$this->_po = $po;
$this->_vpo = $vpo;
$this->_podetails = $podetails;
$this->_coreRegistry = $registry;
$this->_urlBuilder = $urlinterface;
$this->_customerRepository = $customerRepositoryFactory;
$this->cartRepositoryInterface=$cartRepositoryInterface;
$this->cartManagementInterface=$cartManagementInterface;


public function poToCart($poid)

try $status == '0')
$poData->setData('status', '1');
$poData->save();

$podetail = $poData->getCollection()->addFieldToFilter('po_increment_id', $po_incId)->addFieldToFilter('status', '1')->getData();

if (sizeof($podetail)>0)
$poProd=$this->_objectManager->create('MyCrequestModelPoDetail')->getCollection()->addFieldToFilter('po_id', $po_incId)->getData();


$cartId = $this->cartManagementInterface->createEmptyCart(); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
$quote->setStore($store);
// if you have allready buyer id then you can load customer directly
$customer= $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer

//add items in quote
foreach ($poProd as $item)
$product=$this->_product->load($item['product_id']);
$product->setPrice($item['po_price']);
$quote->addProduct($product, intval($item['product_qty']));


$quote->save(); //Now Save quote and your quote is ready

return "Added Cart";


catch (Exception $ex)
return $ex->getMessage();





When i tried to call this API. I am getting below error message.



MagentoFrameworkExceptionCouldNotSaveException: Cannot create quote in /var/www/html/myproj/vendor/magento/module-quote/Model/QuoteManagement.php:239
Stack trace:
#0 /var/www/html/myproj/app/code/My/Crequest/Model/PoApi.php(316): MagentoQuoteModelQuoteManagement->createEmptyCart()
#1 [internal function]: MyCrequestModelPoApi->poToCart('PO000101')


I tried another code as well by hitting API programmatically.



$store=$this->_storeManager->getStore();
$repository = $this->_objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customer = $repository->getById(2);
$customerId = $customerObj->getId();

$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/customers/' . $customerId . '/carts',
'httpMethod' => MagentoFrameworkWebapiRestRequest::HTTP_METHOD_POST,
]
];

echo $quoteId = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);


But this is also giving an error like below.



 Uncaught Error: Call to undefined method MyCrequestModelPoApi::_webApiCall() in









share|improve this question
























  • Please specify cartManagementInterface and cartRepositoryInterface er class name

    – Amit Bera
    Mar 27 at 11:22











  • Please check updated edits , I mentioned total code in my post.

    – Dinesh
    Mar 28 at 5:30













0












0








0








I want to set custom pricing for magento2 product through API . I googled for the same and tried to implement the solutions one by one. But no solution is worked out.



$cartId = $this->cartManagementInterface->createEmptyCartForCustomer($customer_id); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId);


I am getting error on creating empty cart for customer.



"Warning: Illegal offset type in isset or empty in /var/www/html/mypro/vendor/magento/module-quote/Model/QuoteRepository.php on line 133"


Can any one help me on this? I am adding complete code that i am trying. Please help me on this.



class PoApi implements PosApiInterface

public function __construct(
MagentoFrameworkAppRequestInterface $request,
MagentoFrameworkObjectManagerInterface $objectManager,
MyRequestToQuoteModelQuote $quote,
MyRequestToQuoteModelQuoteDetail $qdetails,
MyRequestToQuoteModelPo $po,
MyVincrequestModelVpo $vpo,
MyRequestToQuoteModelPoDetail $podetails,
MagentoQuoteApiCartRepositoryInterface $cartRepositoryInterface,
MagentoQuoteApiCartManagementInterface $cartManagementInterface,
MagentoFrameworkRegistry $registry,
MagentoFrameworkUrlInterface $urlinterface,
MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory
)
$this->_request = $request;
$this->_objectManager = $objectManager;
$this->_quote = $quote;
$this->_quotedetails = $qdetails;
$this->_po = $po;
$this->_vpo = $vpo;
$this->_podetails = $podetails;
$this->_coreRegistry = $registry;
$this->_urlBuilder = $urlinterface;
$this->_customerRepository = $customerRepositoryFactory;
$this->cartRepositoryInterface=$cartRepositoryInterface;
$this->cartManagementInterface=$cartManagementInterface;


public function poToCart($poid)

try $status == '0')
$poData->setData('status', '1');
$poData->save();

$podetail = $poData->getCollection()->addFieldToFilter('po_increment_id', $po_incId)->addFieldToFilter('status', '1')->getData();

if (sizeof($podetail)>0)
$poProd=$this->_objectManager->create('MyCrequestModelPoDetail')->getCollection()->addFieldToFilter('po_id', $po_incId)->getData();


$cartId = $this->cartManagementInterface->createEmptyCart(); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
$quote->setStore($store);
// if you have allready buyer id then you can load customer directly
$customer= $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer

//add items in quote
foreach ($poProd as $item)
$product=$this->_product->load($item['product_id']);
$product->setPrice($item['po_price']);
$quote->addProduct($product, intval($item['product_qty']));


$quote->save(); //Now Save quote and your quote is ready

return "Added Cart";


catch (Exception $ex)
return $ex->getMessage();





When i tried to call this API. I am getting below error message.



MagentoFrameworkExceptionCouldNotSaveException: Cannot create quote in /var/www/html/myproj/vendor/magento/module-quote/Model/QuoteManagement.php:239
Stack trace:
#0 /var/www/html/myproj/app/code/My/Crequest/Model/PoApi.php(316): MagentoQuoteModelQuoteManagement->createEmptyCart()
#1 [internal function]: MyCrequestModelPoApi->poToCart('PO000101')


I tried another code as well by hitting API programmatically.



$store=$this->_storeManager->getStore();
$repository = $this->_objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customer = $repository->getById(2);
$customerId = $customerObj->getId();

$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/customers/' . $customerId . '/carts',
'httpMethod' => MagentoFrameworkWebapiRestRequest::HTTP_METHOD_POST,
]
];

echo $quoteId = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);


But this is also giving an error like below.



 Uncaught Error: Call to undefined method MyCrequestModelPoApi::_webApiCall() in









share|improve this question
















I want to set custom pricing for magento2 product through API . I googled for the same and tried to implement the solutions one by one. But no solution is worked out.



$cartId = $this->cartManagementInterface->createEmptyCartForCustomer($customer_id); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId);


I am getting error on creating empty cart for customer.



"Warning: Illegal offset type in isset or empty in /var/www/html/mypro/vendor/magento/module-quote/Model/QuoteRepository.php on line 133"


Can any one help me on this? I am adding complete code that i am trying. Please help me on this.



class PoApi implements PosApiInterface

public function __construct(
MagentoFrameworkAppRequestInterface $request,
MagentoFrameworkObjectManagerInterface $objectManager,
MyRequestToQuoteModelQuote $quote,
MyRequestToQuoteModelQuoteDetail $qdetails,
MyRequestToQuoteModelPo $po,
MyVincrequestModelVpo $vpo,
MyRequestToQuoteModelPoDetail $podetails,
MagentoQuoteApiCartRepositoryInterface $cartRepositoryInterface,
MagentoQuoteApiCartManagementInterface $cartManagementInterface,
MagentoFrameworkRegistry $registry,
MagentoFrameworkUrlInterface $urlinterface,
MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory
)
$this->_request = $request;
$this->_objectManager = $objectManager;
$this->_quote = $quote;
$this->_quotedetails = $qdetails;
$this->_po = $po;
$this->_vpo = $vpo;
$this->_podetails = $podetails;
$this->_coreRegistry = $registry;
$this->_urlBuilder = $urlinterface;
$this->_customerRepository = $customerRepositoryFactory;
$this->cartRepositoryInterface=$cartRepositoryInterface;
$this->cartManagementInterface=$cartManagementInterface;


public function poToCart($poid)

try $status == '0')
$poData->setData('status', '1');
$poData->save();

$podetail = $poData->getCollection()->addFieldToFilter('po_increment_id', $po_incId)->addFieldToFilter('status', '1')->getData();

if (sizeof($podetail)>0)
$poProd=$this->_objectManager->create('MyCrequestModelPoDetail')->getCollection()->addFieldToFilter('po_id', $po_incId)->getData();


$cartId = $this->cartManagementInterface->createEmptyCart(); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
$quote->setStore($store);
// if you have allready buyer id then you can load customer directly
$customer= $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer

//add items in quote
foreach ($poProd as $item)
$product=$this->_product->load($item['product_id']);
$product->setPrice($item['po_price']);
$quote->addProduct($product, intval($item['product_qty']));


$quote->save(); //Now Save quote and your quote is ready

return "Added Cart";


catch (Exception $ex)
return $ex->getMessage();





When i tried to call this API. I am getting below error message.



MagentoFrameworkExceptionCouldNotSaveException: Cannot create quote in /var/www/html/myproj/vendor/magento/module-quote/Model/QuoteManagement.php:239
Stack trace:
#0 /var/www/html/myproj/app/code/My/Crequest/Model/PoApi.php(316): MagentoQuoteModelQuoteManagement->createEmptyCart()
#1 [internal function]: MyCrequestModelPoApi->poToCart('PO000101')


I tried another code as well by hitting API programmatically.



$store=$this->_storeManager->getStore();
$repository = $this->_objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customer = $repository->getById(2);
$customerId = $customerObj->getId();

$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/customers/' . $customerId . '/carts',
'httpMethod' => MagentoFrameworkWebapiRestRequest::HTTP_METHOD_POST,
]
];

echo $quoteId = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);


But this is also giving an error like below.



 Uncaught Error: Call to undefined method MyCrequestModelPoApi::_webApiCall() in






magento2 magento-2.1 cart customer quote






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 30 at 8:57









Raul Sanchez

2,16131336




2,16131336










asked Mar 27 at 10:12









DineshDinesh

12712




12712












  • Please specify cartManagementInterface and cartRepositoryInterface er class name

    – Amit Bera
    Mar 27 at 11:22











  • Please check updated edits , I mentioned total code in my post.

    – Dinesh
    Mar 28 at 5:30

















  • Please specify cartManagementInterface and cartRepositoryInterface er class name

    – Amit Bera
    Mar 27 at 11:22











  • Please check updated edits , I mentioned total code in my post.

    – Dinesh
    Mar 28 at 5:30
















Please specify cartManagementInterface and cartRepositoryInterface er class name

– Amit Bera
Mar 27 at 11:22





Please specify cartManagementInterface and cartRepositoryInterface er class name

– Amit Bera
Mar 27 at 11:22













Please check updated edits , I mentioned total code in my post.

– Dinesh
Mar 28 at 5:30





Please check updated edits , I mentioned total code in my post.

– Dinesh
Mar 28 at 5:30










2 Answers
2






active

oldest

votes


















1














Try this:



$customer = $this->_customerRepository->getById($customerId);
$quote = $this->_quoteFactory->create();
$quote->setStoreId($storeId);
$quote->assignCustomer($customer);





share|improve this answer























  • Tried this code , But $quote->getItems() showing nothing.

    – Dinesh
    Mar 27 at 10:37











  • you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

    – Mohit chauhan
    Mar 27 at 10:41












  • Yes i added products programmatically by calling $quote->addproduct($product,$qty);

    – Dinesh
    Mar 27 at 12:18


















0














I tried below code , Now i am able to add product to customer cart finely but it is showing price as 0.



 $store=$this->_storeManager->getStore();
$cartId = $this->cartManagementInterface->createEmptyCartForCustomer($poData->getPoCustomerId()); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
$quote->setStore($store);
// if you have allready buyer id then you can load customer directly
$customer= $this->_customerRepository->getById($poData->getPoCustomerId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer

//add items in quote
foreach($poProd as $item)
//$product=$this->_product->load($item['product_id']);
$product = $this->_objectManager->create ( 'MagentoCatalogModelProduct' )->load ( $item['product_id']);
$product->setPrice($item['po_price']);
$quote->addProduct($product, intval($item['product_qty']));


$quote->save(); //Now Save quote and your quote is ready

return "Added Cart";


I am getting the below response from post man when i access V1/carts/mine/items



[

"item_id": 815,
"sku": "004444000033",
"qty": 15,
"name": "Women's Cotton Dress (PINK)",
"price": 0,
"product_type": "simple",
"quote_id": "324",
"extension_attributes":
"image_url": "/B/0/B07JDYS8VX_1.jpg"


]





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%2f267614%2fhow-to-add-quote-to-customer-in-magento2%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Try this:



    $customer = $this->_customerRepository->getById($customerId);
    $quote = $this->_quoteFactory->create();
    $quote->setStoreId($storeId);
    $quote->assignCustomer($customer);





    share|improve this answer























    • Tried this code , But $quote->getItems() showing nothing.

      – Dinesh
      Mar 27 at 10:37











    • you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

      – Mohit chauhan
      Mar 27 at 10:41












    • Yes i added products programmatically by calling $quote->addproduct($product,$qty);

      – Dinesh
      Mar 27 at 12:18















    1














    Try this:



    $customer = $this->_customerRepository->getById($customerId);
    $quote = $this->_quoteFactory->create();
    $quote->setStoreId($storeId);
    $quote->assignCustomer($customer);





    share|improve this answer























    • Tried this code , But $quote->getItems() showing nothing.

      – Dinesh
      Mar 27 at 10:37











    • you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

      – Mohit chauhan
      Mar 27 at 10:41












    • Yes i added products programmatically by calling $quote->addproduct($product,$qty);

      – Dinesh
      Mar 27 at 12:18













    1












    1








    1







    Try this:



    $customer = $this->_customerRepository->getById($customerId);
    $quote = $this->_quoteFactory->create();
    $quote->setStoreId($storeId);
    $quote->assignCustomer($customer);





    share|improve this answer













    Try this:



    $customer = $this->_customerRepository->getById($customerId);
    $quote = $this->_quoteFactory->create();
    $quote->setStoreId($storeId);
    $quote->assignCustomer($customer);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 27 at 10:17









    Mohit chauhanMohit chauhan

    636212




    636212












    • Tried this code , But $quote->getItems() showing nothing.

      – Dinesh
      Mar 27 at 10:37











    • you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

      – Mohit chauhan
      Mar 27 at 10:41












    • Yes i added products programmatically by calling $quote->addproduct($product,$qty);

      – Dinesh
      Mar 27 at 12:18

















    • Tried this code , But $quote->getItems() showing nothing.

      – Dinesh
      Mar 27 at 10:37











    • you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

      – Mohit chauhan
      Mar 27 at 10:41












    • Yes i added products programmatically by calling $quote->addproduct($product,$qty);

      – Dinesh
      Mar 27 at 12:18
















    Tried this code , But $quote->getItems() showing nothing.

    – Dinesh
    Mar 27 at 10:37





    Tried this code , But $quote->getItems() showing nothing.

    – Dinesh
    Mar 27 at 10:37













    you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

    – Mohit chauhan
    Mar 27 at 10:41






    you will also need to add products to quote programatically. then you will be able to use $quote->getItems(). Above code just creates a quote for particular customer

    – Mohit chauhan
    Mar 27 at 10:41














    Yes i added products programmatically by calling $quote->addproduct($product,$qty);

    – Dinesh
    Mar 27 at 12:18





    Yes i added products programmatically by calling $quote->addproduct($product,$qty);

    – Dinesh
    Mar 27 at 12:18













    0














    I tried below code , Now i am able to add product to customer cart finely but it is showing price as 0.



     $store=$this->_storeManager->getStore();
    $cartId = $this->cartManagementInterface->createEmptyCartForCustomer($poData->getPoCustomerId()); //Create empty cart
    $quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
    $quote->setStore($store);
    // if you have allready buyer id then you can load customer directly
    $customer= $this->_customerRepository->getById($poData->getPoCustomerId());
    $quote->setCurrency();
    $quote->assignCustomer($customer); //Assign quote to customer

    //add items in quote
    foreach($poProd as $item)
    //$product=$this->_product->load($item['product_id']);
    $product = $this->_objectManager->create ( 'MagentoCatalogModelProduct' )->load ( $item['product_id']);
    $product->setPrice($item['po_price']);
    $quote->addProduct($product, intval($item['product_qty']));


    $quote->save(); //Now Save quote and your quote is ready

    return "Added Cart";


    I am getting the below response from post man when i access V1/carts/mine/items



    [

    "item_id": 815,
    "sku": "004444000033",
    "qty": 15,
    "name": "Women's Cotton Dress (PINK)",
    "price": 0,
    "product_type": "simple",
    "quote_id": "324",
    "extension_attributes":
    "image_url": "/B/0/B07JDYS8VX_1.jpg"


    ]





    share|improve this answer



























      0














      I tried below code , Now i am able to add product to customer cart finely but it is showing price as 0.



       $store=$this->_storeManager->getStore();
      $cartId = $this->cartManagementInterface->createEmptyCartForCustomer($poData->getPoCustomerId()); //Create empty cart
      $quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
      $quote->setStore($store);
      // if you have allready buyer id then you can load customer directly
      $customer= $this->_customerRepository->getById($poData->getPoCustomerId());
      $quote->setCurrency();
      $quote->assignCustomer($customer); //Assign quote to customer

      //add items in quote
      foreach($poProd as $item)
      //$product=$this->_product->load($item['product_id']);
      $product = $this->_objectManager->create ( 'MagentoCatalogModelProduct' )->load ( $item['product_id']);
      $product->setPrice($item['po_price']);
      $quote->addProduct($product, intval($item['product_qty']));


      $quote->save(); //Now Save quote and your quote is ready

      return "Added Cart";


      I am getting the below response from post man when i access V1/carts/mine/items



      [

      "item_id": 815,
      "sku": "004444000033",
      "qty": 15,
      "name": "Women's Cotton Dress (PINK)",
      "price": 0,
      "product_type": "simple",
      "quote_id": "324",
      "extension_attributes":
      "image_url": "/B/0/B07JDYS8VX_1.jpg"


      ]





      share|improve this answer

























        0












        0








        0







        I tried below code , Now i am able to add product to customer cart finely but it is showing price as 0.



         $store=$this->_storeManager->getStore();
        $cartId = $this->cartManagementInterface->createEmptyCartForCustomer($poData->getPoCustomerId()); //Create empty cart
        $quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
        $quote->setStore($store);
        // if you have allready buyer id then you can load customer directly
        $customer= $this->_customerRepository->getById($poData->getPoCustomerId());
        $quote->setCurrency();
        $quote->assignCustomer($customer); //Assign quote to customer

        //add items in quote
        foreach($poProd as $item)
        //$product=$this->_product->load($item['product_id']);
        $product = $this->_objectManager->create ( 'MagentoCatalogModelProduct' )->load ( $item['product_id']);
        $product->setPrice($item['po_price']);
        $quote->addProduct($product, intval($item['product_qty']));


        $quote->save(); //Now Save quote and your quote is ready

        return "Added Cart";


        I am getting the below response from post man when i access V1/carts/mine/items



        [

        "item_id": 815,
        "sku": "004444000033",
        "qty": 15,
        "name": "Women's Cotton Dress (PINK)",
        "price": 0,
        "product_type": "simple",
        "quote_id": "324",
        "extension_attributes":
        "image_url": "/B/0/B07JDYS8VX_1.jpg"


        ]





        share|improve this answer













        I tried below code , Now i am able to add product to customer cart finely but it is showing price as 0.



         $store=$this->_storeManager->getStore();
        $cartId = $this->cartManagementInterface->createEmptyCartForCustomer($poData->getPoCustomerId()); //Create empty cart
        $quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
        $quote->setStore($store);
        // if you have allready buyer id then you can load customer directly
        $customer= $this->_customerRepository->getById($poData->getPoCustomerId());
        $quote->setCurrency();
        $quote->assignCustomer($customer); //Assign quote to customer

        //add items in quote
        foreach($poProd as $item)
        //$product=$this->_product->load($item['product_id']);
        $product = $this->_objectManager->create ( 'MagentoCatalogModelProduct' )->load ( $item['product_id']);
        $product->setPrice($item['po_price']);
        $quote->addProduct($product, intval($item['product_qty']));


        $quote->save(); //Now Save quote and your quote is ready

        return "Added Cart";


        I am getting the below response from post man when i access V1/carts/mine/items



        [

        "item_id": 815,
        "sku": "004444000033",
        "qty": 15,
        "name": "Women's Cotton Dress (PINK)",
        "price": 0,
        "product_type": "simple",
        "quote_id": "324",
        "extension_attributes":
        "image_url": "/B/0/B07JDYS8VX_1.jpg"


        ]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 13:09









        DineshDinesh

        12712




        12712



























            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%2f267614%2fhow-to-add-quote-to-customer-in-magento2%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?