public function delete() { parent::delete(); Mage::dispatchEvent($this->_eventPrefix.'_delete_after_done', array($this->_eventObject=>$this)); return $this; }
修改成php
public function delete() { parent::delete(); Mage::dispatchEvent($this->_eventPrefix.'_delete_after_done', array($this->_eventObject=>$this)); foreach ($this->getMediaGallery('images') as $image) { $image_path = $this->getMediaConfig()->getMediaPath($image['file']); if (file_exists($image_path)) { @unlink($image_path); } } return $this; }
<?xml version="1.0"?>
<config>
<modules>
<MagentoBoy_DeleteProductImages>
<active>true</active>
<codePool>local</codePool>
</MagentoBoy_DeleteProductImages>
</modules>
</config>
<?xml version="1.0"?> <config> <modules> <MagentoBoy_DeleteProductImages> <version>0.1.0</version> </MagentoBoy_DeleteProductImages> </modules> </config>
<?php class MagentoBoy_DeleteProductImages_Model_Observer { public function processProductAfterDeleteEvent(Varien_Event_Observer $observer) { $eventProduct = $observer->getEvent()->getProduct(); if ($eventProduct && $eventProduct->getId()) { foreach ($eventProduct->getMediaGallery('images') as $image) { $image_path = $eventProduct->getMediaConfig()->getMediaPath($image['file']); if (file_exists($image_path)) { @unlink($image_path); } } } return $this; } }
<config> <global> <models> <deleteproductimages> <class>MagentoBoy_DeleteProductImages_Model</class> </deleteproductimages> </models> <events> <catalog_product_delete_after_done> <observers> <deleteproductimages> <class>deleteproductimages/observer</class> <method>processProductAfterDeleteEvent</method> </deleteproductimages> </observers> </catalog_product_delete_after_done> </events> </global> </config>