You are here:  » How To Import & Handle Product Attributes


How To Import & Handle Product Attributes

Submitted by ItsDavid on Fri, 2017-10-27 13:55 in

Hi David

Is there an easy way to import attributes for products and display them with the products they belong to?

I have some feeds that have product attributes in the following format.

ATTRIBUTECLASS
ATTRIBUTECLASS-CLASS_ID 60
ATTRIBUTECLASS/PRODUCT_TYPE Shoes
ATTRIBUTECLASS/SIZE 8~~9~~10~~11~~12~~13
ATTRIBUTECLASS/COLOR Brown CH
ATTRIBUTECLASS/STYLE Casual~~Dual Comfort~~Sandal~~Slip On

How can I import product attributes and allow filtering by product attributes?

Best Regards
David

Submitted by support on Sat, 2017-10-28 08:47

Hi David,

There's a few steps involved here but it's possible to add comma separated values support for filter / custom fields. Firstly, you would need to add the custom fields in the usual way as described here.

After registering your feeds with the appropriate attribute fields mapped, add Search and Replace filters as required (either global or per feed) to convert ~~ into , giving you comma separated values instead of ~~ separation.

Next, you'll find the steps for adding a new custom field filter in this comment.

The example uses a custom field "colour" (note UK spelling). To convert the changes to support comma separated values, in place of the following code added to search.php beginning at line 76:

  if ($colourFilter)
  {
    $priceWhere .= " AND colour = '".database_safe($colourFilter)."' ";
  }

...you would use:

  if ($colourFilter)
  {
    $priceWhere .= " AND CONCAT(',',colour,',') LIKE '%,".database_safe($colourFilter).",%' ";
  }

And as a complete alternative to the drop down field code added to html/searchfilters.php, use:

  $sql1 = "SELECT DISTINCT(colour) FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." AND colour <> '' ORDER BY colour";
  if (database_querySelect($sql1,$rows1))
  {
    $newRows1 = array();
    foreach($rows1 as $row)
    {
      $colours = explode(",",$row["colour"]);
      foreach($colours as $colour)
      {
        $colour = trim($colour);
        if ($colour)
        {
          $newRows1[$colour]["colour"] = $colour;
        }
      }
    }
    ksort($newRows1);
    $rows1 = $newRows1;
    print "<div class='small-12 medium-2 columns'>";
    print "<label>Colour<<br />";
    print "<select name='colourFilter'>";
    print "<option value=''>".translate("All")."</option>";
    foreach($rows1 as $row)
    {
      $selected = ($colourFilter==$row["colour"]?"selected='selected'":"");
      print "<option value='".htmlspecialchars($row["colour"],ENT_QUOTES,$config_charset)."' ".$selected.">".$row["colour"]."</option>";
    }
    print "</select>";
    print "</label>";
    print "</div>";
  }

Cheers,
David.
--
PriceTapestry.com