Example #1
0
 public function toOptionArray($key)
 {
     $key = str_replace("/", DS, $key);
     $importDir = Mage::getBaseDir('skin') . DS . 'frontend' . DS . $key . DS . 'import' . DS;
     $fileType = '.json';
     $files = glob($importDir . '*' . $fileType);
     $outputs = array();
     $outputs[] = array('label' => '-- Please Select --', 'value' => '');
     foreach ($files as $k => $v) {
         $labelFile = str_replace($importDir, "", $v);
         $file_content = file_get_contents($v);
         $file_content = Mage::helper('core')->jsonDecode($file_content);
         $created_at = $comment = '';
         if (isset($file_content['created_at']) && $file_content['created_at'] != '') {
             $created_at = ' - ' . $file_content['created_at'];
         }
         if (isset($file_content['comment']) && $file_content['comment'] != '') {
             $comment = ' - ' . $file_content['comment'];
         }
         $labelFile = $labelFile . ' ' . $created_at . ' ' . $comment;
         $outputs[] = array('label' => $labelFile, 'value' => $v);
     }
     $outputs[] = array('value' => 'data_import_file', 'label' => Mage::helper('themesettings')->__('Upload custom file...'));
     return $outputs;
 }
Example #2
0
 /**
  * Extracting available images
  *
  * @param string $thumbSize dimensions of thumbnail image (either number of width pixels or {width]x{height}
  * @param string $imageSize dimensions of detail image (either number of width pixels or {width]x{height}
  * @return unknown
  */
 public function getImages($thumbSize = null, $imageSize = null)
 {
     if (!($faq = $this->getFaq())) {
         return false;
     }
     // read images from dataset
     $images = $faq->getImage();
     $result = array();
     // if we have found images - process them
     if (is_array($images) && !empty($images)) {
         // get media model
         $mediaConfig = Mage::getSingleton('faq/faq_media_config');
         $mediaModel = Mage::getSingleton('media/image')->setConfig($mediaConfig);
         // iterate through images
         foreach ($images as $image) {
             // only go on if the image can be found
             if (file_exists(Mage::getBaseDir('media') . DS . 'faq' . DS . $image)) {
                 // gather needed information
                 $newImage = array('original' => $image, 'galleryUrl' => $this->getGalleryUrl($image));
                 if ($thumbSize) {
                     $newImage['src'] = $mediaModel->getSpecialLink($image, $thumbSize);
                 }
                 if ($imageSize) {
                     $newImage['href'] = $mediaModel->getSpecialLink($image, $imageSize);
                     $newImage['width'] = intval($imageSize);
                 } else {
                     $newImage['href'] = Mage::getBaseUrl('media') . '/faq/' . $image;
                     $newImage['width'] = $mediaModel->setFileName($image)->getDimensions()->getWidth();
                 }
                 $result[] = $newImage;
             }
         }
     }
     return $result;
 }
 /**
  * (non-PHPdoc)
  * @see lib/Varien/Varien_Object#_construct()
  */
 public function _construct()
 {
     // Note that the channel_id refers to the key field in your database table.
     $this->_init('manager/channel', 'channel_id');
     // initialize the PEAR service implementation
     $this->_service = Faett_Core_Factory::get(Mage::getBaseDir());
 }
 /**
  * Retrieve all options array
  *
  * @return array
  */
 public function getAllOptions()
 {
     $taxonomyPath = Mage::getBaseDir() . self::TAXONOMY_FILE_PATH;
     $lang = Mage::getStoreConfig('general/locale/code', Mage::app()->getRequest()->getParam('store', 0));
     $taxonomyFile = $taxonomyPath . "taxonomy-with-ids." . $lang . ".txt";
     if (!file_exists($taxonomyFile)) {
         $taxonomyFile = $taxonomyPath . "taxonomy-with-ids.en_US.txt";
     }
     if (is_null($this->_options)) {
         $this->_options = array();
         $this->_options[0] = array('value' => 0, 'label' => "0 Other");
         if (($fh = fopen($taxonomyFile, "r")) !== false) {
             $line = 0;
             while (($category = fgets($fh)) !== false) {
                 $line++;
                 if ($line === 1) {
                     continue;
                 }
                 // skip first line
                 $option = explode(' - ', $category);
                 $this->_options[] = array('value' => $option[0], 'label' => $category);
             }
         }
     }
     return $this->_options;
 }
