How to get product images based on its sku?
Clash 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 !
magento2 admin image sku
add a comment |Â
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 !
magento2 admin image sku
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
add a comment |Â
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 !
magento2 admin image sku
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
magento2 admin image sku
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
add a comment |Â
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
add a comment |Â
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');
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
add a comment |Â
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');
New contributor
add a comment |Â
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;
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
add a comment |Â
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);
add a comment |Â
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');
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
add a comment |Â
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');
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
add a comment |Â
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');
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');
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
add a comment |Â
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
add a comment |Â
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');
New contributor
add a comment |Â
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');
New contributor
add a comment |Â
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');
New contributor
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');
New contributor
New contributor
answered 1 hour ago
Hit's
1536
1536
New contributor
New contributor
add a comment |Â
add a comment |Â
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;
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
add a comment |Â
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;
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
add a comment |Â
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;
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;
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
add a comment |Â
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
add a comment |Â
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);
add a comment |Â
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);
add a comment |Â
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);
Use this :
Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);
$attributes = array('image', 'thumbnail');
Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);
answered 31 mins ago
Puspalata Panigrahi
3617
3617
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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