Domanda

In the download page, on the customer side (the page where customers can download the files for downloadable products), I am trying to add the product image next to every download item. However, I am having a problem in getting the product ID associated with each download.

In the database, I looked and found the table called "downloadable_link_purchased" in which the product-name is being saved but not the product-id.

enter image description here

I do not really need the product_name, so can I somehow set the product_ID of each item in the same column? There is not even need to make a new column or rename the product_name column, I just require to fill the product_name column with the product_id instead. I hope I have been clear enough, if not, please let me know and I will be happy to provide more info, is there a way to achieve this?

Any help is greatly appreciated.

È stato utile?

Soluzione

Option 1:

You can see that in the same table you can find the product_sku as well. Now you can get the product object by following code:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();    
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
$product = $productRepository->get($product_sku);

This is not a correct way to load product on your template file. Inject the ProductRepository to your desired block file and then create your own function from where you can get the product object by passing sku from your template file.

Option 2:

You can also get the product id by using this method "getIdBySku" to your productRepository object.

Hope this helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top