Exemplo 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;
     }
 }
Exemplo n.º 2
0
 /**
  * This methods overwrites Mage_Adminhtml_Model_System_Config_Backend_File::_beforeSave
  * in a bad way, just because the "$uploader = new class".
  * 
  * @param Mage_Adminhtml_Model_System_Config_Backend_File $model
  * @param type $uploadDir
  * @param type $allowedExtensions
  * @return Mage_Adminhtml_Model_System_Config_Backend_File
  */
 public function systemConfigBackendFileBeforeSave(Mage_Adminhtml_Model_System_Config_Backend_File $model, $uploadDir, $allowedExtensions)
 {
     $value = $model->getValue();
     if ($_FILES['groups']['tmp_name'][$model->getGroupId()]['fields'][$model->getField()]['value']) {
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$model->getGroupId()]['fields'][$model->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$model->getGroupId()]['fields'][$model->getField()]['value'];
             $uploader = new MageFM_CDN_Model_Uploader($file);
             $uploader->setAllowedExtensions($allowedExtensions);
             $uploader->setAllowRenameFiles(true);
             $uploader->addValidateCallback('size', $model, 'validateMaxSize');
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $model;
         }
         $filename = $result['file'];
         if ($filename) {
             $filename = $model->prependScopeInfo($filename);
             $model->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             $model->setValue('');
         } else {
             $model->unsValue();
         }
     }
     return $model;
 }