From e8b0e34e2150051a936b18db4098582ef3dd0cb2 Mon Sep 17 00:00:00 2001 From: andryeyev Date: Wed, 25 Nov 2015 14:45:34 +0200 Subject: [PATCH] + fix дублей модификаций товара при импорте --- libs/catalogs.class.php | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/libs/catalogs.class.php b/libs/catalogs.class.php index 826550e..6f3a908 100644 --- a/libs/catalogs.class.php +++ b/libs/catalogs.class.php @@ -592,33 +592,45 @@ ORDER BY catalogs_users.mktime DESC"; $this->tpl->assign('usersData', $res); } - - function viewModifications($product_id){ - $sql = "select * from catalogs_modifications where product_id=? order by id desc"; - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); - if(trim($_REQUEST['test2'])=='1') print_r($row); - $this->tpl->assign('modifications', $row); - } - - function viewModificationsProduct($product_id){ - $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc"; - // $sql = "select m.* from catalogs_keys_products_cities k left join catalogs_modifications m on m.code=k.mod_code where k.product_id=? and k.count>0 order by k.mod_code desc"; - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); - - -for($i=0;$idb->getRow("SELECT * FROM catalogs_keys_products_cities WHERE product_id='".$product_id."' AND mod_code='".@$row[$i]['code']."' LIMIT 1;",array(),DB_FETCHMODE_ASSOC); -//if($row2['city_id']==25){ unset($row[$i]); } + +// ====================== +// ==== MODIFICATION ==== +// ====================== + +function viewModifications ($product_id) +{ + $sql = "select * from catalogs_modifications where product_id=? order by id desc"; + $row = $this->db->getAll ($sql, array ( + $product_id + ), DB_FETCHMODE_ASSOC); + if (trim ($_REQUEST['test2']) == '1') + print_r ($row); + $this->tpl->assign ('modifications', $row); } -$new_row = array(); -//if($_GET['test']=='18') print_r($row); -foreach ($row as $key => $value) { - //$new_row[] = $value; + +function viewModificationsProduct ($product_id) +{ + $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc"; + // $sql = "select m.* from catalogs_keys_products_cities k left join catalogs_modifications m on m.code=k.mod_code where k.product_id=? and k.count>0 order by k.mod_code desc"; + $row = $this->db->getAll ($sql, array ( + $product_id + ), DB_FETCHMODE_ASSOC); + + for ($i = 0; $i < count ($row); $i ++) + { + $row2 = $this->db->getRow ("SELECT * FROM catalogs_keys_products_cities WHERE product_id='" . $product_id . "' AND mod_code='" . @$row[$i]['code'] . "' LIMIT 1;", array (), DB_FETCHMODE_ASSOC); + // if($row2['city_id']==25){ unset($row[$i]); } + } + $new_row = array (); + // if($_GET['test']=='18') print_r($row); + foreach ($row as $key => $value) + { + // $new_row[] = $value; + } + // if($_GET['test']=='18') print_r($new_row); + $this->tpl->assign ('modifications', $row); + return $row; } -//if($_GET['test']=='18') print_r($new_row); - $this->tpl->assign('modifications', $row); - return $row; - } function viewModificationOne ($id) { @@ -637,6 +649,18 @@ function getModificationProduct_id ($code) )); } +function getModification ($product_id, $code) +{ + return $this->db->getOne (" + SELECT id + FROM catalogs_modifications + WHERE product_id=? + AND code=?", array ( + $product_id, + $code + )); +} + function SaveModification ($data, $upload) { $table_name = "catalogs_modifications"; @@ -750,6 +774,10 @@ function deleteModificationPics ($id, $pics = array('pic_big','pic')) // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}"); } +// ================= +// ==== PRODUCT ==== +// ================= + function ProductClick($id){ $this->db->query("update catalogs_products set click=click+1 where id='$id'"); } @@ -3441,7 +3469,7 @@ function viewTmpProducts () $this->saveProductParams ($product_id, $pruduct_params); $this->saveGalleryPics ($product_id, $pruduct_gallery_pics); // íå óäàëÿåì ! - // $this->deleteProductModifications ($product_id, true); + //$this->deleteProductModifications ($product_id, true); $m_i = 0; for ($i = 19; $i < count ($row_line); $i ++) @@ -3462,22 +3490,28 @@ function viewTmpProducts () $size_mod = explode ("*", $row_mod [1]); $rost = (isset ($size_mod [1])) ? $size_mod [1] : ''; + + // íàõîäèì modifications_id + $modifications_id = $this->getModification($product_id, $row_mod[0]); + + // ñîõðàíÿåì $this->SaveModification (array ( 'product_id' => $product_id, 'code' => $row_mod [0], 'size' => $size_mod [0], 'rost' => $rost, 'color' => $row_mod [2], - 'active' => $row_mod [4] - ), $upload_mod); + 'active' => $row_mod [4], + 'update_id' => (int)$modifications_id + ), $upload_mod); - if ($row_mod [4] > 0) + if ($row_mod[4] > 0) { $m_i ++; } } } - + $this->updateProduct_countModification ($product_id, $m_i); // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]); -- libgit2 0.21.4