Example #1
0
function tableSellingPointMatrix($jng_sp_id)
{
    if ($jng_sp_id == '2') {
        //OT.DE
        $max_selling_point = 5;
        $max_char_per_bullet = 50;
        $y_axis = array('1' => 'Silver pure', '52' => 'Silver with Diamond', '2' => 'Silver with Zirconia', '4' => 'Silver with Swarovski', '22' => 'Silver with Enamel', '53' => 'Silver with Gemstones', '17' => 'Goldplated pure', '17-2' => 'Goldplated with Zirconia', '17-4' => 'Goldplated with Swarovski', '17-22' => 'Goldplated with Enamel', '17-53' => 'Goldplated with Gemstones', '57' => '14k Yellow Gold pure', '57-52' => '14k Yellow Gold with Diamond', '59' => '14k White Gold pure', '59-52' => '14k White Gold with Diamond', '60' => '9k Yellow Gold pure', '60-5' => '9k Yellow Gold with Freshwater Pearls', '60-52' => '9k Yellow Gold with Diamond', '60-52-5' => '9k Yellow Gold with Diamond and Freshwater Pearls', '61' => '9k White Gold pure', '61-52' => '9k White Gold with Diamond', '64' => 'Rose Goldplated pure', '64-2' => 'Rose Goldplated with Zirconia', '64-4' => 'Rose Goldplated with Swarovski', '64-22' => 'Rose Goldplated with Enamel', '64-53' => 'Rose Goldplated with Gemstone');
        $x_axis = array('Necklace' => '2', 'Bracelet' => '3', 'Rings' => '29', 'Earrings' => '4', 'Charms' => '9', 'Beads' => 'beads', 'Pendants' => '28', 'Anklets' => '33', 'Sets' => '30');
    } elseif ($jng_sp_id == '5') {
        //AM.DE
        $max_selling_point = 3;
        $max_char_per_bullet = 150;
        $y_axis = array('1' => 'Silver pure', '52' => 'Silver with Diamond', '52-5' => 'Silver with Diamond & Freshwater Pearl', '2' => 'Silver with Zirconia', '4' => 'Silver with Swarovski', '22' => 'Silver with Enamel', '53' => 'Silver with Gemstones', '17' => 'Goldplated pure', '17-2' => 'Goldplated with Zirconia', '17-4' => 'Goldplated with Swarovski', '17-22' => 'Goldplated with Enamel', '17-53' => 'Goldplated with Gemstones', '5' => 'Silver with Freshwater Pearl', '5-4' => 'Silver with Freshwater Pearl & Swarovski', '5-2' => 'Silver with Freshwater Pearl & Zirconia', '17-5' => 'Goldplated with Freshwater Pearl', '17-5-2' => 'Goldplated with Freshwater Pearl & Zirconia', '17-5-4' => 'Goldplated with Freshwater Pearl & Swarovski', '57' => '14k Yellow Gold pure', '57-52' => '14k Yellow Gold with Diamond', '59' => '14k White Gold pure', '59-52' => '14k White Gold with Diamond', '60' => '9k Yellow Gold pure', '60-5' => '9k Yellow Gold with Freshwater Pearls', '60-52' => '9k Yellow Gold with Diamond', '60-52-5' => '9k Yellow Gold with Diamond and Freshwater Pearls', '61' => '9k White Gold pure', '61-52' => '9k White Gold with Diamond', '64' => 'Rose Goldplated pure', '64-2' => 'Rose Goldplated with Zirconia', '64-4' => 'Rose Goldplated with Swarovski', '64-53' => 'Rose Goldplated with Gemstone');
        $x_axis = array('Necklace' => '2', 'Bracelet' => '3', 'Rings' => '29', 'Earrings' => '4', 'Charms' => '9', 'Beads' => 'beads', 'Pendants' => '28', 'Anklets' => '33', 'Sets' => '30');
    } elseif ($jng_sp_id == '1001') {
        //LA.ID
        $max_selling_point = 5;
        $max_char_per_bullet = 'no information yet';
        $y_axis = array('1' => 'Silver pure', '2' => 'Silver with CZ', '4' => 'Silver with Swarovski', '5' => 'Silver with Freshwater Pearl', '5-2' => 'Silver with Freshwater Pearl & Swarovski', '17-5' => 'Goldplated with Freshwater Pearl', '5-4' => 'Silver with Freshwater Pearl & Swarovski', '13' => 'Silver with Rock Crystal', '17' => 'Goldplated', '17-2' => 'Goldplated with CZ', '17-4' => 'Goldplated with Swarovski', '17-5' => 'Goldplated with Freshwater Pearls', '17-13' => 'Goldplated with Rock Crystal', '1-stones' => 'Silver with stones', '17-stones' => 'Goldplated with stones');
        $x_axis = array('Necklace' => '2', 'Bracelet' => '3', 'Rings' => '29', 'Earrings' => '4', 'Sets' => '30');
    }
    if (count($y_axis) > 0) {
        $result = '<h3>Max selling point: ' . $max_selling_point . '<br/>Max character per selling point: ' . $max_char_per_bullet . ($max_char_per_bullet > 0 ? ' chars' : '') . '</h3>';
        $result .= '<div id="selling-point-container" class="draw-table">';
        $result .= '<table class="selling_points_matrix sticky-tablehead" cellpadding="0" cellspacing="0">';
        $result .= '<thead><tr>';
        $result .= '<th>&nbsp;</th>';
        foreach ($x_axis as $cat_name => $cat_id) {
            $result .= '<th>' . $cat_name . '</th>';
        }
        $result .= '</tr></thead>';
        $result .= '<tbody>';
        foreach ($y_axis as $m_key => $mat) {
            $n++;
            $row_class = $n % 2 == 0 ? 'e' : 'o';
            $result .= '<tr class="' . $row_class . '">';
            $result .= '<td><b><small>' . $y_axis[$m_key] . '</b></small></td>';
            foreach ($x_axis as $cat) {
                $sel_pt = getSellingPointMatrix($cat, $m_key, $jng_sp_id);
                $sel_pt_arr = explode(';', $sel_pt);
                $sel_pt_total = count(explode(';', $sel_pt));
                $title = $sel_pt_total >= $max_selling_point ? 'No new selling point could be added to this category' : 'There still ' . (5 - $sel_pt_total) . ' new selling point could be added to this category';
                $sel_pt_available = $max_selling_point - $sel_pt_total;
                $spa_color = 'red';
                $spa_text = 'full';
                if ($sel_pt_available > 0) {
                    $spa_color = 'green';
                    $spa_text = "{$sel_pt_available} available";
                }
                $result .= '<td style="vertical-align:top;">' . '<div title="' . $title . '"><small class="' . $spa_color . '">' . $spa_text . '</small></div>' . '<div><small><ul style="padding-left:10px;"><li style="padding-bottom:10px;">' . implode('</li><li style="padding-bottom:10px;">', $sel_pt_arr) . '</li></ul></small></div>' . '</td>';
            }
            $result .= '</tr>';
        }
        $result .= '</tbody>';
        $result .= '</table>';
        $result .= '</div>';
    } else {
        $result = 'No selling points matrix for this Sales Partner';
    }
    return $result;
}
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
require_once DIR_WS_FUNCTIONS . 'html_output.php';
tep_db_connect();
$max_selling_point = 5;
$y_axis = array('1' => 'Silver pure', '2' => 'Silver with CZ', '4' => 'Silver with Swarovski', '5' => 'Silver with Freshwater Pearl', '5-2' => 'Silver with Freshwater Pearl & Swarovski', '17-5' => 'Goldplated with Freshwater Pearl', '5-4' => 'Silver with Freshwater Pearl & Swarovski', '13' => 'Silver with Rock Crystal', '17' => 'Goldplated', '17-2' => 'Goldplated with CZ', '17-4' => 'Goldplated with Swarovski', '17-5' => 'Goldplated with Freshwater Pearls', '17-13' => 'Goldplated with Rock Crystal', '1-stones' => 'Silver with stones', '17-stones' => 'Goldplated with stones');
$x_axis = array('2', '3', '29', '4', '30');
$border = ' style="border:solid 1px #000;"';
echo '<table border="0" cellpadding="0" cellspacing="0"' . $border . '>';
echo '<tr>';
echo '<td' . $border . '>&nbsp;</td>';
echo '<td align="center"' . $border . '><b>Necklace</b></td>';
echo '<td align="center"' . $border . '><b>Bracelet</b></td>';
echo '<td align="center"' . $border . '><b>Rings</b></td>';
echo '<td align="center"' . $border . '><b>Earring</b></td>';
echo '<td align="center"' . $border . '><b>Sets</b></td>';
echo '</tr>';
foreach ($y_axis as $m_key => $mat) {
    echo '<tr>';
    echo '<td align="center"' . $border . '><b>' . $y_axis[$m_key] . '</b></td>';
    foreach ($x_axis as $cat) {
        $sel_pt = getSellingPointMatrix($cat, $m_key, '1001');
        $sel_pt_total = count(explode(';', $sel_pt));
        $color = $sel_pt_total >= $max_selling_point ? '#ff868b' : '#8dc63f';
        $title = $sel_pt_total >= $max_selling_point ? 'No new selling point could be added to this category' : 'There still ' . (5 - $sel_pt_total) . ' new selling point could be added to this category';
        echo '<td style="background:' . $color . ';border:solid 1px #000;"><span style="background:black;color:white;padding:2px;" title="' . $title . '">' . $sel_pt_total . '</span><br/>' . str_replace(';', ';<br/>', str_replace('Das ideale Geschenk für die Frau oder Freundin', '<b>Das ideale Geschenk für die Frau oder Freundin</b>', $sel_pt)) . ';</td>';
    }
    echo '</tr>';
}
echo '</table>';
<?php

