function lazadaTemplate($is_article, $product_id, $var_ean, $var_length)
{
    global $class_pm, $class_pmat, $class_pa, $r;
    $product_materials_name = '';
    $product = $class_pm->retrieveDetail($product_id, 'p,pd,pd2,pc,pnc,cat,pei,pci');
    $product_name = $product['pd'][3]['products_name'];
    $product_articles = $class_pa->retrieveList($product_id);
    $product_articles_total = count($product_articles);
    //    $productLength = ($product['pc']['products_length'] !== false) ? $product['pc']['products_length']/10 : $product['pnc']['products_length']/10;
    if ($product['pc'] !== false) {
        $product_length = $product['pc']['products_length'];
        //        $productLengthForVar = number_format($productLength, 0);
        $product_length_for_var = 'One size';
        //FOR NOW WE ALWAYS USE One Size for every Categories except ring
        $length_code = '_' . number_format($product_length, 0);
    } else {
        $product_length = $product['pnc']['products_length'];
        //PNC is default length
        //        $productLengthForVar = number_format($productLength, 0);
        $product_length_for_var = 'One size';
        //FOR NOW WE ALWAYS USE One Size for every Categories except ring
        $length_code = '_' . number_format($product_length, 0);
    }
    if ($product_length == '0.00') {
        $length_code = '';
        $product_length_for_var = 'One size';
    }
    //    $productLength = ($product['pc'] !== false) ? $product['pc']['products_length'] : $product['pnc']['products_length'];
    if ($product['pd2']['width'] == '0.00') {
        $product_width = '';
    } else {
        $product_width = $product['pd2']['width'] / 10;
    }
    if ($product['pd2']['height'] == '0.00') {
        $product_height = '';
    } else {
        $product_height = $product['pd2']['height'] / 10;
    }
    if ($product['pd2']['weight'] == '0.00') {
        $product_weight = '';
    } else {
        $product_weight = $product['pd2']['weight'] / 1000;
    }
    if ($product['pd2']['diameter'] == '0') {
        $product_diameter = '';
    } else {
        $product_diameter = $product['pd2']['diameter'] / 10;
    }
    $product_ean = $product['p']['products_ean'];
    $product_keywords = $product['pd'][3]['products_head_keywords_tag'];
    $product_description = $product['pd'][3]['products_description'];
    $product_selling_points = explode(';', $product['pd'][3]['products_selling_points']);
    $materials = $class_pmat->retrieveList('', 'material_name');
    $product_materials = $class_pm->loadProductMaterials($product_id);
    $separator = '';
    foreach ($materials as $mat) {
        if (in_array($mat['products_materials_id'], $product_materials)) {
            $materials_name = explode(',', $mat['material_name']);
            $product_materials_name .= $separator;
            $product_materials_name .= $materials_name[2];
            if (!$separator) {
                $separator = ',';
            }
        }
    }
    $query_color = "SELECT ptcp.products_id, ptcp.color_pattern_id, cpd.name FROM products_to_color_pattern ptcp";
    $query_color .= " LEFT JOIN color_pattern_description cpd ON cpd.color_pattern_id = ptcp.color_pattern_id";
    $query_color .= " WHERE ptcp.products_id = {$product_id} AND languages_id = 1";
    $query_color_result = tep_db_query($query_color);
    $product_color_row = mysql_fetch_row($query_color_result);
    $product_color = $product_color_row[2];
    if ($product_color_row[1] == '19') {
        $product_color_family = 'Blue';
    } elseif ($product_color_row[1] == '21') {
        $product_color_family = 'Green';
    } elseif ($product_color_row[1] == '22' || $product_color_row[1] == '15') {
        $product_color_family = 'Multicolor';
    } elseif ($product_color_row[1] == '13') {
        $product_color_family = 'Pink';
    } elseif ($product_color_row[1] == '20') {
        $product_color_family = 'Light Purple';
    } elseif ($product_color_row[1] == '17') {
        $product_color_family = 'Red';
    } elseif ($product_color_row[1] == '14') {
        $product_color_family = 'White';
    } else {
        $product_color_family = $product_color_row[2];
    }
    if ($product['categories_id'] == 2) {
        $category = '4944';
    } elseif ($product['categories_id'] == 4) {
        $category = '4943';
    } elseif ($product['categories_id'] == 3) {
        $category = '4942';
    } elseif ($product['categories_id'] == 29) {
        $category = '4941';
        if ($is_article) {
            if ($product_articles_total > 0) {
                $product_ean = $var_ean;
                $product_length = $var_length;
            }
        }
        $product_length_code = $product_length * 10;
        $product_length = $product_length;
        $product_length = ringSizeConvert($product_length);
        //        $product_length = '11'; //FOR NOW WE ALWAYS USE 52MM SIZE (11 ID Size)
        $length_code = '_' . $product_length_code;
        $product_length_for_var = $product_length;
    } elseif ($product['categories_id'] == 30) {
        $category = '4940';
    }
    $product_code = $product['p']['products_model'];
    $sale_start_date = date("Y-m-d");
    //Always using today's date.
    $x = array();
    /*A - [M] Name      */
    $x[0][0] = 'Bellina Germany ' . $product_name;
    /*B - [O] PrimaryCategory */
    $x[0][1] = '4939';
    /*C - [M] Brand */
    $x[0][2] = 'BELLINA GERMANY';
    /*D - [O] Categories */
    $x[0][3] = $category;
    /*E - [O] Model  */
    $x[0][4] = '';
    /*F - [O] Color  */
    $x[0][5] = $product_color;
    /*G - [O] SalePrice   */
    $x[0][6] = '';
    /*H - [M] Price    */
    $x[0][7] = '';
    /*I - [O] SaleStartDate  */
    $x[0][8] = $sale_start_date;
    /*J - [O] SaleEndDate  */
    $x[0][9] = '2016-10-01';
    //Miriam Confirmed. 14.10.2014
    /*K - [O] SellerSku    */
    $x[0][10] = $product_code . $length_code;
    /*L - [M] Variation   */
    $x[0][11] = $product_length_for_var;
    /*M - [O] ProductId    */
    $x[0][12] = $product_ean;
    $get_def_length = $class_pa->getDefault($product_id);
    $length_for_code = '_' . number_format($get_def_length['products_length'] * 10, 0);
    if ($is_article) {
        $parent_sku = $product_code . $length_for_code;
    } else {
        if ($product_articles_total > 0) {
            if ($product['categories_id'] == 29) {
                $parent_sku = $product_code . $length_for_code;
            }
        } else {
            $parent_sku = '';
        }
    }
    /*N - [O] ParentSku    */
    $x[0][13] = $parent_sku;
    /*O - [M] Quantity    */
    $x[0][14] = '50';
    /*P - [O] ProductLine    */
    $x[0][15] = $product_keywords;
    /*Q - [O] ColorFamily    */
    $x[0][16] = $product_color_family;
    /*R - [O] MaterialFamily  */
    $x[0][17] = '';
    /*S - [O] MainMaterial    */
    $x[0][18] = $product_materials_name;
    /*T - [M] Description    */
    $x[0][19] = $product_description . '<br><br>BELLINA GERMANY creates genuine 925 Sterling Silver jewelry made with German quality and design & a dash of Love - Especially for you.<br><br><br><strong>Tentang WeLoveJewels</strong><br><br>WeLoveJewels adalah gambaran dari perhiasan yang trendi yang terbuat dari 925 Sterling Silver asli. Kami menciptakan produk-produk yang bernilai tinggi dengan desain dan kualitas berstandar Jerman.<br><br>Produk kami dibuat untuk para wanita yang mencintai perhiasan yang trendi dan terbaru dengan desain yang klasik, serta sangat mementingkan kualitas. Nyaman dikenakan kapan pun, saat di kantor atau berkumpul bersama teman-teman. Brand kami BELLINA GERMANY berkarakter, fashionable, dengan koleksi yang uptodate, kualitas standar yang tinggi, material asli dan berharga namun dengan harga yang terjangkau.<br><br>BELLINA GERMANY memproduksi perhiasan yang terbuat dari 925 Sterling Silver dan dikombinasikan dengan berbagai material berharga seperti Original Swarovski Elements, Cubic Zirconia, Mutiara air tawar, batu-batu mulia serta masih banyak lagi bahan yang dibentuk dengan rapi dan indah.<br>WeLoveJewels mengadopsi tren fashion terbaru dan setiap minggu menciptakan koleksi perhiasan yang unik yang selalu mengikuti tren warna, serta dilengkapi dengan desain yang klasik dan elegan.';
    /*U - [O] Video    */
    $x[0][20] = '';
    $products_selling_points_html = '<ul><li>' . $product_selling_points[0] . '</li><li>' . $product_selling_points[1] . '</li><li>' . $product_selling_points[2] . '</li><li>' . $product_selling_points[3] . '</li><li>' . $product_selling_points[4] . '</li></ul>';
    /*V - [O] ShortDescription*/
    $x[0][21] = $products_selling_points_html;
    /*W - [O] PackageContent*/
    $x[0][22] = '<ul><li>Bellina Germany' . $product_name . '</li><li>Elegant Black Satin Bag</li></ul>';
    /*X - [O] Note    */
    $x[0][23] = $product_id;
    /*Y - [M] MinDeliveryTime */
    $x[0][24] = '2';
    /*Z - [M] MaxDeliveryTime */
    $x[0][25] = '5';
    $product_measures = '';
    if ($product_length == '0.00') {
        if ($product_width != '' && $product_height != '') {
            $product_measures = $product_width . ' x ' . $product_height . ' cm';
        } elseif ($product_width != '' && $product_height == '') {
            $product_measures = $product_width . ' cm';
        } elseif ($product_width == '' && $product_height != '') {
            $product_measures = $product_height . ' cm';
        } elseif ($product_width == '' && $product_height == '') {
            $product['categories_id'] == 4 ? $product_measures = $product_diameter . ' cm' : ($product_measures = '');
        }
    } elseif ($product_width == '') {
        if ($product_length != '0.00' && $product_height != '') {
            $product_measures = number_format($product_length, 0) . ' x ' . $product_height;
        } elseif ($product_length == '0.00' && $product_height != '') {
            $product_measures = $product_height . ' cm';
        } elseif ($product_length != '0.00' && $product_height == '') {
            $product_measures = number_format($product_length, 0) . ' cm';
        } elseif ($product_length == '0.00' && $product_height == '') {
            $product['categories_id'] == 4 ? $product_measures = $product_diameter . ' cm' : ($product_measures = '');
        }
    } elseif ($product_height == '') {
        if ($product_length != '0.00' && $product_width != '') {
            $product_measures = number_format($product_length, 0) . ' x ' . $product_width . ' cm';
        } elseif ($product_length == '0.00' && $product_width != '') {
            $product_measures = $product_width . ' cm';
        } elseif ($product_length != '0.00' && $product_width == '') {
            $product_measures = number_format($product_length, 0) . ' cm';
        } elseif ($product_length == '0.00' && $product_height == '') {
            $product['categories_id'] == 4 ? $product_measures = $product_diameter . ' cm' : ($product_measures = '');
        }
    } else {
        $product_measures = number_format($product_length, 0) . ' x ' . $product_width . ' x ' . $product_height . ' cm';
    }
    /*AA - [O] ProductMeasures */
    $x[0][26] = $product_measures;
    /*AB - [O] ProductWeight */
    $x[0][27] = $product_weight != '' ? $product_weight . ' kg' : '0.003 kg';
    /*AC - [O] PackageHeight */
    $x[0][28] = '4';
    /*AD - [O] PackageWidth */
    $x[0][29] = '14';
    /*AE - [O] PackageLength */
    $x[0][30] = '18';
    /*AF - [M] PackageWeigth */
    $x[0][31] = '1';
    /*AG - [O] Certifications */
    $x[0][32] = '';
    /*AH - [O] ProductionCountry*/
    $x[0][33] = '';
    /*AI - [O] ManufacturerTxt */
    $x[0][34] = '';
    /*AJ - [O] CareLabel */
    $x[0][35] = '';
    /*AK - [O] ProductWarranty */
    $x[0][36] = '';
    $csv_row = array();
    $csv_row['data'] = $x;
    //    $csv_row['temp_images'] = (!$is_article) ? $temp_images : '';
    return $csv_row;
}
function zaloraTemplate($is_article, $product_id, $var_ean, $var_length)
{
    global $class_pm, $class_pmat, $class_pa, $r;
    $product_materials_name = '';
    $product = $class_pm->retrieveDetail($product_id, 'p,pd,pd2,pc,pnc,cat,pei,pci');
    $product_name = $product['pd'][3]['products_name'];
    $product_articles = $class_pa->retrieveList($product_id);
    $product_articles_total = count($product_articles);
    //    $productLength = ($product['pc']['products_length'] !== false) ? $product['pc']['products_length']/10 : $product['pnc']['products_length']/10;
    if ($product['pc'] !== false) {
        $product_length = $product['pc']['products_length'];
        //        $productLengthForVar = number_format($productLength, 0);
        $product_length_for_var = 'One Size';
        //FOR NOW WE ALWAYS USE One Size for every Categories except ring
        $length_code = '_' . number_format($product_length, 0);
    } else {
        $product_length = $product['pnc']['products_length'];
        //PNC is default length
        //        $productLengthForVar = number_format($productLength, 0);
        $product_length_for_var = 'One Size';
        //FOR NOW WE ALWAYS USE One Size for every Categories except ring
        $length_code = '_' . number_format($product_length, 0);
    }
    if ($product_length == '0.00') {
        $length_code = '';
        $product_length_for_var = 'One Size';
    }
    //    $productLength = ($product['pc'] !== false) ? $product['pc']['products_length'] : $product['pnc']['products_length'];
    if ($product['pd2']['width'] == '0.00') {
        $product_width = '';
    } else {
        $product_width = $product['pd2']['width'] / 10;
    }
    if ($product['pd2']['height'] == '0.00') {
        $product_height = '';
    } else {
        $product_height = $product['pd2']['height'] / 10;
    }
    if ($product['pd2']['weight'] == '0.00') {
        $product_weight = '';
    } else {
        $product_weight = $product['pd2']['weight'] / 1000;
    }
    if ($product['pd2']['diameter'] == '0') {
        $product_diameter = '';
    } else {
        $product_diameter = $product['pd2']['diameter'] / 10;
    }
    $product_ean = $product['p']['products_ean'];
    $product_keywords = $product['pd'][3]['products_head_keywords_tag'];
    $product_description = $product['pd'][3]['products_description'];
    $product_selling_points = explode(';', $product['pd'][3]['products_selling_points']);
    $materials = $class_pmat->retrieveList('', 'material_name');
    $product_materials = $class_pm->loadProductMaterials($product_id);
    $separator = '';
    foreach ($materials as $mat) {
        if (in_array($mat['products_materials_id'], $product_materials)) {
            $materials_name = explode(',', $mat['material_name']);
            $product_materials_name .= $separator;
            $product_materials_name .= $materials_name[2];
            if (!$separator) {
                $separator = ',';
            }
        }
    }
    $query_color = "SELECT ptcp.products_id, ptcp.color_pattern_id, cpd.name FROM products_to_color_pattern ptcp";
    $query_color .= " LEFT JOIN color_pattern_description cpd ON cpd.color_pattern_id = ptcp.color_pattern_id";
    $query_color .= " WHERE ptcp.products_id = {$product_id} AND languages_id = 1";
    $query_color_result = tep_db_query($query_color);
    $product_color_row = mysql_fetch_row($query_color_result);
    $product_color = $product_color_row[2];
    if ($product_color_row[1] == '19' || $product_color_row[1] == '18') {
        $product_color_family = 'Blue';
    } elseif ($product_color_row[1] == '21') {
        $product_color_family = 'Green';
    } elseif ($product_color_row[1] == '22' || $product_color_row[1] == '15') {
        $product_color_family = 'Multi';
    } elseif ($product_color_row[1] == '13') {
        $product_color_family = 'Pink';
    } elseif ($product_color_row[1] == '20') {
        $product_color_family = 'Purple';
    } elseif ($product_color_row[1] == '17') {
        $product_color_family = 'Red';
    } elseif ($product_color_row[1] == '14') {
        $product_color_family = 'White';
    } elseif ($product_color_row[1] == '23') {
        $product_color_family = 'Gold';
    } else {
        $product_color_family = $product_color_row[2];
    }
    if ($product['categories_id'] == 2) {
        $category = '4944';
    } elseif ($product['categories_id'] == 4) {
        $category = '4943';
    } elseif ($product['categories_id'] == 3) {
        $category = '4942';
    } elseif ($product['categories_id'] == 29) {
        $category = '4941';
        if ($is_article) {
            if ($product_articles_total > 0) {
                $product_ean = $var_ean;
                $product_length = $var_length;
            }
        }
        $product_length_code = $product_length * 10;
        $product_length = $product_length;
        $product_length = ringSizeConvert($product_length);
        //        $product_length = '11'; //FOR NOW WE ALWAYS USE 52MM SIZE (11 ID Size)
        $length_code = '_' . $product_length_code;
        $product_length_for_var = $product_length;
    } elseif ($product['categories_id'] == 30) {
        $category = '4940';
    }
    $product_code = $product['p']['products_model'];
    $care_label = 'Tips merawat perhiasan: Tidak untuk olahraga, mandi, bersih-bersih & tidur. Jangan terkena kaporit , air garam & makeup karena bisa merusak. Bersihkan dengan air hangat dan tisu/sabun khusus untuk perhiasan poles.';
    if ($is_article) {
        $parent_def_length = $class_pa->getDefault($product_id);
        $def_article_convert = number_format($parent_def_length['products_length'] * 10, 0);
        $parent_sku = $product_code . '_' . $def_article_convert;
    } else {
        if ($product_articles_total > 0) {
            if ($product['categories_id'] == 29) {
                $parent_def_length = $class_pa->getDefault($product_id);
                $def_article_convert = number_format($parent_def_length['products_length'] * 10, 0);
                $parent_sku = $product_code . '_' . $def_article_convert;
            }
        } else {
            $parent_sku = '';
        }
    }
    $products_selling_points_html = '- ' . $product_selling_points[0] . '<br>- ' . $product_selling_points[1] . '<br>- ' . $product_selling_points[2] . '<br>- ' . $product_selling_points[3] . '<br>- ' . $product_selling_points[4];
    $product_measures = '';
    if ($product_length == '0.00') {
        if ($product_width != '' && $product_height != '') {
            $product_measures = $product_width . ' x ' . $product_height . ' cm';
        } elseif ($product_width != '' && $product_height == '') {
            $product_measures = $product_width . ' cm';
        } elseif ($product_width == '' && $product_height != '') {
            $product_measures = $product_height . ' cm';
        } elseif ($product_width == '' && $product_height == '') {
            $product['categories_id'] == 4 ? $product_measures = $product_diameter . ' cm' : ($product_measures = '');
        }
    } elseif ($product_width == '') {
        if ($product_length != '0.00' && $product_height != '') {
            $product_measures = number_format($product_length, 0) . ' x ' . $product_height;
        } elseif ($product_length == '0.00' && $product_height != '') {
            $product_measures = $product_height . ' cm';
        } elseif ($product_length != '0.00' && $product_height == '') {
            $product_measures = number_format($product_length, 0) . ' cm';
        } elseif ($product_length == '0.00' && $product_height == '') {
            $product['categories_id'] == 4 ? $product_measures = $product_diameter . ' cm' : ($product_measures = '');
        }
    } elseif ($product_height == '') {
        if ($product_length != '0.00' && $product_width != '') {
            $product_measures = number_format($product_length, 0) . ' x ' . $product_width . ' cm';
        } elseif ($product_length == '0.00' && $product_width != '') {
            $product_measures = $product_width . ' cm';
        } elseif ($product_length != '0.00' && $product_width == '') {
            $product_measures = number_format($product_length, 0) . ' cm';
        } elseif ($product_length == '0.00' && $product_height == '') {
            $product['categories_id'] == 4 ? $product_measures = $product_diameter . ' cm' : ($product_measures = '');
        }
    } else {
        $product_measures = number_format($product_length, 0) . ' x ' . $product_width . ' x ' . $product_height . ' cm';
    }
    $sale_start_date = date("Y-m-d");
    //Always using today's date.
    $x = array();
    /*A - [M] Name      */
    $x[0][0] = 'Bellina Germany ' . $product_name;
    /*B - [O] PrimaryCategory */
    $x[0][1] = '3237';
    //THIS IS CATEGORY FOR JEWELLRY
    /*C - [M] Brand */
    $x[0][2] = 'Bellina Germany';
    /*D - [O] Categories */
    $x[0][3] = '3237';
    /*E - [O] Color  */
    $x[0][4] = $product_color_family;
    /*F - [O] ParentSku  */
    $x[0][5] = $parent_sku;
    /*G - [O] Quantity   */
    $x[0][6] = '50';
    /*H - [M] ColorFamily    */
    $x[0][7] = $product_color_family;
    /*I - [O] Gender  */
    $x[0][8] = 'Female';
    /*J - [O] Season  */
    $x[0][9] = 'Year Round';
    /*K - [O] Year    */
    $x[0][10] = '2014';
    /*L - [M] SalePrice   */
    $x[0][11] = '';
    /*M - [O] SellerSKU    */
    $x[0][12] = $product_code . $length_code;
    /*N - [O] Price    */
    $x[0][13] = '';
    /*O - [M] SaleStartDate  */
    $x[0][14] = $sale_start_date;
    /*P - [O] SaleEndDate    */
    $x[0][15] = '2016-10-01';
    /*Q - [O] Variation    */
    $x[0][16] = $product_length_for_var;
    /*R - [O] CareLabel       */
    $x[0][17] = $care_label;
    /*S - [O] Description    */
    $x[0][18] = $product_description . '<br><br><br><br>' . $products_selling_points_html;
    /*T - [M] Measurements    */
    $x[0][19] = $product_measures;
    /*U - [O] MainImage    */
    $x[0][20] = $product_id;
    //Miriam used this for give price for each products using formula. She will remove this afterwards.
    /*V - [O] Image2*/
    $x[0][21] = '';
    /*W - [O] Image3*/
    $x[0][22] = '';
    /*X - [O] Image4*/
    $x[0][23] = '';
    /*Y - [M] Image5*/
    $x[0][24] = '';
    /*Z - [M] Image6*/
    $x[0][25] = '';
    /*AA - [O] Image7 */
    $x[0][26] = '';
    /*AB - [O] Image8 */
    $x[0][27] = '';
    $csv_row = array();
    $csv_row['data'] = $x;
    //    $csv_row['temp_images'] = (!$is_article) ? $temp_images : '';
    return $csv_row;
}