Back to PhocacartAttribute class

Method getAttributesSelectedOnly

public static
getAttributesSelectedOnly
(mixed $attributes)

Method getAttributesSelectedOnly - Source code

/* When product is displayed, it has selected the default values
 * We need to filter all attributes assigned to product so the product only includes selected attributes and otpions
 * and we can make by this selection productKey
 */
public static function getAttributesSelectedOnly($attributes)
{
    $sAttributes = array();
    if (!empty($attributes)) {
        foreach ($attributes as $k => $v) {
            if (!empty($v->options)) {
                foreach ($v->options as $k2 => $v2) {
                    if (isset($v2->default_value) && $v2->default_value == 1) {
                        $sAttributes[$k][$v2->id] = $v2->id;
                    }
                }
            }
        }
    }
    return $sAttributes;
}