1

I have the following problem:

I want to get the final price programatically but it always displays 0

I tried with :

$product->getSpecialPrice();

$product->getPriceInfo()->getPrice("final_price")->getValue();

both displays 0

On the other hand $product->getPrice() displays the normal regular price correctly

Is there an other way to get the special price?

I get the products like this:

$collection = $block->getResourceModel('catalog/product_collection')
    ->addAttributeToFilter( 'sku', array('in' => $alle_skus) )
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('thumbnail')
    ->addMinimalPrice()
    ->addFinalPrice()
    ->addTaxPercents()
    ->load();
5
  • What is the code you are using to create $product object? – Sukumar Gorai Sep 8 '20 at 12:53
  • actually i got the answer. $product->getPriceInfo()->getPrice("final_price")->getMinimalPrice()->getValue(); – Ifaruki Sep 8 '20 at 12:55
  • No not this one. $product object creation code? – Sukumar Gorai Sep 8 '20 at 12:55
  • @SukumarGorai let me see – Ifaruki Sep 8 '20 at 12:58
  • @SukumarGorai i have added the code – Ifaruki Sep 8 '20 at 13:02
0

You can use \Magento\Catalog\Model\ProductRepository to get Special Price.

To get the special price you can do it a couple of ways, this one being by product ID:

/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$this->_productRepository = $productRepository;

$product = $this->_productRepository->getById($id); <-- get the product by product ID
return $product->getSpecialPrice();

Or you can do by product SKU:

/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$this->_productRepository = $productRepository;

$product = $this->_productRepository->get($sku); <!-- get the product by product SKU
return $product->getSpecialPrice();
0

Get product special price

// get product regular price
$prd_regular_pice = $product->getPrice();

//get product final price
$prd_final_pice = $product->getFinalPrice(); // special price 

if($prd_regular_pice != $prd_final_pice) {
    $special price = $prd_final_pice;
} else {
    $special price = "No Special Price"
}
// get special price

echo  "Special Price  ".$special price;

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.