Пример #1
0
 /**
  * downloads a file
  *
  * @return void
  */
 function downloadFile()
 {
     $user = JFactory::getUser();
     $productfile_id = intval(JRequest::getvar('id', '', 'request', 'int'));
     $product_id = intval(JRequest::getvar('product_id', '', 'request', 'int'));
     $link = 'index.php?option=com_tienda&view=products&task=edit&id=' . $product_id;
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance('ProductDownload', 'TiendaHelper');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
     $productfile = JTable::getInstance('ProductFiles', 'TiendaTable');
     $productfile->load($productfile_id);
     if (empty($productfile->productfile_id)) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_INVALID FILE');
         $this->setRedirect($link, $this->message, $this->messagetype);
         return false;
     }
     // log and download
     Tienda::load('TiendaFile', 'library.file');
     // geting the ProductDownloadId to updated for which productdownload_max  is greater then 0
     $productToDownload = $helper->getProductDownloadInfo($productfile->productfile_id, $user->id);
     if ($downloadFile = TiendaFile::download($productfile)) {
         $link = JRoute::_($link, false);
         $this->setRedirect($link);
     }
 }
Пример #2
0
 private function _migrateProduct($data)
 {
     // Check for product_name.
     if (!empty($data->product_name)) {
         $isNew = false;
         if (!empty($data->product_id)) {
             if ((int) $data->product_id) {
                 $data['product_id'] = 0;
                 $isNew = true;
             }
         }
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
         $product = JTable::getInstance('Products', 'TiendaTable');
         if (!$isNew) {
             if (!$product->load($data['product_id'])) {
                 $isNew = true;
                 $data['product_id'] = 0;
             }
         }
         // If is a new product, use product->create()
         if ($isNew) {
             $product->product_price = 0;
             $product->product_quantity = 0;
             $product->bind($this->simpleXml2Array($data));
             if ($product->product_full_image) {
                 Tienda::load('TiendaFile', 'library.file');
                 // Do the same cleaning to the image title that the image helper does
                 $name = explode('.', $product->product_full_image);
                 $name = TiendaFile::cleanTitle($name[0]) . '.' . $name[count($name) - 1];
                 $product->product_full_image = $name;
             }
             $product->create();
             $this->_migrateAttributes($product->product_id, $data->product_attributes);
             $this->_migrateCategories($product->product_id, $data->product_categories);
             $this->_migrateFiles($product->product_id, $data->product_files);
             $this->_migrateImages($product->product_id, $data->product_images);
             $this->_migrateChildren($product->product_id, $data->product_children);
             $this->_migrateRelated($product->product_id, $data->related_products);
             $this->_migrateCustomFields($product->product_id, $data->product_custom_fields);
         } else {
             $product->bind($this->simpleXml2Array($data));
             //check if normal price exists
             Tienda::load("TiendaHelperProduct", 'helpers.product');
             $prices = TiendaHelperProduct::getPrices($product->product_id);
             $quantities = TiendaHelperProduct::getProductQuantities($product->product_id);
             if ($product->save()) {
                 $product->product_id = $product->id;
                 // New price?
                 if (empty($prices)) {
                     // set price if new or no prices set
                     $price = JTable::getInstance('Productprices', 'TiendaTable');
                     $price->product_id = $product->id;
                     $price->product_price = (string) $data->product_price;
                     $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                     $price->save();
                 } else {
                     // set price if new or no prices set
                     $price = JTable::getInstance('Productprices', 'TiendaTable');
                     $price->load($prices[0]->product_price_id);
                     $price->product_price = (string) $data->product_price;
                     $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                     $price->save();
                 }
                 // New quantity?
                 if (empty($quantities)) {
                     // save default quantity
                     $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                     $quantity->product_id = $product->id;
                     $quantity->quantity = (string) $data->product_quantity;
                     $quantity->save();
                 } else {
                     // save default quantity
                     $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                     $quantity->load($quantities[0]->productquantity_id);
                     $quantity->product_id = $product->id;
                     $quantity->quantity = (string) $data->product_quantity;
                     $quantity->save();
                 }
             }
         }
         return $product;
     }
     return null;
 }
