Back to PhocacartId class

Method getIdItemsChangedByAttributes

public
getIdItemsChangedByAttributes
(mixed &$item, mixed $attributes, mixed $ajax = 0)

Method getIdItemsChangedByAttributes - Source code

/* Change ID (EAN, SKU, ...) based on Advanced Stock Management */
public function getIdItemsChangedByAttributes(&$item, $attributes, $ajax = 0)
{
    //  $paramsC            = PhocacartUtils::getComponentParameters();
    //  $fullAttributes = array();// Array of integers only
    $thinAttributes = array();
    // Array of full objects (full options object)
    if ($ajax == 1) {
        // $fullAttributes = PhocacartAttribute::getAttributeFullValues($attributes);
        $thinAttributes = $attributes;
    } else {
        // $fullAttributes = $attributes;
        $thinAttributes = PhocacartAttribute::getAttributesSelectedOnly($attributes);
    }
    // Stock Calculation
    // 0 ... Main Product
    // 1 ... Product Variations
    // 2 ... Advanced Stock Management
    // 3 ... Advanced Stock and Price Management
    if ($item->stock_calculation == 2 || $item->stock_calculation == 3) {
        // Advanced Stock Management
        $k = PhocacartProduct::getProductKey((int) $item->id, $thinAttributes);
        $dataASM = PhocacartAttribute::getCombinationsDataByKey($k);
        if (isset($dataASM['sku']) && $dataASM['sku'] != '') {
            $item->sku = $dataASM['sku'];
        }
        if (isset($dataASM['ean']) && $dataASM['ean'] != '') {
            $item->ean = $dataASM['ean'];
        }
    }
}