Skip to content

Commit

Permalink
[-] BO : Fix PSCSX-2998 category tree with product import
Browse files Browse the repository at this point in the history
  • Loading branch information
sfroment committed Aug 14, 2014
1 parent 96b4dae commit cabc1fe
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions controllers/admin/AdminImportController.php
Expand Up @@ -439,7 +439,7 @@ public function __construct()
);
break;
}

// @since 1.5.0
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
switch ((int)Tools::getValue('entity'))
Expand Down Expand Up @@ -498,7 +498,7 @@ public function __construct()
'tax_rate' => '0',
);
break;

}

$this->separator = ($separator = Tools::substr(strval(trim(Tools::getValue('separator'))), 0, 1)) ? $separator : ';';
Expand All @@ -521,7 +521,7 @@ public function setMedia()
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js');
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload.js');
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js');
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js');
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js');
$this->addJs(__PS_BASE_URI__.'js/vendor/spin.js');
$this->addJs(__PS_BASE_URI__.'js/vendor/ladda.js');
}
Expand Down Expand Up @@ -957,7 +957,7 @@ protected static function fillInfo($infos, $key, &$entity)
$entity->{$key}[$id_lang_tmp] = $value;
}
else
if (!empty($infos) || $infos == '0') // ($infos == '0') => if you want to disable a product by using "0" in active because empty('0') return true
if (!empty($infos) || $infos == '0') // ($infos == '0') => if you want to disable a product by using "0" in active because empty('0') return true
$entity->{$key} = isset(self::$validators[$key]) ? call_user_func(self::$validators[$key], $infos) : $infos;

return true;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public function categoryImport()
$cat_moved[$category->id] = (int)$category_already_created['id_category'];
$category->id = (int)$category_already_created['id_category'];
}

if ($category->id && $category->id == $category->id_parent)
{
$this->errors[] = Tools::displayError('A category cannot be its own parent');
Expand Down Expand Up @@ -1215,7 +1215,7 @@ public function categoryImport()

// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);

foreach ($info['shop'] as $shop)
if (!empty($shop) && !is_numeric($shop))
$category->addShop(Shop::getIdByName($shop));
Expand Down Expand Up @@ -1433,7 +1433,7 @@ public function productImport()
}

$product->id_category_default = isset($product->id_category[0]) ? (int)$product->id_category[0] : '';

$link_rewrite = (is_array($product->link_rewrite) && isset($product->link_rewrite[$id_lang])) ? trim($product->link_rewrite[$id_lang]) : '';

$valid_link = Validate::isLinkRewrite($link_rewrite);
Expand Down Expand Up @@ -1467,7 +1467,7 @@ public function productImport()
foreach (Product::$definition['fields'] as $key => $array)
if ($array['type'] == Product::TYPE_FLOAT)
$product->{$key} = str_replace(',', '.', $product->{$key});

// Indexation is already 0 if it's a new product, but not if it's an update
$product->indexed = 0;

Expand Down Expand Up @@ -1567,10 +1567,10 @@ public function productImport()
$info['shop'] = 1;
elseif (!isset($info['shop']) || empty($info['shop']))
$info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());

// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);

$id_shop_list = array();
foreach ($info['shop'] as $shop)
if (!empty($shop) && !is_numeric($shop))
Expand Down Expand Up @@ -1775,7 +1775,7 @@ public function productImport()
$this->warnings[] = sprintf(Tools::displayError('Warehouse did not exist, can not set on product %1$s.'),$product->name[$default_language_id]);
}
}

// stock available
if (isset($product->depends_on_stock))
{
Expand All @@ -1785,7 +1785,7 @@ public function productImport()
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management not enabled, can not set "depends on stock" for product %1$s '),$product->name[$default_language_id]);
else
StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock);

