Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
Created May 31, 2012 16:06
Show Gist options
  • Save GreatPotato/2844430 to your computer and use it in GitHub Desktop.
Save GreatPotato/2844430 to your computer and use it in GitHub Desktop.
Gets a list of attributes that are unique to the products in a given category
public static function list_unique_values_in_category($name, $category = NULL)
{
$category = (int) $category;
$values = Db_DbHelper::scalarArray('
SELECT DISTINCT value, t4.name
FROM shop_product_properties t1
LEFT JOIN shop_products_categories t3
ON t1.product_id = t3.shop_product_id
LEFT JOIN shop_categories t4
ON t3.shop_category_id = t4.id
WHERE t4.id = :cat_id
AND t1.name = :name
', array('name'=>$name,'cat_id'=>$category));
$result = array();
foreach ($values as $value)
{
if (strlen($value) && !in_array($value, $result)) $result[] = $value;
}
sort($result);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment