How to get product images based on its sku?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












I implemented a custom module Company/Module.



In the controller folder i have upload.php file.



I need to modify this file to display the output in a tabular form with sku and product image.



Please suggest me the possible ways.



Thank you in advance !










share|improve this question























  • please check my answer and let me know if not solve.
    – Rohan Hapani
    1 hour ago










  • Happy to help :) Happy coding !! Please accept answer @Charan
    – Rohan Hapani
    29 mins ago










  • hi @charan, do you mean want display sku and product image as list like in the table ?
    – mrfizh
    14 mins ago

















up vote
3
down vote

favorite












I implemented a custom module Company/Module.



In the controller folder i have upload.php file.



I need to modify this file to display the output in a tabular form with sku and product image.



Please suggest me the possible ways.



Thank you in advance !










share|improve this question























  • please check my answer and let me know if not solve.
    – Rohan Hapani
    1 hour ago










  • Happy to help :) Happy coding !! Please accept answer @Charan
    – Rohan Hapani
    29 mins ago










  • hi @charan, do you mean want display sku and product image as list like in the table ?
    – mrfizh
    14 mins ago













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I implemented a custom module Company/Module.



In the controller folder i have upload.php file.



I need to modify this file to display the output in a tabular form with sku and product image.



Please suggest me the possible ways.



Thank you in advance !










share|improve this question















I implemented a custom module Company/Module.



In the controller folder i have upload.php file.



I need to modify this file to display the output in a tabular form with sku and product image.



Please suggest me the possible ways.



Thank you in advance !







magento2 admin image sku






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 43 mins ago









Rutvee Sojitra

1,0301119




1,0301119










asked 1 hour ago









charan

183




183











  • please check my answer and let me know if not solve.
    – Rohan Hapani
    1 hour ago










  • Happy to help :) Happy coding !! Please accept answer @Charan
    – Rohan Hapani
    29 mins ago










  • hi @charan, do you mean want display sku and product image as list like in the table ?
    – mrfizh
    14 mins ago

















  • please check my answer and let me know if not solve.
    – Rohan Hapani
    1 hour ago










  • Happy to help :) Happy coding !! Please accept answer @Charan
    – Rohan Hapani
    29 mins ago










  • hi @charan, do you mean want display sku and product image as list like in the table ?
    – mrfizh
    14 mins ago
















please check my answer and let me know if not solve.
– Rohan Hapani
1 hour ago




please check my answer and let me know if not solve.
– Rohan Hapani
1 hour ago












Happy to help :) Happy coding !! Please accept answer @Charan
– Rohan Hapani
29 mins ago




Happy to help :) Happy coding !! Please accept answer @Charan
– Rohan Hapani
29 mins ago












hi @charan, do you mean want display sku and product image as list like in the table ?
– mrfizh
14 mins ago





hi @charan, do you mean want display sku and product image as list like in the table ?
– mrfizh
14 mins ago











4 Answers
4






active

oldest

votes

















up vote
1
down vote













Inject MagentoCatalogApiProductRepositoryInterfaceFactory in your constructor.



protected $_productRepository;

public function __construct(
MagentoCatalogApiProductRepositoryInterface $productRepository
)

$this->_productRepository = $productRepository;



We can get the image:



$product = $this->_productRepository->get($sku);
$product->getData('image');
$product->getData('thumbnail');
$product->getData('small_image');





share|improve this answer




















  • Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
    – charan
    25 mins ago

















up vote
0
down vote













follow below code



public function __construct(MagentoCatalogModelProductFactory $productFactory)

$this->productFactory = $productFactory;



public function execute()

$sku='your-sku';
$product = $this->productFactory->create();
$productDetails = $product->load($product->getIdBySku($sku));
$productDetails->getData('image');
$productDetails->getData('thumbnail');
$productDetails->getData('small_image');






share|improve this answer








