Created
October 26, 2012 11:07
-
-
Save phproberto/3958221 to your computer and use it in GitHub Desktop.
Prestashop importer override to update prices without losing product names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AdminImportController extends AdminImportControllerCore | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function renderView() | |
{ | |
$this->addJS(_PS_JS_DIR_.'adminImport.js'); | |
$handle = $this->openCsvFile(); | |
$nb_column = $this->getNbrColumn($handle, $this->separator); | |
$nb_table = ceil($nb_column / MAX_COLUMNS); | |
$res = array(); | |
foreach ($this->required_fields as $elem) | |
$res[] = '\''.$elem.'\''; | |
$data = array(); | |
for ($i = 0; $i < $nb_table; $i++) | |
$data[$i] = $this->generateContentTable($i, $nb_column, $handle, $this->separator); | |
$this->tpl_view_vars = array( | |
'import_matchs' => Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'import_match'), | |
'fields_value' => array( | |
'csv' => Tools::getValue('csv'), | |
'convert' => Tools::getValue('convert'), | |
'entity' => (int)Tools::getValue('entity'), | |
'iso_lang' => Tools::getValue('iso_lang'), | |
'truncate' => Tools::getValue('truncate'), | |
'forceIDs' => Tools::getValue('forceIDs'), | |
'match_ref' => Tools::getValue('match_ref'), | |
'keep_names' => Tools::getValue('keep_names'), | |
'separator' => $this->separator, | |
'multiple_value_separator' => $this->multiple_value_separator | |
), | |
'nb_table' => $nb_table, | |
'nb_column' => $nb_column, | |
'res' => implode(',', $res), | |
'max_columns' => MAX_COLUMNS, | |
'no_pre_select' => array('price_tin', 'feature'), | |
'available_fields' => $this->available_fields, | |
'data' => $data | |
); | |
return AdminController::renderView(); | |
} | |
public function productImport() | |
{ | |
$this->receiveTab(); | |
$handle = $this->openCsvFile(); | |
$default_language_id = (int)Configuration::get('PS_LANG_DEFAULT'); | |
AdminImportController::setLocale(); | |
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) | |
{ | |
if (Tools::getValue('convert')) | |
$line = $this->utf8EncodeArray($line); | |
$info = AdminImportController::getMaskedRow($line); | |
if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id']) | |
$product = new Product((int)$info['id']); | |
else | |
{ | |
if (array_key_exists('id', $info) && (int)$info['id'] && Product::existsInDatabase((int)$info['id'], 'product')) | |
$product = new Product((int)$info['id']); | |
else | |
$product = new Product(); | |
} | |
if (array_key_exists('id', $info) && (int)$info['id'] && Product::existsInDatabase((int)$info['id'], 'product')) | |
{ | |
$product->loadStockData(); | |
$category_data = Product::getProductCategories((int)$product->id); | |
foreach ($category_data as $tmp) | |
$product->category[] = $tmp; | |
} | |
AdminImportController::setEntityDefaultValues($product); | |
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product); | |
if (!Shop::isFeatureActive()) | |
$product->shop = 1; | |
elseif (!isset($product->shop) || empty($product->shop)) | |
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID()); | |
if (!Shop::isFeatureActive()) | |
$product->id_shop_default = 1; | |
else | |
$product->id_shop_default = (int)Context::getContext()->shop->id; | |
// link product to shops | |
$product->id_shop_list = array(); | |
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) | |
if (!is_numeric($shop)) | |
$product->id_shop_list[] = Shop::getIdByName($shop); | |
else | |
$product->id_shop_list[] = $shop; | |
if ((int)$product->id_tax_rules_group != 0) | |
{ | |
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) | |
{ | |
$address = $this->context->shop->getAddress(); | |
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group); | |
$product_tax_calculator = $tax_manager->getTaxCalculator(); | |
$product->tax_rate = $product_tax_calculator->getTotalRate(); | |
} | |
else | |
$this->addProductWarning( | |
'id_tax_rules_group', | |
$product->id_tax_rules_group, | |
Tools::displayError('Invalid tax rule group ID, you first need a group with this ID.') | |
); | |
} | |
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int)$product->manufacturer)) | |
$product->id_manufacturer = (int)$product->manufacturer; | |
else if (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) | |
{ | |
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) | |
$product->id_manufacturer = (int)$manufacturer; | |
else | |
{ | |
$manufacturer = new Manufacturer(); | |
$manufacturer->name = $product->manufacturer; | |
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && | |
($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) | |
$product->id_manufacturer = (int)$manufacturer->id; | |
else | |
{ | |
$this->errors[] = sprintf( | |
Tools::displayError('%1$s (ID: %2$s) cannot be saved'), | |
$manufacturer->name, | |
(isset($manufacturer->id) ? $manufacturer->id : 'null') | |
); | |
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : ''). | |
Db::getInstance()->getMsgError(); | |
} | |
} | |
} | |
if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int)$product->supplier)) | |
$product->id_supplier = (int)$product->supplier; | |
else if (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) | |
{ | |
if ($supplier = Supplier::getIdByName($product->supplier)) | |
$product->id_supplier = (int)$supplier; | |
else | |
{ | |
$supplier = new Supplier(); | |
$supplier->name = $product->supplier; | |
$supplier->active = true; | |
if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && | |
($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) | |
{ | |
$product->id_supplier = (int)$supplier->id; | |
$supplier->associateTo($product->id_shop_list); | |
} | |
else | |
{ | |
$this->errors[] = sprintf( | |
Tools::displayError('%1$s (ID: %2$s) cannot be saved'), | |
$supplier->name, | |
(isset($supplier->id) ? $supplier->id : 'null') | |
); | |
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : ''). | |
Db::getInstance()->getMsgError(); | |
} | |
} | |
} | |
if (isset($product->price_tex) && !isset($product->price_tin)) | |
$product->price = $product->price_tex; | |
else if (isset($product->price_tin) && !isset($product->price_tex)) | |
{ | |
$product->price = $product->price_tin; | |
// If a tax is already included in price, withdraw it from price | |
if ($product->tax_rate) | |
$product->price = (float)number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', ''); | |
} | |
else if (isset($product->price_tin) && isset($product->price_tex)) | |
$product->price = $product->price_tex; | |
if (isset($product->category) && is_array($product->category) && count($product->category)) | |
{ | |
$product->id_category = array(); // Reset default values array | |
foreach ($product->category as $value) | |
{ | |
if (is_numeric($value)) | |
{ | |
if (Category::categoryExists((int)$value)) | |
$product->id_category[] = (int)$value; | |
else | |
{ | |
$category_to_create = new Category(); | |
$category_to_create->id = (int)$value; | |
$category_to_create->name = AdminImportController::createMultiLangField($value); | |
$category_to_create->active = 1; | |
$category_to_create->id_parent = Configuration::get('PS_HOME_CATEGORY'); // Default parent is home for unknown category to create | |
$category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]); | |
$category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite); | |
if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) === true && | |
($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $category_to_create->add()) | |
$product->id_category[] = (int)$category_to_create->id; | |
else | |
{ | |
$this->errors[] = sprintf( | |
Tools::displayError('%1$s (ID: %2$s) cannot be saved'), | |
$category_to_create->name[$default_language_id], | |
(isset($category_to_create->id) ? $category_to_create->id : 'null') | |
); | |
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : ''). | |
Db::getInstance()->getMsgError(); | |
} | |
} | |
} | |
else if (is_string($value) && !empty($value)) | |
{ | |
$category = Category::searchByName($default_language_id, trim($value), true); | |
if ($category['id_category']) | |
$product->id_category[] = (int)$category['id_category']; | |
else | |
{ | |
$category_to_create = new Category(); | |
if (!Shop::isFeatureActive()) | |
$category_to_create->id_shop_default = 1; | |
else | |
$category_to_create->id_shop_default = (int)Context::getContext()->shop->id; | |
$category_to_create->name = AdminImportController::createMultiLangField(trim($value)); | |
$category_to_create->active = 1; | |
$category_to_create->id_parent = (int)Configuration::get('PS_HOME_CATEGORY'); // Default parent is home for unknown category to create | |
$category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]); | |
$category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite); | |
if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) === true && | |
($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $category_to_create->add()) | |
$product->id_category[] = (int)$category_to_create->id; | |
else | |
{ | |
$this->errors[] = sprintf( | |
Tools::displayError('%1$s (ID: %2$s) cannot be saved'), | |
$category_to_create->name[$default_language_id], | |
(isset($category_to_create->id) ? $category_to_create->id : 'null') | |
); | |
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : ''). | |
Db::getInstance()->getMsgError(); | |
} | |
} | |
} | |
} | |
} | |
$product->id_category_default = isset($product->id_category[0]) ? (int)$product->id_category[0] : ''; | |
$link_rewrite = (is_array($product->link_rewrite) && count($product->link_rewrite)) ? trim($product->link_rewrite[$default_language_id]) : ''; | |
$valid_link = Validate::isLinkRewrite($link_rewrite); | |
if ((isset($product->link_rewrite[$default_language_id]) && empty($product->link_rewrite[$default_language_id])) || !$valid_link) | |
{ | |
$link_rewrite = Tools::link_rewrite($product->name[$default_language_id]); | |
if ($link_rewrite == '') | |
$link_rewrite = 'friendly-url-autogeneration-failed'; | |
} | |
if (!$valid_link) | |
$this->warnings[] = sprintf( | |
Tools::displayError('Rewrite link for %1$s (ID: %2$s) was re-written as %3$s.'), | |
$link_rewrite, | |
(isset($info['id']) ? $info['id'] : 'null'), | |
$link_rewrite | |
); | |
$product->link_rewrite = AdminImportController::createMultiLangField($link_rewrite); | |
// replace the value of separator by coma | |
if ($this->multiple_value_separator != ',') | |
foreach ($product->meta_keywords as &$meta_keyword) | |
if (!empty($meta_keyword)) | |
$meta_keyword = str_replace($this->multiple_value_separator, ',', $meta_keyword); | |
$res = false; | |
$preloadProduct = false; | |
$preloadById = ($product->id && Product::existsInDatabase((int)$product->id, 'product')); | |
$preloadByreference = (Tools::getValue('match_ref') == 1 && $product->reference && $product->existsRefInDatabase($product->reference)); | |
if ($preloadByreference || $preloadById) | |
{ | |
$preloadProduct = true; | |
$sql = 'SELECT | |
product_shop.`date_add`, p.`id_product`, pl.`name` | |
FROM | |
`'._DB_PREFIX_.'product` p | |
LEFT JOIN | |
'._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product AND pl.`id_lang` = ' . (int) $default_language_id . ') | |
' . Shop::addSqlAssociation('product', 'p'); | |
if ($preloadByreference) | |
{ | |
$sql .= 'WHERE p.`reference` = "' . $product->reference . '" '; | |
} | |
if ($preloadById) | |
{ | |
$sql .= 'WHERE p.`id_product` = ' . (int) $product->id; | |
} | |
$datas = Db::getInstance()->getRow($sql); | |
$product->id = (int)$datas['id_product']; | |
$product->date_add = pSQL($datas['date_add']); | |
// Check quantity | |
if ($product->quantity == null) | |
{ | |
$product->quantity = 0; | |
} | |
// Inherit product name if required or not set | |
if (Tools::getValue('keep_names') || !isset($product->name) || empty($product->name)) | |
{ | |
$product->name = pSQL($datas['name']); | |
} | |
} | |
$field_error = $product->validateFields(UNFRIENDLY_ERROR, true); | |
$lang_field_error = $product->validateFieldsLang(UNFRIENDLY_ERROR, true); | |
if ($field_error === true && $lang_field_error === true) | |
{ | |
if ($preloadProduct) | |
{ | |
$res = $product->update(); | |
} | |
// If no id_product or update failed | |
if (!$res) | |
{ | |
if (isset($product->date_add) && $product->date_add != '') | |
$res = $product->add(false); | |
else | |
$res = $product->add(); | |
} | |
} | |
$shops = array(); | |
$product_shop = explode($this->multiple_value_separator, $product->shop); | |
foreach ($product_shop as $shop) | |
{ | |
$shop = trim($shop); | |
if (!is_numeric($shop)) | |
$shop = ShopGroup::getIdByName($shop); | |
$shops[] = $shop; | |
} | |
if (empty($shops)) | |
$shops = Shop::getContextListShopID(); | |
// If both failed, mysql error | |
if (!$res) | |
{ | |
$this->errors[] = sprintf( | |
Tools::displayError('%1$s (ID: %2$s) cannot be saved'), | |
$info['name'], | |
(isset($info['id']) ? $info['id'] : 'null') | |
); | |
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : ''). | |
Db::getInstance()->getMsgError(); | |
} | |
else | |
{ | |
// Product supplier | |
if (isset($product->id_supplier) && isset($product->supplier_reference)) | |
{ | |
$id_product_supplier = ProductSupplier::getIdByProductAndSupplier((int)$product->id, 0, (int)$product->id_supplier); | |
if ($id_product_supplier) | |
$product_supplier = new ProductSupplier((int)$id_product_supplier); | |
else | |
$product_supplier = new ProductSupplier(); | |
$product_supplier->id_product = $product->id; | |
$product_supplier->id_product_attribute = 0; | |
$product_supplier->id_supplier = $product->id_supplier; | |
$product_supplier->product_supplier_price_te = $product->wholesale_price; | |
$product_supplier->product_supplier_reference = $product->supplier_reference; | |
$product_supplier->save(); | |
} | |
// SpecificPrice (only the basic reduction feature is supported by the import) | |
if ((isset($info['reduction_price']) && $info['reduction_price'] > 0) || (isset($info['reduction_percent']) && $info['reduction_percent'] > 0)) | |
{ | |
$specific_price = new SpecificPrice(); | |
$specific_price->id_product = (int)$product->id; | |
// @todo multishop specific price import | |
$specific_price->id_shop = $this->context->shop->id; | |
$specific_price->id_currency = 0; | |
$specific_price->id_country = 0; | |
$specific_price->id_group = 0; | |
$specific_price->price = -1; | |
$specific_price->id_customer = 0; | |
$specific_price->from_quantity = 1; | |
$specific_price->reduction = (isset($info['reduction_price']) && $info['reduction_price']) ? $info['reduction_price'] : $info['reduction_percent'] / 100; | |
$specific_price->reduction_type = (isset($info['reduction_price']) && $info['reduction_price']) ? 'amount' : 'percentage'; | |
$specific_price->from = (isset($info['reduction_from']) && Validate::isDate($info['reduction_from'])) ? $info['reduction_from'] : '0000-00-00 00:00:00'; | |
$specific_price->to = (isset($info['reduction_to']) && Validate::isDate($info['reduction_to'])) ? $info['reduction_to'] : '0000-00-00 00:00:00'; | |
if (!$specific_price->add()) | |
$this->addProductWarning($info['name'], $product->id, $this->l('Discount is invalid')); | |
} | |
if (isset($product->tags) && !empty($product->tags)) | |
{ | |
// Delete tags for this id product, for no duplicating error | |
Tag::deleteTagsForProduct($product->id); | |
if (!is_array($product->tags)) | |
{ | |
$product->tags = AdminImportController::createMultiLangField($product->tags); | |
foreach ($product->tags as $key => $tags) | |
{ | |
$is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator); | |
if (!$is_tag_added) | |
{ | |
$this->addProductWarning($info['name'], $product->id, $this->l('Tags list is invalid')); | |
break; | |
} | |
} | |
} | |
else | |
{ | |
foreach ($product->tags as $key => $tags) | |
{ | |
$str = ''; | |
foreach ($tags as $one_tag) | |
$str .= $one_tag.$this->multiple_value_separator; | |
$str = rtrim($str, $this->multiple_value_separator); | |
$is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator); | |
if (!$is_tag_added) | |
{ | |
$this->addProductWarning($info['name'], $product->id, 'Invalid tag(s) ('.$str.')'); | |
break; | |
} | |
} | |
} | |
} | |
//delete existing images if "delete_existing_images" is set to 1 | |
if (isset($product->delete_existing_images)) | |
if ((bool)$product->delete_existing_images) | |
$product->deleteImages(); | |
else if (isset($product->image) && is_array($product->image) && count($product->image)) | |
$product->deleteImages(); | |
if (isset($product->image) && is_array($product->image) && count($product->image)) | |
{ | |
$product_has_images = (bool)Image::getImages($this->context->language->id, (int)$product->id); | |
foreach ($product->image as $key => $url) | |
{ | |
$url = trim($url); | |
$error = false; | |
if (!empty($url)) | |
{ | |
$url = str_replace(' ', '%20', $url); | |
$image = new Image(); | |
$image->id_product = (int)$product->id; | |
$image->position = Image::getHighestPosition($product->id) + 1; | |
$image->cover = (!$key && !$product_has_images) ? true : false; | |
// file_exists doesn't work with HTTP protocol | |
if (@fopen($url, 'r') == false) | |
$error = true; | |
else if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true && | |
($lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $image->add()) | |
{ | |
// associate image to selected shops | |
$image->associateTo($shops); | |
if (!AdminImportController::copyImg($product->id, $image->id, $url)) | |
{ | |
$image->delete(); | |
$this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url); | |
} | |
} | |
else | |
$error = true; | |
} | |
else | |
$error = true; | |
if ($error) | |
$this->warnings[] = sprintf(Tools::displayError('Product n°%1$d: the picture cannot be saved: %2$s'), $image->id_product, $url); | |
} | |
} | |
if (isset($product->id_category)) | |
$product->updateCategories(array_map('intval', $product->id_category)); | |
// Features import | |
$features = get_object_vars($product); | |
if (isset($features['features']) && !empty($features['features'])) | |
foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) | |
{ | |
$tab_feature = explode(':', $single_feature); | |
$feature_name = trim($tab_feature[0]); | |
$feature_value = trim($tab_feature[1]); | |
$position = isset($tab_feature[2]) ? $tab_feature[2]: false; | |
$id_feature = Feature::addFeatureImport($feature_name, $position); | |
$id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $feature_value); | |
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value); | |
} | |
// clean feature positions to avoid conflict | |
Feature::cleanPositions(); | |
} | |
// stock available | |
if (Shop::isFeatureActive()) | |
{ | |
foreach ($shops as $shop) | |
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, (int)$shop); | |
} | |
else | |
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id); | |
} | |
if (Configuration::get('PS_SEARCH_INDEXATION')) | |
Search::indexation(true); | |
$this->closeCsvFile($handle); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{* | |
* 2007-2012 PrestaShop | |
* | |
* NOTICE OF LICENSE | |
* | |
* This source file is subject to the Academic Free License (AFL 3.0) | |
* that is bundled with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://opensource.org/licenses/afl-3.0.php | |
* If you did not receive a copy of the license and are unable to | |
* obtain it through the world-wide-web, please send an email | |
* to [email protected] so we can send you a copy immediately. | |
* | |
* DISCLAIMER | |
* | |
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | |
* versions in the future. If you wish to customize PrestaShop for your | |
* needs please refer to http://www.prestashop.com for more information. | |
* | |
* @author PrestaShop SA <[email protected]> | |
* @copyright 2007-2012 PrestaShop SA | |
* @version Release: $Revision: 8971 $ | |
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | |
* International Registered Trademark & Property of PrestaShop SA | |
*} | |
{include file="toolbar.tpl" toolbar_btn=$toolbar_btn toolbar_scroll=$toolbar_scroll title=$title} | |
<div class="leadin">{block name="leadin"}{/block}</div> | |
{if $module_confirmation} | |
<div class="module_confirmation conf confirm"> | |
{l s='Your .CSV file has been sucessfully imported into your shop.'} | |
</div> | |
{/if} | |
<script type="text/javascript"> | |
var truncateAuthorized = {$truncateAuthorized|intval}; | |
$(document).ready(function(){ | |
activeClueTip(); | |
$("a#upload_file_import_link").fancybox({ | |
'titleShow' : false, | |
'transitionIn' : 'elastic', | |
'transitionOut' : 'elastic' | |
}); | |
$('#preview_import').submit(function(e) { | |
if ($('#truncate').get(0).checked) | |
{ | |
console.log(truncateAuthorized); | |
if (truncateAuthorized) | |
{ | |
if (!confirm('{l s='Are you sure you want to delete' js=1}' + ' ' + $.trim($('#entity > option:selected').text().toLowerCase()) + '{l s='?' js=1}')) | |
{ | |
e.preventDefault(); | |
} | |
} | |
else | |
{ | |
jAlert('{l s='You do not have permission to delete here. When the multi-store is enable, only a SuperAdmin can delete all items before import.'}'); | |
return false; | |
} | |
} | |
}); | |
}); | |
function activeClueTip() | |
{ | |
$('.info_import').cluetip({ | |
splitTitle: '|', | |
showTitle: false | |
}); | |
}; | |
</script> | |
{** | |
* Upload fancybox | |
*} | |
<div style="display: none"> | |
<div id="upload_file_import" style="padding-left: 10px; background-color: #EBEDF4; border: 1px solid #CCCED7"> | |
<div class="clear"> </div> | |
<form action="{$current}&token={$token}" method="post" enctype="multipart/form-data"> | |
<label class="clear" style="width:160px; text-align: left;">{l s='Select your CSV file'} </label> | |
<div class="margin-form" style="padding-left:190px;"> | |
<input name="file" type="file" /> | |
<p class="preference_description"> | |
{l s='You can also upload your file via FTP to the following directory:'} {$path_import}. | |
</p> | |
</div> | |
<div class="margin-form" style="padding-left:190px;"> | |
<input type="submit" name="submitFileUpload" value="{l s='Upload'}" class="button" /> | |
<p class="preference_description"> | |
{l s='Only UTF-8 and ISO-8859-1 encoding are allowed'} | |
</p> | |
</div> | |
</form> | |
<div class="clear"> </div> | |
<div style="width:50%; margin: 0 auto;"> | |
{l s='Note that our samples are available below.'} | |
<div class="clear"> </div> | |
<ul id="sample_files_import"> | |
<li><a href="../docs/csv_import/categories_import.csv">{l s='Sample Categories file'}</a></li> | |
<li><a href="../docs/csv_import/products_import.csv">{l s='Sample Products file'}</a></li> | |
<li><a href="../docs/csv_import/combinations_import.csv">{l s='Sample Combinations file'}</a></li> | |
<li><a href="../docs/csv_import/customers_import.csv">{l s='Sample Customers file'}</a></li> | |
<li><a href="../docs/csv_import/addresses_import.csv">{l s='Sample Addresses file'}</a></li> | |
<li><a href="../docs/csv_import/manufacturers_import.csv">{l s='Sample Manufacturers file'}</a></li> | |
<li><a href="../docs/csv_import/suppliers_import.csv">{l s='Sample Suppliers file'}</a></li> | |
{if $PS_ADVANCED_STOCK_MANAGEMENT} | |
<li><a href="../docs/csv_import/supply_orders_import.csv">{l s='Supply Orders sample file'}</a></li> | |
<li><a href="../docs/csv_import/supply_orders_details_import.csv">{l s='Supply Orders Details sample file'}</a></li> | |
{/if} | |
</ul> | |
</div> | |
<div class="clear"> </div> | |
</div> | |
</div> | |
<div class="clear"> </div> | |
{** | |
* Import fieldset | |
*} | |
<form id="preview_import" | |
action="{$current}&token={$token}" | |
method="post" | |
style="display:inline" | |
enctype="multipart/form-data" | |
class="clear"> | |
<fieldset style="float: left; margin: 0pt 20px 0pt 0pt; width: 70%;"> | |
<legend><img src="../img/admin/import.gif" />{l s='Import'}</legend> | |
<label class="clear">{if count($files_to_import) > 1}{l s='Your CSV file (%d files):' sprintf=count($files_to_import)}{else}{l s='Your CSV file (%d file):' sprintf=count($files_to_import)}{/if}</label> | |
<div class="margin-form"> | |
{if count($files_to_import)} | |
<select name="csv"> | |
{foreach $files_to_import AS $filename} | |
<option value="{$filename}">{$filename}</option> | |
{/foreach} | |
</select> | |
{/if} | |
| |
<a href="#upload_file_import" id="upload_file_import_link" class="button"><img src="../img/admin/add.gif" alt="Uplaod" title="Upload" />{l s='Upload'}</a> | |
</div> | |
<label class="clear">{l s='What kind of Entity would you like to import?'} </label> | |
<div class="margin-form"> | |
<select name="entity" id="entity"> | |
{foreach $entities AS $entity => $i} | |
<option value="{$i}" {if $entity == $i}selected="selected"{/if}> | |
{$entity} | |
</option> | |
{/foreach} | |
</select> | |
</div> | |
<label class="clear">{l s='Language of the file'}</label> | |
<div class="margin-form"> | |
<select name="iso_lang"> | |
{foreach $languages AS $lang} | |
<option value="{$lang.iso_code}" {if $lang.id_lang == $id_language} selected="selected"{/if}>{$lang.name}</option> | |
{/foreach} | |
</select> | |
{l s='The locale must be installed'} | |
</div> | |
<label for="convert" class="clear">{l s='ISO-8859-1 encoded file?'} </label> | |
<div class="margin-form"> | |
<input name="convert" id="convert" type="checkbox" style="margin-top: 6px;"/> | |
</div> | |
<label class="clear">{l s='Field separator'} </label> | |
<div class="margin-form"> | |
<input type="text" size="2" value=";" name="separator"/> | |
{l s='e.g. '}"1<span class="bold" style="color: red">;</span>Ipod<span class="bold" style="color: red">;</span>129.90<span class="bold" style="color: red">;</span>5" | |
</div> | |
<label class="clear">{l s='Multiple value separator'} </label> | |
<div class="margin-form"> | |
<input type="text" size="2" value="," name="multiple_value_separator"/> | |
{l s='e.g. '}"Ipod;red.jpg<span class="bold" style="color: red">,</span>blue.jpg<span class="bold" style="color: red">,</span>green.jpg;129.90" | |
</div> | |
<label for="truncate" class="clear">{l s='Delete all'} <span id="entitie">{l s='categories'}</span> {l s='before import?'} </label> | |
<div class="margin-form"> | |
<input name="truncate" id="truncate" type="checkbox"/> | |
</div> | |
<label for="match_ref" class="clear" style="display: none">{l s='Use product reference as key?'}</label> | |
<div class="margin-form"> | |
<input name="match_ref" id="match_ref" type="checkbox" style="margin-top: 6px; display:none"/> | |
</div> | |
<label for="keep_names" class="clear" style="display: none">{l s='Keep product names?'}</label> | |
<div class="margin-form"> | |
<input name="keep_names" id="keep_names" type="checkbox" style="margin-top: 6px; display:none"/> | |
</div> | |
<label for="forceIDs" class="clear">{l s='Force all ids during import?'} </label> | |
<div class="margin-form"> | |
<input name="forceIDs" id="forceIDs" type="checkbox"/> {l s='If you don\'t use this option, all IDs will be auto-incremented.'} | |
</div> | |
<div class="space margin-form"> | |
<input type="submit" name="submitImportFile" value="{l s='Next step'}" class="button" {if empty($files_to_import)}disabled{/if}/> | |
{if empty($files_to_import)}<span style="color:red;">{l s='You must upload a file for go to the next step.'}</span>{/if} | |
</div> | |
<div class="warn import_products_categories" style="margin-top: 20px;"> | |
<p>{l s='Note that the category import does not support categories of the same name.'}</p> | |
<p>{l s='Note that you can have several products with the same reference.'}</p> | |
</div> | |
<div class="warn import_supply_orders_details" style="margin-top: 20px; display:none"> | |
<p>{l s='Importing Supply Order Details will first reset the products ordered, if any.'}</p> | |
</div> | |
{if !count($files_to_import)} | |
<div class="warn" style="margin-top: 20px;"> | |
<p>{l s='There is no CSV file available, please upload one using the \'Upload\' button above.'}</p> | |
<ul> | |
<li>{l s='You can read informations on CSV import at:'} <a href="http://doc.prestashop.com/display/PS14/Troubleshooting#Troubleshooting-HowtocorrectlyimportaccentuatedcontentusingaCSVfile%3F" target="_blank">http://doc.prestashop.com/display/PS14/Troubleshooting</a></li> | |
<li>{l s='Read more about CSV format at:'} <a href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">http://en.wikipedia.org/wiki/Comma-separated_values</a></li> | |
</ul> | |
</div> | |
{/if} | |
</fieldset> | |
</form> | |
<fieldset style="display:block;"> | |
<legend> | |
<img src="../img/admin/import.gif" />{l s='Available fields'} | |
</legend> | |
<div id="availableFields"> | |
{$available_fields} | |
</div> | |
<div class="clear"> | |
<br /><br />{l s='*Required field'} | |
</div> | |
</fieldset> | |
<div class="clear"> </div> | |
<script type="text/javascript"> | |
$("select#entity").change( function() { | |
if ($("#entity > option:selected").val() == 7 || $("#entity > option:selected").val() == 8) | |
{ | |
$("label[for=truncate],#truncate").hide(); | |
} | |
else | |
$("label[for=truncate],#truncate").show(); | |
if ($("#entity > option:selected").val() == 8) | |
{ | |
$(".import_supply_orders_details").show(); | |
$('input[name=multiple_value_separator]').val('|'); | |
} | |
else | |
{ | |
$(".import_supply_orders_details").hide(); | |
$('input[name=multiple_value_separator]').val(','); | |
} | |
if ($("#entity > option:selected").val() == 1) | |
{ | |
$("label[for=match_ref],#match_ref").show(); | |
$("label[for=keep_names],#keep_names").show(); | |
} | |
else | |
{ | |
$("label[for=match_ref],#match_ref").hide(); | |
$("label[for=keep_names],#keep_names").hide(); | |
} | |
if ($("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 0) | |
{ | |
$(".import_products_categories").show(); | |
} | |
else | |
$(".import_products_categories").hide(); | |
if ($("#entity > option:selected").val() == 0 || $("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 3 || $("#entity > option:selected").val() == 5 || $("#entity > option:selected").val() == 6) | |
$("label[for=forceIDs],#forceIDs").show(); | |
else | |
$("label[for=forceIDs],#forceIDs").hide(); | |
$("#entitie").html($("#entity > option:selected").text().toLowerCase()); | |
$.ajax({ | |
url: 'ajax.php', | |
data: { | |
getAvailableFields:1, | |
entity: $("#entity").val() | |
}, | |
dataType: 'json', | |
success: function(j) { | |
var fields = ""; | |
$("#availableFields").empty(); | |
for (var i = 0; i < j.length; i++) | |
fields += j[i].field; | |
$("#availableFields").html(fields); | |
activeClueTip(); | |
}, | |
error: function(j) { | |
} | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{* | |
* 2007-2012 PrestaShop | |
* | |
* NOTICE OF LICENSE | |
* | |
* This source file is subject to the Academic Free License (AFL 3.0) | |
* that is bundled with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://opensource.org/licenses/afl-3.0.php | |
* If you did not receive a copy of the license and are unable to | |
* obtain it through the world-wide-web, please send an email | |
* to [email protected] so we can send you a copy immediately. | |
* | |
* DISCLAIMER | |
* | |
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | |
* versions in the future. If you wish to customize PrestaShop for your | |
* needs please refer to http://www.prestashop.com for more information. | |
* | |
* @author PrestaShop SA <[email protected]> | |
* @copyright 2007-2012 PrestaShop SA | |
* @version Release: $Revision: 8971 $ | |
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | |
* International Registered Trademark & Property of PrestaShop SA | |
*} | |
{extends file="helpers/view/view.tpl"} | |
{block name="override_tpl"} | |
<script type="text/javascript"> | |
var errorEmpty = "{l s='Please name your matching configuration to save.'}" | |
var token = '{$token}'; | |
</script> | |
<div id="container-customer"> | |
<h2>{l s='View your data'}</h2> | |
<div> | |
<b>{l s='Save and load your matching configuration'} : </b><br><br> | |
<input type="text" name="newImportMatchs" id="newImportMatchs"> | |
<a id="saveImportMatchs" class="button" href="#">{l s='Save'}</a><br><br> | |
<div id="selectDivImportMatchs" {if !$import_matchs}style="display:none"{/if}> | |
<select id="valueImportMatchs"> | |
{foreach $import_matchs as $match} | |
<option id="{$match.id_import_match}" value="{$match.match}">{$match.name}</option> | |
{/foreach} | |
</select> | |
<a class="button" id="loadImportMatchs" href="#">{l s='Load'}</a> | |
<a class="button" id="deleteImportMatchs" href="#">{l s='Delete'}</a> | |
</div> | |
</div> | |
<h3>{l s='Please set the value type of each column'}</h3> | |
<div id="error_duplicate_type" class="warning warn" style="display:none;"> | |
<h3>{l s='Columns cannot have the same value type'}</h3> | |
</div> | |
<div id="required_column" class="warning warn" style="display:none;"> | |
<h3>{l s='Column'} <span id="missing_column"> </span> {l s='must be set'}</h3> | |
</div> | |
<form action="{$current}&token={$token}" method="post" id="import_form" name="import_form"> | |
{l s='Skip'} <input type="text" size="2" name="skip" value="0" /> {l s='lines'} | |
<input type="hidden" name="csv" value="{$fields_value.csv}" /> | |
<input type="hidden" name="convert" value="{$fields_value.convert}" /> | |
<input type="hidden" name="entity" value="{$fields_value.entity}" /> | |
<input type="hidden" name="iso_lang" value="{$fields_value.iso_lang}" /> | |
{if $fields_value.truncate} | |
<input type="hidden" name="truncate" value="1" /> | |
{/if} | |
{if $fields_value.forceIDs} | |
<input type="hidden" name="forceIDs" value="1" /> | |
{/if} | |
{if $fields_value.match_ref} | |
<input type="hidden" name="match_ref" value="1" /> | |
{/if} | |
{if $fields_value.keep_names} | |
<input type="hidden" name="keep_names" value="1" /> | |
{/if} | |
<input type="hidden" name="separator" value="{$fields_value.separator}"> | |
<input type="hidden" name="multiple_value_separator" value="{$fields_value.multiple_value_separator}"> | |
<script type="text/javascript"> | |
var current = 0; | |
function showTable(nb) | |
{ | |
getE('btn_left').disabled = null; | |
getE('btn_right').disabled = null; | |
if (nb <= 0) | |
{ | |
nb = 0; | |
getE('btn_left').disabled = 'true'; | |
} | |
if (nb >= {$nb_table} - 1) | |
{ | |
nb = {$nb_table} - 1; | |
getE('btn_right').disabled = 'true'; | |
} | |
toggle(getE('table'+current), false); | |
current = nb; | |
toggle(getE('table'+current), true); | |
} | |
$(function() { | |
var btn_save_import = $('span[class~="process-icon-save-import"]').parent(); | |
var btn_submit_import = $('#import'); | |
if (btn_save_import.length > 0 && btn_submit_import.length > 0) | |
{ | |
btn_submit_import.hide(); | |
btn_save_import.find('span').removeClass('process-icon-save-import'); | |
btn_save_import.find('span').addClass('process-icon-save'); | |
btn_save_import.click(function() { | |
btn_submit_import.before('<input type="hidden" name="'+btn_submit_import.attr("name")+'" value="1" />'); | |
$('#import_form').submit(); | |
}); | |
} | |
}); | |
</script> | |
<table> | |
<tr> | |
<td colspan="3" align="center"> | |
<input name="import" type="submit" onclick="return (validateImportation(new Array({$res})));" id="import" value="{l s='Import .CSV data'}" class="button" /> | |
</td> | |
</tr> | |
<tr> | |
<td valign="top" align="center"> | |
<input id="btn_left" value="{l s='<<'}" type="button" class="button" onclick="showTable(current - 1)" /> | |
</td> | |
<td align="left"> | |
{section name=nb_i start=0 loop=$nb_table step=1} | |
{assign var=i value=$smarty.section.nb_i.index} | |
{$data.$i} | |
{/section} | |
</td> | |
<td valign="top" align="center"> | |
<input id="btn_right" value="{l s='>>'}" type="button" class="button" onclick="showTable(current + 1)" /> | |
</td> | |
</tr> | |
</table> | |
<script type="text/javascript">showTable(current);</script> | |
</form> | |
</div> | |
{/block} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i'd be interested in this too. it seems to be that will enable me to import quantity discounts /specifc_prices isnt that the case?