if (!empty($total_details['use_shipping_insurance_alt'])) {
     $total_details['shipping_insurance_alt'] = cw_aom_validate_price($total_details['shipping_insurance_alt']);
     $aom_orders[$doc_id]['info']['shipping_insurance'] = $total_details['shipping_insurance_alt'];
     $aom_orders[$doc_id]['info']['shipping_insurance_alt'] = $total_details['shipping_insurance_alt'];
     $aom_orders[$doc_id]['info']['use_shipping_insurance_alt'] = "Y";
 } else {
     unset($aom_orders[$doc_id]['info']['use_shipping_insurance_alt']);
 }
 if (!empty($total_details['use_discount_alt']) && !empty($total_details['discount_alt'])) {
     $aom_orders[$doc_id]['info']['discount_alt'] = $aom_orders[$doc_id]['info']['discount'] = $total_details['discount_alt'] = cw_aom_validate_price($total_details['discount_alt']);
     $aom_orders[$doc_id]['info']['use_discount_alt'] = "Y";
 } else {
     unset($aom_orders[$doc_id]['info']['use_discount_alt']);
 }
 if (!empty($total_details['use_coupon_discount_alt']) && !empty($total_details['coupon_discount_alt'])) {
     $aom_orders[$doc_id]['info']['coupon_discount_alt'] = $aom_orders[$doc_id]['coupon_discount'] = $total_details['coupon_discount_alt'] = cw_aom_validate_price($total_details['coupon_discount_alt']);
     $aom_orders[$doc_id]['info']['use_coupon_discount_alt'] = "Y";
     if (empty($total_details['coupon_alt'])) {
         $aom_orders[$doc_id]['info']['coupon'] = $aom_orders[$doc_id]['info']['coupon'] = "#" . $aom_orders[$doc_id]['doc_id'];
         $aom_orders[$doc_id]['info']['use_coupon_alt'] = "Y";
     }
 } else {
     unset($aom_orders[$doc_id]['info']['use_coupon_discount_alt']);
 }
 if (!empty($total_details['coupon_alt'])) {
     if ($total_details['coupon_alt'] == '__old_coupon__') {
         $aom_orders[$doc_id]['info']['coupon'] = $aom_orders[$doc_id]['info']['coupon'] = $doc_data['order']['coupon'];
         cw_unset($aom_orders[$doc_id]['info'], "use_coupon_alt");
     } else {
         $aom_orders[$doc_id]['info']['coupon'] = $aom_orders[$doc_id]['info']['coupon'] = $total_details['coupon_alt'];
         $aom_orders[$doc_id]['info']['use_coupon_alt'] = "Y";
if ($action == 'update_item_info' && isset($index) && !$aom_orders[$doc_id]['saved']) {
    $aom_orders[$doc_id]['info']['use_shipping_cost_alt'] = 'N';
    $doc_data = cw_doc_get($doc_id, 0);
    $product_id = $aom_orders[$doc_id]['products'][$index]['product_id'];
    $v = $product_details[$index];
    $v['amount'] = intval($v['amount']);
    $count_product_in_stock = cw_aom_get_quantity_in_stock($aom_orders[$doc_id]['products'][$index]['warehouse_customer_id'], $product_id, $doc_data['order']['status'], $v['product_options'], $doc_data['products'][$index]);
    if ($is_old) {
        $count_product_in_stock += $v['amount'];
    }
    # kornev
    # pos orders && supplier orders are unlimited
    if ($v['amount'] > 0) {
        $aom_orders[$doc_id]['products'][$index]['amount'] = $config['unlimited_products'] ? $v['amount'] : min($v['amount'], $count_product_in_stock);
    }
    $v['price'] = cw_aom_validate_price($v['price']);
    if ($config['Taxes']['display_taxed_order_totals'] == 'Y') {
        $v['price'] = cw_taxes_price_without_tax($v['price'], $aom_orders[$doc_id]['products'][$index]['taxes']);
    }
    $product_options_result = array();
    # kornev, TOFIX
    if ($v['product_options'] && $addons['product_options']) {
        if (!cw_check_product_options($product_id, $v['product_options'])) {
            $v['product_options'] = cw_get_default_options($product_id, $v['amount'], $aom_orders[$doc_id]['userinfo']['membership_id']);
        }
        list($variant, $product_options_result) = cw_get_product_options_data($product_id, $v['product_options'], $aom_orders[$doc_id]['userinfo']['membership_id']);
        $aom_orders[$doc_id]['products'][$index]['options_surcharge'] = 0;
        if ($product_options_result) {
            foreach ($product_options_result as $key => $o) {
                $aom_orders[$doc_id]['products'][$index]['options_surcharge'] += $o['modifier_type'] == '%' ? $v['price'] * $o['price_modifier'] / 100 : $o['price_modifier'];
            }