function setParams($products_id, $param_code)
 {
     use_class('products_minierp');
     $class_pm = new products_minierp();
     if ($param_code == 'M') {
         $param_id_arrays = $class_pm->loadProductMaterials($products_id);
         $field_name = 'material';
     } elseif ($param_code == 'C') {
         $param_id_arrays = $class_pm->loadColorPattern($products_id);
         $field_name = 'color';
     } else {
         $param_id_arrays = array();
         $field_name = '';
     }
     if ($field_name != '') {
         if (count($param_id_arrays) == 0) {
             $sda = array($field_name => '');
             tep_db_perform('jng_sp_catalog', $sda, 'update', "products_id = {$products_id}");
         } else {
             use_class('jng_sp_catalog');
             $class_jc = new jng_sp_catalog();
             $q = tep_db_query("SELECT jng_sp_catalog_id, jng_sp_id FROM jng_sp_catalog WHERE products_id = {$products_id}");
             $sp_list = array();
             while ($row = tep_db_fetch_array($q)) {
                 $sp_list[$row['jng_sp_catalog_id']] = $row['jng_sp_id'];
             }
             foreach ($sp_list as $catalog_id => $jng_sp_id) {
                 $sp_params_raw = $this->load($jng_sp_id, $param_code);
                 $sp_params = array();
                 foreach ($sp_params_raw as $spr) {
                     if (in_array($spr['param_id'], $param_id_arrays)) {
                         $sp_params[] = $spr['param_value'];
                     }
                 }
                 $sda = array($field_name => implode(', ', $sp_params));
                 $class_jc->updateField($catalog_id, $sda);
             }
         }
     }
 }
예제 #2
0
function sp_addProductToCatalog($jng_sp_id, $product_id)
{
    use_class('Product');
    use_class('jng_sp');
    use_class('products_minierp');
    use_class('jng_sp_catalog');
    use_class('jng_sp_catalog_params');
    $class_sp = new jng_sp();
    $class_pm = new products_minierp();
    $class_jc = new jng_sp_catalog();
    $class_jcp = new jng_sp_catalog_params();
    $sp_detail = $class_sp->retrieveDetail($jng_sp_id);
    $sp_used_selling_points = getSalesPartnerUseSellingPoint();
    $sp_used_selling_points_amde = getSalesPartnerUseSellingPoint(true);
    if (!is_array($product_id)) {
        $product_id = explode(',', $product_id);
    }
    $new_id = array();
    foreach ($product_id as $pid) {
        $check_exist = $class_jc->retrieveDetail(null, $jng_sp_id, $pid);
        if ($check_exist === false) {
            $obj_product = new Product($pid);
            $product_data_raw = $class_pm->retrieveDetail($pid);
            $products_selling_points = '';
            $psp = $product_data_raw['pd'][2]['products_selling_points'];
            $pspa = $product_data_raw['pd'][2]['products_selling_points_amde'];
            if (in_array($jng_sp_id, $sp_used_selling_points)) {
                $products_selling_points = $psp;
            } elseif (in_array($jng_sp_id, $sp_used_selling_points_amde)) {
                $products_selling_points = $pspa;
            }
            if (!is_null($obj_product->id)) {
                $desc = $product_data_raw['pd'][$sp_detail['languages_id']];
                $product = array();
                $product['products_length'] = $product_data_raw['pnc']['products_length'];
                $product['products_name'] = $desc['products_name'];
                $product['products_description'] = $desc['products_description'];
                $product['products_head_keywords_tag'] = $desc['products_head_keywords_tag'];
                $article_number = str_replace('-', '_', $obj_product->code);
                $price_uvp = $obj_product->getPriceUVP();
                $price_default = $obj_product->getPriceDefault();
                //TODO: USE B2B FLAG
                if ($jng_sp_id == '5') {
                    $product_price = $obj_product->getPriceSellingDefaultB2B($price_uvp, $jng_sp_id);
                    $product_price_old = 0;
                    $product_price_new = 0;
                    $active_status = '1';
                } else {
                    $product_price = $price_default;
                    $product_price_old = $price_uvp > $price_default ? $price_uvp : 0;
                    $product_price_new = 0;
                    $active_status = '0';
                }
                $product_name = $product['products_name'];
                $product_desc = $product['products_description'];
                $keywords_ok = array();
                $keywords_temp = str_replace('|||', ',', $product['products_head_keywords_tag']);
                $keywords_split = explode(',', $keywords_temp);
                foreach ($keywords_split as $kws) {
                    $kws = trim($kws);
                    if ($kws != '') {
                        $rule1 = strpos($product_name, $kws) === false;
                        $rule2 = strpos($product_desc, $kws) === false;
                        $rule3 = strpos($kws, 'cm') === false;
                        if ($rule1 && $rule2 && $rule3) {
                            $keywords_ok[] = $kws;
                        }
                    }
                }
                $product_keywords = count($keywords_ok) > 0 ? implode(', ', $keywords_ok) : '';
                $product_length = $product['products_length'] == '' ? '0' : $product['products_length'];
                //Retrieve Products Color and connect it with SP Colors
                $color_pattern_id = $class_pm->loadColorPattern($obj_product->id);
                $sp_params_raw = $class_jcp->load($jng_sp_id, 'C');
                $sp_params = array();
                foreach ($sp_params_raw as $spr) {
                    if (in_array($spr['param_id'], $color_pattern_id)) {
                        $sp_params[] = $spr['param_value'];
                    }
                }
                $product_color = implode(', ', $sp_params);
                //Retrieve Products Materials and connect it with SP Materials
                $products_materials_id = $class_pm->loadProductMaterials($obj_product->id);
                $sp_params_raw = $class_jcp->load($jng_sp_id, 'M');
                $sp_params = array();
                foreach ($sp_params_raw as $spr) {
                    if (in_array($spr['param_id'], $products_materials_id)) {
                        $sp_params[] = $spr['param_value'];
                    }
                }
                $product_material = implode(', ', $sp_params);
                $date_added = date('Y-m-d H:i:s');
                //Retrieve Max Resourcing Days
                $elmax_rd_query = "SELECT pe.products_id, MAX(es.resourcing_day) AS max_res_day";
                $elmax_rd_query .= " FROM products_use_elements pe";
                $elmax_rd_query .= " LEFT JOIN elements_stock es ON es.elements_id=pe.elements_id";
                $elmax_rd_query .= " WHERE pe.products_id = {$obj_product->id}";
                $elmax_rd_query .= " GROUP BY pe.products_id";
                $elmax_rd_result = tep_db_query($elmax_rd_query);
                $elmax_rd = tep_db_fetch_array($elmax_rd_result);
                $resplacement_days = $elmax_rd['max_res_day'] == '' ? '0' : $elmax_rd['max_res_day'];
                //INSERT DATA
                $sda = array('jng_sp_id' => $jng_sp_id, 'products_id' => $obj_product->id, 'article_number' => $article_number, 'price' => $product_price, 'price_old' => $product_price_old, 'price_new' => $product_price_new, 'name' => $product_name, 'description' => $product_desc, 'keywords' => $product_keywords, 'length' => $product_length, 'color' => $product_color, 'material' => $product_material, 'use_logo' => '1', 'status_image' => '0', 'date_added' => $date_added, 'replacement_days' => $resplacement_days, 'products_selling_points' => $products_selling_points, 'active_status' => $active_status);
                tep_db_perform('jng_sp_catalog', $sda);
                $new_id[] = tep_db_insert_id();
            }
        }
    }
    return $new_id;
}
 /**
  * Add products to a family
  * @param Int $products_id
  * @return Boolean
  */
 function addToFamily($products_id)
 {
     if (!is_array($products_id)) {
         $products_id = explode(',', $products_id);
     }
     if ($this->id != '') {
         use_class('products_minierp');
         use_class('products_brand');
         $class_pm = new products_minierp();
         $class_pb = new products_brand();
         $p_added = array();
         //Avoid :
         //1) added product which color is same with product member of a family
         //2) added product which brand is different with family brand
         foreach ($products_id as $pid) {
             $cpids = $class_pm->loadColorPattern($pid);
             $new_product_brand_id = $class_pb->retrieveProductBrand($pid);
             $brand_ok = $new_product_brand_id == $this->brand_id;
             foreach ($cpids as $cpid) {
                 if ($brand_ok && !in_array($cpid, $this->colors)) {
                     $p_added[] = $pid;
                 }
             }
         }
         if (count($p_added) > 0) {
             tep_db_query("UPDATE products SET family_id = '" . $this->id . "' WHERE products_id IN (" . implode(',', $p_added) . ")");
             $this->recalcTotalMembers();
             return true;
         }
     }
     return false;
 }
