Commit e8b0e34e2150051a936b18db4098582ef3dd0cb2

Authored by andryeyev
1 parent 6102a857

+ fix дублей модификаций товара при импорте

Showing 1 changed file with 64 additions and 30 deletions   Show diff stats
libs/catalogs.class.php
@@ -592,33 +592,45 @@ ORDER BY catalogs_users.mktime DESC"; @@ -592,33 +592,45 @@ ORDER BY catalogs_users.mktime DESC";
592 592
593 $this->tpl->assign('usersData', $res); 593 $this->tpl->assign('usersData', $res);
594 } 594 }
595 -  
596 - function viewModifications($product_id){  
597 - $sql = "select * from catalogs_modifications where product_id=? order by id desc";  
598 - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC);  
599 - if(trim($_REQUEST['test2'])=='1') print_r($row);  
600 - $this->tpl->assign('modifications', $row);  
601 - }  
602 -  
603 - function viewModificationsProduct($product_id){  
604 - $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc";  
605 - // $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";  
606 - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC);  
607 -  
608 -  
609 -for($i=0;$i<count($row);$i++){  
610 -$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);  
611 -//if($row2['city_id']==25){ unset($row[$i]); } 595 +
  596 +// ======================
  597 +// ==== MODIFICATION ====
  598 +// ======================
  599 +
  600 +function viewModifications ($product_id)
  601 +{
  602 + $sql = "select * from catalogs_modifications where product_id=? order by id desc";
  603 + $row = $this->db->getAll ($sql, array (
  604 + $product_id
  605 + ), DB_FETCHMODE_ASSOC);
  606 + if (trim ($_REQUEST['test2']) == '1')
  607 + print_r ($row);
  608 + $this->tpl->assign ('modifications', $row);
612 } 609 }
613 -$new_row = array();  
614 -//if($_GET['test']=='18') print_r($row);  
615 -foreach ($row as $key => $value) {  
616 - //$new_row[] = $value; 610 +
  611 +function viewModificationsProduct ($product_id)
  612 +{
  613 + $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc";
  614 + // $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";
  615 + $row = $this->db->getAll ($sql, array (
  616 + $product_id
  617 + ), DB_FETCHMODE_ASSOC);
  618 +
  619 + for ($i = 0; $i < count ($row); $i ++)
  620 + {
  621 + $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);
  622 + // if($row2['city_id']==25){ unset($row[$i]); }
  623 + }
  624 + $new_row = array ();
  625 + // if($_GET['test']=='18') print_r($row);
  626 + foreach ($row as $key => $value)
  627 + {
  628 + // $new_row[] = $value;
  629 + }
  630 + // if($_GET['test']=='18') print_r($new_row);
  631 + $this->tpl->assign ('modifications', $row);
  632 + return $row;
617 } 633 }
618 -//if($_GET['test']=='18') print_r($new_row);  
619 - $this->tpl->assign('modifications', $row);  
620 - return $row;  
621 - }  
622 634
623 function viewModificationOne ($id) 635 function viewModificationOne ($id)
624 { 636 {
@@ -637,6 +649,18 @@ function getModificationProduct_id ($code) @@ -637,6 +649,18 @@ function getModificationProduct_id ($code)
637 )); 649 ));
638 } 650 }
639 651
  652 +function getModification ($product_id, $code)
  653 +{
  654 + return $this->db->getOne ("
  655 + SELECT id
  656 + FROM catalogs_modifications
  657 + WHERE product_id=?
  658 + AND code=?", array (
  659 + $product_id,
  660 + $code
  661 + ));
  662 +}
  663 +
640 function SaveModification ($data, $upload) 664 function SaveModification ($data, $upload)
641 { 665 {
642 $table_name = "catalogs_modifications"; 666 $table_name = "catalogs_modifications";
@@ -750,6 +774,10 @@ function deleteModificationPics ($id, $pics = array(&#39;pic_big&#39;,&#39;pic&#39;)) @@ -750,6 +774,10 @@ function deleteModificationPics ($id, $pics = array(&#39;pic_big&#39;,&#39;pic&#39;))
750 // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}"); 774 // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}");
751 } 775 }
752 776
  777 +// =================
  778 +// ==== PRODUCT ====
  779 +// =================
  780 +
753 function ProductClick($id){ 781 function ProductClick($id){
754 $this->db->query("update catalogs_products set click=click+1 where id='$id'"); 782 $this->db->query("update catalogs_products set click=click+1 where id='$id'");
755 } 783 }
@@ -3441,7 +3469,7 @@ function viewTmpProducts () @@ -3441,7 +3469,7 @@ function viewTmpProducts ()
3441 $this->saveProductParams ($product_id, $pruduct_params); 3469 $this->saveProductParams ($product_id, $pruduct_params);
3442 $this->saveGalleryPics ($product_id, $pruduct_gallery_pics); 3470 $this->saveGalleryPics ($product_id, $pruduct_gallery_pics);
3443 // íå óäàëÿåì ! 3471 // íå óäàëÿåì !
3444 - // $this->deleteProductModifications ($product_id, true); 3472 + //$this->deleteProductModifications ($product_id, true);
3445 $m_i = 0; 3473 $m_i = 0;
3446 3474
3447 for ($i = 19; $i < count ($row_line); $i ++) 3475 for ($i = 19; $i < count ($row_line); $i ++)
@@ -3462,22 +3490,28 @@ function viewTmpProducts () @@ -3462,22 +3490,28 @@ function viewTmpProducts ()
3462 3490
3463 $size_mod = explode ("*", $row_mod [1]); 3491 $size_mod = explode ("*", $row_mod [1]);
3464 $rost = (isset ($size_mod [1])) ? $size_mod [1] : ''; 3492 $rost = (isset ($size_mod [1])) ? $size_mod [1] : '';
  3493 +
  3494 + // íàõîäèì modifications_id
  3495 + $modifications_id = $this->getModification($product_id, $row_mod[0]);
  3496 +
  3497 + // ñîõðàíÿåì
3465 $this->SaveModification (array ( 3498 $this->SaveModification (array (
3466 'product_id' => $product_id, 3499 'product_id' => $product_id,
3467 'code' => $row_mod [0], 3500 'code' => $row_mod [0],
3468 'size' => $size_mod [0], 3501 'size' => $size_mod [0],
3469 'rost' => $rost, 3502 'rost' => $rost,
3470 'color' => $row_mod [2], 3503 'color' => $row_mod [2],
3471 - 'active' => $row_mod [4]  
3472 - ), $upload_mod); 3504 + 'active' => $row_mod [4],
  3505 + 'update_id' => (int)$modifications_id
  3506 + ), $upload_mod);
3473 3507
3474 - if ($row_mod [4] > 0) 3508 + if ($row_mod[4] > 0)
3475 { 3509 {
3476 $m_i ++; 3510 $m_i ++;
3477 } 3511 }
3478 } 3512 }
3479 } 3513 }
3480 - 3514 +
3481 $this->updateProduct_countModification ($product_id, $m_i); 3515 $this->updateProduct_countModification ($product_id, $m_i);
3482 3516
3483 // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]); 3517 // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]);