/**
 * Get cell value for Matahari catalog cell
 * @global Int $jng_sp_id
 * @global Array $sp_detail
 * @param String $column_key
 * @param Product $product
 * @param Int $aid
 * @return String
 */
function getMatahariCatalogCellValue($column_key, $product, $aid)
{
    global $class_pb, $jng_sp_id, $sp_detail, $sp_values_brand, $sp_values_colors, $sp_values_navcat, $sp_values_navsubcat, $category_top_id;
    $lid = $sp_detail['languages_id'];
    if (!isset($sp_values_brand[$product->brand_id])) {
        $sp_brands = $class_pb->getSPbrands($product->brand_id);
        $sp_values_brand[$product->brand_id] = $sp_brands[$jng_sp_id];
    }
    $product_old_function = $product->getOldProductFunction()->retrieveDetail($product->id, 'p,pd,pd2,pc,pnc,cat,pei,pci');
    if ($category_top_id == '1') {
        if ($product_old_function['pci']['products_clear_image'] != '') {
            $main_image = substr($product_old_function['pci']['products_clear_image'], 23);
        } else {
            $main_image = substr($product_old_function['p']['products_image'], 23);
        }
    } else {
        $main_image = substr($product_old_function['p']['products_image'], 23);
    }
    $additional_images = array_values($product_old_function['pei']);
    $category_id = $product->category_id;
    $selling_points = $product->getSellingPointsAsArray($lid);
    switch ($column_key) {
        case 'Title*':
            if ($category_top_id == '1') {
                //JEWELRY
                $value = ucwords(strtolower($sp_values_brand[$product->brand_id])) . ' ' . $product_old_function['pd'][3]['products_name'] . ' ' . $product->getColors($lid);
                //                $value = 'VON LORENZ' . ' ' .
                //                    $product_old_function['pd'][3]['products_name'] . ' ' . $product->getColors($lid);
            } else {
                $value = ucwords(strtolower($sp_values_brand[$product->brand_id])) . ' ' . $product->getName($lid) . ' ' . $product->getColors($lid);
            }
            break;
        case 'Brand':
            $value = $sp_values_brand[$product->brand_id];
            //            $value = 'VON LORENZ';
            break;
        case 'Model':
            $value = '';
            break;
        case 'Color*':
            $value = $product->getColors($lid);
            break;
        case 'Sale Price (Amount)*':
            $price = $product->getPriceSelling($jng_sp_id);
            $price_old = $product->getPriceSellingOld($jng_sp_id);
            if ($price_old <= $price) {
                //show blank if its not discounted
                $price = '';
            }
            $value = $price;
            break;
        case 'Price (Amount)*':
            $price = $product->getPriceSelling($jng_sp_id);
            $price_old = $product->getPriceSellingOld($jng_sp_id);
            if ($price_old <= $price) {
                $price_old = $price;
            }
            $value = $price_old;
            break;
        case 'SKU*':
            $value = $product->getSKU($aid);
            break;
        case 'Size':
            //todo: translate ring sizes
            if ($category_top_id == '1') {
                if ($category_id == '29') {
                    $value = $product->convertRingSizeToJapaneseSize($product->getLengthOrSizeAsText($aid));
                } else {
                    $value = 'One Size';
                }
            } else {
                $value = $product->getLengthOrSizeAsText($aid);
            }
            break;
        case 'Model Number':
            $value = $product->getEAN($aid);
            break;
        case 'Stock':
            $value = $product->retrieveStockQuantity($aid);
            break;
        case 'Product Line':
            $value = 'Wanita';
            break;
        case 'Normal Price (Amount)*':
            $value = $product->getPriceDefault();
            break;
        case 'Normal Price (Currency)*':
            $value = 'IDR';
            break;
        case 'Main Material':
            $value = '';
            break;
        case 'Description*':
            $value = $product->getDescription($lid);
            break;
        case 'Youtube URL':
            $value = '';
            break;
        case 'Highlight 1':
            $value = $selling_points[0];
            break;
        case 'Highlight 2':
            $value = $selling_points[1];
            break;
        case 'Highlight 3':
            $value = $selling_points[2];
            break;
        case 'Highlight 4':
            $value = $selling_points[3];
            break;
        case 'Highlight 5':
            $value = $selling_points[4];
            break;
        case 'Highlight 6':
            $value = '';
            break;
        case 'Highlight 7':
            $value = '';
            break;
        case 'Highlight 8':
            $value = '';
            break;
        case 'Highlight 9':
            $value = '';
            break;
        case 'Highlight 10':
            $value = '';
            break;
        case 'Highlight 11':
            $value = '';
            break;
        case 'Highlight 12':
            $value = '';
            break;
        case 'Insurance option':
            $value = '1';
            break;
        case 'Handling fee (IDR)':
            $value = '0';
            break;
        case 'Product Dimension':
            //Measurements is from Zalora Template
            $value = $product->displayMeasurement($lid);
            break;
        case 'Product Weight':
            $value = $product->displayWeight($lid);
            break;
        case 'Package Dimension (L x W x H cm)':
            //todo: use dynamic data
            $value = '40 x 35 x 3 cm';
            break;
        case 'Certification':
            $value = '';
            break;
        case 'Product Country':
            $value = ProductAttribute::displayAttributeName($product->id, ProductAttribute::GROUP_ID_ORIGIN, $lid);
            break;
        case 'Item Condition*':
            $value = 'new';
            break;
        case 'Product Waranty':
            $value = '';
            break;
        case 'Image 1*':
            //Currently Kristel will copy the link to this field manually.
            $value = $main_image;
            break;
        case 'Image 2':
            $value = $additional_images[0] == '' ? '' : substr($additional_images[0], 23);
            break;
        case 'Image 3':
            $value = $additional_images[1] == '' ? '' : substr($additional_images[1], 23);
            break;
        case 'Image 4':
            $value = $additional_images[2] == '' ? '' : substr($additional_images[2], 23);
            break;
        case 'Image 5':
            $value = $additional_images[3] == '' ? '' : substr($additional_images[3], 23);
            break;
        case 'Product Line':
            $value = ucfirst($product->getProductGender('1'));
            break;
        case 'Price (Currency)*':
            $value = 'IDR';
            break;
        case 'Type':
            $value = '';
            break;
        case 'Package Weight (Kg)':
            $value = 0.4;
            break;
        case 'product_id(MUST BE DELETED BEFORE UPLOAD)':
            $value = $product->id;
            break;
        default:
            $value = '';
    }
    return $value;
}