You are here:  » Manual Insert Script for brand

Support Forum



Manual Insert Script for brand

Submitted by webie on Mon, 2007-07-16 14:37 in

Hi David,

I have noticed today that when i am import feeds with brand registered it causes
so many problems as merchant feeds are not very good and the brand has a load c**p in the database now.

So i done a test run with navicat to update products set brand where name equals some brand name is sql command how I would like to get this in a php script so i can arrange brands properly based on product name.

could you guide me on how to do this all the best

Darren

here naviat command on test run
UPDATE products
SET brand = 'Duracell'
WHERE name LIKE "%Duracell%"

Submitted by support on Mon, 2007-07-16 17:16

Hello Darren,

The place to insert this code would be at the end of the following function within includes/admin.php:

function admin_import($filename,$limit=0,$callback="")
{
  // .... rest of code ...
  // .... INSERT NEW CODE HERE .... //
  return "";
}

At the INSERT NEW CODE HERE point as shown above, the following PHP will execute the SQL shown in your post above using Price Tapestry's database library:

    $sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='Duracell' WHERE name LIKE '%Duracell%'";
    database_queryModify($sql,$result);

Now, you could of course just add multiple versions of the above 2 lines for all of your search > brand mappings, however it would be much easier to create an array of mappings, and then loop through the array performing the query for each entry:

    $brands = array("Duracell","EverReady","Energizer");
    foreach($brands as $brand)
    {
      $sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='".$brand."' WHERE name LIKE '%".$brand."%'";
      database_queryModify($sql,$result);
    }

That should do the trick!

Cheers,
David.

Submitted by Mik3 on Mon, 2008-02-18 22:30

David,

I've been trying to get this code to work but I just can't seem to get it to import the brands.

My code addition looks something like this:

$brands = array("Spiderman");
foreach($brands as $brand)
{
$sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='".$brand."' WHERE name LIKE '%".$brand."%'";
database_queryModify($sql,$result);
}

And an example product name might be Spiderman Comic Montage T Shirt. What am I doing wrong?

Submitted by support on Tue, 2008-02-19 04:37

Hi,

The code looks fine... what I normally do in a situation like this is to dump the SQL that is being generated and then run the query manually using something like phpMyAdmin (or similar MySQL admin tool)....

Simply change your code to:

$brands = array("Spiderman");
foreach($brands as $brand)
{
$sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='".$brand."' WHERE name LIKE '%".$brand."%'";
print $sql;
database_queryModify($sql,$result);
}

...and then try running the SQL manually. phpMyAdmin should display any error message that is a result of this...

Cheers,
David.

Submitted by Mik3 on Tue, 2008-02-19 18:29

David,

I have to be honest - you've completely lost me here!!

Submitted by support on Tue, 2008-02-19 20:05

Hi,

No worries! If you could email me your modified includes/admin.php i'll check the changes over for you; and if necessary add some debug code to workout what the problem might be...(reply to your reg code or forum registration email is the easiest way to get me!)

Cheers,
David.