Public Member Functions | |
afterSave ($object) |
Definition at line 35 of file Image.php.
afterSave | ( | $ | object | ) |
Reimplemented from Mage_Eav_Model_Entity_Attribute_Backend_Abstract.
Definition at line 37 of file Image.php.
00038 { 00039 $value = $object->getData($this->getAttribute()->getName()); 00040 00041 if (is_array($value) && !empty($value['delete'])) { 00042 $object->setData($this->getAttribute()->getName(), ''); 00043 $this->getAttribute()->getEntity() 00044 ->saveAttribute($object, $this->getAttribute()->getName()); 00045 return; 00046 } 00047 00048 try { 00049 $uploader = new Varien_File_Uploader($this->getAttribute()->getName()); 00050 $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); 00051 $uploader->setAllowRenameFiles(true); 00052 $uploader->setFilesDispersion(true); 00053 } 00054 catch (Exception $e){ 00055 return $this; 00056 } 00057 $uploader->save(Mage::getStoreConfig('system/filesystem/media').'/catalog/product'); 00058 00059 if ($fileName = $uploader->getUploadedFileName()) { 00060 $object->setData($this->getAttribute()->getName(), $fileName); 00061 $this->getAttribute()->getEntity() 00062 ->saveAttribute($object, $this->getAttribute()->getName()); 00063 00064 } 00065 return $this; 00066 }