I Want Fetch Product Images From Database I Have Already Fetched Product Name From Id In Admin Grid












0


















use MagentoFrameworkViewElementUiComponentFactory;
use MagentoFrameworkViewElementUiComponentContextInterface;



/**
* @api
* @since 100.0.2
*/
class Thumbnail extends MagentoUiComponentListingColumnsColumn
{
const NAME = 'thumbnail';



const ALT_FIELD = 'name';

/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param MagentoCatalogHelperImage $imageHelper
* @param MagentoFrameworkUrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
MagentoCatalogHelperImage $imageHelper,
MagentoFrameworkUrlInterface $urlBuilder,
array $components = ,
array $data =
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->imageHelper = $imageHelper;
$this->urlBuilder = $urlBuilder;
}

/**

* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as & $item) {
$product = new MagentoFrameworkDataObject($item);
$imageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail');
$item[$fieldName . '_src'] = $imageHelper->getUrl();
$item[$fieldName . '_alt'] = $this->getAlt($item) ?: $imageHelper->getLabel();
$item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
'catalog/product/edit',
['productid' => $product->getEntityId(), 'store' => $this->context->getRequestParam('store')]
);
$origImageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail_preview');
$item[$fieldName . '_orig_src'] = $origImageHelper->getUrl();
}
}

return $dataSource;
}

/**
* @param array $row
*
* @return null|string
*/
protected function getAlt($row)
{
$altField = $this->getData('config/altField') ?: self::ALT_FIELD;
return isset($row[$altField]) ? $row[$altField] : null;
}


}



enter image description here









share









