I'm implementing two api. The first one create an empty cart and assign a product to it. Then wrap the cart id with a QuoteMask id and retrive it.

The second api load the cart from the quotemaskid, set a customer then place an order.

The first api works fine, but when i try the second one it never ends. The strange thing is that the order is placed with correct data.

I paste the code of the first and second api.

first api

    public function createCart($dealerCode, VehicleInterface $vehicle, $lang)
    // creazione prodotto virtuale sulla base dei dati ricevuti in $vehicle
    // se esiste lo recuperiamo utilizzando lo sku
    // altrimenti lo creiamo (il prodotto sarà virtuale)
    try {
        $product = $this->productRepository->get($vehicle->getVehicleVin());
    } catch (NoSuchEntityException $e) {
        $product = $this->productFactory->create(['\Magento\Catalog\Model\Product']);
                'use_config_manage_stock' => 0,
                'manage_stock' => 1,
                'is_in_stock' => 1,
                'qty' => 100

    // Generiamo un carrello vuoto e gli assegniamo un QuoteIdMask, utile per gestire il carrello Guest
    /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
    $quoteIdMask = $this->quoteIdMaskFactory->create();
    $cartId = $this->quoteManagement->createEmptyCart();

    // aggiunta al carrello del prodotto virtuale precedentemente creato
    $cart = $this->cartRepository->get($cartId);

    // Restituzione dell'Id maschera per il carrello creato
    return $quoteIdMask->getMaskedId();

second api

    public function placeOrder(
    CustomerInterface $customerData,
    PaymentInterface $paymentMethod,
) {
    $websiteId = $this->storeManager->getStore()->getWebsiteId();

    // Recupero carrello
    /** @var $quoteIdMask QuoteIdMask */
    $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
    $quote = $this->cartRepository->get($quoteIdMask->getQuoteId());

    // Creazione customer
    try {
        $customer = $this->customerRepository->get($customerData->getEmail());
    } catch (NoSuchEntityException $e) {
        $customer = $this->customerFactory->create();

    // Creazione shipping address e method

    // Collect Rates and Set Shipping & Payment Method
    $shippingAddress = $quote->getShippingAddress();

        ->setShippingMethod('flatrate_flatrate'); //shipping method
    $quote->setPaymentMethod($paymentMethod->getMethod()); //payment method
    $quote->setInventoryProcessed(false); //not effect inventory

    // Set Sales Order Payment
    $quote->getPayment()->importData(['method' => 'checkmo']);

    // Create Order From Quote
    $order = $this->quoteManagement->placeOrder($quote->getId());

    return $order;
  • You have return $order object. Try return $order->getData(). Feb 26, 2020 at 12:17
  • The problem is in the instruction $this->quoteManagement->placeOrder($quote->getId()); The function never reaches the return statement
    – Francesco
    Feb 26, 2020 at 13:26

1 Answer 1


The problem is that after i place the order, Magento try to send an email. This was the reason to the never ending order placing.

In the backend I've disable this function setting yes in Magento > Stores > Configuration > Advanced > System > Disable Email Communications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.