New contributor




Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote













    First of all you are in need to load product based on your sku you can use product repository:



    public function __construct(
    Context $context,
    MagentoCatalogModelProductRepository $productRepo,
    MagentoCatalogHelperImageFactory $imageHelperFactory
    )
    parent::__construct($context);
    $this->_productRepo = $productRepo;
    $this->imageHelperFactory = $imageHelperFactory;



    in execute function:



    public function execute() 
    $productSku = 'Test';

    $repoProductById = $this->get($productSku);

    $productName = $repoProductById->getName();
    $productSku = $repoProductById->getSku();
    $imageUrl = $this->imageHelperFactory->create()->init($repoProductById, 'product_thumbnail_image')->getUrl();


    echo '<pre>';
    print_r($repoProductById->getData());
    exit;







    share|improve this answer






















    • Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
      – charan
      34 mins ago










    • Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
      – Narendra
      27 mins ago











    • Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
      – charan
      24 mins ago










    • I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
      – Narendra
      16 mins ago

















    up vote
    0
    down vote













    Use this :



    Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);

    $attributes = array('image', 'thumbnail');

    Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);





    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',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      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%2f245167%2fhow-to-get-product-images-based-on-its-sku%23new-answer', 'question_page');

      );

      Post as a guest






























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      Inject MagentoCatalogApiProductRepositoryInterfaceFactory in your constructor.



      protected $_productRepository;

      public function __construct(
      MagentoCatalogApiProductRepositoryInterface $productRepository
      )

      $this->_productRepository = $productRepository;



      We can get the image:



      $product = $this->_productRepository->get($sku);
      $product->getData('image');
      $product->getData('thumbnail');
      $product->getData('small_image');





      share|improve this answer




















      • Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
        – charan
        25 mins ago














      up vote
      1
      down vote













      Inject MagentoCatalogApiProductRepositoryInterfaceFactory in your constructor.



      protected $_productRepository;

      public function __construct(
      MagentoCatalogApiProductRepositoryInterface $productRepository
      )

      $this->_productRepository = $productRepository;



      We can get the image:



      $product = $this->_productRepository->get($sku);
      $product->getData('image');
      $product->getData('thumbnail');
      $product->getData('small_image');





      share|improve this answer




















      • Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
        – charan
        25 mins ago












      up vote
      1
      down vote










      up vote
      1
      down vote









      Inject MagentoCatalogApiProductRepositoryInterfaceFactory in your constructor.



      protected $_productRepository;

      public function __construct(
      MagentoCatalogApiProductRepositoryInterface $productRepository
      )

      $this->_productRepository = $productRepository;



      We can get the image:



      $product = $this->_productRepository->get($sku);
      $product->getData('image');
      $product->getData('thumbnail');
      $product->getData('small_image');





      share|improve this answer












      Inject MagentoCatalogApiProductRepositoryInterfaceFactory in your constructor.



      protected $_productRepository;

      public function __construct(
      MagentoCatalogApiProductRepositoryInterface $productRepository
      )

      $this->_productRepository = $productRepository;



      We can get the image:



      $product = $this->_productRepository->get($sku);
      $product->getData('image');
      $product->getData('thumbnail');
      $product->getData('small_image');






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 1 hour ago









      Rohan Hapani

      3,82321458




      3,82321458











      • Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
        – charan
        25 mins ago
















      • Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
        – charan
        25 mins ago















      Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
      – charan
      25 mins ago




      Hi@Rohan Hapani I want to implement a custom module. My actual requirement is to upload a csv file which contains sku.and i want to get the product images for those skus.and i want the output in a tabular form with sku and product image.could you suggest me the possible solution.
      – charan
      25 mins ago












      up vote
      0
      down vote













      follow below code



      public function __construct(MagentoCatalogModelProductFactory $productFactory)

      $this->productFactory = $productFactory;



      public function execute()

      $sku='your-sku';
      $product = $this->productFactory->create();
      $productDetails = $product->load($product->getIdBySku($sku));
      $productDetails->getData('image');
      $productDetails->getData('thumbnail');
      $productDetails->getData('small_image');






      share|improve this answer








      New contributor




      Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





















        up vote
        0
        down vote













        follow below code



        public function __construct(MagentoCatalogModelProductFactory $productFactory)

        $this->productFactory = $productFactory;



        public function execute()

        $sku='your-sku';
        $product = $this->productFactory->create();
        $productDetails = $product->load($product->getIdBySku($sku));
        $productDetails->getData('image');
        $productDetails->getData('thumbnail');
        $productDetails->getData('small_image');






        share|improve this answer








        New contributor




        Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



















          up vote
          0
          down vote










          up vote
          0
          down vote









          follow below code



          public function __construct(MagentoCatalogModelProductFactory $productFactory)

          $this->productFactory = $productFactory;



          public function execute()

          $sku='your-sku';
          $product = $this->productFactory->create();
          $productDetails = $product->load($product->getIdBySku($sku));
          $productDetails->getData('image');
          $productDetails->getData('thumbnail');
          $productDetails->getData('small_image');






          share|improve this answer








          New contributor




          Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          follow below code



          public function __construct(MagentoCatalogModelProductFactory $productFactory)

          $this->productFactory = $productFactory;



          public function execute()

          $sku='your-sku';
          $product = $this->productFactory->create();
          $productDetails = $product->load($product->getIdBySku($sku));
          $productDetails->getData('image');
          $productDetails->getData('thumbnail');
          $productDetails->getData('small_image');







          share|improve this answer








          New contributor




          Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 1 hour ago









          Hit's

          1536




          1536




          New contributor




          Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















              up vote
              0
              down vote













              First of all you are in need to load product based on your sku you can use product repository:



              public function __construct(
              Context $context,
              MagentoCatalogModelProductRepository $productRepo,
              MagentoCatalogHelperImageFactory $imageHelperFactory
              )
              parent::__construct($context);
              $this->_productRepo = $productRepo;
              $this->imageHelperFactory = $imageHelperFactory;



              in execute function:



              public function execute() 
              $productSku = 'Test';

              $repoProductById = $this->get($productSku);

              $productName = $repoProductById->getName();
              $productSku = $repoProductById->getSku();
              $imageUrl = $this->imageHelperFactory->create()->init($repoProductById, 'product_thumbnail_image')->getUrl();


              echo '<pre>';
              print_r($repoProductById->getData());
              exit;







              share|improve this answer






















              • Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
                – charan
                34 mins ago










              • Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
                – Narendra
                27 mins ago











              • Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
                – charan
                24 mins ago










              • I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
                – Narendra
                16 mins ago














              up vote
              0
              down vote













              First of all you are in need to load product based on your sku you can use product repository:



              public function __construct(
              Context $context,
              MagentoCatalogModelProductRepository $productRepo,
              MagentoCatalogHelperImageFactory $imageHelperFactory
              )
              parent::__construct($context);
              $this->_productRepo = $productRepo;
              $this->imageHelperFactory = $imageHelperFactory;



              in execute function:



              public function execute() 
              $productSku = 'Test';

              $repoProductById = $this->get($productSku);

              $productName = $repoProductById->getName();
              $productSku = $repoProductById->getSku();
              $imageUrl = $this->imageHelperFactory->create()->init($repoProductById, 'product_thumbnail_image')->getUrl();


              echo '<pre>';
              print_r($repoProductById->getData());
              exit;







              share|improve this answer






















              • Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
                – charan
                34 mins ago










              • Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
                – Narendra
                27 mins ago











              • Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
                – charan
                24 mins ago










              • I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
                – Narendra
                16 mins ago












              up vote
              0
              down vote










              up vote
              0
              down vote









              First of all you are in need to load product based on your sku you can use product repository:



              public function __construct(
              Context $context,
              MagentoCatalogModelProductRepository $productRepo,
              MagentoCatalogHelperImageFactory $imageHelperFactory
              )
              parent::__construct($context);
              $this->_productRepo = $productRepo;
              $this->imageHelperFactory = $imageHelperFactory;



              in execute function:



              public function execute() 
              $productSku = 'Test';

              $repoProductById = $this->get($productSku);

              $productName = $repoProductById->getName();
              $productSku = $repoProductById->getSku();
              $imageUrl = $this->imageHelperFactory->create()->init($repoProductById, 'product_thumbnail_image')->getUrl();


              echo '<pre>';
              print_r($repoProductById->getData());
              exit;







              share|improve this answer














              First of all you are in need to load product based on your sku you can use product repository:



              public function __construct(
              Context $context,
              MagentoCatalogModelProductRepository $productRepo,
              MagentoCatalogHelperImageFactory $imageHelperFactory
              )
              parent::__construct($context);
              $this->_productRepo = $productRepo;
              $this->imageHelperFactory = $imageHelperFactory;



              in execute function:



              public function execute() 
              $productSku = 'Test';

              $repoProductById = $this->get($productSku);

              $productName = $repoProductById->getName();
              $productSku = $repoProductById->getSku();
              $imageUrl = $this->imageHelperFactory->create()->init($repoProductById, 'product_thumbnail_image')->getUrl();


              echo '<pre>';
              print_r($repoProductById->getData());
              exit;








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 48 mins ago

























              answered 1 hour ago









              Narendra

              105




              105











              • Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
                – charan
                34 mins ago










              • Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
                – Narendra
                27 mins ago











              • Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
                – charan
                24 mins ago










              • I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
                – Narendra
                16 mins ago
















              • Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
                – charan
                34 mins ago










              • Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
                – Narendra
                27 mins ago











              • Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
                – charan
                24 mins ago










              • I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
                – Narendra
                16 mins ago















              Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
              – charan
              34 mins ago




              Hi@Narendra i want to implement a custom module.my actual requirement is to upload a csv file which contains sku.and i want to display the output with sku and product image in a tabular form.could you pls suggest me the possible solution.
              – charan
              34 mins ago












              Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
              – Narendra
              27 mins ago





              Hi, your requirement is not clear to me. correct me if i am wrong. you want to upload a csv containing skus in backend and in frontend want to show skus with images. right ?
              – Narendra
              27 mins ago













              Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
              – charan
              24 mins ago




              Hi@Narendra.I want to implement this on my local host.i want to upload csv file in frontend only.
              – charan
              24 mins ago












              I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
              – Narendra
              16 mins ago




              I can tell you the approach, from frontend when you upload csv you will be in need to read that csv in controller, there you can get images from product collection as per sku in loop as described above. Create array of sku and images as you want and pass that to view, you can take help of blocks, blocks will render data to phtml their you can take a table structure
              – Narendra
              16 mins ago










              up vote
              0
              down vote













              Use this :



              Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);

              $attributes = array('image', 'thumbnail');

              Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);





              share|improve this answer
























                up vote
                0
                down vote













                Use this :



                Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);

                $attributes = array('image', 'thumbnail');

                Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Use this :



                  Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);

                  $attributes = array('image', 'thumbnail');

                  Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);





                  share|improve this answer












                  Use this :



                  Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);

                  $attributes = array('image', 'thumbnail');

                  Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 31 mins ago









                  Puspalata Panigrahi

                  3617




                  3617



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245167%2fhow-to-get-product-images-based-on-its-sku%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      Installing NextGIS Connect into QGIS 3?

                      One-line joke