How to create custom php script to display products special price in magento 2?












0















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










share|improve this question

























  • 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
















0















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










share|improve this question

























  • 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














0












0








0








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










share|improve this question
















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







php magento-2.1.3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 mins ago









Teja Bhagavan Kollepara

2,94841847




2,94841847










asked Apr 3 '17 at 3:02









MazeStricksMazeStricks

678628




678628













  • 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



















  • 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

















Write more about it.

– Sohel Rana
Apr 3 '17 at 3:46





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





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










2 Answers
2






active

oldest

votes


















2














Use these Code for your requirement



<?php
use MagentoFrameworkAppBootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$productCollectionFactory = $objectManager->get('MagentoCatalogModelResourceModelProductCollectionFactory');
$productcollection = $productCollectionFactory->create()
->addAttributeToSelect('*')
->load();

foreach ($productcollection as $product) {
if($product->getSpecialPrice()==0)
{
echo $product->getId()."<br>";
echo $product->getSku()."<br>";
}
}





share|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



















1














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



Inser below code into test.php



<?php

use MagentoFrameworkAppBootstrap;

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

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

$obj = $bootstrap->getObjectManager();

$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$productCollection = $obj->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();

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






share|improve this answer


























  • Hi Rajesh, Thanks for this code also.

    – MazeStricks
    Apr 3 '17 at 7:00











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f167310%2fhow-to-create-custom-php-script-to-display-products-special-price-in-magento-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Use these Code for your requirement



<?php
use MagentoFrameworkAppBootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$productCollectionFactory = $objectManager->get('MagentoCatalogModelResourceModelProductCollectionFactory');
$productcollection = $productCollectionFactory->create()
->addAttributeToSelect('*')
->load();

foreach ($productcollection as $product) {
if($product->getSpecialPrice()==0)
{
echo $product->getId()."<br>";
echo $product->getSku()."<br>";
}
}





share|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
















2














Use these Code for your requirement



<?php
use MagentoFrameworkAppBootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$productCollectionFactory = $objectManager->get('MagentoCatalogModelResourceModelProductCollectionFactory');
$productcollection = $productCollectionFactory->create()
->addAttributeToSelect('*')
->load();

foreach ($productcollection as $product) {
if($product->getSpecialPrice()==0)
{
echo $product->getId()."<br>";
echo $product->getSku()."<br>";
}
}





share|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














2












2








2







Use these Code for your requirement



<?php
use MagentoFrameworkAppBootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$productCollectionFactory = $objectManager->get('MagentoCatalogModelResourceModelProductCollectionFactory');
$productcollection = $productCollectionFactory->create()
->addAttributeToSelect('*')
->load();

foreach ($productcollection as $product) {
if($product->getSpecialPrice()==0)
{
echo $product->getId()."<br>";
echo $product->getSku()."<br>";
}
}





share|improve this answer













Use these Code for your requirement



<?php
use MagentoFrameworkAppBootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$productCollectionFactory = $objectManager->get('MagentoCatalogModelResourceModelProductCollectionFactory');
$productcollection = $productCollectionFactory->create()
->addAttributeToSelect('*')
->load();

foreach ($productcollection as $product) {
if($product->getSpecialPrice()==0)
{
echo $product->getId()."<br>";
echo $product->getSku()."<br>";
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 3 '17 at 6:55









Learing_CoderLearing_Coder

664317




664317













  • 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



















  • 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

















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





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





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





your Welcome @MazeStricks

– Learing_Coder
Apr 3 '17 at 7:04













1














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



Inser below code into test.php



<?php

use MagentoFrameworkAppBootstrap;

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

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

$obj = $bootstrap->getObjectManager();

$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$productCollection = $obj->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();

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






share|improve this answer


























  • Hi Rajesh, Thanks for this code also.

    – MazeStricks
    Apr 3 '17 at 7:00
















1














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



Inser below code into test.php



<?php

use MagentoFrameworkAppBootstrap;

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

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

$obj = $bootstrap->getObjectManager();

$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$productCollection = $obj->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();

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






share|improve this answer


























  • Hi Rajesh, Thanks for this code also.

    – MazeStricks
    Apr 3 '17 at 7:00














1












1








1







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



Inser below code into test.php



<?php

use MagentoFrameworkAppBootstrap;

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

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

$obj = $bootstrap->getObjectManager();

$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$productCollection = $obj->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();

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






share|improve this answer















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



Inser below code into test.php



<?php

use MagentoFrameworkAppBootstrap;

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

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

$obj = $bootstrap->getObjectManager();

$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$productCollection = $obj->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();

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







share|improve this answer














share|improve this answer



share|improve this answer








edited May 24 '17 at 4:41









Rafael Corrêa Gomes

4,33222963




4,33222963










answered Apr 3 '17 at 6:21









Rajesh HothiRajesh Hothi

17616




17616













  • Hi Rajesh, Thanks for this code also.

    – MazeStricks
    Apr 3 '17 at 7:00



















  • Hi Rajesh, Thanks for this code also.

    – MazeStricks
    Apr 3 '17 at 7:00

















Hi Rajesh, Thanks for this code also.

– MazeStricks
Apr 3 '17 at 7:00





Hi Rajesh, Thanks for this code also.

– MazeStricks
Apr 3 '17 at 7:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f167310%2fhow-to-create-custom-php-script-to-display-products-special-price-in-magento-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What other Star Trek series did the main TNG cast show up in?

Berlina muro

Berlina aerponto