function cw_warehouse_get_avails($product_id)
{
    global $tables, $addons;
    //    $ret = cw_query("select pa.* from $tables[products_warehouses_amount] as pa, $tables[customers] as c where c.customer_id=pa.warehouse_customer_id and pa.product_id='$product_id' and pa.avail > 0 order by pa.warehouse_customer_id, pa.variant_id");
    $ret = cw_query($sql = "select pa.*, wd.title as warehouse_title from {$tables['products_warehouses_amount']} as pa, {$tables['warehouse_divisions']} as wd where wd.division_id=pa.warehouse_customer_id and pa.product_id='{$product_id}' order by pa.warehouse_customer_id, pa.variant_id");
    # kornev, TOFIX
    if (is_array($ret) && $addons['product_options']) {
        $tmp = cw_get_hash_options($product_id);
        foreach ($ret as $k => $value) {
            if ($value['variant_id']) {
                $options = cw_query("select option_id from {$tables['product_variant_items']} where variant_id='{$value['variant_id']}'");
                if (is_array($options)) {
                    foreach ($options as $opt) {
                        $ret[$k]['options'][] = $tmp[$opt['option_id']];
                    }
                }
            }
        }
    }
    return $ret;
}
function cw_get_product_exceptions($product_id, $area = false)
{
    global $tables, $current_area, $current_language;
    $keys = cw_get_hash_options($product_id);
    if ($area === false) {
        $area = $current_area;
    }
    $avail_condition = '';
    if ($area == 'C') {
        $avail_condition = " AND {$tables['product_options']}.avail = 1 AND {$tables['product_options_values']}.avail = 1";
    }
    $exceptions = cw_query("SELECT {$tables['products_options_ex']}.* FROM {$tables['products_options_ex']}, {$tables['product_options']}, {$tables['product_options_values']} WHERE {$tables['product_options']}.product_option_id = {$tables['product_options_values']}.product_option_id AND {$tables['product_options_values']}.option_id = {$tables['products_options_ex']}.option_id AND {$tables['product_options']}.product_id = '{$product_id}'" . $avail_condition . " GROUP BY {$tables['products_options_ex']}.exception_id, {$tables['products_options_ex']}.option_id ORDER BY {$tables['product_options']}.orderby");
    $return = array();
    if ($exceptions) {
        foreach ($exceptions as $exception) {
            if (!isset($return[$exception['exception_id']])) {
                $return[$exception['exception_id']] = array();
            }
            $return[$exception['exception_id']][$exception['option_id']] = $keys[$exception['option_id']];
        }
    }
    return $return;
}