I create an order programmatically like this:

$store = $this->storeManager->getStore();
$websiteId = $this->storeManager->getStore()->getWebsiteId();
$customer = $this->_customerFactory->create();
$quote = $this->quote->create();  
$customer = $this->_customerRepoInterface->getById($customer->getEntityId());

foreach ($productsOrder as $productOrder) {
  $productId = $productOrder['product_id'];
  $qty = $productOrder['qty'];
  $product = $this->_product->load($productId);
  $price = $product->getPrice();


$shippingAddress = $quote->getShippingAddress();

$quote->getPayment()->importData(['method' => $paymentMethod]);


$order = $this->quoteManagement->submit($quote);

how can i apply coupon code in here and validate the coupon code?

1 Answer 1


Add this code to quote


after $quote->save();

  • how to validate the coupon code ? Jul 3, 2018 at 9:15
  • I have to check
    – Amit Bera
    Jul 4, 2018 at 10:36

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.