예제 #4
0
$content .= '</div>';
$content .= '<input id="prodet-complete" style="margin-top:10px;" type="button" class="green" value="Product Details Completed" />';
$content .= '</div>';
//closed id="sop-detail-done"
$content .= '</td></tr>';
$content .= '</table>';
$content .= '</div>';
//closed id="step-processes"
$content .= '</div>';
$content .= '<div id="sop-action"></div>';
//CHECK NAME n COLORS:
$content .= '<div id="checkname-act" style="display:none;">';
$content .= '<div class="notice">';
$content .= '<strong>Product Name</strong><br /><input id="prodname" type="text" value="' . htmlspecialchars($product['pd']['2']['products_name']) . '" maxlength="75" style="width:600px;" />';
$cp_columns = 4;
$products_colpats = $class_pm->loadColorPattern($products_id);
$content .= '<br /><br />';
$content .= '<strong>Product Color</strong><br />';
$content .= '<table class="form" border="0" cellpadding="0" cellspacing="0">';
$col = 0;
foreach ($colpats as $cp) {
    $col++;
    $cbid = 'color_' . $cp['color_pattern_id'];
    $cp_img = webImageSource('color-pattern-' . $cp['color_pattern_id'] . '.png');
    $checked = in_array($cp['color_pattern_id'], $products_colpats) ? 'checked="checked"' : '';
    if ($col == 0) {
        $content .= '<tr>';
    }
    $content .= '<td width="20"><input type="checkbox" id="' . $cbid . '" name="col" value="' . $cp['color_pattern_id'] . '" ' . $checked . ' /></td>';
    $content .= '<td width="20"><label for="' . $cbid . '"><img src="' . $cp_img . '" width="20" height="20" /></label></td>';
    $content .= '<td width="120"><label for="' . $cbid . '">' . $cp['name'] . '</label></td>';