Example #5
0
 /**
  * Create Backup
  *
  * @return Mage_Log_Model_Cron
  */
 public function scheduledBackup()
 {
     if (!Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_ENABLED)) {
         return $this;
     }
     if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
         Mage::helper('backup')->turnOnMaintenanceMode();
     }
     $type = Mage::getStoreConfig(self::XML_PATH_BACKUP_TYPE);
     $this->_errors = array();
     try {
         $backupManager = Mage_Backup::getBackupInstance($type)->setBackupExtension(Mage::helper('backup')->getExtensionByType($type))->setTime(time())->setBackupsDir(Mage::helper('backup')->getBackupsDir());
         Mage::register('backup_manager', $backupManager);
         if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
             $backupManager->setRootDir(Mage::getBaseDir())->addIgnorePaths(Mage::helper('backup')->getBackupIgnorePaths());
         }
         $backupManager->create();
         Mage::log(Mage::helper('backup')->getCreateSuccessMessageByType($type));
     } catch (Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         Mage::log($e->getMessage(), Zend_Log::ERR);
         Mage::logException($e);
     }
     if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
         Mage::helper('backup')->turnOffMaintenanceMode();
     }
     return $this;
 }
    /**
     * @title "Execution Time Test"
     * @description "Execution Time Test"
     * @new_line
     */
    public function testExecutionTimeAction()
    {
        ini_set('display_errors', 1);
        $seconds = (int) $this->getRequest()->getParam('seconds', null);
        $logDir = Mage::getBaseDir('var') . DS . 'log' . DS;
        $fileName = 'm2epro_execution_time.log';
        $isLogFileExists = is_file($logDir . $fileName);
        if ($seconds) {
            $isLogFileExists && unlink($logDir . $fileName);
            $i = 0;
            while ($i < $seconds) {
                sleep(1);
                ++$i % 10 == 0 && Mage::log("{$i} seconds passed", null, $fileName, 1);
            }
            echo "<div>{$seconds} seconds passed successfully!</div><br/>";
        }
        if ($isLogFileExists) {
            $contentsRows = explode("\n", file_get_contents($logDir . $fileName));
            if (count($contentsRows) >= 2) {
                $lastRecord = trim($contentsRows[count($contentsRows) - 2], "\r\n");
                echo "<button onclick=\"alert('{$lastRecord}')\">show prev. log</button>";
            }
        }
        $url = Mage::helper('adminhtml')->getUrl('*/*/*');
        return print <<<HTML
<form action="{$url}" method="get">
    <input type="text" name="seconds" class="input-text" value="180" style="text-align: right; width: 100px" />
    <button type="submit">Test</button>
</form>
HTML;
    }
 function is_writable($is_use_session = true)
 {
     $dir = Mage::getBaseDir('var') . DS;
     $msg = false;
     if (is_writable($dir)) {
         $dir .= 'ThememanagerExport' . DS;
         if (file_exists($dir)) {
             if (!is_dir($dir)) {
                 $msg = Mage::helper('thememanager')->__('"%s" is not a dir', $dir);
             }
         } else {
             mkdir($dir, 0777);
         }
         if (!is_writable($dir)) {
             $msg = Mage::helper('thememanager')->__('"%s" is not writable', $dir);
         }
     } else {
         $msg = Mage::helper('thememanager')->__('"%s" is not writable', $dir);
     }
     if ($msg) {
         $this->error_msg[] = $msg;
         if ($is_use_session) {
             Mage::getSingleton('core/session')->addError($msg);
         }
         return false;
     } else {
         $this->files_dir = $dir . date('U') . DS;
         mkdir($this->files_dir, 0777);
         return $this->files_dir;
     }
 }
