Magento Asked by ineluki on February 9, 2021
How can I get parent image from a simple product if the simple product has no base image?
The following code gets the simple product image in a template file.
$_imagehelper = $this->helper('MagentoCatalogHelperImage');
$productImage = $_imagehelper->init($product, 'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl();
Assuming you want the parent of the simple product you would use the following
$product = $_product->getId();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->create('MagentoConfigurableProductModelResourceModelProductTypeConfigurable')->getParentIdsByChild($product);
if(isset($product[0])){
//this is parent product id..
$product[0];
//here you can load up the parent product and get its image just rememeber to wrap in an if statement to check if child product image is set
}
Answered by Dava Gordon on February 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP