Jump to content

I can update product images but not add them


jaumerrr

Recommended Posts

As I can't add new images I have figured a way to do it .. its annoying but it works

Here I explained the problem I have, that I can't add images to products:
http://www.prestashop.com/forums/viewthread/45461/general_discussion/cant_add_images_to_products

Here I asked how the image add function worked but got no response ...
http://www.prestashop.com/forums/viewthread/48950/general_discussion/can_someone_explain_what_this_function_does

And playing around I have found out a way to add images to products ... I have modified the function adding an echo and it seems to work .. .it adds the images (wrong way because they are blank) but then I can click to edit and update them ... and the update function its working OK.

I have added just the " echo $image->add(); " to the function .. .this line seems to interrupt prestashop from giving the error, and it adds the broken image that can later be updated correctly.

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



This happens to me in prestashop 1.3.X ... happened when it was alpha and through all svn ... i'm running now latest SVN version. When I was on Prestashop 1.2.5 I never had this problem.

I put this as a bug in the bugtracker but It was closed saying it was not a bug but in my opinion its a clear bug ... maybe a bug that triggers only in certain conditions that I don't know ... i just put here some details more so maybe someone can help:

-I am running now latest SVN version
-Permissions are OK, rechecked many times.
-Prestashop requirements are satisfied 100% when installing/upgrading.
-I have just one language active, spanish
-I have 27 main categories, hundreds of subcategories, and dozens of 3rd level categories.
-I have over 1500 products.
-Dedicated linux server, Centos 5.4 32bit, PHP 5.2.12 , Apache 2.2.3, Mysql 5.0.77

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

I had this problem because of doubled $this->q($query);

    public function    autoExecute($table, $values, $type, $where = false, $limit = false)
   {
       if (!sizeof($values))
           return true;

       if (strtoupper($type) == 'INSERT')
       {
           $query = 'INSERT INTO `'.$table.'` (';
           foreach ($values AS $key => $value)
               $query .= '`'.$key.'`,';
           $query = rtrim($query, ',').') VALUES (';
           foreach ($values AS $key => $value)
               $query .= '\''.$value.'\',';
           $query = rtrim($query, ',').')';
           if ($limit)
               $query .= ' LIMIT '.intval($limit);
                  $this->q($query);
           return $this->q($query);
       }
       elseif (strtoupper($type) == 'UPDATE')
       {
           $query = 'UPDATE `'.$table.'` SET ';
           foreach ($values AS $key => $value)
               $query .= '`'.$key.'` = \''.$value.'\',';
           $query = rtrim($query, ',');
           if ($where)
               $query .= ' WHERE '.$where;
           if ($limit)
               $query .= ' LIMIT '.intval($limit);
           return $this->q($query);
       }

       return false;
   }



so

            if ($limit)
               $query .= ' LIMIT '.intval($limit);
                  $this->q($query);
           return $this->q($query);



goes into

           if ($limit)
               $query .= ' LIMIT '.intval($limit);
                  //$this->q($query);
           return $this->q($query); 



Post reply if it helped!

Link to comment
Share on other sites

  • 2 years later...

Hi there, I have been having this problem for months and have been manually adding image entries directly into the database which creates a blank, but then i can correctly upload the correct image. It seems that the necessary table in the database is no longer created when trying to upload a new image...?

It was working fine previously, so what caused it to bug I do not know...!

WHat file did you modify to resolve this?

THanks a million,

Link to comment
Share on other sites

  • 6 months later...

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