101 votes
Accepted

Product.OptionsPrice is not a constructor magento 1.9.3

It's caused by your custom theme not adding the new product_options.js file. Edit your theme layout file (either local.xml or catalog.xml) and add the following under the <catalog_product_view> ...
Raphael at Digital Pianism's user avatar
86 votes
Accepted

How to load product by SKU in magento 2

The correct way, according to Magento 2 service contracts, is using repositories: $product = $this->productRepositoryInterface->get($sku); Use Magento\Catalog\Api\ProductRepositoryInterface to ...
Phoenix128_RiccardoT's user avatar
58 votes
Accepted

How to get the product type?

You should try $product->getTypeId() It will return configurable, simple, grouped, virtual, downloadable and bundle.
Abhishek Panchal's user avatar
46 votes
Accepted

Magento 2 : Get Custom Attribute Value of Product

To fetch value of attribute Use: First get Your Product Collection and then $this->getProduct()->getAttributeText('attribute_text'); e.g: $this->getProduct()->getAttributeText('metal_pads'...
Sameer Bhayani's user avatar
39 votes

How do I get the current product?

Although other answers are correct, they're not the recommended/proper solution either. Using the ObjectManager is absolutely prohibited in Magento 2. So please don't rely on this solution, but use ...
Wesley Vestjens's user avatar
39 votes

Getting full image URL of product in template

If your block extends Magento\Catalog\Block\Product\AbstractProduct, you can use: $imageType = 'category_page_list'; // choose which image $image = $block->getImage($product, $imageType); Then ...
Fabian Schmengler's user avatar
39 votes
Accepted

Magento2 : How to get product id to my custom module

Try this: <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get ...
Abdul's user avatar
  • 9,701
39 votes

How to get product image and URL in Magento 2?

If you need to return a product URL it should look like this: //todo get product object $product $objectManager =\Magento\Framework\App\ObjectManager::getInstance(); $helperImport = $objectManager-&...
Shaoqing Ma's user avatar
38 votes

Programmatically create a simple product in magento 2

First, in your constructor you'll want to include three classes for dependency injection: Magento\Catalog\Api\Data\ProductInterfaceFactory, Magento\Catalog\Api\ProductRepositoryInterface and Magento\...
Navarr's user avatar
  • 1,712
35 votes

How to get a list of all products in Magento 2?

You should use Magento\Catalog\Model\ProductRepository or Magento\Catalog\Model\ResourceModel\Product\Collection according your needs. You can use both methods to get product instances with all data. ...
Siarhey Uchukhlebau's user avatar
35 votes
Accepted

How to get product image and URL in Magento 2?

This way may not the best way to get a product image. Inject \Magento\Catalog\Api\ProductRepositoryInterfaceFactory in the constructor. protected $_productRepositoryFactory; public function ...
Khoa TruongDinh's user avatar
35 votes

Invalid Form Key. Please refresh the page?

This bug arises due to php.ini variable "max_input_vars" Increase it to 10000 through below php function: ini_set('max_input_vars', 10000); OR Using linux command line cd /etc/php/7.0/apache2/ vi ...
Ahmad Vaqas Khan's user avatar
33 votes
Accepted

Magento 2: Product URL Suffix

Open your admin panel navigate on Stores->configuration->Catalog click on Search Engine Optimization tab Here you can remove Product URL Suffix = Category URL Suffix = Make these fields ...
Arunendra's user avatar
  • 7,446
32 votes

How to load product by SKU in magento 2

Instead of using the object manager directly, inject the ProductFactory: public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory) { $this->productFactory = $...
Fabian Schmengler's user avatar
28 votes
Accepted

Programmatically create a simple product in magento 2

Here, I found the solutions to create a product programmatically via custom php file i.e. test.php . <?php use Magento\Framework\App\Bootstrap; include('app/bootstrap.php'); $bootstrap = ...
Amit Maurya's user avatar
  • 2,871
27 votes

How to get product image and URL in Magento 2?

If you want the published/cache frontend URL of an image for a specific store view (like I did) this is working for me: /** * @var \Magento\Store\Model\App\Emulation */ protected $appEmulation; /**...
thaddeusmt's user avatar
  • 1,395
26 votes
Accepted

Where is the settings to check Use default Value in magento 2?

If you want all products have checked Use Default value then run below sql in database: DELETE FROM `catalog_product_entity_text` where store_id = 1; DELETE FROM `catalog_product_entity_datetime` ...
Jarnail S's user avatar
  • 4,697
25 votes

Magento 2: Set Custom product attribute value programmatically on product save

Official method should work, but Not The official method setCustomAttribute($attributeCode, $attributeValue) below should work but NOT because the official bug https://github.com/magento/magento2/...
Key Shang's user avatar
  • 3,415
24 votes

Magento 2 - How to get attribute of product?

Best practice in magento is to do it via xml. To get a standard attribute you do something like this in catalog_product_view.xml for example: <referenceContainer name="product.info.main"> &...
Claudiu Creanga's user avatar
24 votes
Accepted

Magento 2 - How to get attribute of product?

Another way, for the custom attributes: we can simply get the value by using getCustomAttribute() if (null !== $product->getCustomAttribute('your_custom_attribute')) { echo $product->...
Khoa TruongDinh's user avatar
24 votes
Accepted

Best way to update product's attribute value

I have used method updateAttributes of class \Magento\Catalog\Model\ResourceModel\Product\Action. Method can update multiple products and attribute values, but if you want to update just one product ...
Bartosz Kubicki's user avatar
24 votes

Magento 2.3.2 Product Export Message: "Message is added to queue, wait to get your file soon"

Run this command then check in admin php bin/magento queue:consumers:start exportProcessor you will get download option
Ansar Husain's user avatar
  • 3,409
23 votes

Assign products to category programatically in magento2

I think, this needs an updated answer which does not make use of the object manager. Also, there are some kinks involved which are not mentioned anywhere. In your constructor, inject the ...
T. Dreiling's user avatar
22 votes
Accepted

magento 2 - How to get attribute set name in product listing and product detail page

We can use \Magento\Eav\Api\AttributeSetRepositoryInterface to get attribute set name. Detail Page We need to override the \Magento\Catalog\Block\Product\View block. Inject this class on the ...
Khoa TruongDinh's user avatar
22 votes

Magento 2 How to Remove product information tabs

You can use the following in your layout file to remove the "More Information" tab: <referenceBlock name="product.attributes" remove="true" /> If you need to remove the "Details" tab: <...
Raphael at Digital Pianism's user avatar
20 votes

How do I get the current product?

If you are using Magento 2.1 or major, you can use this helper because the old method was deprecated. ... use Magento\Catalog\Helper\Data; ... public function __construct( Context $context, ...
Rafael Corrêa Gomes's user avatar
19 votes

Faster way to load media images in a product collection

The accepted answer works, but involves loading all the product attributes into memory when perhaps they are unnecessary. To take a slightly more surgical approach (tested in 1.9.2.2 CE) do $...
Aaron Bonner's user avatar
19 votes
Accepted

How do I get the current product?

In order to get the current product, one of the recommended ways is: Extend or use block class: Magento\Catalog\Block\Product\View\AbstractView. Get product using: $block->getProduct() in your ...
Rahil Patel's user avatar
18 votes
Accepted

get product collection for specific ids in magento 1.9.2?

try this $getData= array(166,167,164); $productCollection = Mage::getModel('catalog/product')->getCollection() ->addFieldToFilter('entity_id', array('in'=> $getData)); $...
Abdul's user avatar
  • 9,701
18 votes
Accepted

Assign products to category programatically in magento2

You need to get category Ids and product Id to set data: impliment this : $this->getCategoryLinkManagement()->assignProductToCategories( $product->getSku(), $...
Ronak Chauhan's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible