How to get Sku, name, and image in magento2 through programmatically?
I don't know how to implement this task. I want to get product name, SKU, and image in magento2. Can you please help me?
product admin product-attribute magento-2.2.5
add a comment |
I don't know how to implement this task. I want to get product name, SKU, and image in magento2. Can you please help me?
product admin product-attribute magento-2.2.5
where you want to get those data?
– Amit Bera♦
Aug 27 '18 at 6:19
Hi @ Amit Bera, I have created one php file in the magento2 root folder. This is my required file path localhost/magento2test/example.php
– Dileep Kumar
Aug 27 '18 at 6:21
add a comment |
I don't know how to implement this task. I want to get product name, SKU, and image in magento2. Can you please help me?
product admin product-attribute magento-2.2.5
I don't know how to implement this task. I want to get product name, SKU, and image in magento2. Can you please help me?
product admin product-attribute magento-2.2.5
product admin product-attribute magento-2.2.5
edited Aug 27 '18 at 10:10
Ansar Husain
1,687217
1,687217
asked Aug 27 '18 at 6:14
Dileep KumarDileep Kumar
1237
1237
where you want to get those data?
– Amit Bera♦
Aug 27 '18 at 6:19
Hi @ Amit Bera, I have created one php file in the magento2 root folder. This is my required file path localhost/magento2test/example.php
– Dileep Kumar
Aug 27 '18 at 6:21
add a comment |
where you want to get those data?
– Amit Bera♦
Aug 27 '18 at 6:19
Hi @ Amit Bera, I have created one php file in the magento2 root folder. This is my required file path localhost/magento2test/example.php
– Dileep Kumar
Aug 27 '18 at 6:21
where you want to get those data?
– Amit Bera♦
Aug 27 '18 at 6:19
where you want to get those data?
– Amit Bera♦
Aug 27 '18 at 6:19
Hi @ Amit Bera, I have created one php file in the magento2 root folder. This is my required file path localhost/magento2test/example.php
– Dileep Kumar
Aug 27 '18 at 6:21
Hi @ Amit Bera, I have created one php file in the magento2 root folder. This is my required file path localhost/magento2test/example.php
– Dileep Kumar
Aug 27 '18 at 6:21
add a comment |
5 Answers
5
active
oldest
votes
I think you can fetch all product data using following code. Just put this code in your php file example.php
. Hope it works.
<?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');
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
$mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $product)
echo 'Name = '.$product->getName().'<br>';
echo 'Sku = '.$product->getSku().'<br><br>';
$imagepath = $mediaurl.'catalog/product'.$product->getImage();
$img = '<img src='.$imagepath.' />';
echo $img;
?>
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
|
show 2 more comments
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
try
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_Id = 5;
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_Id);
//product name
echo $product->getName();
//product Sku
echo $product->getSku();
//Product Image
if($product->getImage() != '')
echo $product->getImage();
catch(Exception $e)
echo $e->getMessage();
exit;
add a comment |
SKU:
<?php $block->escapeHtml($_product->getSku()) ?>
Product Name:
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
Image:
<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$img = $this->helper('MagentoCatalogHelperImage')
->init($product, 'product_base_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepTransparency(TRUE)
->keepFrame(FALSE)
->resize(320, 240);
?>
Use below line wherever you want your image to be displayed:
<?php echo $img->getUrl(); ?>
add a comment |
Just put below code in your file example.php
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$store = $obj->get('MagentoStoreModelStoreManagerInterface')->getStore();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
/** get product data by product id ****/
$productId = 1;
$product = $obj->get('MagentoCatalogModelProductRepository')
->getById($productId);
echo "Name :".$product->getName();
echo "Sku :". $product->getSku();
echo "Image : ".$store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
?>
add a comment |
You can manage to work this by using following code:
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()->addAttributeToSelect('*')->load();
foreach ($collection as $product)
$name = $product->getName();
$sku = $product->getSku();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
$image = '<img src="'.$imageUrl.'"/>';
?>
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f239661%2fhow-to-get-sku-name-and-image-in-magento2-through-programmatically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you can fetch all product data using following code. Just put this code in your php file example.php
. Hope it works.
<?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');
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
$mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $product)
echo 'Name = '.$product->getName().'<br>';
echo 'Sku = '.$product->getSku().'<br><br>';
$imagepath = $mediaurl.'catalog/product'.$product->getImage();
$img = '<img src='.$imagepath.' />';
echo $img;
?>
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
|
show 2 more comments
I think you can fetch all product data using following code. Just put this code in your php file example.php
. Hope it works.
<?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');
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
$mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $product)
echo 'Name = '.$product->getName().'<br>';
echo 'Sku = '.$product->getSku().'<br><br>';
$imagepath = $mediaurl.'catalog/product'.$product->getImage();
$img = '<img src='.$imagepath.' />';
echo $img;
?>
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
|
show 2 more comments
I think you can fetch all product data using following code. Just put this code in your php file example.php
. Hope it works.
<?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');
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
$mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $product)
echo 'Name = '.$product->getName().'<br>';
echo 'Sku = '.$product->getSku().'<br><br>';
$imagepath = $mediaurl.'catalog/product'.$product->getImage();
$img = '<img src='.$imagepath.' />';
echo $img;
?>
I think you can fetch all product data using following code. Just put this code in your php file example.php
. Hope it works.
<?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');
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
$mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $product)
echo 'Name = '.$product->getName().'<br>';
echo 'Sku = '.$product->getSku().'<br><br>';
$imagepath = $mediaurl.'catalog/product'.$product->getImage();
$img = '<img src='.$imagepath.' />';
echo $img;
?>
edited Aug 27 '18 at 9:39
answered Aug 27 '18 at 6:27
RajRaj
311112
311112
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
|
show 2 more comments
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
Hi @ Raj, I want to get and display image also along with name and SKU.
– Dileep Kumar
Aug 27 '18 at 7:14
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
@DileepKumar Have you tried $product->getImage(); or $product->getMediaGalleryImages() for displaying image?
– Raj
Aug 27 '18 at 7:17
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
Hi @ Raj, it is displaying URL path but I want to display the image?
– Dileep Kumar
Aug 27 '18 at 7:18
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
@DileepKumar Then you can add that url path in <img src="image_url"/> tag.
– Raj
Aug 27 '18 at 7:19
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
Hi @ Raj , I have added this code <img src="<?php $product->getImage(); ?>"> but image not displaying
– Dileep Kumar
Aug 27 '18 at 7:38
|
show 2 more comments
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
try
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_Id = 5;
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_Id);
//product name
echo $product->getName();
//product Sku
echo $product->getSku();
//Product Image
if($product->getImage() != '')
echo $product->getImage();
catch(Exception $e)
echo $e->getMessage();
exit;
add a comment |
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
try
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_Id = 5;
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_Id);
//product name
echo $product->getName();
//product Sku
echo $product->getSku();
//Product Image
if($product->getImage() != '')
echo $product->getImage();
catch(Exception $e)
echo $e->getMessage();
exit;
add a comment |
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
try
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_Id = 5;
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_Id);
//product name
echo $product->getName();
//product Sku
echo $product->getSku();
//Product Image
if($product->getImage() != '')
echo $product->getImage();
catch(Exception $e)
echo $e->getMessage();
exit;
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
try
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_Id = 5;
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_Id);
//product name
echo $product->getName();
//product Sku
echo $product->getSku();
//Product Image
if($product->getImage() != '')
echo $product->getImage();
catch(Exception $e)
echo $e->getMessage();
exit;
answered Aug 27 '18 at 6:29
Dhiren VasoyaDhiren Vasoya
4,32951842
4,32951842
add a comment |
add a comment |
SKU:
<?php $block->escapeHtml($_product->getSku()) ?>
Product Name:
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
Image:
<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$img = $this->helper('MagentoCatalogHelperImage')
->init($product, 'product_base_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepTransparency(TRUE)
->keepFrame(FALSE)
->resize(320, 240);
?>
Use below line wherever you want your image to be displayed:
<?php echo $img->getUrl(); ?>
add a comment |
SKU:
<?php $block->escapeHtml($_product->getSku()) ?>
Product Name:
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
Image:
<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$img = $this->helper('MagentoCatalogHelperImage')
->init($product, 'product_base_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepTransparency(TRUE)
->keepFrame(FALSE)
->resize(320, 240);
?>
Use below line wherever you want your image to be displayed:
<?php echo $img->getUrl(); ?>
add a comment |
SKU:
<?php $block->escapeHtml($_product->getSku()) ?>
Product Name:
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
Image:
<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$img = $this->helper('MagentoCatalogHelperImage')
->init($product, 'product_base_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepTransparency(TRUE)
->keepFrame(FALSE)
->resize(320, 240);
?>
Use below line wherever you want your image to be displayed:
<?php echo $img->getUrl(); ?>
SKU:
<?php $block->escapeHtml($_product->getSku()) ?>
Product Name:
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
Image:
<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$img = $this->helper('MagentoCatalogHelperImage')
->init($product, 'product_base_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepTransparency(TRUE)
->keepFrame(FALSE)
->resize(320, 240);
?>
Use below line wherever you want your image to be displayed:
<?php echo $img->getUrl(); ?>
answered Aug 27 '18 at 6:36
Chintan KaneriyaChintan Kaneriya
320214
320214
add a comment |
add a comment |
Just put below code in your file example.php
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$store = $obj->get('MagentoStoreModelStoreManagerInterface')->getStore();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
/** get product data by product id ****/
$productId = 1;
$product = $obj->get('MagentoCatalogModelProductRepository')
->getById($productId);
echo "Name :".$product->getName();
echo "Sku :". $product->getSku();
echo "Image : ".$store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
?>
add a comment |
Just put below code in your file example.php
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$store = $obj->get('MagentoStoreModelStoreManagerInterface')->getStore();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
/** get product data by product id ****/
$productId = 1;
$product = $obj->get('MagentoCatalogModelProductRepository')
->getById($productId);
echo "Name :".$product->getName();
echo "Sku :". $product->getSku();
echo "Image : ".$store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
?>
add a comment |
Just put below code in your file example.php
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$store = $obj->get('MagentoStoreModelStoreManagerInterface')->getStore();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
/** get product data by product id ****/
$productId = 1;
$product = $obj->get('MagentoCatalogModelProductRepository')
->getById($productId);
echo "Name :".$product->getName();
echo "Sku :". $product->getSku();
echo "Image : ".$store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
?>
Just put below code in your file example.php
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$store = $obj->get('MagentoStoreModelStoreManagerInterface')->getStore();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
/** get product data by product id ****/
$productId = 1;
$product = $obj->get('MagentoCatalogModelProductRepository')
->getById($productId);
echo "Name :".$product->getName();
echo "Sku :". $product->getSku();
echo "Image : ".$store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
?>
answered Aug 27 '18 at 6:30
Ansar HusainAnsar Husain
1,687217
1,687217
add a comment |
add a comment |
You can manage to work this by using following code:
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()->addAttributeToSelect('*')->load();
foreach ($collection as $product)
$name = $product->getName();
$sku = $product->getSku();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
$image = '<img src="'.$imageUrl.'"/>';
?>
add a comment |
You can manage to work this by using following code:
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()->addAttributeToSelect('*')->load();
foreach ($collection as $product)
$name = $product->getName();
$sku = $product->getSku();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
$image = '<img src="'.$imageUrl.'"/>';
?>
add a comment |
You can manage to work this by using following code:
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()->addAttributeToSelect('*')->load();
foreach ($collection as $product)
$name = $product->getName();
$sku = $product->getSku();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
$image = '<img src="'.$imageUrl.'"/>';
?>
You can manage to work this by using following code:
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$collection = $productCollection->create()->addAttributeToSelect('*')->load();
foreach ($collection as $product)
$name = $product->getName();
$sku = $product->getSku();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
$image = '<img src="'.$imageUrl.'"/>';
?>
answered Aug 27 '18 at 7:28
Sukumar GoraiSukumar Gorai
6,6653629
6,6653629
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f239661%2fhow-to-get-sku-name-and-image-in-magento2-through-programmatically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
where you want to get those data?
– Amit Bera♦
Aug 27 '18 at 6:19
Hi @ Amit Bera, I have created one php file in the magento2 root folder. This is my required file path localhost/magento2test/example.php
– Dileep Kumar
Aug 27 '18 at 6:21