Jump to content



Latest News: (loading..)

- - - - -

Copy Product Problem


  • Please log in to reply
10 replies to this topic

#1   Xpajun

Xpajun
  • Members
  • 1,295 posts
  • Real Name:Julian
  • Gender:Male
  • Location:UK

Posted 10 August 2012 - 08:41 AM

I've recently added to Table Products Description 3 extra columns with a corresponding 3 extra fields in categories.php to add data in them. All 3 extra columns are TEXT and add additional details to the item description such as technical specifications etc.

Everything works perfectly until I try to copy an item (or, I suspect, move it as well). The copy script selects the data from all 9 columns of  Table Products Description but then combines the extra 3 TEXT columns to the original products_description and then tries to insert the result back into Table Products Description.

Consequently I'm getting a 1136 - Column count doesn't match value count at row 1

Does anyone have any idea where my problem may lie or where the copy script gets it's select information from?

#2   multimixer

multimixer

    Lemons or Melons ?

  • Partner
  • 4,401 posts
  • Real Name:George Zarkadas
  • Gender:Male
  • Location:Greece

Posted 10 August 2012 - 08:44 AM

Did you update the "action" "copy_to_confirm" in file admin/categories.php?

You need to make sure that the query pick the 3 new fields and then insert them again

			$description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'");
			while ($description = tep_db_fetch_array($description_query)) {
			  tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')");
			}


#3   Xpajun

Xpajun
  • Members
  • 1,295 posts
  • Real Name:Julian
  • Gender:Male
  • Location:UK

Posted 10 August 2012 - 08:57 AM

Hi George,

Thanks for the fast response - the answer is no because I don't seem to have that in my categories.php - I have the 2010 version of 2.3.1 running at the moment

Is that in the 2.3.3 categories.php?

#4   multimixer

multimixer

    Lemons or Melons ?

  • Partner
  • 4,401 posts
  • Real Name:George Zarkadas
  • Gender:Male
  • Location:Greece

Posted 10 August 2012 - 08:59 AM

Yes, that is in version 2.3, but it's the same in the older version. Go to " case 'copy_to_confirm':" and you'll see it in there

#5   Xpajun

Xpajun
  • Members
  • 1,295 posts
  • Real Name:Julian
  • Gender:Male
  • Location:UK

Posted 10 August 2012 - 01:36 PM

Sorry for the delay in answering, George, yes - I do have that - obviously in too much of a hurry earlier...

I have indeed updated both the (copy_to_confirm) search query and the insert query, and both those bits seem to be working alright - the script searches and get the data from all nine columns, it tries to put that resulting data back into the table...

but in between times it has somehow joined all the data from my new columns to the products_description so the script is now trying to fit 6 fields into 9 columns

#6   Xpajun

Xpajun
  • Members
  • 1,295 posts
  • Real Name:Julian
  • Gender:Male
  • Location:UK

Posted 10 August 2012 - 01:52 PM

Just done a check now - it shows that 'move_to' works but not 'copy_to'


<EDIT>

'copy_to' as a link seems to work as well - which narrows it down to 'copy_to' duplicate

and 'delete' works as well

Edited by Xpajun, 10 August 2012 - 01:59 PM.


#7   bktrain

bktrain
  • Members
  • 2,104 posts
  • Real Name:Brian
  • Gender:Male
  • Location:On the brink of insanity

Posted 10 August 2012 - 04:19 PM

View PostXpajun, on 10 August 2012 - 01:52 PM, said:

narrows it down to 'copy_to' duplicate
That is in the copy_to_confirm case as well.

Just below
		  } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
you will find
			$description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'");
			while ($description = tep_db_fetch_array($description_query)) {
			  tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')");
			}
If you are using multiple languages you will need to edit admin/languages.php.
Edit this section
// create additional products_description records
		$products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, pd.products_url from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id where pd.language_id = '" . (int)$languages_id . "'");
		while ($products = tep_db_fetch_array($products_query)) {
		  tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url) values ('" . (int)$products['products_id'] . "', '" . (int)$insert_id . "', '" . tep_db_input($products['products_name']) . "', '" . tep_db_input($products['products_description']) . "', '" . tep_db_input($products['products_url']) . "')");
		}
and this section
		tep_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where language_id = '" . (int)$lID . "'");

Remember to backup database, files and pictures.

I have a problem for your solution
I reject your reality and substitute my own
My mind not only wanders, it sometimes leaves completely
The problem with the gene pool is that there is no lifeguard
Everyone’s entitled to my opinion


Links
Security
SSL Help
Basics for design
Basics for design V2.3+
How Do I ...?

#8   Xpajun

Xpajun
  • Members
  • 1,295 posts
  • Real Name:Julian
  • Gender:Male
  • Location:UK

Posted 10 August 2012 - 06:15 PM

Hi Brian - thanks for your input,

View Postbktrain, on 10 August 2012 - 04:19 PM, said:

That is in the copy_to_confirm case as well.

Just below
		  } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
you will find
			$description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'");
			while ($description = tep_db_fetch_array($description_query)) {
			  tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')");
			}


That's the same bit of code that George mentions above and which I have altered with my extra field/column names - the thing is that that bit seems to work - it gets the data from all 9 of my table columns and then tries to insert them back into all 9 columns but in between times (sometime during the copy process?) it joins my new field/column data to the products_description data (and reduces the value count back to 6)


View Postbktrain, on 10 August 2012 - 04:19 PM, said:

If you are using multiple languages you will need to edit admin/languages.php.
Edit this section
// create additional products_description records
		$products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, pd.products_url from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id where pd.language_id = '" . (int)$languages_id . "'");
		while ($products = tep_db_fetch_array($products_query)) {
		  tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url) values ('" . (int)$products['products_id'] . "', '" . (int)$insert_id . "', '" . tep_db_input($products['products_name']) . "', '" . tep_db_input($products['products_description']) . "', '" . tep_db_input($products['products_url']) . "')");
		}
and this section
		tep_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where language_id = '" . (int)$lID . "'");

I hadn't found that languages one - I've updated it now - but it's not made a difference (only have the one language)

#9   Xpajun

Xpajun
  • Members
  • 1,295 posts
  • Real Name:Julian
  • Gender:Male
  • Location:UK

Posted 10 August 2012 - 06:32 PM

Problem solved - my bad coding :blush:

instead of
. tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_

I'd written
. tep_db_input($description['products_description']) . tep_db_input($description['products_


Thanks George and Brian for helping to look in the right places to get it sorted

#10   bktrain

bktrain
  • Members
  • 2,104 posts
  • Real Name:Brian
  • Gender:Male
  • Location:On the brink of insanity

Posted 10 August 2012 - 07:38 PM

View PostXpajun, on 10 August 2012 - 06:15 PM, said:

That's the same bit of code that George mentions above
So much for me paying attention

Quote

Problem solved - my bad coding :blush:
I was just coming back to say I just tried with no problems.

Glad you got it working

Edited by bktrain, 10 August 2012 - 07:39 PM.

Remember to backup database, files and pictures.

I have a problem for your solution
I reject your reality and substitute my own
My mind not only wanders, it sometimes leaves completely
The problem with the gene pool is that there is no lifeguard
Everyone’s entitled to my opinion


Links
Security
SSL Help
Basics for design
Basics for design V2.3+
How Do I ...?

#11   multimixer

multimixer

    Lemons or Melons ?

  • Partner
  • 4,401 posts
  • Real Name:George Zarkadas
  • Gender:Male
  • Location:Greece

Posted 11 August 2012 - 04:01 AM

Julian, yes, this was not very nice
. tep_db_input($description['products_description']) . tep_db_input($description['products_

What to do, things like this happen

Just for general info and about your above statement

View PostXpajun, on 10 August 2012 - 01:52 PM, said:

Just done a check now - it shows that 'move_to' works but not 'copy_to'
...
'copy_to' as a link seems to work as well - which narrows it down to 'copy_to' duplicate

1) The copy product action has to ways of working

Copy as link, just add one more entry to table "products to categories", the product tables themselves remain untuched
Copy as duplicate, is the real copy action, it "read" all data for an existing product and insert it again with a new product id

2) The move product action, is similar to the copy as link: All it does is, to change the entry in table products to categories, the product tables are not affected

Edited by multimixer, 11 August 2012 - 04:02 AM.