Example #8
0
 /**
  * @return Varien_Io_Abstract
  */
 public function getResource($forWrite = false)
 {
     if (!$this->_resource) {
         $type = $this->getVar('type', 'file');
         $className = 'Varien_Io_' . ucwords($type);
         $this->_resource = new $className();
         $isError = false;
         $ioConfig = $this->getVars();
         switch ($this->getVar('type', 'file')) {
             case 'file':
                 //validate export/import path
                 $path = rtrim($ioConfig['path'], '\\/') . DS . $ioConfig['filename'];
                 /** @var $validator Mage_Core_Model_File_Validator_AvailablePath */
                 $validator = Mage::getModel('core/file_validator_availablePath');
                 $validator->setPaths(Mage::getStoreConfig(self::XML_PATH_EXPORT_LOCAL_VALID_PATH));
                 if (!$validator->isValid($path)) {
                     foreach ($validator->getMessages() as $message) {
                         Mage::throwException($message);
                         return false;
                     }
                 }
                 if (preg_match('#^' . preg_quote(DS, '#') . '#', $this->getVar('path')) || preg_match('#^[a-z]:' . preg_quote(DS, '#') . '#i', $this->getVar('path'))) {
                     $path = $this->_resource->getCleanPath($this->getVar('path'));
                 } else {
                     $baseDir = Mage::getBaseDir();
                     $path = $this->_resource->getCleanPath($baseDir . DS . trim($this->getVar('path'), DS));
                 }
                 $this->_resource->checkAndCreateFolder($path);
                 $realPath = realpath($path);
                 if (!$isError && $realPath === false) {
                     $message = Mage::helper('dataflow')->__('The destination folder "%s" does not exist or there is no access to create it.', $ioConfig['path']);
                     Mage::throwException($message);
                 } elseif (!$isError && !is_dir($realPath)) {
                     $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a directory.', $realPath);
                     Mage::throwException($message);
                 } elseif (!$isError) {
                     if ($forWrite && !is_writeable($realPath)) {
                         $message = Mage::helper('dataflow')->__('Destination folder "%s" is not writable.', $realPath);
                         Mage::throwException($message);
                     } else {
                         $ioConfig['path'] = rtrim($realPath, DS);
                     }
                 }
                 break;
             default:
                 $ioConfig['path'] = rtrim($this->getVar('path'), '/');
                 break;
         }
         if ($isError) {
             return false;
         }
         try {
             $this->_resource->open($ioConfig);
         } catch (Exception $e) {
             $message = Mage::helper('dataflow')->__('An error occurred while opening file: "%s".', $e->getMessage());
             Mage::throwException($message);
         }
     }
     return $this->_resource;
 }
Example #9
0
 public function getCsvFileEnhanced()
 {
     $collectionData = $this->getCollection()->getData();
     $this->_isExport = true;
     $io = new Varien_Io_File();
     $path = Mage::getBaseDir('var') . DS . 'export' . DS;
     $name = md5(microtime());
     $file = $path . DS . $name . '.csv';
     while (file_exists($file)) {
         sleep(1);
         $name = md5(microtime());
         $file = $path . DS . $name . '.csv';
     }
     $io->setAllowCreateFolders(true);
     $io->open(array('path' => $path));
     $io->streamOpen($file, 'w+');
     $io->streamLock(true);
     if ($this->_columns) {
         $io->streamWriteCsv($this->_columns);
     }
     foreach ($collectionData as $item) {
         if ($this->_removeIndexes && is_array($this->_removeIndexes)) {
             foreach ($this->_removeIndexes as $index) {
                 unset($item[$index]);
             }
         }
         $io->streamWriteCsv($item);
     }
     $io->streamUnlock();
     $io->streamClose();
     return array('type' => 'filename', 'value' => $file, 'rm' => true);
 }
Example #10
0
 public function __construct()
 {
     $this->localFolder = Mage::getBaseDir('var') . DS . 'lecom';
     $this->localInbound = $this->localFolder . DS . 'inbound';
     $this->localInboundOrdship = $this->localInbound . DS . 'ordshipment' . DS;
     $this->localInboundOrdshipArcv = $this->localInbound . DS . 'ordshipment_arcv' . DS;
     $this->localInboundOrdshipErr = $this->localInbound . DS . 'ordshipment_err' . DS;
     $remoteInboundOrdship = Mage::getStoreConfig('orders/paths/otfshipment');
     $this->remoteInboundOrdship = trim($remoteInboundOrdship);
     Mage::getModel('logger/logger')->saveLogger("order_shipment", "Information", __FILE__, "DB Inbound Path:" . $this->remoteInboundOrdship);
     if (empty($this->remoteInboundOrdship)) {
         $this->remoteInboundOrdship = '/mnt/lecomotf/inbound/ordshipment/';
     }
     if (!is_dir($this->localFolder)) {
         mkdir($this->localFolder, 0777);
         chmod($this->localFolder, 0777);
     }
     if (!is_dir($this->localInbound)) {
         mkdir($this->localInbound, 0777);
         chmod($this->localInbound, 0777);
     }
     if (!is_dir($this->localInboundOrdship)) {
         mkdir($this->localInboundOrdship, 0777);
         chmod($this->localInboundOrdship, 0777);
     }
     if (!is_dir($this->localInboundOrdshipArcv)) {
         mkdir($this->localInboundOrdshipArcv, 0777);
         chmod($this->localInboundOrdshipArcv, 0777);
     }
     if (!is_dir($this->localInboundOrdshipErr)) {
         mkdir($this->localInboundOrdshipErr, 0777);
         chmod($this->localInboundOrdshipErr, 0777);
     }
 }
