Back to PhocacartAttribute class

Method getCombinations

public static
getCombinations
(mixed $id, mixed $title, mixed $attributes, mixed &$combinations = array())

Method getCombinations - Source code

public static function getCombinations($id, $title, $attributes, &$combinations = array())
{
    $array = array();
    $requiredArray = array();
    if (!empty($attributes)) {
        ksort($attributes);
        $i = 0;
        foreach ($attributes as $k => $v) {
            if (!empty($v->options)) {
                ksort($v->options);
                foreach ($v->options as $k2 => $v2) {
                    $array[$i]['pid'] = $id;
                    $array[$i]['ptitle'] = $title;
                    $array[$i]['aid'] = $v->id;
                    $array[$i]['atitle'] = $v->title;
                    $array[$i]['oid'] = $v2->id;
                    $array[$i]['otitle'] = $v2->title;
                    $array[$i]['multiple'] = self::isMultipleAttribute($v->type);
                    $array[$i]['required'] = $v->required;
                    $i++;
                }
            }
            if ($v->required == 1) {
                $requiredArray[] = $v->id;
            }
        }
    }
    // All combinations of attributes
    $pA = self::makeCombination($array, $requiredArray);
    // Add to the array product itself (product without any variation)
    // Only in case, there is no required attribute
    $pI = array();
    if (empty($requiredArray)) {
        $pIPK = $id . '::';
        $pI[$pIPK]['title'] = '(' . Text::_('COM_PHOCACART_NO_ATTRIBUTES') . ')';
        $pI[$pIPK]['cannotcombinate'] = 0;
        $pI[$pIPK]['product_id'] = $id;
        $pI[$pIPK]['product_title'] = $title;
        $pI[$pIPK]['attributes'] = array();
        $pI[$pIPK]['product_key'] = $pIPK;
        $pI[$pIPK]['stock'] = 0;
        $pI[$pIPK]['price'] = '';
        $pI[$pIPK]['sku'] = '';
        $pI[$pIPK]['ean'] = '';
        $pI[$pIPK]['image'] = '';
    }
    $combinations = array_merge($pI, $pA);
    return true;
}