Пример #3
0
 /**
  * downloads a file
  *
  * @return void
  */
 function downloadFile()
 {
     $user = JFactory::getUser();
     $productfile_id = intval(JRequest::getvar('id', '', 'request', 'int'));
     $product_id = intval(JRequest::getvar('product_id', '', 'request', 'int'));
     $link = 'index.php?option=com_tienda&controller=products&view=products&task=view&id=' . $product_id;
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance('ProductDownload', 'TiendaHelper');
     if (!($canView = $helper->canDownload($productfile_id, JFactory::getUser()->id))) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_NOT_AUTHORIZED_TO_DOWNLOAD_FILE');
         $this->setRedirect($link, $this->message, $this->messagetype);
         return false;
     }
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $productfile = JTable::getInstance('ProductFiles', 'TiendaTable');
     $productfile->load($productfile_id);
     if (empty($productfile->productfile_id)) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_INVALID FILE');
         $this->setRedirect($link, $this->message, $this->messagetype);
         return false;
     }
     // log and download
     Tienda::load('TiendaFile', 'library.file');
     // Log the download
     $productfile->logDownload($user->id);
     // After download complete it will update the productdownloads on the basis of the user
     // geting the ProductDownloadId to updated for which productdownload_max  is greater then 0
     $productToDownload = $helper->getProductDownloadInfo($productfile->productfile_id, $user->id);
     if (!empty($productToDownload)) {
         $productDownload = JTable::getInstance('ProductDownloads', 'TiendaTable');
         $productDownload->load($productToDownload->productdownload_id);
         $productDownload->productdownload_max = $productDownload->productdownload_max - 1;
         if (!$productDownload->save()) {
             // TODO in case product Download is not updating properly .
         }
     }
     if ($downloadFile = TiendaFile::download($productfile)) {
         $link = JRoute::_($link, false);
         $this->setRedirect($link);
     }
 }
Пример #4
0
 /**
  * Do the migration
  *
  * @return array
  */
 function _migrate($datas)
 {
     $queries = array();
     $results = array();
     $n = 0;
     // Loop though the rows
     foreach ($datas as $data) {
         // Check for product_name. Explode() could have generated an empty row
         if (!empty($data['product_name'])) {
             $isNew = false;
             if (!$data['product_id']) {
                 $data['product_id'] = 0;
                 $isNew = true;
             }
             JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
             $product = JTable::getInstance('Products', 'TiendaTable');
             if (!$isNew) {
                 if (!$product->load($data['product_id'])) {
                     $isNew = true;
                     $data['product_id'] = 0;
                 }
             }
             // If is a new product, use product->create()
             if ($isNew) {
                 $product->product_price = 0;
                 $product->product_quantity = 0;
                 $product->bind($data);
                 if ($product->product_full_image) {
                     Tienda::load('TiendaFile', 'library.file');
                     // Do the same cleaning to the image title that the image helper does
                     $name = explode('.', $product->product_full_image);
                     $name = TiendaFile::cleanTitle($name[0]) . '.' . $name[count($name) - 1];
                     $product->product_full_image = $name;
                 }
                 $product->create();
                 $this->_migrateAttributes($product->product_id, $data['product_attributes']);
             } else {
                 $product->bind($data);
                 //check if normal price exists
                 Tienda::load("TiendaHelperProduct", 'helpers.product');
                 $prices = TiendaHelperProduct::getPrices($product->product_id);
                 $quantities = TiendaHelperProduct::getProductQuantities($product->product_id);
                 if ($product->save()) {
                     $product->product_id = $product->id;
                     // New price?
                     if (empty($prices)) {
                         // set price if new or no prices set
                         $price = JTable::getInstance('Productprices', 'TiendaTable');
                         $price->product_id = $product->id;
                         $price->product_price = $data['product_price'];
                         $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                         $price->save();
                     } else {
                         // set price if new or no prices set
                         $price = JTable::getInstance('Productprices', 'TiendaTable');
                         $price->load($prices[0]->product_price_id);
                         $price->product_price = $data['product_price'];
                         $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                         $price->save();
                     }
                     // New quantity?
                     if (empty($quantities)) {
                         // save default quantity
                         $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                         $quantity->product_id = $product->id;
                         $quantity->quantity = $data['product_quantity'];
                         $quantity->save();
                     } else {
                         // save default quantity
                         $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                         $quantity->load($quantities[0]->productquantity_id);
                         $quantity->product_id = $product->id;
                         $quantity->quantity = $data['product_quantity'];
                         $quantity->save();
                     }
                 }
             }
             // at this point, the product is saved, so now do additional relationships
             // such as categories
             if (!empty($product->product_id) && !empty($data['product_categories'])) {
                 foreach ($data['product_categories'] as $category_id) {
                     // This is probably not the best way to do it
                     // Numeric = id, string = category name
                     if (!is_numeric($category_id)) {
                         // check for existance
                         JModel::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'models');
                         $model = JModel::getInstance('Categories', 'TiendaModel');
                         $model->setState('filter_name', $category_id);
                         $matches = $model->getList();
                         $matched = false;
                         if ($matches) {
                             foreach ($matches as $match) {
                                 // is a perfect match?
                                 if (strtolower($category_id) == strtolower($match->category_name)) {
                                     $category_id = $match->category_id;
                                     $matched = true;
                                 }
                             }
                         }
                         // Not matched, create category
                         if (!$matched) {
                             $category = JTable::getInstance('Categories', 'TiendaTable');
                             $category->category_name = $category_id;
                             $category->parent_id = 1;
                             $category->category_enabled = 1;
                             $category->save();
                             $category_id = $category->category_id;
                         }
                     }
                     // save xref in every case
                     $xref = JTable::getInstance('ProductCategories', 'TiendaTable');
                     $xref->product_id = $product->product_id;
                     $xref->category_id = $category_id;
                     $xref->save();
                 }
             }
             $results[$n]->title = $product->product_name;
             $results[$n]->query = "";
             $results[$n]->error = implode('\\n', $product->getErrors());
             $results[$n]->affectedRows = 1;
             $n++;
             $this->_migrateImages($product->product_id, $data['product_images'], $results);
         }
     }
     return $results;
 }
