I'm new to Magento and working on an integration where I've created a custom API which is creating a product, if not available and then creating an order. But I'm facing this error "Product that you are trying to add is not available." while creating an order programmatically just after creating the product. I've checked the product details, and the product is enabled and also in stock.

More specifically I'm getting this error while adding the product to quote $quote->addProduct($product, intval($item['qty'])).
Reference used: https://www.rakeshjesadiya.com/how-to-create-order-programmatically-in-magento-2/
Magento version: 2.4.6

The error occurs only when I create both product and order in the same call. If the product is already present then the code is working fine and I can't share my own code as it is for client.

1 Answer 1


The reason for this issue is related to the indexer. After successfully creating a product, it is necessary to perform a re-index to ensure that the changes take effect immediately. Whenever you make modifications to a product, updating the indexer is essential.

If the cron job is running, Magento automatically performs the re-indexing process every minute. However, if you are making both the product creation and order from the same api call then you will need to programmatically re-index the data after creating the product via the API.

enter image description here

You can re-index by following this:- How to programmatically reindex product after update ex. price/stock quantity

Note:- You need to make sure re-index only perform if product get created otherwise it may increase a load on your server.


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.