Импорт/экспорт товаров с фотографией в joomshoping

Тема в разделе "Движки", создана пользователем Kluch, 10 янв 2016.

  1. Kluch

    Kluch Новорег

    Регистрация:
    19 дек 2015
    Сообщения:
    189
    Симпатии:
    30
    Розыгрышей:
    0
    Пол:
    Мужской
    В бесплатный магазинах есть такая фишечка- как Импорт/экспорт товаров. Это дело платное стоит 30-70 евро плагинчег. Можно до усрачки искать бесплатный плагин,но в поиске Вам будут выдавать платные модули. Что делать если вы начали парсить товары,и вам нужно их уже закидывать в магазин тысячами и делать это за пару часов. Вы хотите видеть описание,цену,вменяемый url спарсенного товара+ фото хотябы одно.чтобы понимать,что вы вообще загрузили к себе на сайт.Вообщем много было потрачено времени чтобы найти ответ для магазина joomshoping.Нашлось решение для загрузки товара с одной фоткой,ну это лучше чем вообще ничего и достаточно если вы загружаете товары в авто режиме и не пишите каждый товар руками.
    открыть файлы

    administrator\components\com_jshopping\importexport\simpleexport\simpleexport.php
    administrator\components\com_jshopping\importexport\simpleimport\simpleimport.php
    Файл nrexportutf8.php копируем этот код
    <?php
    defined( '_JEXEC' ) or die( 'Restricted access' );
    jimport('joomla.filesystem.folder');

    class IeNRExportUtf8 extends IeController{

    function view(){
    $jshopConfig = JSFactory::getConfig();
    $ie_id = JRequest::getInt("ie_id");
    $_importexport = JTable::getInstance('ImportExport', 'jshop');
    $_importexport->load($ie_id);
    $name = $_importexport->get('name');
    $ie_params_str = $_importexport->get('params');
    $ie_params = parseParamsToArray($ie_params_str);

    $files = JFolder::files($jshopConfig->importexport_path.$_importexport->get('alias'), '.csv');
    $count = count($files);

    JToolBarHelper::title(_JSHOP_EXPORT. ' "'.$name.'"', 'generic.png' );
    JToolBarHelper::custom("backtolistie", "back", 'browser.png', _JSHOP_BACK_TO.' "'._JSHOP_PANEL_IMPORT_EXPORT.'"', false );
    JToolBarHelper::spacer();
    JToolBarHelper::save("save", _JSHOP_EXPORT);

    include(dirname(__FILE__)."/list_csv.php");
    }

    function save(){
    $mainframe = JFactory::getApplication();

    include_once(JPATH_COMPONENT_SITE."/lib/csv.io.class.php");

    $ie_id = JRequest::getInt("ie_id");
    if (!$ie_id) $ie_id = $this->get('ie_id');

    $_importexport = JTable::getInstance('ImportExport', 'jshop');
    $_importexport->load($ie_id);
    $alias = $_importexport->get('alias');
    $_importexport->set('endstart', time());
    $params = JRequest::getVar("params");
    if (is_array($params)){
    $paramsstr = parseArrayToParams($params);
    $_importexport->set('params', $paramsstr);
    }
    $_importexport->store();

    $ie_params_str = $_importexport->get('params');
    $ie_params = parseParamsToArray($ie_params_str);

    $jshopConfig = JSFactory::getConfig();
    $lang = JSFactory::getLang();
    $db = JFactory::getDBO();

    $query = "SELECT
    prod.product_id,
    prod.product_ean,
    prod.product_quantity,
    prod.product_date_added,
    prod.product_price,
    tax.tax_value as tax,
    prod.`".$lang->get('name')."` as name,
    prod.`".$lang->get('short_description')."` as short_description,
    prod.`".$lang->get('description')."` as description,
    cat.`".$lang->get('name')."` as cat_name,
    categ.category_id,
    prod.product_manufacturer_id,
    prod.`".$lang->get('meta_description')."` as meta_description,
    prod.`".$lang->get('meta_keyword')."` as meta_keyword,
    prod.product_publish,
    prod.product_template,
    prod.delivery_times_id,
    prod.image
    FROM `#__jshopping_products` AS prod
    LEFT JOIN `#__jshopping_products_images` AS img USING (product_id)
    LEFT JOIN `#__jshopping_products_to_categories` AS categ USING (product_id)
    LEFT JOIN `#__jshopping_categories` as cat on cat.category_id=categ.category_id
    LEFT JOIN `#__jshopping_taxes` AS tax ON tax.tax_id = prod.product_tax_id
    GROUP BY prod.product_id";
    $db->setQuery($query);
    $products = $db->loadObjectList();

    $data = array();
    $head = array("product_id","ean","qty","date","price","tax","category","name","short_description","description", "category_id", "product_manufacturer_id", "meta_description", "meta_keyword", "product_publish", "product_template", "delivery_times_id","image");
    $data[] = $head;

    foreach($products as $prod){
    $row = array();
    $row[] = $prod->product_id;
    $row[] = $prod->product_ean;
    $row[] = $prod->product_quantity;
    $row[] = $prod->product_date_added;
    $row[] = $prod->product_price;
    $row[] = $prod->tax;
    $row[] = ($prod->cat_name);
    $row[] = ($prod->name);
    $row[] = ($prod->short_description);
    $row[] = ($prod->description);
    $row[] = ($prod->category_id);
    $row[] = ($prod->product_manufacturer_id);
    $row[] = ($prod->meta_description);
    $row[] = ($prod->meta_keyword);
    $row[] = $prod->product_publish;
    $row[] = $prod->product_template;
    $row[] = $prod->delivery_times_id;
    $row[] = $prod->image;
    $data[] = $row;
    }


    $filename = $jshopConfig->importexport_path.$alias."/".$ie_params['filename']."_".date("d-m-Y_H_i").".csv";

    $csv = new csv();
    $csv->write($filename, $data);

    if (!JRequest::getInt("noredirect")){
    $mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=".$ie_id, _JSHOP_COMPLETED);
    }
    }

    function filedelete(){
    $mainframe = JFactory::getApplication();
    $jshopConfig = JSFactory::getConfig();
    $ie_id = JRequest::getInt("ie_id");
    $_importexport = JTable::getInstance('ImportExport', 'jshop');
    $_importexport->load($ie_id);
    $alias = $_importexport->get('alias');
    $file = JRequest::getVar("file");
    $filename = $jshopConfig->importexport_path.$alias."/".$file;
    @unlink($filename);
    $mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=".$ie_id);
    }

    }
    ?>
     
  2. Kluch

    Kluch Новорег

    Регистрация:
    19 дек 2015
    Сообщения:
    189
    Симпатии:
    30
    Розыгрышей:
    0
    Пол:
    Мужской
    Файл nrimportutf8.php копируем и сохраняем
    <?php
    defined( '_JEXEC' ) or die( 'Restricted access' );
    jimport('joomla.filesystem.folder');

    class IeNRImportUtf8 extends IeController{

    function view(){
    $jshopConfig = &JSFactory::getConfig();
    $ie_id = JRequest::getInt("ie_id");
    $_importexport = &JTable::getInstance('ImportExport', 'jshop');
    $_importexport->load($ie_id);
    $name = $_importexport->get('name');

    JToolBarHelper::title(_JSHOP_IMPORT. ' "'.$name.'"', 'generic.png' );
    JToolBarHelper::custom("backtolistie", "back", 'browser.png', _JSHOP_BACK_TO.' "'._JSHOP_PANEL_IMPORT_EXPORT.'"', false );
    JToolBarHelper::spacer();
    JToolBarHelper::save("save", _JSHOP_IMPORT);

    include(dirname(__FILE__)."/form.php");
    }

    function save(){
    $mainframe =& JFactory::getApplication();

    $jshopConfig = &JSFactory::getConfig();
    require_once(JPATH_COMPONENT_SITE.'/lib/uploadfile.class.php');
    require_once(JPATH_COMPONENT_SITE."/lib/csv.io.class.php");

    $ie_id = JRequest::getInt("ie_id");
    if (!$ie_id) $ie_id = $this->get('ie_id');

    $lang = &JSFactory::getLang();
    $db = &JFactory::getDBO();

    $_importexport = &JTable::getInstance('ImportExport', 'jshop');
    $_importexport->load($ie_id);
    $alias = $_importexport->get('alias');
    $_importexport->set('endstart', time());
    $_importexport->store();

    //get list tax
    $query = "SELECT tax_id, tax_value FROM `#__jshopping_taxes`";
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    $listTax = array();
    foreach($rows as $row){
    $listTax[intval($row->tax_value)] = $row->tax_id;
    }
    //

    //get list category
    $query = "SELECT category_id as id, `".$lang->get("name")."` as name FROM `#__jshopping_categories`";
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    $listCat = array();
    foreach($rows as $row){
    $listCat[$row->name] = $row->id;
    }

    $_products = JModelLegacy::getInstance('products', 'JshoppingModel');

    $dir = $jshopConfig->importexport_path.$alias."/";

    $upload = new UploadFile($_FILES['file']);
    $upload->setAllowFile(array('csv'));
    $upload->setDir($dir);
    if ($upload->upload()){
    $filename = $dir."/".$upload->getName();
    @chmod($filename, 0777);
    $csv = new csv();
    $data = $csv->read($filename);
    if (is_array($data)){
    foreach($data as $k=>$row){
    if (count($row)<2 || $k==0) continue;

    $tax_value = intval($row[5]);
    if (!isset($listTax[$tax_value])){
    $tax = JTable::getInstance('tax', 'jshop');
    $tax->set('tax_name', $tax_value);
    $tax->set('tax_value', $tax_value);
    $tax->store();
    $listTax[$tax_value] = $tax->get("tax_id");
    }

    $category_name = $row['6'];
    if (!isset($listCat[$category_name]) && $category_name!=""){
    $cat = JTable::getInstance("category","jshop");
    $query = "SELECT max(ordering) FROM `#__jshopping_categories`";
    $db->setQuery($query);
    $ordering = $db->loadResult() + 1;
    $cat->set($lang->get("name"), $category_name);
    $cat->set("category_ordertype", 1);
    $cat->set("products_sorting", 1);
    $cat->set("products_sorting2", 1);
    $cat->set("products_page", 12);
    $cat->set("products_row", 1);
    $cat->set("category_publish", 0);
    $cat->set("category_ordering", $ordering);
    $cat->store();
    $listCat[$category_name] = $cat->get("category_id");
    }

    $product = JTable::getInstance('product', 'jshop');
    $product_id = $row[0];
    if ($product_id!=""){
    $product->set("product_id", $product_id);
    }
    $product->set("product_ean", $row[1]);
    $product->set("product_quantity", $row[2]);
    $product->set("product_date_added", $row[3]);
    $product->set("product_date_added", date("Y-m-d H:i:s"));
    $product->set("product_price", $row[4]);
    $product->set("product_tax_id", $listTax[$tax_value]);
    $product->set($lang->get("name"), ($row[7]));
    $product->set($lang->get("short_description"), ($row[8]));
    $product->set($lang->get("description"), ($row[9]));
    $product->set("product_manufacturer_id", $row[11]);
    $product->set($lang->get("meta_description"), ($row[12]));
    $product->set($lang->get("meta_keyword"), ($row[13]));
    $product->set("product_publish", $row[14]);
    $product->set("product_template", $row[15]);
    $product->set("delivery_times_id", $row[16]);
    $product->set("image", $row[17]);

    $product->store();

    $image =& JTable::getInstance('image', 'jshop');
    $query = "SELECT image_id FROM `#__jshopping_products_images` WHERE `product_id` = $product_id ";
    $db->setQuery($query);
    $image_id = $db->loadResult();
    $image->set("image_id", $image_id);
    $image->set("product_id", $product_id);
    $image->set("image_name", $row[17]);
    $image->store();

    if ($product_id==null){
    $product_id = $product->get("product_id");
    }
    $category_id = $row[10];
    if ($category_id==""){
    $category_id = $listCat[$category_name];
    }
    if ($category_name!="" && $category_id){
    $_products->setCategoryToProduct($product_id, array($category_id));
    }

    unset($product);
    }
    }
    }else{
    JError::raiseWarning("", _JSHOP_ERROR_UPLOADING);
    }

    if (!JRequest::getInt("noredirect")){
    $mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=".$ie_id, _JSHOP_COMPLETED);
    }
    }

    }

    ?>
     

Поделиться этой страницей

Яндекс.Метрика