Пример #5
0
 /**
  * 
  * Method to upload and verify file if uploaded
  * @return boolean
  */
 function _verifyFile()
 {
     $state = $this->_getState();
     $success = false;
     // Uploads the file
     Tienda::load('TiendaFile', 'library.file');
     $upload = new TiendaFile();
     // we have to upload the file
     if (@$state->uploaded_file == '') {
         // handle upload creates upload object properties
         $success = $upload->handleUpload('file');
         if ($success) {
             if (strtolower($upload->getExtension()) != 'sql') {
                 $this->setError(JText::_('COM_TIENDA_THIS_IS_NOT_AN_SQL_FILE'));
                 return false;
             }
             // Move the file to let us reuse it
             $upload->setDirectory(JFactory::getConfig()->get('tmp_path', JPATH_SITE . '/tmp'));
             $success = $upload->upload();
             if (!$success) {
                 $this->setError($upload->getError());
                 return false;
             }
             $upload->file_path = $upload->getFullPath();
         } else {
             $this->setError(JText::_('COM_TIENDA_COULD_NOT_UPLOAD_SQL_FILE' . $upload->getError()));
             $success = false;
         }
     } else {
         $upload->full_path = $upload->file_path = @$state->uploaded_file;
         $upload->proper_name = TiendaFile::getProperName(@$state->uploaded_file);
         $success = true;
     }
     if ($success) {
         // Set the uploaded file as the file to use during the real import
         $this->_uploaded_file = $upload->getFullPath();
         $this->_uploaded_filename = str_replace(".sql", "", $upload->physicalname);
     }
     return $success;
 }
Пример #6
0
 function loadImportingData()
 {
     Tienda::load('TiendaFile', 'library.file');
     $this->vars->upload = new TiendaFile();
     $this->vars->upload->full_path = $this->vars->upload->file_path = $this->source_import;
     $this->vars->upload->proper_name = TiendaFile::getProperName($this->source_import);
     // load file
     if (!$this->import_throttled_import) {
         $this->vars->upload->fileToText();
         $this->source_data = $this->vars->upload->fileastext;
     }
     return true;
 }
Пример #7
0
 /**
  * Uploads a file to associate to an item
  *
  * @return unknown_type
  */
 function addfile($fieldname = 'createproductfile_file', $path = 'products_files')
 {
     Tienda::load('TiendaFile', 'library.file');
     $upload = new TiendaFile();
     // handle upload creates upload object properties
     $upload->handleUpload($fieldname);
     // then save image to appropriate folder
     if ($path == 'products_files') {
         $path = Tienda::getPath('products_files');
     }
     $upload->setDirectory($path);
     $dest = $upload->getDirectory() . DS . $upload->getPhysicalName();
     // delete the file if dest exists
     if ($fileexists = JFile::exists($dest)) {
         JFile::delete($dest);
     }
     // save path and filename or just filename
     if (!JFile::upload($upload->file_path, $dest)) {
         $this->setError(sprintf(JText::_('COM_TIENDA_MOVE_FAILED_FROM'), $upload->file_path, $dest));
         return false;
     }
     $upload->full_path = $dest;
     return $upload;
 }