Skip to content

“Product that you are trying to add is not available.” While creating the order programmatically

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

P.S
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.