Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_downloadable_product.php
Go to the documentation of this file.
1 <?php
7 require __DIR__ . '/../../../Magento/Downloadable/_files/product_downloadable.php';
8 
11  ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
13 $product = $productRepository->get('downloadable-product');
14 
17  \Magento\Downloadable\Model\Link::class
18 )->getCollection()->addProductToFilter(
19  $product->getId()
20 )->addTitleToResult(
21  $product->getStoreId()
22 )->addPriceToResult(
23  $product->getStore()->getWebsiteId()
24 );
25 
27 $link = $linkCollection->getFirstItem();
28 
29 $requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'links' => [$link->getId()]]);
30 
33 $cart->addProduct($product, $requestInfo);
34 $cart->save();
35 
38 $objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60