function drawLengthsForm($products_id)
{
    global $class_pm, $class_pa;
    use_class('Product');
    $product = $class_pm->retrieveDetail($products_id, 'p,pd,pnc,cat');
    $articles = $class_pa->retrieveList($products_id);
    $category = $class_pm->retrieveCategoryName($product['categories_id'], '1');
    $use_size = Product::isUsingSizeInsteadOfLength($product['categories_id']);
    $result = '<h2 class="red-bright" style="margin-bottom:0;text-transform:uppercase;">' . $category . '</h2>';
    $result .= '<span class="red">Please make sure product category is correct,<br />contact IT Team if you need to change it!</span><br /><br />';
    $result .= 'Default Length/Size:<br />';
    $input_id = 'deflength';
    $input_class = 'class="w080"';
    if ($use_size) {
        $sizes = getLength2Sizes();
        $size_options = loadComboListFromArray($sizes, null, $product['pnc']['products_length'], false);
        $result .= '<select id="' . $input_id . '" ' . $input_class . '>' . $size_options . '</select>';
    } else {
        $result .= '<input type="text" id="' . $input_id . '" ' . $input_class . 'value="' . number_format($product['pnc']['products_length'], 2) . '" onfocus="$(this).select();" /> cm';
    }
    $result .= '<br /><br />';
    //Set MAX additional length per category
    switch ($product['categories_id']) {
        case '2':
        case '3':
        case '30':
            $al_max = 2;
            break;
        case '4':
        case '9':
        case '28':
            $al_max = 0;
            break;
        case '29':
            $al_max = 7;
            break;
        default:
            $al_max = 5;
    }
    $al_count = 0;
    if ($al_max > 0 || count($articles) > 0) {
        $result .= 'Additional Lengt/Size:<br />';
        if (count($articles) > 0) {
            $input_class = 'class="updlength w080"';
            foreach ($articles as $a) {
                $al_count++;
                $input_id = 'paid-' . $a['products_articles_id'];
                if ($use_size) {
                    $size_options = loadComboListFromArray($sizes, null, $a['length'], false);
                    $result .= $al_count . ' - <select id="' . $input_id . '" ' . $input_class . '>' . $size_options . '</select>';
                } else {
                    $result .= $al_count . ' - <input type="text" id="' . $input_id . '" ' . $input_class . ' value="' . number_format($a['length'], 2) . '" /> cm';
                }
                $result .= '<br />';
            }
        }
        if ($al_count < $al_max) {
            $input_class = 'class="addlength w080"';
            for ($al = $al_count + 1; $al <= $al_max; $al++) {
                if ($use_size) {
                    $size_options = loadComboListFromArray($sizes, null, null, false);
                    $result .= $al . ' - <select ' . $input_class . '>' . $size_options . '</select>';
                } else {
                    $result .= $al . ' - <input type="text" ' . $input_class . ' value="" /> cm';
                }
                $result .= '<br />';
            }
        }
        $result .= '<br /><br />';
    }
    $result .= '<input id="setlengthok" type="button" class="button green" value="Save Lengths" />';
    return $result;
}
 }
 //Start taking available returns item
 list($pcode, $plength) = explode('_', $seller_sku);
 $product = Product::loadObjectFromProductCode($pcode);
 if ($product === false) {
     $error_product = true;
     $product_id = 0;
     $article_id = 0;
     $ean_no = '';
 } else {
     $product_id = $product->id;
     if (is_null($plength) || is_numeric($plength) && $plength == 0) {
         $article_id = 0;
     } else {
         //if product with size, translate first to length
         if (Product::isUsingSizeInsteadOfLength($product->category_id)) {
             $plength = translateSize2Length($plength);
         } else {
             //if ring then change length from sku to cm
             if (Product::isUsingLengthInMilimeter($product->category_id)) {
                 //some ring products were uploaded with
                 //additional length added separated with "-"
                 if (!is_numeric($plength)) {
                     list($length_int, $length_ext) = explode('-', $plength);
                     $plength = $length_int;
                 }
                 $plength = $plength / 10;
             }
         }
         $article_id = $product->getArticleIDFromLength($plength);
     }
function getZaloraBMPStockValue($column_key, $product, $aid)
{
    foreach ($product->articles as $article) {
        if ($article['products_articles_id'] == $aid) {
            $stock = $product->retrieveStockQuantity($aid);
            $length = $article['length'];
            if (Product::isUsingSizeInsteadOfLength($product->category_id)) {
                $sizes = getLength2Sizes();
                $length = $sizes[$length];
            }
            if ($length == $column_key || $column_key == 'FREE' && ($length == 'One size' || $length == '0')) {
                return $stock;
            } else {
                $value = '';
            }
        }
    }
    return $value;
}