Example #11
0
 public function resize($width, $height)
 {
     if (!($imageUrl = $this->getImageUrl())) {
         return '';
     }
     $dir = Mage::getBaseDir('media') . DS . "testimonials" . DS . "pictures" . DS . "resized";
     if (!file_exists($dir)) {
         mkdir($dir, 0777);
     }
     $imageName = substr(strrchr($imageUrl, "/"), 1);
     $imageName = $width . '_' . $height . '_' . $imageName;
     $imageResized = $dir . DS . $imageName;
     $imagePath = str_replace(Mage::getBaseUrl('media'), 'media/', $imageUrl);
     $imagePath = Mage::getBaseDir() . DS . str_replace("/", DS, $imagePath);
     if (!file_exists($imageResized) && file_exists($imagePath)) {
         $imageObj = new Varien_Image($imagePath);
         $imageObj->constrainOnly(true);
         $imageObj->keepAspectRatio(true);
         $imageObj->keepFrame(false);
         $imageObj->keepTransparency(true);
         $imageObj->resize($width, $height);
         $imageObj->save($imageResized);
     }
     $imageUrl = Mage::getBaseUrl('media') . "testimonials/pictures/resized/" . $imageName;
     return $imageUrl;
 }
Example #12
0
 public function getShortImageSize($item)
 {
     $width_max = Mage::getStoreConfig('clnews/news/shortdescr_image_max_width');
     $height_max = Mage::getStoreConfig('clnews/news/shortdescr_image_max_height');
     if (Mage::getStoreConfig('clnews/news/resize_to_max') == 1) {
         $width = $width_max;
         $height = $height_max;
     } else {
         $imageObj = new Varien_Image(Mage::getBaseDir('media') . DS . $item->getImageShortContent());
         $original_width = $imageObj->getOriginalWidth();
         $original_height = $imageObj->getOriginalHeight();
         if ($original_width > $width_max) {
             $width = $width_max;
         } else {
             $width = $original_width;
         }
         if ($original_height > $height_max) {
             $height = $height_max;
         } else {
             $height = $original_height;
         }
     }
     if ($item->getShortWidthResize()) {
         $width = $item->getShortWidthResize();
     } else {
         $width;
     }
     if ($item->getShortHeightResize()) {
         $height = $item->getShortHeightResize();
     } else {
         $height;
     }
     return array('width' => $width, 'height' => $height);
 }
Example #13
0
 public function getPostImage($width = false, $height = false)
 {
     $img = $this->getData('post_image');
     if (empty($img)) {
         return false;
     }
     $imgDir = dirname($img);
     $imgFile = basename($img);
     if (!$width) {
         return $img;
     }
     //if(!$height) $height = $width;
     $imageUrl = Mage::getBaseDir('media') . DS . $img;
     if (!is_file($imageUrl)) {
         return false;
     }
     $imageResized = Mage::getBaseDir('media') . DS . $imgDir . "/resized/" . $width . "x" . $height . DS . $imgFile;
     if (file_exists($imageResized)) {
         return $imgDir . "/resized/" . $width . "x" . $height . DS . $imgFile;
     }
     $imageObj = new Varien_Image($imageUrl);
     $imageObj->constrainOnly(TRUE);
     $imageObj->keepAspectRatio(TRUE);
     $imageObj->keepFrame(FALSE);
     $imageObj->quality(100);
     $imageObj->resize($width, $height);
     $imageObj->save($imageResized);
     return $imgDir . "/resized/" . $width . "x" . $height . DS . $imgFile;
 }
 /**
  * Assemble themes inheritance config
  *
  */
 public function __construct(array $params = array())
 {
     if (isset($params['designRoot'])) {
         if (!is_dir($params['designRoot'])) {
             throw new Mage_Core_Exception("Design root '{$params['designRoot']}' isn't a directory.");
         }
         $this->_designRoot = $params['designRoot'];
     } else {
         $this->_designRoot = Mage::getBaseDir('design');
     }
     $this->_cacheChecksum = null;
     $this->setCacheId('config_theme');
     $this->setCache(Mage::app()->getCache());
     if (!$this->loadCache()) {
         $this->loadString('<theme />');
         $path = str_replace('/', DS, $this->_designRoot . '/*/*/*/etc/theme.xml');
         $files = glob($path);
         foreach ($files as $file) {
             $config = new Varien_Simplexml_Config();
             $config->loadFile($file);
             list($area, $package, $theme) = $this->_getThemePathSegments($file);
             $this->setNode($area . '/' . $package . '/' . $theme, null);
             $this->getNode($area . '/' . $package . '/' . $theme)->extend($config->getNode());
         }
         $this->saveCache();
     }
 }
