Ejemplo n.º 1
0
 /**
  * This methods overwrites Mage_Eav_Model_Entity_Attribute_Backend_Abstract::afterSave
  * in a bad way, just because the "$uploader = new class".
  * 
  * @param type $object
  * @return type
  */
 public function afterSave($object)
 {
     if (!Mage::helper('magefm_cdn')->isEnabled()) {
         return parent::afterSave($object);
     }
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     $path = 'catalog' . DS . 'category';
     try {
         $uploader = new MageFM_CDN_Model_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         /** @TODO ??? */
         return;
     }
 }
Ejemplo n.º 2
-1
 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  */
 public function afterSave($object)
 {
     if (!Mage::helper('uaudio_storage')->isEnabled()) {
         return parent::afterSave($object);
     }
     $value = $object->getData($this->getAttribute()->getName());
     $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     if (is_array($value) && !empty($value['delete'])) {
         $model = Mage::getModel('core/file_storage')->getStorageModel();
         $model->deleteFile($path . $value['value']);
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     }
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         if (class_exists('Mage_Core_Model_File_Validator_Image')) {
             // added for mage patch SUPEE-7405
             $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
         }
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         return null;
     }
 }