$size = textLength($data['length'], false);
 if ($size == '0' || $size == '') {
     $size = 'none';
 }
 if (!in_array($data['products_ean'], $products_manual_ean)) {
     $reported_data[] = array('products_id' => $products_id, 'products_ean' => $data['products_ean'], 'reported_stock' => $reported_stock, 'item_no' => $data['article_number'], 'size' => $size, 'delivery_time' => $stock_info['delivery_time']);
 }
 if ($reported_stock > 0) {
     $product_has_stock = true;
 }
 //ADDITIONAL LENGTHS
 $articles = $class_pa->retrieveList($data['products_id']);
 foreach ($articles as $row) {
     if ($row['products_ean'] != '' && !in_array($row['products_ean'], $deleted_eans_reported) && !in_array($row['products_ean'], $products_manual_ean)) {
         $actual_stock = $products_stock[$data['products_id'] . '-' . $row['products_articles_id']];
         $stock_info = actualStockReport($actual_stock, $data['products_weight'], $data['stars'], $data['complexity'], $data['age'], $data['total_sold_lastyear'], $data['total_sold_thisyear'], $data['total_sold_l30d'], $sp_detail, $data['reported_stock'], $data['delivery_days'], $data['is_wholesale'] == 1);
         $reported_stock = ($data['active_status'] == '0' || $row['active_status'] == '0') && $stock_info['stock_isreal'] == '0' ? '0' : $stock_info['stock'];
         //If products are not supposed to be hidden,
         //has real stock report and real stock < virtual stock,
         //then report virtual stock instead
         if ($stock_info['stock_ishide'] == '0' && $stock_info['stock_isreal'] == '1' && $reported_stock < $data['reported_stock']) {
             $reported_stock = $data['reported_stock'];
         }
         $size = textLength($row['length'], false);
         $reported_data[] = array('products_id' => $row['products_id'], 'products_ean' => $row['products_ean'], 'reported_stock' => $reported_stock, 'item_no' => $data['article_number'], 'size' => $size, 'delivery_time' => $stock_info['delivery_time']);
         if ($reported_stock > 0) {
             $product_has_stock = true;
         }
     }
 }
 if (count($reported_data) > 0) {
function generateXMLarticle($article_number, $sp_detail, $p, $uselength = false)
{
    global $component_length_id, $component_length_name;
    global $products_stock, $hide_extreme_flag, $hide_hard_flag, $hide_nostock_flag;
    $actual_stock = $products_stock[$p['products_id'] . '-' . $p['articles_id']];
    $stock_info = actualStockReport($sp_detail, $p['reported_stock'], $actual_stock, $p['delivery_days'], $p['is_bestselling'], $p['complexity'], $hide_extreme_flag, $hide_hard_flag, $hide_nostock_flag);
    $reported_stock = $p['active_status'] == '0' && $stock_info['stock_isreal'] == '0' ? '0' : $stock_info['stock'];
    //TODO: Remove 4 lines below to reactive bestselling in NM.DE
    //      It is currently deactivate to wait final confirmation
    //      on future partnership with NM.DE (sahat - 20.07.2012)
    //if($p['is_bestselling']=='1') {
    $reported_stock = '0';
    $stock_info['delivery_time'] = '14';
    //}
    //------------------------------------------------------------
    $result = '';
    //XML ARTICLES
    $result .= writeXMLopen('ARTICLEDATA', 1);
    $result .= writeLine();
    //XML ARTICLE DETAIL
    $article_number_used = $article_number;
    if ($p['length'] != '' && $p['length'] != '0') {
        $article_number_used .= '_' . textLength($p['length'], false);
    }
    if ($p['text'] != '' && $p['text_code'] != '') {
        $article_number_used .= '_' . $p['text_code'];
    }
    $billing_text = neckermannBillingText(15, $p['categories_id'], $p['name'], $p['length']);
    $result .= writeXMLline('A_SUP_ARTNO', $article_number_used, 2);
    $result .= writeXMLline('A_EAN', $p['products_ean'], 2);
    $result .= writeXMLline('A_BILLING_TEXT', $billing_text, 2);
    //XML ARTICLE COMPONENT
    if ($uselength) {
        //                $length = textLength($p['length'], false);
        //                if($p['categories_id']=='29') $length = ringSizeToDiameter($length);
        //                if($length>0) {
        //TEMPORARILY USING OLD SIZE ATTRIBUTES UNTIL NM.DE BUG IS FIXED
        if ($p['length'] > 0) {
            $length = textLength($p['length']);
            $component_id = '8571220';
            $component_name = 'Größe';
            //                    if(isset($component_length_id[$p['categories_id']])) {
            //                        $component_id = $component_length_id[$p['categories_id']];
            //                        $component_name = $component_length_name[$p['categories_id']];
            //                    } else {
            //                        $component_id = '970981';
            //                        $component_name = 'Länge (ca. cm)';
            //                    }
            $result .= writeXMLopen('A_COMPONENT', 2);
            $result .= writeXMLopen('COMPONENT', 3);
            $result .= writeXMLline('COMPONENT_ID', $component_id, 4);
            $result .= writeXMLline('COMPONENT_NAME', $component_name, 4);
            $result .= writeXMLclose('COMPONENT', 3);
            $result .= writeXMLline('COMPONENT_VALUE', $length, 3);
            $result .= writeXMLclose('A_COMPONENT', 2);
            $result .= writeLine();
        }
    }
    if ($p['text'] != '' && $p['text_code'] != '') {
        //                $component_id = '4053';
        //                $component_name = 'Text';
        $component_id = '976260';
        $component_name = 'Variante';
        $result .= writeXMLopen('A_COMPONENT', 2);
        $result .= writeXMLopen('COMPONENT', 3);
        $result .= writeXMLline('COMPONENT_ID', $component_id, 4);
        $result .= writeXMLline('COMPONENT_NAME', $component_name, 4);
        $result .= writeXMLclose('COMPONENT', 3);
        $text = $p['text'];
        $result .= writeXMLline('COMPONENT_VALUE', $text, 3);
        $result .= writeXMLclose('A_COMPONENT', 2);
        $result .= writeLine();
    }
    $valid_date = date('Y-m-d', strtotime($p['date_added']));
    $result .= writeXMLline('A_SEGMENT', '785', 2);
    $result .= writeXMLline('A_VALID_DATE', $valid_date, 2);
    $result .= writeLine();
    //XML ARTICLE STOCK
    $result .= writeXMLline('A_UNIT', 'ST', 2);
    //below additional stock is to handle neckermann error about hiding resourcable products when stock is 0
    //if($p['reported_stock']>0) $p['reported_stock'] += 49;
    //thile line above should be deleted once this error is fixed
    $result .= writeXMLline('A_STOCK', $reported_stock, 2);
    $result .= writeLine();
    //XML ARTICLE PRICING
    $result .= writeXMLopen('A_PRICE', 2);
    $result .= writeXMLline('PRICE_VK', $p['price'], 3);
    if ($p['price_old'] > 0 && $p['price_old'] > $p['price']) {
        $result .= writeXMLline('PRICE_VK_OLD', $p['price_old'], 3);
    }
    $result .= writeXMLline('PRICE_TAX', '2', 3);
    $result .= writeXMLline('PRICE_PROVISION_TYPE', $sp_detail['provision'], 3);
    $result .= writeXMLclose('A_PRICE', 2);
    $result .= writeLine();
    //XML ARTICLE ORDERING
    $result .= writeXMLopen('A_ORDER', 2);
    $result .= writeXMLline('ORDER_QUANTITY_MIN', '1', 3);
    $result .= writeXMLline('ORDER_QUANTITY_INTERVALL', '1', 3);
    $result .= writeXMLclose('A_ORDER', 2);
    $result .= writeLine();
    //XML DELIVERY
    //$delivery_time = ($p['delivery_days']==0) ? $sp_detail['delivery_time'] : $p['delivery_days'];
    $delivery_time = $stock_info['delivery_time'];
    if ($reported_stock == 0 || $p['reported_stock'] == 0) {
        $replacement = 'N';
        $delivery_replacement_time = '';
    } else {
        $replacement = 'J';
        $delivery_replacement_time = $delivery_time + 2;
    }
    $result .= writeXMLopen('A_DELIVERY', 2);
    $result .= writeXMLline('DELIVERY_TIME', $delivery_time, 3);
    $result .= writeXMLline('DELIVERY_REPLACEMENT', $replacement, 3);
    $result .= writeXMLline('DELIVERY_REPLACEMENT_TIME', $delivery_replacement_time, 3);
    $result .= writeXMLline('DELIVERY_PARCEL_TYPE', 'PAK', 3);
    $result .= writeXMLline('DELIVERY_CARRIER', '1', 3);
    $result .= writeXMLclose('A_DELIVERY', 2);
    $result .= writeLine();
    $result .= writeXMLclose('ARTICLEDATA', 1);
    $result .= writeLine();
    return $result;
}
 function generateXMLarticle($article_number, $p)
 {
     global $sp_detail;
     global $products_stock, $hide_extreme_flag, $hide_hard_flag, $hide_nostock_flag;
     $actual_stock = $products_stock[$p['products_id'] . '-' . $p['articles_id']];
     $stock_info = actualStockReport($sp_detail, $p['reported_stock'], $actual_stock, $p['delivery_days'], $p['is_bestselling'], $p['complexity'], $hide_extreme_flag, $hide_hard_flag, $hide_nostock_flag);
     $reported_stock = $p['active_status'] == '0' && $stock_info['stock_isreal'] == '0' ? '0' : $stock_info['stock'];
     //TODO: Remove 4 lines below to reactive bestselling in NM.DE
     //      It is currently deactivate to wait final confirmation
     //      on future partnership with NM.DE (sahat - 20.07.2012)
     //if($p['is_bestselling']=='1') {
     $reported_stock = '0';
     $stock_info['delivery_time'] = '14';
     //}
     //------------------------------------------------------------
     $result = '';
     //XML ARTICLES
     $result .= writeXMLopen('ARTICLEDATA', 1);
     $result .= writeLine();
     //XML ARTICLE DETAIL
     $article_number_used = $article_number;
     if ($p['length'] != '' && $p['length'] != '0') {
         $plength = textLength($p['length'], false);
         $plength = intval($plength);
         if ($plength != 0) {
             $article_number_used .= '_' . $plength;
         }
     }
     if ($p['text'] != '' && $p['text_code'] != '') {
         $article_number_used .= '_' . $p['text_code'];
     }
     $result .= writeXMLline('A_SUP_ARTNO', $article_number_used, 2);
     $result .= writeXMLline('A_EAN', $p['products_ean'], 2);
     $valid_date = date('Y-m-d', strtotime($p['date_added']));
     $result .= writeXMLline('A_VALID_DATE', $valid_date, 2);
     $result .= writeLine();
     //XML ARTICLE STOCK
     //below additional stock is to handle neckermann error about hiding resourcable products when stock is 0
     //if($p['reported_stock']>0) $p['reported_stock'] += 49;
     //thile line above should be deleted once this error is fixed
     $result .= writeXMLline('A_STOCK', $reported_stock, 2);
     $result .= writeLine();
     //XML ARTICLE PRICING
     $result .= writeXMLopen('A_PRICE', 2);
     $result .= writeXMLline('PRICE_VK', $p['price'], 3);
     if ($p['price_old'] > 0 && $p['price_old'] > $p['price']) {
         $result .= writeXMLline('PRICE_VK_OLD', $p['price_old'], 3);
     }
     //$result .= writeXMLline('PRICE_TAX', '2', 3);
     $result .= writeXMLline('PRICE_PROVISION_TYPE', $sp_detail['provision'], 3);
     $result .= writeXMLclose('A_PRICE', 2);
     $result .= writeLine();
     //XML DELIVERY
     //$delivery_time = ($p['delivery_days']==0) ? $sp_detail['delivery_time'] : $p['delivery_days'];
     $delivery_time = $stock_info['delivery_time'];
     if ($reported_stock == 0 || $p['reported_stock'] == 0) {
         $replacement = 'N';
         $delivery_replacement_time = '';
     } else {
         $replacement = 'J';
         $delivery_replacement_time = $delivery_time + 2;
     }
     $result .= writeXMLopen('A_DELIVERY', 2);
     $result .= writeXMLline('DELIVERY_TIME', $delivery_time, 3);
     $result .= writeXMLline('DELIVERY_REPLACEMENT', $replacement, 3);
     $result .= writeXMLline('DELIVERY_REPLACEMENT_TIME', $delivery_replacement_time, 3);
     $result .= writeXMLclose('A_DELIVERY', 2);
     $result .= writeLine();
     $result .= writeXMLclose('ARTICLEDATA', 1);
     $result .= writeLine();
     return $result;
 }