Example #15
0
 public function process(array $csvData, $cid, $imageDir)
 {
     $cnt = count($csvData);
     $importDir = Mage::getBaseDir() . DS . 'media' . DS . 'marketplace' . DS . $cid . DS . $imageDir . DS;
     if ($cnt > 1) {
         for ($i = 1; $i < $cnt; $i++) {
             try {
                 $sku = $csvData[$i][0];
                 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
                 $fileName = trim($csvData[$i][11]);
                 $filePath = $importDir . $fileName;
                 if (file_exists($filePath) && $fileName != '') {
                     $types = array('image', 'small_image', 'thumbnail');
                     foreach ($types as $type) {
                         $product->addImageToMediaGallery($filePath, array($type), false);
                     }
                     $mediaGallery = $product->getMediaGallery();
                     if (isset($mediaGallery['images'])) {
                         foreach ($mediaGallery['images'] as $key => $image) {
                             Mage::getSingleton('catalog/product_action')->updateAttributes(array($product->getId()), array($types[$key] => $image['file']), 0);
                         }
                     }
                     $product->save();
                     unlink($filePath);
                 } else {
                     $message = 'Image does not exist for sku ' . $sku;
                     Mage::log($message, null, 'sellerimages_debug.log', true);
                 }
             } catch (Exception $e) {
                 Mage::logException($e);
             }
         }
     }
     return true;
 }
Example #16
0
 /**
  * import images
  *
  * @access public
  * @param $product, $image, $sku
  * @return void
  * 
  */
 private function importImages($product, $image, $sku)
 {
     $image_url = $image['img'];
     $image_url = str_replace("https://", "http://", $image_url);
     $image_type = substr(strrchr($image_url, "."), 1);
     $split = explode("?", $image_type);
     $image_type = $split[0];
     $imgName = basename($image_url);
     $imgName = str_replace('.' . $image_type, "", $imgName);
     $filename = md5($imgName . $sku) . '.' . $image_type;
     $dirPath = Mage::getBaseDir('media') . DS . 'import';
     if (!file_exists($dirPath)) {
         mkdir($dirPath, 0777, true);
     }
     $filepath = $dirPath . DS . $filename;
     $curl_handle = curl_init();
     curl_setopt($curl_handle, CURLOPT_URL, $image_url);
     curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
     curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Cirkel');
     $query = curl_exec($curl_handle);
     curl_close($curl_handle);
     file_put_contents($filepath, $query);
     if (file_exists($filepath)) {
         $attrIMG = array();
         if (array_key_exists('main', $image)) {
             if ($image['main'] == true) {
                 $attrIMG = array('image', 'thumbnail', 'small_image');
             }
         }
         $productMG = Mage::getModel('catalog/product')->loadByAttribute('sku', $product->getSku());
         $productMG->addImageToMediaGallery($filepath, $attrIMG, false, false);
         $productMG->save();
     }
 }
Example #17
0
 /**
  * Change encryption key
  *
  * @throws Exception
  * @param string $key
  * @return string
  */
 public function changeEncryptionKey($key = null)
 {
     // prepare new key, encryptor and new file contents
     $file = Mage::getBaseDir('etc') . DS . 'local.xml';
     if (!is_writeable($file)) {
         throw new Exception(Mage::helper('enterprise_pci')->__('File %s is not writeable.', realpath($file)));
     }
     $contents = file_get_contents($file);
     if (null === $key) {
         $key = md5(time());
     }
     $this->_encryptor = clone Mage::helper('core')->getEncryptor();
     $this->_encryptor->setNewKey($key);
     $contents = preg_replace('/<key><\\!\\[CDATA\\[(.+?)\\]\\]><\\/key>/s', '<key><![CDATA[' . $this->_encryptor->exportKeys() . ']]></key>', $contents);
     // update database and local.xml
     $this->beginTransaction();
     try {
         $this->_reEncryptSystemConfigurationValues();
         $this->_reEncryptCreditCardNumbers();
         file_put_contents($file, $contents);
         $this->commit();
         return $key;
     } catch (Exception $e) {
         $this->rollBack();
         throw $e;
     }
 }
Example #18
0
 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  */
 public function 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 = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $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);
         }
         /** @TODO ??? */
         return;
     }
 }
