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); } } } }
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; }
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; } $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($pid); $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 = {$pid} AND languages_id = 1"; $query_color_result = tep_db_query($query_color);
$catalogs = array(); $ignore_family = false; //LOOPING FOR PRODUCTS OF A FAMILY //In this loop we validate product and catalog data and //rearrange the products in each familiy $products_processed_status = array(); while ($r_catalog = tep_db_fetch_array($dbqcat)) { $pid = $r_catalog['products_id']; $is_mother = $pid == $family->mother; if (!array_key_exists($pid, $products_processed_status)) { //Process product data $product_errors = array(); $pdata = $class_pm->retrieveDetail($pid, 'p,pd,pd2,pci,pei,pnc,cat'); $category = new Category($pdata['categories_id']); $category_name = $category->getName($lid); $mat_ids = $class_pm->loadProductMaterials($pid); $pdata['materials'] = array(); foreach ($mat_ids as $mat_id) { if ($materials_name[$mat_id] != '') { $pdata['materials'][] = $materials_name[$mat_id]; } } //MATERIALS CHECK if (count($pdata['materials']) == 0) { $product_errors[] = 'Product has no Materials'; } //BRAND CHECK if ($pdata['p']['products_brand_name'] == '') { $product_errors[] = 'Product Brand is not yet set'; } //NAME CHECK