You are here:  » How to isolate brand from product name

Support Forum



How to isolate brand from product name

Submitted by teezone on Tue, 2009-07-21 01:49 in

Hi David, hope all is well!

I thought I had seen it all with unusual datafeeds, but this has me stumped. The merchant doesn't offer a separate field for brand, but the product field actually starts with the brand name.. in all-caps.

For example:
BRAND This is the product
SECOND BRAND This is is another product

Do you think there would be any way to isolate brand as the first words in "all caps"..? For now, brand = merchant name, but it would be great to split this out in a filter.

Thanks!
T.

Submitted by support on Tue, 2009-07-21 07:59

Hi Theresa,

Have a go with this filter - Extract Brand, simply add the code to includes/filter.php as with other filters. Register it against the Product Name field, and it will return the product name component as the output of the filter as normal, and also, by accessing global variables, set the brand value (there is no need to register a field for the brand - it makes up a "virutal" field name)...

<?php
  
/*************************************************/
  /* extractBrand                                  */
  /*************************************************/
  
$filter_names["extractBrand"] = "Extract Brand";
  function 
filter_extractBrandConfigure($filter_data)
  {
    print 
"<p>There are no additional configuration parameters for this filter.</p>";
  }
  function 
filter_extractBrandValidate($filter_data)
  {
  }
  function 
filter_extractBrandExec($filter_data,$text)
  {
    global 
$record;
    global 
$admin_importFeed;
    
$words explode(" ",$text);
    
$brandWords = array();
    
$productWords = array();
    
$done FALSE;
    foreach(
$words as $word)
    {
      if (
ctype_upper($word) && !$done)
      {
        
$brandWords[] = $word;
      }
      else
      {
        
$productWords[] = $word;        
        
$done TRUE;
      }
    }
    
$brandName implode(" ",$brandWords);
    
$productName implode(" ",$productWords);
    
$admin_importFeed["field_brand"] = "_FILTER_BRAND";
    
$record[$admin_importFeed["field_brand"]] = $brandName;
    return 
$productName;
  }
?>

Cheers,
David.