Example #19
0
 public function start()
 {
     Varien_Profiler::start(__METHOD__ . '/setOptions');
     $options = array('save_path' => Mage::getBaseDir('session'), 'use_only_cookies' => 'off', 'throw_startup_exceptions' => E_ALL ^ E_NOTICE);
     if ($this->getCookieDomain()) {
         $options['cookie_domain'] = $this->getCookieDomain();
     }
     if ($this->getCookiePath()) {
         $options['cookie_path'] = $this->getCookiePath();
     }
     if ($this->getCookieLifetime()) {
         $options['cookie_lifetime'] = $this->getCookieLifetime();
     }
     Zend_Session::setOptions($options);
     Varien_Profiler::stop(__METHOD__ . '/setOptions');
     /*
             Varien_Profiler::start(__METHOD__.'/setHandler');
             $sessionResource = Mage::getResourceSingleton('core/session');
             if ($sessionResource->hasConnection()) {
                 Zend_Session::setSaveHandler($sessionResource);
             }
             Varien_Profiler::stop(__METHOD__.'/setHandler');
     */
     Varien_Profiler::start(__METHOD__ . '/start');
     Zend_Session::start();
     Varien_Profiler::stop(__METHOD__ . '/start');
     return $this;
 }
 /**
  * prevAction Preview Assign product controller action
  * @var Int $id Assign product id
  * @var Object $model Assign product model object
  * @var Object $products Catalog product model object
  * @var String $mediDir Conatines Media deirectory path
  * @var String $imagesdir Conatines Assign product image directory path
  * @var String $url Assign product image url
  * @var Array $products Assign product details
  * @return JSON $products Assign product detail in json format
  */
 public function prevAction()
 {
     $id = $this->getRequest()->getParam('id');
     $model = Mage::getModel('mpassignproduct/mpassignproduct')->load($id);
     $products = Mage::getModel('catalog/product')->load($model->getProductId())->toArray();
     $mediDir = Mage::getBaseDir('media');
     $imagesdir = $mediDir . '/mpassignproduct/' . $id . '/';
     $url = 0;
     if (file_exists($imagesdir)) {
         foreach (new DirectoryIterator($imagesdir) as $fileInfo) {
             if ($fileInfo->isDot() || $fileInfo->isDir()) {
                 continue;
             }
             if ($fileInfo->isFile()) {
                 $url = Mage::getBaseUrl('media') . 'mpassignproduct/' . $id . '/' . $fileInfo;
                 break;
             }
         }
     }
     if (!$url) {
         $url = Mage::getDesign()->getSkinUrl('images/catalog/product/placeholder/', array('_area' => 'frontend')) . "image.jpg";
     }
     $products['price'] = $model->getPrice();
     $products['description'] = $model->getProductDescription();
     $products['url'] = $url;
     echo json_encode($products);
 }
 /**
  * Set base dir
  */
 public function __construct()
 {
     $this->_baseDir = Mage::getBaseDir('var') . DS . 'connect';
     $io = new Varien_Io_File();
     $io->setAllowCreateFolders(true)->createDestinationDir($this->_baseDir);
     $this->addTargetDir($this->_baseDir);
 }