// This code allows us to set qty and disable depends on stock
if (isset($product->quantity) && $product->depends_on_stock == 0)
{
Expand Down Expand Up @@ -1831,7 +1831,7 @@ public function productImportCreateCat($default_language_id, $category_name, $id
$category_to_create->id_shop_default = (int)Context::getContext()->shop->id;
$category_to_create->name = AdminImportController::createMultiLangField(trim($category_name));
$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_to_create->id_parent = (int)$id_parent_category ? (int)$id_parent_category : (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 &&
Expand Down Expand Up @@ -1883,20 +1883,20 @@ public function attributeImport()

// Get shops for each attributes
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);

$id_shop_list = array();
if (is_array($info['shop']) && count($info['shop']))
foreach ($info['shop'] as $shop)
if (!empty($shop) && !is_numeric($shop))
$id_shop_list[] = Shop::getIdByName($shop);
elseif (!empty($shop))
$id_shop_list[] = $shop;

if(isset($info['id_product']))
$product = new Product((int)$info['id_product'], false, $default_language);
else
continue;

$id_image = null;

//delete existing images if "delete_existing_images" is set to 1
Expand Down Expand Up @@ -1972,16 +1972,16 @@ public function attributeImport()
$type = 'select';
else
$type = trim($tab_group[1]);

// sets group
$groups_attributes[$key]['group'] = $group;

// if position is filled
if (isset($tab_group[2]))
$position = trim($tab_group[2]);
else
$position = false;

if (!isset($groups[$group]))
{
$obj = new AttributeGroup();
Expand All @@ -1990,7 +1990,7 @@ public function attributeImport()
$obj->name[$default_language] = $group;
$obj->public_name[$default_language] = $group;
$obj->position = (!$position) ? AttributeGroup::getHigherPosition() + 1 : $position;

if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true &&
($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
{
Expand All @@ -2000,7 +2000,7 @@ public function attributeImport()
}
else
$this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');

// fills groups attributes
$id_attribute_group = $obj->id;
$groups_attributes[$key]['id'] = $id_attribute_group;
Expand Down Expand Up @@ -2030,7 +2030,7 @@ public function attributeImport()
$position = trim($tab_attribute[1]);
else
$position = false;

if (isset($groups_attributes[$key]))
{
$group = $groups_attributes[$key]['group'];
Expand All @@ -2042,7 +2042,7 @@ public function attributeImport()
$obj->id_attribute_group = $groups_attributes[$key]['id'];
$obj->name[$default_language] = str_replace('\n', '', str_replace('\r', '', $attribute));
$obj->position = (!$position && isset($groups[$group])) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position;

if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true &&
($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
{
Expand All @@ -2053,19 +2053,19 @@ public function attributeImport()
else
$this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
}

$info['minimal_quantity'] = isset($info['minimal_quantity']) && $info['minimal_quantity'] ? (int)$info['minimal_quantity'] : 1;

$info['wholesale_price'] = str_replace(',', '.', $info['wholesale_price']);
$info['price'] = str_replace(',', '.', $info['price']);
$info['ecotax'] = str_replace(',', '.', $info['ecotax']);
$info['weight'] = str_replace(',', '.', $info['weight']);

// if a reference is specified for this product, get the associate id_product_attribute to UPDATE
if (isset($info['reference']) && !empty($info['reference']))
{
$id_product_attribute = Combination::getIdByReference($product->id, strval($info['reference']));

// updates the attribute
if ($id_product_attribute)
{
Expand Down Expand Up @@ -2100,7 +2100,7 @@ public function attributeImport()
}
}
}

// if no attribute reference is specified, creates a new one
if (!$id_product_attribute)
{
Expand Down Expand Up @@ -2128,7 +2128,7 @@ public function attributeImport()
// fills our attributes array, in order to add the attributes to the product_attribute afterwards
if(isset($attributes[$group.'_'.$attribute]))
$attributes_to_add[] = (int)$attributes[$group.'_'.$attribute];

// after insertion, we clean attribute position and group attribute position
$obj = new Attribute();
$obj->cleanPositions((int)$id_attribute_group, false);
Expand Down Expand Up @@ -2296,7 +2296,7 @@ public function customerImport()
if (Validate::isLoadedObject($myGroup))
$customer_groups[] = (int)$group;
continue;
}
}
$myGroup = Group::searchByName($group);
if (isset($myGroup['id_group']) && $myGroup['id_group'])
$id_group = (int)$myGroup['id_group'];
Expand All @@ -2317,7 +2317,7 @@ public function customerImport()
}
elseif(empty($info['group']) && isset($customer->id) && $customer->id)
$customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP'));

AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer);

if ($customer->passwd)
Expand Down Expand Up @@ -2632,7 +2632,7 @@ public function addressImport()
}
}
else
{
{
$address->force_id = (bool)Tools::getValue('forceIDs');
if ($address->id && $address->addressExists($address->id))
$res = $address->update();
Expand Down Expand Up @@ -2836,7 +2836,7 @@ public function aliasImport()
}

AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $alias);

