1

Below is my product collection code:

$productCollection = $this->productCollectionFactory->create();
$productCollection->addMinimalPrice();
$productCollection->addFinalPrice();
$productCollection->addAttributeToFilter('status',
                      array('eq' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED));
$productCollection->addAttributeToFilter('type_id',
                      array('eq' => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE));
$productCollection->addAttributeToFilter(
                        'visibility', array('in' =>
                                array(
                                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH,
                                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG
                                )
                             )
                    );
        if ($productCollection->count())
        {
         foreach ($productCollection as $product)
          {
            echo $product->getFinalPrice();
            echo $product->getPrice();
          }
        }

Both price gives same amount.It should give product original price and special price. Please advise me for if I have missed something in code.

P_U
  • 808
  • 8
  • 19

2 Answers2

0

Can you please try

$final_price = $_product->getPriceInfo()->getPrice('final_price')->getValue();

and

$regular_price = $_product->getPriceInfo()->getPrice('regular_price')->getValue();

also make sure that promotion and taxation is getting applicable on the product into consideration. In case they are not applied, both these prices would remain the same.

Kumar A.
  • 493
  • 6
  • 16
0

update your code as below and try

    $productCollection = $this->productCollectionFactory->create();
    $productCollection->addAttributeToSelect(*);
    $productCollection->addAttributeToFilter('status',
                          array('eq' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED));
    $productCollection->addAttributeToFilter('type_id',
                          array('eq' => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE));
    $productCollection->addAttributeToFilter(
                            'visibility', array('in' =>
                                    array(
                                        \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH,
                                        \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG
                                    )
                                 )
                        );
            if ($productCollection->count())
            {
             foreach ($productCollection as $product)
              {
                echo $product->getFinalPrice();
                echo $product->getPrice();
              }
            }
Gohil Rajesh
  • 2,914
  • 1
  • 13
  • 23