Example #22
0
 protected function _doUpload()
 {
     $uploadDir = Mage::getBaseDir('media') . DIRECTORY_SEPARATOR . 'amcustomerattr' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
     /**
      * Deleting
      */
     $toDelete = Mage::app()->getRequest()->getPost('amcustomerattr_icon_delete');
     if ($toDelete) {
         foreach ($toDelete as $optionId => $del) {
             if ($del) {
                 @unlink($uploadDir . $optionId . '.jpg');
             }
         }
     }
     /**
      * Uploading files
      */
     if (isset($_FILES['amcustomerattr_icon']) && isset($_FILES['amcustomerattr_icon']['error'])) {
         foreach ($_FILES['amcustomerattr_icon']['error'] as $optionId => $errorCode) {
             if (UPLOAD_ERR_OK == $errorCode) {
                 if (!is_dir($uploadDir)) {
                     mkdir($uploadDir, 0755, true);
                 }
                 move_uploaded_file($_FILES['amcustomerattr_icon']['tmp_name'][$optionId], $uploadDir . $optionId . '.jpg');
             }
         }
     }
 }
 public function _afterCreditmemoSave(Varien_Event_Observer $event)
 {
     $base_path = Mage::getBaseDir('base');
     $orgin_string = str_replace(PHP_EOL, '', file_get_contents($base_path . "/app/code/local/Nextorder/Refundbanking/Helper/sepaCheck.txt"));
     if ($orgin_string == 0) {
         return true;
     } else {
         $incrementCreditID = $event->getEvent()->getDataObject()->getCreditmemo()->getIncrementId();
         if (file_exists($base_path . "/media/Sepa_Gutschrift/" . $incrementCreditID . ".xml")) {
             //            Mage::log( "it works!!!!!!!!!!!: test ", null, 'xulin.log');
             return true;
         } else {
             $adminUser = Mage::getSingleton('admin/session')->getUser()->getUsername();
             //        $order = $event->getEvent()->getOrder();
             $Grand_Total = $event->getEvent()->getDataObject()->getCreditmemo()->getData('grand_total');
             //        $Base_Total = $event->getEvent()->getDataObject()->getCreditmemo()->getData('base_grand_total');
             //        Mage::log($event->getEvent()->getDataObject()->getCreditmemo()->getData() , null, 'xulin.log');
             $helper = Mage::helper("refundbanking/data");
             $orderNr = $event->getEvent()->getDataObject()->getCreditmemo()->getData('order_id');
             $order = Mage::getModel('sales/order')->load($orderNr);
             $payment_code = $order->getPayment()->getMethodInstance()->getCode();
             $paymentPools = array('ops_cc', 'paypal_billing_agreement', 'paypal_express');
             //        Mage::log( "it works +1", null, 'xulin.log');
             if ($helper->isConfig($payment_code)) {
                 $kontoInfos_shop = $helper->getKontonForRefund($payment_code);
                 $customer = Mage::getModel('customer/customer')->load($order->getData('customer_id'));
                 $urlForXML = $helper->getSepaXML($customer->getData('debit_payment_acount_name'), $customer->getId(), $customer->getData('debit_payment_account_iban'), $customer->getData('debit_payment_account_swift'), $kontoInfos_shop['inhaber'], $kontoInfos_shop['iban'], $kontoInfos_shop['bic'], $order->getIncrementId(), $incrementCreditID, $Grand_Total);
                 Mage::getSingleton('adminhtml/session')->addSuccess("Sepa XML Gutschrit ist von User " . $adminUser . " erstellt.<a href='" . str_replace('index.php/', '', Mage::getUrl()) . "media/Sepa_Gutschrift/" . $incrementCreditID . ".xml' download> Zum Download </a>");
                 $event->getEvent()->getDataObject()->getCreditmemo()->addComment("Sepa XML Gutschrit ist von User " . $adminUser . " erstellt.<a href='" . str_replace('index.php/', '', Mage::getUrl()) . "media/Sepa_Gutschrift/" . $incrementCreditID . ".xml' download> Zum Download </a>", true, true);
             }
         }
     }
 }
Example #24
0
 public function __construct()
 {
     //Create paths
     $this->_generatedCssFolder = 'css/_config/';
     $this->_generatedCssPath = 'frontend/mtghost/default/' . $this->_generatedCssFolder;
     $this->_generatedCssDir = Mage::getBaseDir('skin') . '/' . $this->_generatedCssPath;
 }
Example #25
0
 public function resizeImg($fileName, $width, $height = '')
 {
     $folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
     $imageURL = $folderURL . $fileName;
     $basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $fileName;
     $newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . "resized" . DS . $fileName;
     //if width empty then return original size image's URL
     if ($width != '') {
         //if image has already resized then just return URL
         if (file_exists($basePath) && is_file($basePath) && !file_exists($newPath)) {
             $imageObj = new Varien_Image($basePath);
             $imageObj->constrainOnly(TRUE);
             $imageObj->keepAspectRatio(TRUE);
             $imageObj->keepFrame(TRUE);
             $imageObj->backgroundColor(array(255, 255, 255));
             // white background!
             $imageObj->resize($width, $height);
             $imageObj->save($newPath);
         }
         $resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "resized" . DS . $fileName;
     } else {
         $resizedURL = $imageURL;
     }
     return $resizedURL;
 }
 /**
  * @test
  */
 public function scheduleJobAndRunCron()
 {
     $sameRequest = false;
     if ($sameRequest) {
         // dispatch event
         $event = new Varien_Event_Observer(array('include_groups' => array($this->groups['groupA'])));
         $observer = new Aoe_Scheduler_Model_Observer();
         $observer->dispatch($event);
     } else {
         $this->exec('cd ' . Mage::getBaseDir() . '/shell && /usr/bin/php scheduler.php --action cron --mode always --includeGroups ' . $this->groups['groupA']);
     }
     $schedulesJobWithGroupA = Mage::getModel('cron/schedule')->getCollection()->addFieldToFilter('job_code', $this->jobs['jobWithGroupA']->getJobCode());
     $this->assertCount(1, $schedulesJobWithGroupA);
     foreach ($schedulesJobWithGroupA as $schedule) {
         /* @var $schedule Aoe_Scheduler_Model_Schedule */
         $this->assertEquals(Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS, $schedule->getStatus());
     }
     $schedulesJobWithGroupB = Mage::getModel('cron/schedule')->getCollection()->addFieldToFilter('job_code', $this->jobs['jobWithGroupB']->getJobCode());
     $this->assertCount(0, $schedulesJobWithGroupB);
     $schedulesJobWithGroupAandB = Mage::getModel('cron/schedule')->getCollection()->addFieldToFilter('job_code', $this->jobs['jobWithGroupAandB']->getJobCode());
     $this->assertCount(1, $schedulesJobWithGroupAandB);
     foreach ($schedulesJobWithGroupAandB as $schedule) {
         /* @var $schedule Aoe_Scheduler_Model_Schedule */
         $this->assertEquals(Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS, $schedule->getStatus());
     }
 }
