Home / Uncategorized / Adding new fields to CSV Importer – PrestaShop

Adding new fields to CSV Importer – PrestaShop

First You need to go Controller/admin & copy AdminImportController.php file and override AdminImportController.php file on override/controllers/admin (if you have already file on override/controllers/admin ignore copy past just edit that’s file directly).

Here you see some section for category / product /etc file just see don’t edit it.

class AdminImportController extends AdminImportControllerCore
{
        $this->bootstrap = true;
        $this->entities = array(
            $this->l('Categories'),
            $this->l('Products'),
            $this->l('Combinations'),
            $this->l('Customers'),
            $this->l('Addresses'),
            $this->l('Manufacturers'),
            $this->l('Suppliers'),
            $this->l('Alias'),
        );
        // more code here
 
        $this->separator = ($separator = Tools::substr(strval(trim(Tools::getValue('separator'))), 0, 1)) ? $separator :  ';';
        $this->multiple_value_separator = ($separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator'))), 0, 1)) ? $separator :  ',';
        AdminController::__construct();
}

You have similar Look. I want to add field on product so i just go bellow link and inject custom_field after name field.

$this->available_fields = array(
     'no' => array('label' => $this->l('Ignore this column')),
     'id' => array('label' => $this->l('ID')),
     'active' => array('label' => $this->l('Active (0/1)')),
     'name' => array('label' => $this->l('Name')),
     'custom_field' => array(
         'label' => $this->l('Custom Field'),
         'help' => $this->l('Custom Field')
     ),
     'category' => array('label' => $this->l('Categories (x,y,z...)')),
     'price_tex' => array('label' => $this->l('Price tax excluded')),
     'price_tin' => array('label' => $this->l('Price tax included')),
     'id_tax_rules_group' => array('label' => $this->l('Tax rules ID')),
     'wholesale_price' => array('label' => $this->l('Wholesale price')),
     'on_sale' => array('label' => $this->l('On sale (0/1)')),
     'reduction_price' => array('label' => $this->l('Discount amount')),
     'reduction_percent' => array('label' => $this->l('Discount percent')),
     'reduction_from' => array('label' => $this->l('Discount from (yyyy-mm-dd)')),
     'reduction_to' => array('label' => $this->l('Discount to (yyyy-mm-dd)')),
     'reference' => array('label' => $this->l('Reference #')),
     'supplier_reference' => array('label' => $this->l('Supplier reference #')),
     'supplier' => array('label' => $this->l('Supplier')),
     'manufacturer' => array('label' => $this->l('Manufacturer')),
     'ean13' => array('label' => $this->l('EAN13')),
     'upc' => array('label' => $this->l('UPC')),
     'ecotax' => array('label' => $this->l('Ecotax')),
     'width' => array('label' => $this->l('Width')),
     'height' => array('label' => $this->l('Height')),
     'depth' => array('label' => $this->l('Depth')),
     'weight' => array('label' => $this->l('Weight')),
     'quantity' => array('label' => $this->l('Quantity')),
     'minimal_quantity' => array('label' => $this->l('Minimal quantity')),
     'visibility' => array('label' => $this->l('Visibility')),
     'additional_shipping_cost' => array('label' => $this->l('Additional shipping cost')),
     'unity' => array('label' => $this->l('Unit for the unit price')),
     'unit_price' => array('label' => $this->l('Unit price')),
     'description_short' => array('label' => $this->l('Short description')),
     'description' => array('label' => $this->l('Description')),
     'tags' => array('label' => $this->l('Tags (x,y,z...)')),
     'meta_title' => array('label' => $this->l('Meta title')),
     'meta_keywords' => array('label' => $this->l('Meta keywords')),
     'meta_description' => array('label' => $this->l('Meta description')),
     'link_rewrite' => array('label' => $this->l('URL rewritten')),
     'available_now' => array('label' => $this->l('Text when in stock')),
     'available_later' => array('label' => $this->l('Text when backorder allowed')),
     'available_for_order' => array('label' => $this->l('Available for order (0 = No, 1 = Yes)')),
     'available_date' => array('label' => $this->l('Product availability date')),
     'date_add' => array('label' => $this->l('Product creation date')),
     'show_price' => array('label' => $this->l('Show price (0 = No, 1 = Yes)')),
     'image' => array('label' => $this->l('Image URLs (x,y,z...)')),
     'delete_existing_images' => array(
         'label' => $this->l('Delete existing images (0 = No, 1 = Yes)')
     ),
     'features' => array('label' => $this->l('Feature (Name:Value:Position:Customized)')),
     'online_only' => array('label' => $this->l('Available online only (0 = No, 1 = Yes)')),
     'condition' => array('label' => $this->l('Condition')),
     'customizable' => array('label' => $this->l('Customizable (0 = No, 1 = Yes)')),
     'uploadable_files' => array('label' => $this->l('Uploadable files (0 = No, 1 = Yes)')),
     'text_fields' => array('label' => $this->l('Text fields (0 = No, 1 = Yes)')),
     'out_of_stock' => array('label' => $this->l('Action when out of stock')),
     'shop' => array(
         'label' => $this->l('ID / Name of shop'),
         'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.'),
     ),
     'advanced_stock_management' => array(
         'label' => $this->l('Advanced Stock Management'),
         'help' => $this->l('Enable Advanced Stock Management on product (0 = No, 1 = Yes).')
     ),
     'depends_on_stock' => array(
         'label' => $this->l('Depends on stock'),
         'help' => $this->l('0 = Use quantity set in product, 1 = Use quantity from warehouse.')
     )
 );

* Don’t for get to add custom field information on csv. Check Demo.

Now Need to find this section. you can search by processDeferedFuncCall or updateTagCount and match with bellow codes.

$this->closeCsvFile($handle);
Module::processDeferedFuncCall();
Module::processDeferedClearCache();
Tag::updateTagCount();

add bellow code after the upper code. Done.

Db::getInstance()->update('product', array('extrafield' => $info['extrafield']), 'id_product = ' . (int)$product->id);

Don’t forget to add csv like bellow:
products_import

Hits: 135

%d bloggers like this: