Jump to content

Importing Manufacturers - missing fields


Recommended Posts

Hi,

I am looking into importing some existing data in Presta. The inbuilt import routine in Presta seem to work well, though I do notice that there are quite a few missing fields.

For example "Manufacturers" seems to be missing the ability to import the image and any tags you might want?

I really did to include these into the data, so do I have to waste time creating my own import routinue do this, or do I just go though the data again after import and manual add the missing information ??

Andy

Link to comment
Share on other sites

  • 2 weeks later...

I know this reply is probably a bit old for your question, but I thought I'd post it anyway in case it helps someone else in the same position.

I also wanted to be able to bulk import some extra manufacturer fields, particularly the descriptions and an image.
Here's what I did to achieve it:

I changed admin/tabs/AdminImport.php:

in __construct(), under where it has

            case $this->entities[$this->l('Manufacturers')]:
           case $this->entities[$this->l('Suppliers')]:


I added the extra fields I wanted to import:

               $this->available_fields = array(
               'no' => $this->l('Ignore this column'),
               'id' => $this->l('ID'),
               'name' => $this->l('Name *'),
               'description' => $this->l('Description'),
               'description_short' => $this->l('Short description'),
               'image' => $this->l('Image URL'));



in copyImg I added another case for manufacturer images:

           case 'manufacturers':
               $path = _PS_MANU_IMG_DIR_.intval($id_entity);
           break;



and in the manufacturerImport function I added a few lines to import images as an else block for 'if (!$res)'

           else
           {
               if (isset($manufacturer->image) AND !empty($manufacturer->image))
                   if (!(self::copyImg($manufacturer->id, NULL, $manufacturer->image, 'manufacturers')))
                       $this->_warnings[] = $manufacturer->image.' '.Tools::displayError('cannot be copied');
           }




Then in classes/Manufacturer.php I added

   /** @var string id_image is the manufacturer ID when an image exists and 'default' otherwise */
   public        $id_image = 'default';    



just above the __construct function, and as the last line within that function I added

       $this->id_image = ($this->id AND file_exists(_PS_MANU_IMG_DIR_.intval($this->id).'.jpg')) ? intval($this->id) : false;



I also added this code to the end of the delete function to clean up if needed

       /* Delete manufacturers images */
       foreach ($toDelete AS $id_manufacturer)
           deleteImage(intval($id_manufacturer));    





So basically all I had to do for most fields was add them to the AdminImport constructor. There were a few more tricks for getting images working, but it wasn't too hard either. Can we have this functionality in a future release please?

Link to comment
Share on other sites

Hi thanks for this, this is very useful code.

Though does not really help me out much as I am importing via a VB app directly into the data tables. I am copying the image files to the current directory, but I can not see anywhere in the tables that links images to Manufacturers.

Andy

Link to comment
Share on other sites

I don't think the link from Manufacturers to their logos/images is stored directly in the database. Instead it seems to be based on the ID of the manufacturer and is based on the changes I posted above to the Manufacturer class.
So if you have a manufacturer of id = 20, the associated image would need to be called 20.jpg and be stored in the _PS_MANU_IMG_DIR_ directory.
I haven't tested this theory out too much but it seems to be what the code is suggesting and is much the same way that category images work.
Hope this helps!

Link to comment
Share on other sites

  • 1 year later...

Hy,

 

I don't think the link from Manufacturers to their logos/images is stored directly in the database.

You're right

Instead it seems to be based on the ID of the manufacturer and is based on the changes I posted above to the Manufacturer class.

You're right once again

 

So if you have a manufacturer of id = 20, the associated image would need to be called 20.jpg and be stored in the _PS_MANU_IMG_DIR_ directory.

I haven't tested this theory out too much but it seems to be what the code is suggesting and is much the same way that category images work.

Hope this helps!

Personnaly I've tested this one and it works but leads to update problems. Whatever, your post leads me to a great solution.

 

Regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...