0
A
回答
0
public function saveAction()
{
/* START: Handle the max images per product */
$data = $this->getRequest()->getPost();
$images = Mage::helper('core')->jsonDecode($data['product']['media_gallery']['images']);
if($totalImages = count($images)) {
$maxPhotoPerProduct = 5;
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);
//Return the allowed images back to the $_POST
$_POST['product']['media_gallery']['images'] = Mage::helper('core')->jsonEncode($_allowedImages);
}
/* END: Handle the max images per product */
//Zend_Debug::dump(Mage::helper('core')->jsonDecode($_POST['product']['media_gallery']['images'])); exit;
//Run standard saveAction()
parent::saveAction();
}
注意上面的代碼是從位於「應用程序/代碼/本地/ MyCompany的/ Mymodule中/控制器/ Adminhtml /目錄/ ProductController.php」文件我Mycompany_Mymodule_Adminhtml_Catalog_ProductController類。
含義我使用下面的Mymodule config.xml文件中顯示的語法覆蓋默認的「app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php」控制器。
</config>
...
<admin>
<routers>
<adminhtml>
<args>
<modules>
<sintax before="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</sintax>
</modules>
</args>
</adminhtml>
</routers>
</admin>
...
</config>
相關問題
- 1. Magento:限制產品最大數量每個客戶(不是每個訂單)
- 2. Magento限制新產品區塊中展示的產品數量
- 3. 極限數量的產品頁面上顯示產品reveiws magento
- 4. Magento禁用沒有圖像的產品
- 5. 限購物車每個屬性/類型有1個產品 - Magento
- 6. 如何限制Magento產品頁面中產品縮略圖的數量
- 7. magento產品圖像樣本
- 8. Magento簡單產品圖像
- 9. Magento的1.7產品圖像導入未分配圖像產品
- 10. 在magento中將每個客戶的產品數量限制爲1
- 11. Magento:刪除產品圖像和產品數據
- 12. Magento - 每個產品的設置載體
- 13. Magento中的隨機產品塊中顯示的產品數量限制
- 14. Magento限制管理產品
- 15. Magento產品比較限制
- 16. Magento捆綁產品限制
- 17. Magento的產品圖像佔位符
- 18. 替換Magento中的產品圖像
- 19. Cloud的小產品圖像放大Magento?
- 20. Magento的產品說明圖像缺
- 21. Magento顯示動畫產品的圖像
- 22. 獲取Magento目錄中每個產品的產品選項
- 23. 試圖獲得Magento產品圖像 - 只獲取一個圖像
- 24. 簡單的產品圖像在配置產品 - Magento 1.5
- 25. 過濾器Magento產品集合的產品與圖像
- 26. Magento - 鏈接可配置的產品圖像,以簡單的產品圖像
- 27. Magento列出每個產品類別
- 28. 隨機產品magento每次顯示2個固定產品
- 29. WooCommerce產品有'產品圖像',但沒有'精選圖像'
- 30. Magento:限制產品最大數量爲每個訂單1。數量2 = 2個訂單
感謝您的回覆。我不確定這是否適用於從前端添加產品的多賣家商店? – Gabento
我實現了代碼,但用戶仍然可以添加超過6張圖片:( – Gabento
ATT All Users。上面的代碼不起作用 – Gabento