New contributor




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

























    0


















    use MagentoFrameworkViewElementUiComponentFactory;
    use MagentoFrameworkViewElementUiComponentContextInterface;



    /**
    * @api
    * @since 100.0.2
    */
    class Thumbnail extends MagentoUiComponentListingColumnsColumn
    {
    const NAME = 'thumbnail';



    const ALT_FIELD = 'name';

    /**
    * @param ContextInterface $context
    * @param UiComponentFactory $uiComponentFactory
    * @param MagentoCatalogHelperImage $imageHelper
    * @param MagentoFrameworkUrlInterface $urlBuilder
    * @param array $components
    * @param array $data
    */
    public function __construct(
    ContextInterface $context,
    UiComponentFactory $uiComponentFactory,
    MagentoCatalogHelperImage $imageHelper,
    MagentoFrameworkUrlInterface $urlBuilder,
    array $components = ,
    array $data =
    ) {
    parent::__construct($context, $uiComponentFactory, $components, $data);
    $this->imageHelper = $imageHelper;
    $this->urlBuilder = $urlBuilder;
    }

    /**

    * Prepare Data Source
    *
    * @param array $dataSource
    * @return array
    */
    public function prepareDataSource(array $dataSource)
    {
    if (isset($dataSource['data']['items'])) {
    $fieldName = $this->getData('name');
    foreach ($dataSource['data']['items'] as & $item) {
    $product = new MagentoFrameworkDataObject($item);
    $imageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail');
    $item[$fieldName . '_src'] = $imageHelper->getUrl();
    $item[$fieldName . '_alt'] = $this->getAlt($item) ?: $imageHelper->getLabel();
    $item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
    'catalog/product/edit',
    ['productid' => $product->getEntityId(), 'store' => $this->context->getRequestParam('store')]
    );
    $origImageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail_preview');
    $item[$fieldName . '_orig_src'] = $origImageHelper->getUrl();
    }
    }

    return $dataSource;
    }

    /**
    * @param array $row
    *
    * @return null|string
    */
    protected function getAlt($row)
    {
    $altField = $this->getData('config/altField') ?: self::ALT_FIELD;
    return isset($row[$altField]) ? $row[$altField] : null;
    }


    }



    enter image description here









    share









    New contributor




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























      0












      0








      0











      use MagentoFrameworkViewElementUiComponentFactory;
      use MagentoFrameworkViewElementUiComponentContextInterface;



      /**
      * @api
      * @since 100.0.2
      */
      class Thumbnail extends MagentoUiComponentListingColumnsColumn
      {
      const NAME = 'thumbnail';



      const ALT_FIELD = 'name';

      /**
      * @param ContextInterface $context
      * @param UiComponentFactory $uiComponentFactory
      * @param MagentoCatalogHelperImage $imageHelper
      * @param MagentoFrameworkUrlInterface $urlBuilder
      * @param array $components
      * @param array $data
      */
      public function __construct(
      ContextInterface $context,
      UiComponentFactory $uiComponentFactory,
      MagentoCatalogHelperImage $imageHelper,
      MagentoFrameworkUrlInterface $urlBuilder,
      array $components = ,
      array $data =
      ) {
      parent::__construct($context, $uiComponentFactory, $components, $data);
      $this->imageHelper = $imageHelper;
      $this->urlBuilder = $urlBuilder;
      }

      /**

      * Prepare Data Source
      *
      * @param array $dataSource
      * @return array
      */
      public function prepareDataSource(array $dataSource)
      {
      if (isset($dataSource['data']['items'])) {
      $fieldName = $this->getData('name');
      foreach ($dataSource['data']['items'] as & $item) {
      $product = new MagentoFrameworkDataObject($item);
      $imageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail');
      $item[$fieldName . '_src'] = $imageHelper->getUrl();
      $item[$fieldName . '_alt'] = $this->getAlt($item) ?: $imageHelper->getLabel();
      $item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
      'catalog/product/edit',
      ['productid' => $product->getEntityId(), 'store' => $this->context->getRequestParam('store')]
      );
      $origImageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail_preview');
      $item[$fieldName . '_orig_src'] = $origImageHelper->getUrl();
      }
      }

      return $dataSource;
      }

      /**
      * @param array $row
      *
      * @return null|string
      */
      protected function getAlt($row)
      {
      $altField = $this->getData('config/altField') ?: self::ALT_FIELD;
      return isset($row[$altField]) ? $row[$altField] : null;
      }


      }



      enter image description here









      share









      New contributor




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















      use MagentoFrameworkViewElementUiComponentFactory;
      use MagentoFrameworkViewElementUiComponentContextInterface;



      /**
      * @api
      * @since 100.0.2
      */
      class Thumbnail extends MagentoUiComponentListingColumnsColumn
      {
      const NAME = 'thumbnail';



      const ALT_FIELD = 'name';

      /**
      * @param ContextInterface $context
      * @param UiComponentFactory $uiComponentFactory
      * @param MagentoCatalogHelperImage $imageHelper
      * @param MagentoFrameworkUrlInterface $urlBuilder
      * @param array $components
      * @param array $data
      */
      public function __construct(
      ContextInterface $context,
      UiComponentFactory $uiComponentFactory,
      MagentoCatalogHelperImage $imageHelper,
      MagentoFrameworkUrlInterface $urlBuilder,
      array $components = ,
      array $data =
      ) {
      parent::__construct($context, $uiComponentFactory, $components, $data);
      $this->imageHelper = $imageHelper;
      $this->urlBuilder = $urlBuilder;
      }

      /**

      * Prepare Data Source
      *
      * @param array $dataSource
      * @return array
      */
      public function prepareDataSource(array $dataSource)
      {
      if (isset($dataSource['data']['items'])) {
      $fieldName = $this->getData('name');
      foreach ($dataSource['data']['items'] as & $item) {
      $product = new MagentoFrameworkDataObject($item);
      $imageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail');
      $item[$fieldName . '_src'] = $imageHelper->getUrl();
      $item[$fieldName . '_alt'] = $this->getAlt($item) ?: $imageHelper->getLabel();
      $item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
      'catalog/product/edit',
      ['productid' => $product->getEntityId(), 'store' => $this->context->getRequestParam('store')]
      );
      $origImageHelper = $this->imageHelper->init($product, 'product_listing_thumbnail_preview');
      $item[$fieldName . '_orig_src'] = $origImageHelper->getUrl();
      }
      }

      return $dataSource;
      }

      /**
      * @param array $row
      *
      * @return null|string
      */
      protected function getAlt($row)
      {
      $altField = $this->getData('config/altField') ?: self::ALT_FIELD;
      return isset($row[$altField]) ? $row[$altField] : null;
      }


      }



      enter image description here







      magento2 admin grid product-images





      share









      New contributor




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










      share









      New contributor




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








      share



      share








      edited 2 mins ago







      Harsh Jayswal













      New contributor




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









      asked 7 mins ago









      Harsh JayswalHarsh Jayswal

      11




      11




      New contributor




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





      New contributor





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






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






















          0






          active

          oldest

          votes











          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
          });


          }
          });






          Harsh Jayswal is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262164%2fi-want-fetch-product-images-from-database-i-have-already-fetched-product-name-fr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Harsh Jayswal is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Harsh Jayswal is a new contributor. Be nice, and check out our Code of Conduct.













          Harsh Jayswal is a new contributor. Be nice, and check out our Code of Conduct.












          Harsh Jayswal is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f262164%2fi-want-fetch-product-images-from-database-i-have-already-fetched-product-name-fr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

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

          Berlina muro

          Berlina aerponto