Can you help me on how to create a php script to display all products with special price including it's sku.

  • Write more about it. – Sohel Rana Apr 3 '17 at 3:46
  • Hi Sohel, I'd like to display only the products with special price with a value of 0 only and display also it's SKU so that I can track them down. Thanks – MazeStricks Apr 3 '17 at 3:54

Use these Code for your requirement

use \Magento\Framework\App\Bootstrap;
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
//$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$productcollection = $productCollectionFactory->create()

foreach ($productcollection as $product) {
        echo $product->getId()."<br>";
        echo $product->getSku()."<br>";
| improve this answer | |
  • Hi Pranay k, Thanks for this code. I'll try this and let you know if it worked. Thanks again – MazeStricks Apr 3 '17 at 7:00
  • This code works better in my end. Thanks again – MazeStricks Apr 3 '17 at 7:03
  • your Welcome @MazeStricks – Learing_Coder Apr 3 '17 at 7:04

Please create a test.php file at your magento2 root directory

Inser below code into test.php


use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';

$params = $_SERVER; 
$bootstrap = Bootstrap::create(BP, $params);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');

$productCollection = $obj->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()

foreach ($collection as $product){

     echo 'SKU:  '.$product->getSku().'<br>';   
     echo 'Name:  '.$product->getName().'<br>';
     echo 'Price:    '.$product->getPrice().'<br>';
     echo 'Special price:    '.$product->getSpecialPrice().'<br>';
     echo '----------------------------<br>';       


now run URL: like : http://yourdomain/test.php

| improve this answer | |

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.