Hi again David :o)
I'm trying to work out a solution on how i get the brand name extracted out of the product name.
My feeds contains a mix of brands within a specific cataegory, but the brand name is not a columm of its own.
Each product contains the brand, but there is not a exact pattern on where in the product name it is loctated.
My idea was to create a table of brand names and then use a sql update that would match one of the brand names with the product name and then insert this match into the brand cell.
is this the rigth way to do this or do you have a more solid solution?
//Brian
PS.sample of a product name:
RockShox Recon 351 Solo Air
in this sample the brand name should be RockShox
Hallo David
Very fast responds - thx
uploaded a _brands.txt into feeds folder (only containing some of the brand names), but
... got this error:
Warning: fopen(../feeds/_brands.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/mydomain.com/pt/includes/admin.php on line 186
Warning: feof(): supplied argument is not a valid stream resource in /home/www/mydomain.com/pt/includes/admin.php on line 187
.. ect.
//Brian
else
{
// $importRecord["brand"] = ""; //http://www.pricetapestry.com/node/3739
$importRecord["brand"] = "";
global $admin_brands;
if (!$admin_brands)
{
$fp = fopen("../feeds/_brands.txt","r");
while(!feof($fp))
{
$line = trim(fgets($fp));
if ($line)
{
$admin_brands[] = $line;
}
}
}
foreach($admin_brands as $admin_brand)
{
if (strpos($importRecord["name"],$admin_brand)!==FALSE)
{
$importRecord["brand"] = $admin_brand;
break;
}
}
}
Hi Brian,
That looks fine - although strictly speaking it should be:
global $config_feedDirectory;
$fp = fopen($config_feedDirectory."_brands.txt","r");
...but that would only be if you weren't using the default feed directory location. The other possibility is that PHP is not configured to internally change directory to the same folder as the script, in which case it might be worth having a go with:
$fp = fopen("/home/www/mydomain.com/pt/feeds/_brands.txt","r");
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Is possible extra brand form Name AND/OR Description?
You can public this mod?
Thank's
Hi Marco,
Sure - the original code point for the latest version is now 207:
elseif($admin_importFeed["user_brand"])
{
$importRecord["brand"] = $admin_importFeed["user_brand"];
}
...and the replacement:
else
{
global $config_feedDirectory;
$importRecord["brand"] = "";
global $admin_brands;
if (!$admin_brands)
{
$fp = fopen($config_feedDirectory."brands.txt","r");
while(!feof($fp))
{
$line = trim(fgets($fp));
if ($line)
{
$admin_brands[] = $line;
}
}
}
foreach($admin_brands as $admin_brand)
{
if (
(strpos($importRecord["name"],$admin_brand)!==FALSE)
||
(strpos($importRecord["description"],$admin_brand)!==FALSE)
)
{
$importRecord["brand"] = $admin_brand;
break;
}
}
}
Cheers,
David.
--
PriceTapestry.com
Nice David,
i add some filed in my pt for create more filter for example
sex,color,material,size
if this field not are in feed i like use this method for populate filter
i try to add this code for material:
// material
if ($importRecord["material"] = "") {
global $admin_materials;
if (!$admin_materials)
{
$fp = fopen("../feeds/materials.txt","r");
while(!feof($fp))
{
$line = trim(fgets($fp));
if ($line)
{
$admin_materials[] = $line;
}
}
}
foreach($admin_brands as $admin_brand)
{
if (
(strpos($importRecord["name"],$admin_brand)!==FALSE)
||
(strpos($importRecord["description"],$admin_brand)!==FALSE)
)
{
$importRecord["brand"] = $admin_brand;
break;
}
}
}
but not work how to solve this problem?
Thanks
global $config_feedDirectory;
if ($importRecord["material"] = "") {
global $admin_materials;
if (!$admin_materials)
{
$fp = fopen($config_feedDirectory."materials.txt","r");
while(!feof($fp))
{
$line = trim(fgets($fp));
if ($line)
{
$admin_materials[] = $line;
}
}
}
foreach($admin_materials as $admin_material)
{
if (
(strpos($importRecord["name"],$admin_material)!==FALSE)
||
(strpos($importRecord["description"],$admin_material)!==FALSE)
)
{
$importRecord["material"] = $admin_material;
break;
}
}
}
Hello Marco,
I think it is just the first line - comparison in PHP is double-equals e.g. == rather than just = (which is assignment). Instead of:
if ($importRecord["material"] = "") {
...use:
if ($importRecord["material"] == "") {
Cheers,
David.
--
PriceTapestry.com
Hello David,
work but i have another problem... Material in some products are more then 1 i can create list?
Material1, Material2, Material3, Material4
If possible save all match in line?
Thank's
Marco
Hi Marco,
Sure, instead of breaking out of the loop you can let it continue, and build up a comma separated list of materials, so in place of:
$importRecord["material"] = $admin_material;
break;
...use:
if (!$importRecord["material"])
{
$importRecord["material"] = $admin_material;
}
else
{
$importRecord["material"] .= ",".$admin_material;
}
Cheers,
David.
--
PriceTapestry.com
Hello David thank's for that but not include comma
Save:
Material1 Material2 Material3
And not Save:
Material1, Material2, Material3
Idea?
Thank's
Hi Marco,
Sure, instead of:
$importRecord["material"] .= ",".$admin_material;
...just use:
$importRecord["material"] .= " ".$admin_material;
Cheers,
David.
--
PriceTapestry.com
Hi Marco,
After the code above did you add (having copied the code from category or brand)
$importRecord["material"] = tapestry_normalise($importRecord["material"]);
...because that would be removing the comma. If this field is only being set by the above logic the tapestry_normalise() function isn't required so you could just remove that line, if you're still not sure, if you could email me your modified includes/admin.php I'll check it out for you..!
Cheers,
David.
--
PriceTapestry.com
Hi Brian,
Quite straight forward actually - easiest done using a text file rather than a new table database table.
1) Create and manage a text file called "brands.txt" located in your /feeds/ folder, containing one brand name per line, e.g.
RockShox
Adidas
Puma
2) Look for the following code beginning at line 177 of includes/admin.php:
else
{
$importRecord["brand"] = "";
}
...and REPLACE with the following:
else
{
$importRecord["brand"] = "";
global $admin_brands;
if (!$admin_brands)
{
$fp = fopen("../feeds/brands.txt","r");
while(!feof($fp))
{
$line = trim(fgets($fp));
if ($line)
{
$admin_brands[] = $line;
}
}
}
foreach($admin_brands as $admin_brand)
{
if (strpos($importRecord["name"],$admin_brand)!==FALSE)
{
$importRecord["brand"] = $admin_brand;
break;
}
}
}
That should do it!
Cheers,
David.
--
PriceTapestry.com