通过重写Magento 的 Product 模块属性,来达到同时删除产品和图片的功能 新建个文件 app/code/local/Mage/Catalog/Model/Product.php, 复制 app/code/core/Mage/Catalog/Model/Product.php 文件里的代码, 将原有的delete函数: public function delete() { parent::delete(); Mage::dispatchEvent($this->_eventPrefix.'_delete_after_done', array($this->_eventObject=>$this)); return $this; } 替换成: public function delete() { foreach ($this->getMediaGallery('images') as $image) { $image_path = $this->getMediaConfig()->getMediaPath($image['file']); if (file_exists($image_path)) { @unlink($image_path); } } parent::delete(); Mage::dispatchEvent($this->_eventPrefix . '_delete_after_done', array($this->_eventObject => $this)); return $this; } 保存,并重新刷新缓存即可。 (责任编辑:好模板) |