}
        if ($v['quantity'] <= 0 || !$v['quantity_old'] && $v['price'] <= 0) {
            continue;
        }
        if (!$k) {
            $v['quantity_old'] = $v['quantity'];
            $v['membership_id_old'] = $v['membership_id'];
        }
        cw_product_update_price($product_id, $v['variant_id'], $v['membership_id'], $v['membership_id_old'], $v['quantity'], $v['quantity_old'], $v['price'], $v['list_price'], $k);
        if ($ge_id && $fields['w_price'][$k] && $info) {
            while ($pid = cw_ge_each($ge_id, 1, $product_id)) {
                cw_product_update_price($pid, $v['variant_id'], $v['membership_id'], $v['membership_id_old'], $v['quantity'], $v['quantity_old'], $v['price'], $v['list_price']);
            }
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_wholesale_upd'), 'type' => 'I');
    cw_refresh($product_id, 'wholesale');
}
if ($action == 'wholesales_delete' && is_array($wprices)) {
    foreach ($wprices as $id => $v) {
        if (!$v['del']) {
            continue;
        }
        if ($v['quantity_old'] > 1 || $v['membership_id'] != 0) {
            db_query("delete from {$tables['products_prices']} where price_id='{$id}'");
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_wholesale_del'), 'type' => 'I');
    cw_refresh($product_id, 'wholesale');
}
$smarty->assign('products_prices', cw_wholesale_get_prices($product_id));
                    cw_array2insert("bonus_conditions", $query_data);
                }
            }
        }
        # Copy conditions products to discount bonus
        $products = cw_query_column("SELECT objid FROM {$tables['bonus_conditions']} WHERE type='P' AND bonusid='{$bonusid}'");
        if (count($products) > 1) {
            # There are additional products in kit - complete bonus creation.
            foreach ($products as $pid) {
                $sup['D']['product'][$pid] = array('pid' => $pid);
            }
            $sup['D']['type'] = 'S';
            $query_data = array("bonusid" => $bonusid, "type" => 'D', "data" => serialize($sup['D']));
            cw_array2insert("bonus_supply", $query_data, true);
        } else {
            # There are no products in kit except main product - delete kit.
            cw_delete_special_offer($bonusid);
        }
        cw_refresh("discountbundles");
    }
} elseif ($section == 'discountbundles') {
    $bonusid = cw_query_first_cell("SELECT bonusid FROM {$tables['bonuses']} WHERE pid='{$productid}' AND bonus_active='Y'");
    if (empty($tables['products_lng_current'])) {
        $tables['products_lng_current'] = $tables['products'];
    }
    // products_lng_current exists in 4.5.x only
    $bonus_details['P'] = cw_query("SELECT conditionid, objid, quantity, product FROM {$tables['bonus_conditions']} bc LEFT JOIN {$tables['products_lng_current']} prod ON bc.objid=prod.productid WHERE bonusid='{$bonusid}' AND type='P' AND objid!='{$productid}'");
    $bonus_details['sup']['D'] = unserialize(cw_query_first_cell("SELECT data FROM {$tables['bonus_supply']} WHERE bonusid='{$bonusid}' AND type='D'"));
    $smarty->assign("bonus_details", $bonus_details);
}
// CartWorks.com - Promotion Suite
    }
    $refresh = $rebuild_quick = true;
} elseif ($action == 'product_variants_search') {
    $search_variants[$product_id] = empty($search) ? array() : $search;
    $refresh = true;
}
if ($rebuild_quick) {
    cw_func_call('cw_product_build_flat', array('product_id' => $product_id));
    if ($ge_id) {
        while ($pid = cw_group_edit_each($ge_id, 100)) {
            cw_func_call('cw_product_build_flat', array('product_id' => $pid));
        }
    }
}
if ($refresh) {
    cw_refresh($product_id, 'product_variants');
}
# Get the product options list
$product_options = cw_call('cw_get_product_classes', array($product_id));
if (!empty($product_options)) {
    $smarty->assign('product_options', $product_options);
}
$variants = cw_call('cw_get_product_variants', array($product_id));
$svariants = $search_variants[$product_id];
if ($svariants && !empty($variants)) {
    $tmp = current($variants);
    $cnt = count($tmp['options']);
    unset($tmp);
    foreach ($variants as $k => $v) {
        $local_cnt = 0;
        foreach ($svariants as $cid => $c) {
    cw_load('magnifier');
    foreach ($file_upload_data['magnifier_images'] as $image) {
        $image_posted = cw_image_check_posted($image);
        if ($image_posted) {
            $image_id = cw_image_save($image, array('id' => $product_id));
            $image = cw_image_get('magnifier_images', $image_id);
            $dir_name = cw_magnifier_create($image['image_path'], $image_id);
            db_query("update {$tables['magnifier_images']} set image_path='{$dir_name}/TileGroup0/0-0-0.jpg' where image_id='{$image_id}'");
        }
    }
    $top_message['content'] = cw_get_langvar_by_name('msg_adm_images_added_4zoomer');
    cw_refresh($product_id, 'zoomer');
}
if ($action == "zoomer_update_availability" && !empty($zoomer_image)) {
    # Update images
    foreach ($zoomer_image as $key => $value) {
        db_query("UPDATE {$tables['magnifier_images']} SET orderby='" . $value['orderby'] . "', avail='" . $value['avail'] . "' WHERE image_id='{$key}'");
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_images_updated_4zoomer");
    cw_refresh($product_id, 'zoomer');
}
if ($action == "product_zoomer_delete") {
    if (!empty($iids)) {
        foreach ($iids as $image_id => $tmp) {
            cw_image_delete($image_id, 'magnifier_images');
        }
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_images_deleted_4zoomer");
    cw_refresh($product_id, 'zoomer');
}
$smarty->assign('zoomer_images', cw_image_get_list('magnifier_images', $product_id));
            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) {
        if ($product_option_ids[$v['product_option_id']]) {
            $product_options[$k]['multi'] = 'Y';
        }
    }
}
if ($product_option_id && $product_options) {
    foreach ($product_options as $v) {
        if ($file_upload_data['products_images_thumb']) {
            $file_upload_data['products_images_thumb']['is_redirect'] = false;
            $product_modified_data['image_thumb'] = $file_upload_data['products_images_thumb'];
        }
        if ($file_upload_data['products_images_det']) {
            $file_upload_data['products_images_det']['is_redirect'] = false;
            $product_modified_data['image_det'] = $file_upload_data['products_images_det'];
        }
    }
    cw_refresh($product_id);
}
if ($REQUEST_METHOD == "POST" && $action == "attributes_modify" && (AREA_TYPE == 'A' || AREA_TYPE == 'V')) {
    $product_data['attributes'] = $attributes;
    cw_call('cw_attributes_save', array('item_id' => $product_id, 'item_type' => 'P', 'attributes' => $product_data['attributes'], 'language' => $edited_language, array('is_default' => false)));
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_wholesale_upd'), 'type' => 'I');
    cw_refresh($product_id, 'attributes');
}
if ($addons['magnifier']) {
    cw_include('addons/magnifier/product_magnifier_modify.php');
}
if ($product_info['product_id'] && $addons['wholesale_trading']) {
    cw_include('addons/wholesale_trading/product_wholesale.php');
}
$product_info['list_tags'] = cw_tags_get_string_tags($product_info['tags']);
if ($section == 'serial_numbers') {
    if (AREA_TYPE == 'A') {
        $serial_numbers = cw_get_serial_numbers('', $product_id, true);
    } else {
        $serial_numbers = cw_get_serial_numbers($customer_id, $product_id);
    }
    $smarty->assign('serial_numbers', array_chunk($serial_numbers, $config['sn']['serial_per_row_product']));