2014-07-11 25 views

回答

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> 
+0

感謝您的回覆。我不確定這是否適用於從前端添加產品的多賣家商店? – Gabento

+0

我實現了代碼,但用戶仍然可以添加超過6張圖片:( – Gabento

+0

ATT All Users。上面的代碼不起作用 – Gabento

相關問題