Limit Number of Images Per Product In Magento
Some time we need to limit number of images for a product in our magento project we can do it
easily with some lines of code. Go to ‘app\code\core\Mage\Adminhtml\controllers\Catalog\ProductController.php’ and in saveAction find $data = $this->getRequest()->getPost(); under it put these line. and you are done.
easily with some lines of code. Go to ‘app\code\core\Mage\Adminhtml\controllers\Catalog\ProductController.php’ and in saveAction find $data = $this->getRequest()->getPost(); under it put these line. and you are done.
$images = Mage::helper(‘core’)->jsonDecode($data[‘product’][‘media_gallery’][‘images’]);
if($totalImages = count($images)) {
$maxPhotoPerProduct = 3;
if($totalImages > $maxPhotoPerProduct) {
Mage::getSingleton(‘core/session’)->addError($this->__(‘Max. number of images per product reached, extra images have been removed’));
}
$_allowedImages = array_slice($images, 0, $maxPhotoPerProduct);
$_POST[‘product’][‘media_gallery’][‘images’] = Mage::helper(‘core’)->jsonEncode($_allowedImages);
}