Magento 2 – Get Special Price of Product by Product ID or SKU

magento-2.1magento2productskuspecial-price

I need to get the special price of a product by product Id or Sku. Let's say I have an existing product with Id '21' and Sku 'test-21'.

This information is provided in my custom block class, how can I get the special price of this product in mentioned custom class?

Best Answer

use Magento/Catalog/Model/ProductFactory to load product, and get price information from the model

Code is like:

$specialPrice = $this->productFactory()->create()->load($id)->getPriceInfo()->getPrice('special_price');

some reference about how to get product model in your custom module

use object manager: http://alanstorm.com/magento_2_object_manager_instance_objects/

use dependency injection: http://www.coolryan.com/magento/2016/01/27/dependency-injection-in-magento-2/

Normally dependency injection is recommended.

Related Topic