How to get Sku, name, and image in magento2 through programmatically?










2















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?










share|improve this question
























  • 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















2















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?










share|improve this question
























  • 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













2












2








2








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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










5 Answers
5






active

oldest

votes


















2














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;


?>





share|improve this answer

























  • 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


















1














<?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;






share|improve this answer






























    1














    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(); ?>





    share|improve this answer






























      0














      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();
      ?>





      share|improve this answer






























        0














        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.'"/>';

        ?>





        share|improve this answer






















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









          2














          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;


          ?>





          share|improve this answer

























          • 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















          2














          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;


          ?>





          share|improve this answer

























          • 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













          2












          2








          2







          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;


          ?>





          share|improve this answer















          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;


          ?>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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

















          • 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













          1














          <?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;






          share|improve this answer



























            1














            <?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;






            share|improve this answer

























              1












              1








              1







              <?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;






              share|improve this answer













              <?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;







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 27 '18 at 6:29









              Dhiren VasoyaDhiren Vasoya

              4,32951842




              4,32951842





















                  1














                  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(); ?>





                  share|improve this answer



























                    1














                    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(); ?>





                    share|improve this answer

























                      1












                      1








                      1







                      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(); ?>





                      share|improve this answer













                      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(); ?>






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 27 '18 at 6:36









                      Chintan KaneriyaChintan Kaneriya

                      320214




                      320214





















                          0














                          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();
                          ?>





                          share|improve this answer



























                            0














                            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();
                            ?>





                            share|improve this answer

























                              0












                              0








                              0







                              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();
                              ?>





                              share|improve this answer













                              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();
                              ?>






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 27 '18 at 6:30









                              Ansar HusainAnsar Husain

                              1,687217




                              1,687217





















                                  0














                                  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.'"/>';

                                  ?>





                                  share|improve this answer



























                                    0














                                    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.'"/>';

                                    ?>





                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      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.'"/>';

                                      ?>





                                      share|improve this answer













                                      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.'"/>';

                                      ?>






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 27 '18 at 7:28









                                      Sukumar GoraiSukumar Gorai

                                      6,6653629




                                      6,6653629



























                                          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%2f239661%2fhow-to-get-sku-name-and-image-in-magento2-through-programmatically%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

                                          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                                          Edmonton

                                          Crossroads (UK TV series)