In the search engine i have searched one product.that product not in the database but product is moving to add to cart page and store in the database and it will show the message not in stock but in short time will give you the product. How to do that?

| improve this question | | | | |

there are a magento simple way via admin configuration , if you enable this, you will have this product



if I right understood ...

| improve this answer | | | | |
  • 1)we want that still our user can able to add that searched product in the cart without price with a message "we will call you shortly for your required product." 2. and after placing order this order should show in our admin panel order section also. – Parshuram May 6 '19 at 7:34
  • create a plugin or observer for search , get query , programmatically create this product and add it to the user shopping cart – alexey boltynov May 6 '19 at 10:53

this is easy, first search where you can get a query from search and then just create product with this name , sku etc. and just use this :

protected $formKey;   
protected $cart;
protected $product;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Data\Form\FormKey $formKey,
\Magento\Checkout\Model\Cart $cart,
\Magento\Catalog\Model\Product $product,
array $data = []) {
    $this->formKey = $formKey;
    $this->cart = $cart;
    $this->product = $product;      

public function execute()
  $productId =10;
  $params = array(
                'form_key' => $this->formKey->getFormKey(),
                'product' => $productId, //product Id
                'qty'   =>1 //quantity of product                
    //Load the product based on productID   
    $_product = $this->product->load($productId);       
    $this->cart->addProduct($_product, $params);
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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