Example #27
0
 /**
  * Renders grid column
  *
  * @param Varien_Object $row
  * @return string
  */
 public function render(Varien_Object $row)
 {
     if ($data = $row->getData($this->getColumn()->getIndex())) {
         if (Mage::app()->getLocale()->getLocale() == 'fa_IR') {
             require_once Mage::getBaseDir('lib') . '/pdate/pdate.php';
             $time = strtotime($data);
             $data = pdate('Y-m-d H:i:s', $time);
         }
         switch ($this->getColumn()->getPeriodType()) {
             case 'month':
                 $dateFormat = 'yyyy-MM';
                 break;
             case 'year':
                 $dateFormat = 'yyyy';
                 break;
             default:
                 $dateFormat = Varien_Date::DATE_INTERNAL_FORMAT;
                 break;
         }
         $format = $this->_getFormat();
         try {
             $data = $this->getColumn()->getGmtoffset() ? Mage::app()->getLocale()->date($data, $dateFormat)->toString($format) : Mage::getSingleton('core/locale')->date($data, Zend_Date::ISO_8601, null, false)->toString($format);
         } catch (Exception $e) {
             $data = $this->getColumn()->getTimezone() ? Mage::app()->getLocale()->date($data, $dateFormat)->toString($format) : Mage::getSingleton('core/locale')->date($data, $dateFormat, null, false)->toString($format);
         }
         return $data;
     }
     return $this->getColumn()->getDefault();
 }
 /**
  * Save form action
  */
 public function saveAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $data = $this->getRequest()->getPost();
             if (isset($_FILES['testimonial_img']['name']) and file_exists($_FILES['testimonial_img']['tmp_name'])) {
                 $uploader = new Varien_File_Uploader('testimonial_img');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $path = Mage::getBaseDir('media') . DS;
                 $uploader->save($path, $_FILES['testimonial_img']['name']);
                 $data['testimonial_img'] = $_FILES['testimonial_img']['name'];
             } else {
                 if (isset($data['testimonial_img']['delete']) && $data['testimonial_img']['delete'] == 1) {
                     $data['testimonial_img'] = '';
                 } else {
                     unset($data['testimonial_img']);
                 }
             }
             $model = Mage::getModel('turnkeye_testimonial/testimonial');
             $model->setData($data)->setTestimonialId($this->getRequest()->getParam('id'))->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('turnkeye_testimonial')->__('Testimonial was successfully saved'));
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
Example #29
0
 public function run()
 {
     // prepare
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
     // verbose mode?
     $verbose = $this->getArg('verbose');
     $mygassi = $this->getArg('mygassionly');
     $limit = $this->getArg('limit');
     $product = $this->getArg('product');
     if ($limit === false) {
         $limit = 100;
     }
     // check what we're up to
     if ($this->getArg('import')) {
         /** @var $importer Codex_Productimport_Model_Import */
         $importer = Mage::getModel('codex_productimport/import');
         if ($product) {
             $importer->importSingleProduct($product, false);
         } else {
             $importer->importProducts($limit, $mygassi, $verbose);
         }
         // clean image cache
         exec("rm -Rf " . Mage::getBaseDir('media') . '/catalog/product/cache');
     } else {
         if ($this->getArg('dump')) {
             /** @var $importer Codex_Productimport_Model_Import */
             $importer = Mage::getModel('codex_productimport/import');
             $importer->dumpProducts($limit, $mygassi, $verbose, $product);
         } else {
             $this->usageHelp();
         }
     }
 }
Example #30
0
 private function getTempImportDir()
 {
     if (!$this->_tempImportDir) {
         $this->_tempImportDir = Mage::getBaseDir('var') . '/sftptmp/';
     }
     return $this->_tempImportDir;
 }