}
        if ($ge_id && $fields['variants']) {
            while ($pid = cw_ge_each($ge_id, 1, $product_id)) {
                $res['id'] = cw_variants_get_same($v, $pid);
                if (empty($res['id'])) {
                    continue;
                }
                cw_image_delete($res['id'], 'products_images_var');
                cw_array2insert('products_images_var', $res);
            }
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_variants_upd'), 'type' => 'I');
    $refresh = $rebuild_quick = true;
} elseif ($action == 'product_variants_rebuild' && AREA_TYPE == 'A') {
    cw_rebuild_variants($product_id, true);
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_product_variants_rebuilded");
    $top_message['type'] = "I";
    $refresh = $rebuild_quick = true;
} elseif ($action == "variants_delete_image" && !empty($vids) and AREA_TYPE == 'A') {
    foreach ($vids as $k => $v) {
        cw_image_delete($k, 'products_images_var');
        # Delete variants image (Group editing of products functionality)
        if ($ge_id && $fields['variants'][$k]) {
            while ($pid = cw_ge_each($ge_id, 1, $product_id)) {
                $vid = cw_variants_get_same($k, $pid);
                if (!empty($vid)) {
                    cw_image_delete($vid, 'products_images_var');
                }
            }
        }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_options_js_upd'), 'type' => 'I');
    $refresh = true;
}
# arteml, not reliable condition based on $section or $js_tab, but otherwise it rebuilds variants after submit of any product modify tab
if ($action && ($section == 'options' || $js_tab == 'product_options')) {
    if ($ge_id) {
        while ($pid = cw_group_edit_each($ge_id, 1)) {
            if ($rebuild) {
                cw_rebuild_variants($pid);
            }
            if ($rebuild_quick) {
                cw_func_call('cw_product_build_flat', array('product_id' => $pid));
            }
        }
    }
    cw_rebuild_variants($product_id);
    cw_func_call('cw_product_build_flat', array('product_id' => $product_id, 'attribute_field' => $attr_field));
    if ($refresh) {
        $added = '';
        if (!empty($product_option_id)) {
            $added = "&product_option_id={$product_option_id}";
        }
        cw_refresh($product_id, 'product_options', $added);
    }
}
# Get the product options list
$product_options = cw_call('cw_get_product_classes', array($product_id, null, null, $edited_language));
$products_options_ex = cw_call('cw_get_product_exceptions', array($product_id));
$product_options_js = cw_call('cw_get_product_js_code', array($product_id));
if ($product_options && !empty($product_option_ids)) {
    foreach ($product_options as $k => $v) {