$res = false;
if (($field_error = $alias->validateFields(UNFRIENDLY_ERROR, true)) === true &&
($lang_field_error = $alias->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
Expand Down Expand Up @@ -2902,7 +2902,7 @@ public function supplyOrdersImport()
$date_delivery_expected = pSQL($info['date_delivery_expected']);
$discount_rate = (float)$info['discount_rate'];
$is_template = (bool)$info['is_template'];

$error = '';
// checks parameters
if (!Supplier::supplierExists($id_supplier))
Expand Down Expand Up @@ -3008,9 +3008,9 @@ public function supplyOrdersDetailsImport()
// checks if one product/attribute is there only once
if (isset($products[$id_product][$id_product_attribute]))
$this->errors[] = sprintf($this->l('Product/Attribute (%d/%d) cannot be added twice (at line %d).'), $id_product,
$id_product_attribute, $current_line + 1);
$id_product_attribute, $current_line + 1);
else
$products[$id_product][$id_product_attribute] = $quantity_expected;
$products[$id_product][$id_product_attribute] = $quantity_expected;

// checks parameters
if (false === ($supplier_reference = ProductSupplier::getProductSupplierReference($id_product, $id_product_attribute, $supply_order->id_supplier)))
Expand Down Expand Up @@ -3104,7 +3104,7 @@ protected function openCsvFile()
{
$file = AdminImportController::getPath(strval(preg_replace('/\.{2,}/', '.', Tools::getValue('csv'))));
$handle = false;
if (is_file($file) && is_readable($file))
if (is_file($file) && is_readable($file))
$handle = fopen($file, 'r');

if (!$handle)
Expand Down Expand Up @@ -3228,7 +3228,7 @@ protected function truncateTables($case)
Image::clearTmpDir();
return true;
}

public function clearSmartyCache()
{
Tools::enableCache();
Expand Down Expand Up @@ -3286,7 +3286,7 @@ public function postProcess()
$this->aliasImport();
break;
}

// @since 1.5.0
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
switch ((int)Tools::getValue('entity'))
Expand All @@ -3298,9 +3298,9 @@ public function postProcess()
case $this->entities[$import_type = $this->l('Supply Order Details')]:
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$this->supplyOrdersDetailsImport();
break;
break;
}

if ($import_type !== false)
{
$log_message = sprintf($this->l('%s import', 'AdminTab', false, false), $import_type);
Expand Down Expand Up @@ -3328,15 +3328,15 @@ public function postProcess()
$bName = explode('.', $bName);
$bName = strtolower($bName[count($bName) - 1]);
$mimeTypes = array('csv' => 'text/csv');

if (isset($mimeTypes[$bName]))
$mimeType = $mimeTypes[$bName];
else
$mimeType = 'application/octet-stream';

if (ob_get_level() && ob_get_length() > 0)
ob_end_clean();

header('Content-Transfer-Encoding: binary');
header('Content-Type: '.$mimeType);
header('Content-Length: '.filesize($file));
Expand All @@ -3346,7 +3346,7 @@ public function postProcess()
echo fgets($fp, 16384);
exit;
}
}
}
}
return parent::postProcess();
}
Expand Down Expand Up @@ -3412,4 +3412,4 @@ public static function getPath($file = '')
return (defined('_PS_HOST_MODE_') ? _PS_ROOT_DIR_ : _PS_ADMIN_DIR_).DIRECTORY_SEPARATOR.'import'
.DIRECTORY_SEPARATOR.$file;
}
}
}

0 comments on commit cabc1fe

Please sign in to comment.