Jump to content

Can someone explain what this function does?


jaumerrr

Recommended Posts

I have a problem and I am stuck with prestashop ... I can't add any image to any product. Here in this post I explain it all: http://www.prestashop.com/forums/viewthread/45461/general_discussion/cant_add_images_to_products

As i can't get any help I would like to investigate even a lot more and know why I am getting this random nasty error.

Can someone explain me what does this function do?

It's in file /admindirectory/tabs/AdminProducts.php

Snippet I am interested becuase I am allways getting this error no matter what .. .I wan't to know why I allways get the " error while creating additional image "

               if (!sizeof($this->_errors))
               {
                   if (!$image->add())
                       $this->_errors[] = Tools::displayError('error while creating additional image');
                   else
                       $this->copyImage($product->id, $image->id, $method);
               }



Whole section

       /* Adding a new product image */
       elseif (isset($_FILES['image_product']['tmp_name']) AND $_FILES['image_product']['tmp_name'] != NULL)
       {
           if (!Validate::isLoadedObject($product))
               $this->_errors[] = Tools::displayError('cannot add image because product add failed');
           else
           {
               $image = new Image();
               $image->id_product = intval($product->id);
               $_POST['id_product'] = $image->id_product;
               $image->position = Image::getHighestPosition($product->id) + 1;
               if (($cover = Tools::getValue('cover')) == 1)
                   Image::deleteCover($product->id);
               $image->cover = !$cover ? !sizeof($product->getImages(Configuration::get('PS_LANG_DEFAULT'))) : true;
               $this->validateRules('Image', 'image');
               $this->copyFromPost($image, 'image');
               if (!sizeof($this->_errors))
               {
                   if (!$image->add())
                       $this->_errors[] = Tools::displayError('error while creating additional image');
                   else
                       $this->copyImage($product->id, $image->id, $method);
               }
           }
           $id_image = $image->id;

       }
       if (isset($image) AND Validate::isLoadedObject($image) AND !file_exists(_PS_IMG_DIR_.'p/'.$image->id_product.'-'.$image->id.'.jpg'))
           $image->delete();
       if (sizeof($this->_errors))
           return false;
       @unlink(dirname(__FILE__).'/../../img/tmp/product_'.$product->id.'.jpg');
       @unlink(dirname(__FILE__).'/../../img/tmp/product_mini_'.$product->id.'.jpg');
       return ((isset($id_image) AND is_int($id_image) AND $id_image) ? $id_image : true);
   }

Link to comment
Share on other sites

You might want to check whether the folder where images are being uploaded is writable. Try settings all folders permissions to 755 and check whether this resolved the issue. Hope it helps.


It's not a permissions problem. I have resetted permissions many times, changed, etc ... makes no difference.
Link to comment
Share on other sites

As i explained in the other post, there are no log errors at all, just this prestashop error. I have php in the most detailed verbose method for errors, and no errors printed on screen or in any log ... its confusing, I just get the prestashop error about additional image ... that's why i want to nail what the hell does this function check to show that error.

If it were a server problem I would get an error log, but thios is a prestashop error that I can't get through.

I will reinstall all again and it will work for some time, then it will block again!!!

Link to comment
Share on other sites

  • 1 year later...

Hello Jaumerrr,

 

Were you able to solve the problem? I am having the exact same problem and cannot figure out how to get a more verbose error. I have tripled-checked the permissions and everything is fine. It was working just a few days ago and has mysteriously stopped.

 

Thanks in advance!

 

~ Jeremy

Link to comment
Share on other sites

  • 5 months later...

Hi there,

We got the same issue. The error thrown up because the table "ps_image_lang" is full. First it was suprising because the table was very light.

It can happens with Innodb table. You can find a full report about this issue here : http://dev.mysql.com/doc/refman/5.0/en/full-table.html

and the solution here : http://dev.mysql.com/doc/refman/5.0/en/innodb-data-log-reconfiguration.html

 

Finally we resolved the issue by modifying the my.cnf file (Mysql configuration file) by editing the max limit of the innodb data file.

 

Hope it can help you.

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
  • 1 year later...
  • 1 month later...

Bump.

 

Same problem since attempted/failed upgrade from Prestashop 1.6.0.14 to 1.6.1. I turned on bug reporting (see 1st screenshot for how to instructions) and get "unexpected token <" there are few thread on the forum where others have experienced the same. Most seem to be suggesting checking permission files are 755 or 777 here's the thread that deals with that and php.ini settings:

 

https://www.prestashop.com/forums/topic/302797-solved-error-uploading-products-images-in-ps-1561/?do=findComment&comment=1535934

 

This hasn't solved the problem for me though. Still looking.

Link to comment
Share on other sites

  • 3 weeks later...

I think i have found the source to the problem, but not an fix!

 

If you guys go to the 'ps_image' AND 'ps_image_shop' tables in you database, and look for rows where `cover` is set to 0 instead of NULL.

If you change these rows to NULL, it will let you upload ONE more picture, but this picture will have a `cover` value of '0'...

 

Can anyone understand why this happens? Or are all the `cover` values in 'ps_image' and 'ps_image_shop' supposed to be the value '0'?

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...
this problem occured when we upgrade Prestashop or when we change the version manually. there are some differences between databases of some versions of prestashop.
 
to solve this problem, and for example, let's say that we have upgraded Prestashop from 1.6.0.14 to 1.6.1.1: 

A ) export tables ps_image, ps_image_lang, ps_image_shop from database related to 1.6.0.14
 
B )delete or rename ps_image, ps_image_lang, ps_image_shop from database related to 1.6.1.1

C ) import tables exported before into database related to your new version (here 1.6.1.1)

Hope this help you.
Edited by jalloun (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

We have at least temporarily solved this by DROPping and editing INDEXes related to "cover" image.

 

1. We DROPped INDEX id_product_cover from ps_image indexes.

2. Also: we set to IGNORE the "cover" field of the INDEX id_image in the ps_image_shop table.

 

This allowed us to upload, but I think you will need to recreate these indexes to get all the functionality to work.

 

We noticed this created a bug (but it all works fine once you know the bug):

     1. The "COVER" checkbox will DELETE that image -- so you can use it for that - Click SAVE and STAY to delete the selected image.

     2. The LAST image you upload will be your COVER image.

      ** All your uploaded images will be marked "Cover" image...

 

Hope that helps someone.

- Dasher

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...