$cid = tep_db_prepare_input($_GET['categories_id']);
$otto_sp_id = '2';
$spm = getSellingPointMatrix($cid, null, $otto_sp_id);
$spm_materials = array('1' => 'Plain Silver', '2' => 'Silver with CZ', '4' => 'Silver with Swarovski', '22' => 'Silver with Enamel', '17' => 'Plain Gold', '17-2' => 'Gold with CZ', '17-4' => 'Gold with Swarovski', '17-22' => 'Gold with Enamel');
$spm_table = array();
$spm_row = array();
$spm_row['id'] = 'No';
$spm_row['long_id'] = 'Material ID';
$spm_row['name'] = 'Material Name';
$spm_row['desc'] = 'Selling Points';
$spm_table[] = $spm_row;
$spm_no = 0;
foreach ($spm_materials as $spm_mat_id => $spm_mat_name) {
    $spm_no++;
    $spm_list = explode(';', $spm[$spm_mat_id]);
    $spm_text = '<ul>';
    foreach ($spm_list as $spl) {
        $spm_text .= '<li>' . $spl . '</li>';
    }
    $spm_text .= '</ul>';
    $spm_row = array();
    $spm_row['id'] = $spm_no;
    $spm_row['long_id'] = $spm_mat_id;
    $spm_row['name'] = $spm_mat_name;
    $spm_row['desc'] = $spm_text;
    $spm_table[] = $spm_row;
}
$content .= tep_draw_table('', $spm_table);
$title = 'Selling Points Matrix for ' . $product_categories_name[$cid];
tep_db_connect();
$max_selling_point = 5;
$y_axis = array('1' => 'Silver pure', '52' => 'Silver with Diamond', '2' => 'Silver with CZ', '4' => 'Silver with Swarovski', '22' => 'Silver with Enamel', '17' => 'Goldplated pure', '17-2' => 'Goldplated with CZ', '17-4' => 'Goldplated with Swarovski', '17-22' => 'Goldplated with Enamel', '57-52' => '14k Yellow Gold with Diamond', '59-52' => '14k White Gold with Diamond', '60-52' => '9k Yellow Gold with Diamond', '61-52' => '9k White Gold with Diamond');
$x_axis = array('2', '3', '29', '4', '9', 'beads', '28', '33', '30');
$border = ' style="border:solid 1px #000;"';
echo '<table border="0" cellpadding="0" cellspacing="0"' . $border . '>';
echo '<tr>';
echo '<td' . $border . '>&nbsp;</td>';
echo '<td align="center"' . $border . '><b>Necklace</b></td>';
echo '<td align="center"' . $border . '><b>Bracelet</b></td>';
echo '<td align="center"' . $border . '><b>Rings</b></td>';
echo '<td align="center"' . $border . '><b>Earring</b></td>';
echo '<td align="center"' . $border . '><b>Charms</b></td>';
echo '<td align="center"' . $border . '><b>Beads</b></td>';
echo '<td align="center"' . $border . '><b>Pendants</b></td>';
echo '<td align="center"' . $border . '><b>Anklets</b></td>';
echo '<td align="center"' . $border . '><b>Sets</b></td>';
echo '</tr>';
foreach ($y_axis as $m_key => $mat) {
    echo '<tr>';
    echo '<td align="center"' . $border . '><b>' . $y_axis[$m_key] . '</b></td>';
    foreach ($x_axis as $cat) {
        $sel_pt = getSellingPointMatrix($cat, $m_key);
        $sel_pt_total = count(explode(';', $sel_pt));
        $color = $sel_pt_total >= $max_selling_point ? '#ff868b' : '#8dc63f';
        $title = $sel_pt_total >= $max_selling_point ? 'No new selling point could be added to this category' : 'There still ' . (5 - $sel_pt_total) . ' new selling point could be added to this category';
        echo '<td style="background:' . $color . ';border:solid 1px #000;"><span style="background:black;color:white;padding:2px;" title="' . $title . '">' . $sel_pt_total . '</span><br/>' . str_replace(';', ';<br/>', str_replace('Das ideale Geschenk für die Frau oder Freundin', '<b>Das ideale Geschenk für die Frau oder Freundin</b>', $sel_pt)) . ';</td>';
    }
    echo '</tr>';
}
echo '</table>';
 /**
  * Set selling point to products with type 1 = Otto DE or 2 = Amazon DE or 3 = Lazada ID
  * @param int $pids
  * @param int $type
  * @param boolean $reset
  * @return int
  */
 function setSellingPointToProducts($pids, $type = null, $reset = false)
 {
     /* PRODUCT CATEGORIES
        2  => Necklace
        3  => Bracelet
        4  => Earrings
        9  => Charms (if style is 32 "Beads Schmuck" so its Beads)
        28 => Pendant
        29 => Rings
        33 => Anklets
        30 => Sets
        */
     $result = array();
     if (!is_null($type) && $type != '') {
         $type = explode(",", $type);
     }
     $sp_used_selling_points = getSalesPartnerUseSellingPoint();
     $sp_used_selling_points_amde = getSalesPartnerUseSellingPoint(true);
     $selling_point_category_ids = array(2, 3, 4, 9, 28, 29, 'beads', 33, 30);
     /* MATERIAL ID's
           1 is default, 17 or 57 or 59 is autochecked when products is contain gold
        */
     $selling_point_material_ids = array(2, 4, 5, 22, 52, 53);
     $selling_point_material_ids_amde = array(2, 4, 5, 22, 52, 53);
     $selling_point_material_ids_laid = array(2, 4, 5, 13);
     /* MATERIAL DEGREE
            1. Diamond (52)
            2. Gemstone (53)
            3. Freshwater Pearl (5)
            4. Swarovski (4)
            5. Zircon (2)
            6. Enamel (22)
            7. Rock Crystal (13)
            8. priority from top to bottom
               ~ 14k(585) Yellow Gold (57) 
               ~ 14k(585) White Gold (59) 
               ~ 9k(375) Yellow Gold (60) 
               ~ 9k(375) White Gold (61) 
               ~ Goldplated (17) 
               ~ Rose Goldplated (64) 
               ~ Silver (1)
        */
     $selling_point_material_degree = array('52' => 1, '53' => 2, '5' => 3, '4' => 4, '2' => 5, '22' => 6, '1' => 7);
     $selling_point_material_degree_amde = array('52' => 1, '53' => 2, '5' => 3, '4' => 4, '2' => 5, '22' => 6, '1' => 7);
     $selling_point_material_degree_laid = array('5' => 1, '4' => 2, '2' => 3, '13' => 4, '1' => 5);
     /* MATERIAL HAVE SUBS
                 $material_have_subs_amde INFO:
                 - on am.de matrix material 5 and 52 could possible combined each-other (52-5) or 5 combined with 2 or 4 (5-2, 5-4) 
                 - please see getSellingPointMatrix on functions-2.php for more details
     
                 $material_have_subs_laid INFO:
                 - on Lazada ID matrix material 5 could possible combined with 2 or 4 (5-2, 5-4) 
              */
     $material_have_subs = array(52);
     $material_have_subs_amde = array(5, 52);
     $material_have_subs_laid = array(5);
     /* MATERIAL GOLDPURE DEGREE
             1. 14k(585) Yellow Gold (57)
             2. 14k(585) White Gold (59)
             3. 9k(375) Yellow Gold (60)
             4. 9k(375) White Gold (61)
        */
     $material_goldpure_degree = array('57' => 1, '59' => 2, '60' => 3, '61' => 4);
     $material_goldpure = array_keys($material_goldpure_degree);
     if (!is_array($pids)) {
         $pids = explode(',', $pids);
     }
     $n_s_point_added = 0;
     $spm_array = array();
     foreach ($pids as $products_id) {
         $materials_id_selected = '1';
         $materials_id_selected_amde = '1';
         $materials_id_selected_laid = '1';
         $materials_id_goldpure_selected = '';
         $mat_goldplated = '';
         $is_goldpure = false;
         $pid = $products_id;
         $cats = $this->retrieveDetail($pid, 'cat');
         $category_id = $cats['categories_id'];
         if ($category_id == '9' && $this->productIsBeads($pid)) {
             $category_id = 'beads';
         }
         $spm = '';
         if (in_array($category_id, $selling_point_category_ids)) {
             $mat_used = $this->retrieveProductMaterialsUsed($pid);
             $dbqg = tep_db_query("SELECT SUM(finishing_goldplate) use_gold, SUM(finishing_rosegoldplate) use_rosegoldplate FROM products_use_elements WHERE products_id = {$pid}");
             $rg = tep_db_fetch_array($dbqg);
             if ($rg['use_gold'] == '1') {
                 $mat_goldplated = '17';
             } elseif ($rg['use_rosegoldplate'] == '1') {
                 $mat_goldplated = '64';
             }
             foreach ($mat_used as $mat_id) {
                 # --------------- Begin Selling Point General Logic ---------------
                 if (in_array($mat_id, $selling_point_material_ids)) {
                     if ($selling_point_material_degree[$mat_id] < $selling_point_material_degree[$materials_id_selected]) {
                         $materials_id_selected = $mat_id;
                     }
                 }
                 if (in_array($mat_id, $material_goldpure)) {
                     $is_goldpure = true;
                     if ($materials_id_goldpure_selected == '') {
                         $materials_id_goldpure_selected = $mat_id;
                     } else {
                         if ($material_goldpure_degree[$mat_id] < $material_goldpure_degree[$materials_id_goldpure_selected]) {
                             $materials_id_goldpure_selected = $mat_id;
                         }
                     }
                 }
                 # --------------- End Selling Point General Logic ---------------
                 # --------------- Begin Selling Point AMDE Logic ---------------
                 if (in_array($mat_id, $selling_point_material_ids_amde)) {
                     if ($selling_point_material_degree_amde[$mat_id] < $selling_point_material_degree_amde[$materials_id_selected_amde]) {
                         $materials_id_selected_amde = $mat_id;
                     }
                 }
                 if (in_array($mat_id, $material_goldpure)) {
                     $is_goldpure = true;
                     if ($materials_id_goldpure_selected_amde == '') {
                         $materials_id_goldpure_selected_amde = $mat_id;
                     } else {
                         if ($material_goldpure_degree[$mat_id] < $material_goldpure_degree[$materials_id_goldpure_selected_amde]) {
                             $materials_id_goldpure_selected_amde = $mat_id;
                         }
                     }
                 }
                 # --------------- End Selling Point AMDE Logic ---------------
                 # --------------- Begin Selling Point Lazada ID Logic ---------------
                 if (in_array($mat_id, $selling_point_material_ids_laid)) {
                     if ($selling_point_material_degree_laid[$mat_id] < $selling_point_material_degree_laid[$materials_id_selected_laid]) {
                         $materials_id_selected_laid = $mat_id;
                     }
                 }
                 # --------------- End Selling Point Lazada ID Logic ---------------
             }
             $materials_id = $materials_id_selected;
             $materials_id_amde = $materials_id_selected_amde;
             $materials_id_laid = $materials_id_selected_laid;
             //if material have subs, get sub materials
             if (in_array($materials_id, $material_have_subs)) {
                 $sub_materials_id = $this->getSubsSellingPoints($mat_used, $materials_id);
                 if ($sub_materials_id != '') {
                     $materials_id = "{$materials_id}-{$sub_materials_id}";
                     $materials_id_selected = $materials_id;
                 }
             }
             if (in_array($materials_id_amde, $material_have_subs_amde)) {
                 $sub_materials_id_amde = $this->getSubsSellingPointsAMDE($mat_used, $materials_id_amde);
                 if ($sub_materials_id_amde != '') {
                     $materials_id_amde = "{$materials_id_amde}-{$sub_materials_id_amde}";
                     $materials_id_selected_amde = $materials_id_amde;
                 }
             }
             if (in_array($materials_id_laid, $material_have_subs_laid)) {
                 $sub_materials_id_laid = $this->getSubsSellingPointsLAID($mat_used, $materials_id_laid);
                 if ($sub_materials_id_laid != '') {
                     $materials_id_laid = "{$materials_id_laid}-{$sub_materials_id_laid}";
                     $materials_id_selected_laid = $materials_id_laid;
                 }
             }
             //if goldplated products
             if ($mat_goldplated != '') {
                 if ($materials_id_selected != '1') {
                     $materials_id = "{$mat_goldplated}-{$materials_id_selected}";
                 } else {
                     $materials_id = $mat_goldplated;
                 }
                 if ($materials_id_selected_amde != '1') {
                     $materials_id_amde = "{$mat_goldplated}-{$materials_id_selected_amde}";
                 } else {
                     $materials_id_amde = $mat_goldplated;
                 }
                 if ($materials_id_selected_laid != '1') {
                     $materials_id_laid = "{$mat_goldplated}-{$materials_id_selected_laid}";
                 } else {
                     $materials_id_laid = $mat_goldplated;
                 }
             }
             //override to goldpure if product is goldpure products (considering also degree of goldpure)
             if ($is_goldpure) {
                 $materials_id = $materials_id_selected != '1' ? "{$materials_id_goldpure_selected}-{$materials_id_selected}" : $materials_id_goldpure_selected;
                 $materials_id_amde = $materials_id_selected_amde != '1' ? "{$materials_id_goldpure_selected_amde}-{$materials_id_selected_amde}" : $materials_id_goldpure_selected_amde;
             }
             //if products have stone except swaro and zircon set it with selling point for stones (Lazada ID)
             $product_elements_used_attr_category = $this->retrieveProductCategoryElementsUsed($products_id);
             $contain_stones = in_array('17', $product_elements_used_attr_category) || in_array('5', $product_elements_used_attr_category);
             if ($contain_stones && ($materials_id_laid == '1' || $materials_id_laid == '17')) {
                 $materials_id_laid = "{$materials_id}-stones";
             }
             $cond_pd1 = "products_id = '{$pid}' AND language_id = 2";
             $cond_pd2 = "products_id = '{$pid}' AND language_id = 2";
             $cond_pd3 = "products_id = '{$pid}' AND language_id = 3";
             $cond_jc1 = "products_id = '{$pid}' AND jng_sp_id IN (" . implode(',', $sp_used_selling_points) . ")";
             $cond_jc2 = "products_id = '{$pid}' AND jng_sp_id IN (" . implode(',', $sp_used_selling_points_amde) . ")";
             //OTTO DE
             if (is_null($type) || array_search('1', $type) !== false) {
                 //echo "$pid || $category_id, $materials_id<br/>";die();
                 $spm = getSellingPointMatrix($category_id, $materials_id, '2');
                 $spm_array[$products_id]['products_selling_points'] = $spm;
                 $res = tep_db_query("SELECT products_id FROM products_description WHERE {$cond_pd1}");
                 if (!$reset) {
                     $cond_pd1 .= " AND (products_selling_points = '' OR products_selling_points IS NULL)";
                     $cond_jc1 .= " AND (products_selling_points = '' OR products_selling_points IS NULL)";
                 }
                 if (tep_db_num_rows($res) > 0) {
                     //Update selling points otto on product level
                     tep_db_perform('products_description', array('products_selling_points' => $spm), 'update', $cond_pd1);
                     //Update selling points on catalog level
                     tep_db_perform('jng_sp_catalog', array('products_selling_points' => $spm), 'update', $cond_jc1);
                 } else {
                     //Add selling points
                     tep_db_perform('products_description', array('products_id' => $products_id, 'language_id' => 2, 'products_selling_points' => $spm));
                 }
             }
             //AMAZON DE
             if (is_null($type) || array_search('2', $type) !== false) {
                 //echo "$pid || $category_id, $materials_id_amde<br/>";die();
                 $spm_amde = getSellingPointMatrix($category_id, $materials_id_amde, '5');
                 $spm_array[$products_id]['products_selling_points_amde'] = $spm_amde;
                 $res = tep_db_query("SELECT products_id FROM products_description WHERE {$cond_pd2}");
                 if (!$reset) {
                     $cond_pd2 .= " AND (products_selling_points_amde = '' OR products_selling_points_amde IS NULL)";
                     $cond_jc2 .= " AND (products_selling_points = '' OR products_selling_points IS NULL)";
                 }
                 if (tep_db_num_rows($res) > 0) {
                     //Update selling points amazon on product level
                     tep_db_perform('products_description', array('products_selling_points_amde' => $spm_amde), 'update', $cond_pd2);
                     //Update selling points on catalog level
                     tep_db_perform('jng_sp_catalog', array('products_selling_points' => $spm_amde), 'update', $cond_jc2);
                 } else {
                     //Add selling points
                     tep_db_perform('products_description', array('products_id' => $products_id, 'language_id' => 2, 'products_selling_points_amde' => $spm_amde));
                 }
             }
             //LAZADA ID
             if (is_null($type) || array_search('3', $type) !== false) {
                 //echo "$pid || $category_id, $materials_id<br/>";die();
                 $spm_laid = getSellingPointMatrix($category_id, $materials_id_laid, '1001');
                 $spm_array[$products_id]['products_selling_points_laid'] = $spm_laid;
                 $res = tep_db_query("SELECT products_id FROM products_description WHERE {$cond_pd3}");
                 if (!$reset) {
                     $cond_pd3 .= " AND (products_selling_points = '' OR products_selling_points IS NULL)";
                     $cond_jc3 .= " AND (products_selling_points = '' OR products_selling_points IS NULL)";
                 }
                 if (tep_db_num_rows($res) > 0) {
                     //Update selling points Lazada ID on product level
                     tep_db_perform('products_description', array('products_selling_points' => $spm_laid), 'update', $cond_pd3);
                     //Update selling points on catalog level (not yet activated since we not prepare yet lazada as sales partner)
                     /*
                                             tep_db_perform(
                            'jng_sp_catalog', 
                            array('products_selling_points' => $spm), 
                            'update', $cond_jc3);
                     */
                 } else {
                     //Add selling points
                     tep_db_perform('products_description', array('products_id' => $products_id, 'language_id' => 3, 'products_selling_points' => $spm_laid));
                 }
             }
             $n_s_point_added++;
         }
     }
     $result = $spm_array;
     $result['total_selling_point_added'] = $n_s_point_added;
     return $result;
 }