Advertisement
amaenta

presta import basic

Mar 28th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 68.10 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package Panel
  4.  */
  5.  
  6. class Panel_ImportController extends IberoBasicController {
  7.  
  8.     public function indexAction(){
  9.         die('...');
  10.     }
  11.  
  12.     private function getPvVal($id)
  13.     {
  14.         $p1 = $this->objPropertiesValues->getAllById($id);
  15.         foreach ($p1 as $k => $v) {
  16.             $v['pv_value'] = str_replace(',', '.', $v['pv_value']);
  17.             $v['pv_value'] = str_replace('+', '', $v['pv_value']);
  18.             $c1[(string)$v['pv_value']] = $v['pv_id'];
  19.         }
  20.         return $c1;
  21.     }
  22.  
  23.     public function stanyAction()
  24.     {
  25.         $row = 1;
  26.         if (($uchwyt = fopen ("items.csv","r")) !== FALSE) {
  27.             while (($data = fgetcsv($uchwyt, 1000, ";")) !== FALSE)  {
  28.  
  29.                 $itemId = $data[0];
  30.                 $amount = (int)$data[3];
  31.                 if ($itemId > 0) {
  32.                     $d = [];
  33.                     $d['item_id'] = $itemId;
  34.                     $d['depot_id'] = 1;
  35.                     $d['mag_id'] = NULL;
  36.                     $d['ia_amount'] = (int)$amount;
  37.                     $d['ia_nolimit'] = 0;
  38.                     $this->objAmount->add($d);
  39.                     pre($d);
  40.                 }
  41.  
  42.             }
  43.             fclose ($uchwyt);
  44.         }
  45.  
  46.         die('1');
  47.     }
  48.  
  49.     public function stany2Action()
  50.     {
  51.         $row = 1;
  52.         if (($uchwyt = fopen ("items2.csv","r")) !== FALSE) {
  53.             while (($data = fgetcsv($uchwyt, 1000, ";")) !== FALSE)  {
  54.  
  55.                 $itemId = $data[0];
  56.                 $magId = $data[1];
  57.                 $amount = (int)$data[4];
  58.                 if ($itemId > 0 && $magId > 0) {
  59.                     $d = [];
  60.                     $d['item_id'] = $itemId;
  61.                     $d['depot_id'] = 1;
  62.                     $d['mag_id'] = $magId;
  63.                     $d['ia_amount'] = (int)$amount;
  64.                     $d['ia_nolimit'] = 0;
  65.                     try {
  66.                         $this->objAmount->add($d);
  67.                         pre($d);
  68.                     } catch (Exception $e) {}
  69.                 }
  70.  
  71.             }
  72.             fclose ($uchwyt);
  73.         }
  74.  
  75.         die('1');
  76.     }
  77.  
  78.     public function rozmiaryAction()
  79.     {
  80.         set_time_limit(0);
  81.         ini_set('memory_limit', '1024M');
  82.  
  83.         $c1 = $this->getPvVal(153);
  84.         $c2 = $this->getPvVal(146);
  85.         $c3 = $this->getPvVal(147);
  86.  
  87.         $res = [];
  88.         $k = 0;
  89.         $array = str_getcsv(file_get_contents('plik.csv'));
  90.         foreach ($array as $val) {
  91.  
  92.             if (substr($val,0,5) == 'barts') {
  93.                 $k++;
  94.                 $val = trim(substr($val,5));
  95.             }
  96.             $res[$k][] = $val;
  97.         }
  98.  
  99.         for ($i = 0; $i <= 17; $i++) {
  100.             $item_id = $res[$i][0];
  101.             $item = $this->objItems->getOneByid($item_id);
  102.             if ($item['item_id'] > 0 && $item['pg_id'] == 23) {
  103.  
  104.                 //   $this->objItemsES->delAllByItemId($item_id);
  105.                 //   continue;
  106.  
  107.                 $res[$i][2] = str_replace(',', '.', $res[$i][2]);
  108.                 $res[$i][3] = str_replace(',', '.', $res[$i][3]);
  109.                 $res[$i][4] = str_replace(',', '.', $res[$i][4]);
  110.                 $moc = explode("\n", $res[$i][2]);
  111.                 $cylinder = explode(";", $res[$i][3]);
  112.                 $os  = explode(";", $res[$i][4]);
  113.  
  114.                 if (substr($res[$i][4], 0,2) == 'od') {
  115.                     $os = [];
  116.                     $a = explode(" ", $res[$i][4]);
  117.                     foreach (range($a[1], $a[3], $a[5]) as $number) {
  118.                         $os[] = $number;
  119.                     }
  120.                 }
  121.  
  122.  
  123.                 foreach ($moc as $moc1) {
  124.                     $a = explode(" ", $moc1);
  125.                     foreach (range($a[1], $a[3], $a[5]) as $number) {
  126.                         $number = (string)$number;
  127.                         if (strpos($number, '.') === false) {
  128.                             $number .= '.0';
  129.                         }
  130.                         if ($number == '0.0') {
  131.                             $number = '0.00';
  132.                         }
  133.                         foreach ($cylinder as $cy) {
  134.                             $cy = trim($cy);
  135.                             if ($cy == '') {
  136.                                 continue;
  137.                             }
  138.                             foreach ($os as $o) {
  139.                                 $o = trim($o);
  140.                                 if ($o == '') {
  141.                                     continue;
  142.                                 }
  143.                                 $itemses = [];
  144.                                 $itemses['item_id'] = $item_id;
  145.                                 $itemses['pv_id_1'] = $c1[$number];
  146.                                 $itemses['pv_id_2'] = $c2[$cy];
  147.                                 $itemses['pv_id_3'] = $c3[$o];
  148.                                 $itemses['item_code'] = '';
  149.                                 $itemses['item_price'] = 0;
  150.                                 $itemses['item_weight'] = 0;
  151.  
  152.                                 if ($itemses['pv_id_1'] < 1 || $itemses['pv_id_2'] < 1 || $itemses['pv_id_3'] < 1) {
  153.                                     pre($itemses, '1:'.$number.' 2:'.$cy.' 3:'.$o);
  154.                                     exit;
  155.                                 }
  156.  
  157.                                 $this->objItemsES->add($itemses);
  158.  
  159.                                 $amount = array();
  160.                                 $amount['item_id'] = $item_id;
  161.                                 $amount['depot_id'] = 1001;
  162.                                 $amount['mag_id'] = $this->objItemsES->getLastId();
  163.                                 $amount['ia_amount'] = 0;
  164.                                 $amount['ia_nolimit'] = 1;
  165.                                 $this->objAmount->add($amount);
  166.  
  167.                             }
  168.                         }
  169.  
  170.                     }
  171.                 }
  172.  
  173.             } else {
  174.                 pre($item_id,'bad item');
  175.             }
  176.         }
  177.  
  178.         die('1');
  179.     }
  180.  
  181.     public function rozmiary2Action()
  182.     {
  183.         set_time_limit(0);
  184.         ini_set('memory_limit', '1024M');
  185.  
  186.         $c1 = $this->getPvVal(153);
  187.         $c2 = $this->getPvVal(150);
  188.         $c3 = $this->getPvVal(149);
  189.  
  190.         $res = [];
  191.         $k = 0;
  192.         $array = str_getcsv(file_get_contents('plik.csv'));
  193.         foreach ($array as $val) {
  194.  
  195.             if (substr($val,0,5) == 'barts') {
  196.                 $k++;
  197.                 $val = trim(substr($val,5));
  198.             }
  199.             $res[$k][] = $val;
  200.         }
  201.  
  202.  
  203.  
  204.         $i = 0;
  205.         $item_id = $res[0][0];
  206.         $item = $this->objItems->getOneByid($item_id);
  207.         if ($item['item_id'] > 0 && $item['pg_id'] == 27) {
  208.  
  209.             //   $this->objItemsES->delAllByItemId($item_id);
  210.             //   continue;
  211.  
  212.             $res[$i][2] = str_replace(',', '.', $res[$i][2]);
  213.             $res[$i][3] = str_replace(',', '.', $res[$i][3]);
  214.             $res[$i][4] = str_replace(',', '.', $res[$i][4]);
  215.             $moc = explode("\n", $res[$i][2]);
  216.             $cylinder = explode(";", $res[$i][3]);
  217.             $os  = explode(";", $res[$i][4]);
  218.  
  219.             if (substr($res[$i][4], 0,2) == 'od') {
  220.                 $os = [];
  221.                 $a = explode(" ", $res[$i][4]);
  222.                 foreach (range($a[1], $a[3], $a[5]) as $number) {
  223.                     if (strpos($number, '.') === false) {
  224.                         $number .= '.0';
  225.                     }
  226.                     $os[] = $number;
  227.                 }
  228.             }
  229.  
  230.             if (substr($res[$i][3], 0,2) == 'od') {
  231.                 $cylinder = [];
  232.                 $a = explode(" ", $res[$i][3]);
  233.                 foreach (range($a[1], $a[3], $a[5]) as $number) {
  234.                     if (strpos($number, '.') === false) {
  235.                         $number .= '.0';
  236.                     }
  237.                     $cylinder[] = $number;
  238.                 }
  239.             }
  240.  
  241.  
  242.             foreach ($moc as $moc1) {
  243.                 $a = explode(" ", $moc1);
  244.                 foreach (range($a[1], $a[3], $a[5]) as $number) {
  245.                     $number = (string)$number;
  246.                     if (strpos($number, '.') === false) {
  247.                         $number .= '.0';
  248.                     }
  249.                     if ($number == '0.0') {
  250.                         $number = '0.00';
  251.                     }
  252.                     foreach ($cylinder as $cy) {
  253.                         $cy = trim($cy);
  254.                         if ($cy == '') {
  255.                             continue;
  256.                         }
  257.                         foreach ($os as $o) {
  258.                             $o = trim($o);
  259.                             if ($o == '') {
  260.                                 continue;
  261.                             }
  262.                             $itemses = [];
  263.                             $itemses['item_id'] = $item_id;
  264.                             $itemses['pv_id_1'] = $c1[$number];
  265.                             $itemses['pv_id_2'] = $c2[$cy];
  266.                             $itemses['pv_id_3'] = $c3[$o];
  267.                             $itemses['item_code'] = '';
  268.                             $itemses['item_price'] = 0;
  269.                             $itemses['item_weight'] = 0;
  270.  
  271.                             if ($itemses['pv_id_1'] < 1 || $itemses['pv_id_2'] < 1 || $itemses['pv_id_3'] < 1) {
  272.                                 pre($itemses, '1:'.$number.' 2:'.$cy.' 3:'.$o);
  273.                                 exit;
  274.                             }
  275.  
  276.                             $this->objItemsES->add($itemses);
  277.  
  278.                             $amount = array();
  279.                             $amount['item_id'] = $item_id;
  280.                             $amount['depot_id'] = 1001;
  281.                             $amount['mag_id'] = $this->objItemsES->getLastId();
  282.                             $amount['ia_amount'] = 0;
  283.                             $amount['ia_nolimit'] = 1;
  284.                             $this->objAmount->add($amount);
  285.  
  286.                         }
  287.                     }
  288.  
  289.                 }
  290.             }
  291.  
  292.         } else {
  293.             pre($item_id,'bad item');
  294.         }
  295.  
  296.  
  297.         die('1');
  298.     }
  299.  
  300.  
  301.     public function amountAction(){
  302.         ini_set('display_errors', 1);
  303.         set_time_limit(0);
  304.         try {
  305.  
  306.             $link = mysqli_connect("localhost","bartek","passwd123","bartek") or die("Error " . mysqli_error($link));
  307.             $link->query("SET NAMES 'utf8'");
  308.  
  309.  
  310.             $db = Zend_Registry::get('dbAdapter');
  311.  
  312.             $result1 = $link->query("SELECT p.*,l.name,l.description,l.description_short,l.meta_description,l.meta_keywords,l.meta_title FROM `ps_product` p INNER JOIN ps_product_lang l
  313.                    ON (p.id_product=l.id_product AND l.id_lang='7') ORDER BY p.id_product ASC");
  314.             while($v = mysqli_fetch_array($result1)) {
  315.  
  316.                 $item_id = $v['id_product'];
  317.                 $this->_setPropMag($item_id);
  318.  
  319.                 if($this->pg_id>1) {
  320.  
  321.                 } else {
  322.                     $amount1 = 0;
  323.                     $sql3 = "SELECT *  FROM `ps_stock_available` WHERE `id_product` = $item_id ";
  324.                     $result3 = $link->query($sql3);
  325.                     while($row3 = mysqli_fetch_array($result3)) {
  326.                         $amount1 = (int)$row3['quantity'];
  327.                         break;
  328.                     }
  329.                     try {
  330.                         $db->query("INSERT INTO items_amount (item_id,depot_id,ia_amount,ia_nolimit) VALUES('$item_id','1','$amount1','0')");
  331.                     } catch (Exception $e) {
  332.  
  333.                     }
  334.                 }
  335.  
  336.             }
  337.  
  338.             die("OK!");
  339.  
  340.         } catch (Exception $e) {
  341.             print_r($e->getMessage());
  342.         }
  343.         die("error!");
  344.     }
  345.  
  346.     public function availabilityAction()
  347.     {
  348.         $link = $this->connect();
  349.  
  350.         $pair = [];
  351.         $pair[1] = 1;
  352.         $pair[2] = 4;
  353.         $pair[3] = 5;
  354.         $pair[5] = 6;
  355.         $pair[6] = 7;
  356.         $pair[8] = 2;
  357.         $pair[10] = 3;
  358.  
  359.         $result1 = $link->query("SELECT id_product,id_availability FROM `ps_product` order by id_product ASC");
  360.         while($v = mysqli_fetch_array($result1)) {
  361.  
  362.             $item_id = $v['id_product'];
  363.  
  364.             $time = 0;
  365.             if (isset($pair[$v['id_availability']])) {
  366.                 $time = $pair[$v['id_availability']];
  367.             }
  368.             $d = [];
  369.             $d['item_shipping_time'] = $time;
  370.             $this->objItems->save($item_id, $d);
  371.  
  372.         }
  373.         die("ok");
  374.     }
  375.  
  376.     public function itemsAction(){
  377.         ini_set('display_errors', 1);
  378.         ini_set('memory_limit', '2048M');
  379.         set_time_limit(0);
  380.         try {
  381.  
  382.             $link = $this->connect();
  383.  
  384.             $db = Zend_Registry::get('dbAdapter');
  385.  
  386.  
  387.             $path = '/home/ftbzrr/domains/fitbay.ebexo.com.pl/public_html/images/items/';
  388.             $type = array('_big','_top','_medium','_small','_micro','_prop');
  389.  
  390.  
  391.             $sql = "SELECT id_manufacturer,name FROM `ps_manufacturer` WHERE active=1 ORDER BY id_manufacturer ASC";
  392.             $result1 = $link->query($sql);
  393.             $i = 0;
  394.             while($row1 = mysqli_fetch_array($result1)) {
  395.                 if(strlen($row1['name'])>1) {
  396.                     $prod = trim($row1['name']);
  397.                     $producers[$row1['id_manufacturer']] = $prod;
  398.                 }
  399.             }
  400.  
  401.             $olddir = '/home/ftbzrr/domains/fitbay.ebexo.com.pl/public_html/p/';
  402.  
  403.             $lastID=0;
  404.             $abc = 0;
  405.             $nowe = 0;
  406.             $result1 = $link->query("SELECT p.*,l.name,l.description,l.description_short,l.meta_description,l.meta_keywords,l.meta_title FROM `ps_product` p INNER JOIN ps_product_lang l
  407.                    ON (p.id_product=l.id_product AND l.id_lang='3') WHERE p.id_product > 0 ORDER BY p.id_product ASC");
  408.             while($v = mysqli_fetch_array($result1)) {
  409.  
  410.                
  411.                 try {
  412.                     $item_id = $v['id_product'];
  413.                     if ($item_id <= 14730) continue;
  414.  
  415.                     $one1 = $this->objItems->getOneById($item_id);
  416.                     if ($one1['item_id'] < 1) continue;
  417.  
  418.                     $item = array();
  419.                     $item['item_buy_price'] = $v['wholesale_price'];
  420.  
  421.  
  422.                     $item['item_id'] = $item_id;
  423.                     $item['item_name'] = $v['name'];
  424.                     $item['item_desc_short'] = $v['description_short'];
  425.                     $item['item_desc'] = $v['description'];
  426.                     switch ($v['id_tax']) {
  427.                         case 1:
  428.                             $tax = 0;
  429.                             break;
  430.                         case 2:
  431.                             $tax = 8;
  432.                             break;
  433.                         case 3:
  434.                             $tax = 23;
  435.                             break;
  436.                         case 4:
  437.                             $tax = 5;
  438.                             break;
  439.                     }
  440.                     $item['item_vat'] = $tax;
  441.                     $item['item_weight'] = $v['weight'];
  442.                     $item['item_active'] = $v['active'];
  443.                     $item['item_shipping_time'] = 1;
  444.  
  445.                     $item['item_exp_store'] = 0;
  446.                     $item['pg_id'] = 1;
  447.  
  448.                     $producent = $producers[$v['id_manufacturer']];
  449.  
  450.                     if ($producent != '') {
  451.                         $p = $this->objProducers->getOneByName($producent);
  452.                         if ($p['producer_id'] > 1) {
  453.                             $item['producer_id'] = $p['producer_id'];
  454.                         } else {
  455.                             $item['producer_id'] = 1;
  456.                         }
  457.                     } else {
  458.                         $item['producer_id'] = 1;
  459.                     }
  460.  
  461.  
  462.                     $item['item_code'] = (string)$v['reference'];
  463.                     $item['item_ean'] = (string)$v['ean13'];
  464.                     $item['item_new'] = 0;
  465.  
  466.                     $priceBrutto = $v['price'] * (1 + $item['item_vat'] / 100);
  467.                     if ($v['reduction_price'] > 0) {
  468.  
  469.                         $price = $priceBrutto - $v['reduction_price'];
  470.  
  471.                         if ($v['reduction_from'] == $v['reduction_to']) {
  472.                             $item['item_promo_price_from'] = '2017-10-03';
  473.                             $item['item_promo_price_to'] = '2020-12-31';
  474.                         } else {
  475.                             $item['item_promo_price_from'] = $v['reduction_from'];
  476.                             $item['item_promo_price_to'] = $v['reduction_to'];
  477.                         }
  478.  
  479.                         $item['item_price'] = $v['price'];
  480.                         $item['item_promo'] = 1;
  481.                         $item['item_promo_price'] = $price;
  482.                         $item['item_real_promo'] = 1;
  483.                         $item['item_actual_price'] = $item['item_promo_price'];
  484.                     } else {
  485.                         $item['item_promo'] = 0;
  486.                         $item['item_price'] = $v['price'];
  487.                         $item['item_actual_price'] = $priceBrutto;
  488.  
  489.                     }
  490.  
  491.                     // dodanie produktu
  492.                     ////////        $this->objItems->add($item);
  493.  
  494.                     $lastID = $item_id;
  495.  
  496.                     $this->_setPropMag($item_id);
  497.                     if ($this->pg_id > 0) {
  498.                         //        $item2 = array();
  499.                         //        $item2['item_exp_store'] = 1;
  500.                         //        $item2['pg_id'] = $this->pg_id;
  501.                         //        $this->objItems->save($item_id,$item2);
  502.                     } else {
  503.                         // magazyn - to dla produktow bez cech mag.
  504.                         $amount = (int)$v['quantity'];
  505.                         $db->query("INSERT INTO items_amount (item_id,depot_id,ia_amount,ia_nolimit) VALUES('$lastID','1','$amount','0')");
  506.                     }
  507.  
  508.                 } catch (Exception $e) {
  509.                     print_r($e->getMessage());
  510.                 }
  511.  
  512.                 continue;
  513.  
  514.                 $this->_setPropInf($item_id);
  515.  
  516.  
  517.  
  518.                 // foto
  519.  
  520.                 @mkdir("{$path}{$lastID}");
  521.  
  522.  
  523.                 $result2 = $link->query("SELECT * FROM `ps_image` where id_product='".$lastID."' order by position ASC");
  524.                 while($foto = mysqli_fetch_array($result2)) {
  525.  
  526.                 //    10779-19481.jpg
  527.                     $img = $lastID.'-'.$foto['id_image'].'.jpg';
  528.  
  529.  
  530.                     if($img != '' && file_exists($olddir.$img) ){
  531.  
  532.                         file_put_contents($path.$lastID.'/'.$foto['id_product'].'-'.$foto['id_image'].'_big.jpg', file_get_contents($olddir.$img));
  533.  
  534.                         $base = $foto['id_product'].'-'.$foto['id_image'].'.jpg';
  535.                         foreach($type as $ftype) {
  536.                             $fname = $foto['id_product'].'-'.$foto['id_image'].$ftype.'.jpg';
  537.                             if($foto['cover']==1) {
  538.                                 $if_root = 1;
  539.                             } else {
  540.                                 $if_root = 0;
  541.                             }
  542.  
  543.                             $db->query("INSERT INTO items_foto (item_id,if_root,if_base_name,if_name,if_type,prop)
  544.                                                    VALUES('$lastID','$if_root','$base','$fname','$ftype','0');");
  545.                         }
  546.  
  547.                     }
  548.  
  549.  
  550.                 }
  551.  
  552.                 // end foto
  553. continue;
  554.  
  555.  
  556.                 // kategorie
  557.                 $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('1','$lastID')";
  558.                 $db->query($sql);
  559.  
  560.                 $i_id = $lastID;
  561.                 $sql6 = "SELECT nowa FROM `ps_category_product` p INNER JOIN kategorie k ON (k.stara=p.id_category) WHERE id_product='$item_id'";
  562.                 $res6 = $link->query($sql6);
  563.                 while($row6 = mysqli_fetch_array($res6)) {
  564.                     $c_id = $cat = $row6['nowa'];
  565.                     $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$cat','$lastID')";
  566.  
  567.                     $db->query($sql);
  568.  
  569.                     $level = $this->treeCat->getLevel($cat);
  570.                     if($level==4) {
  571.                         $parent = $this->treeCat->getParent($c_id);
  572.                         $c_id = $parent['id'];
  573.                         $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
  574.                         try {
  575.                             $db->query($sql);
  576.                         } catch (Exception $e) {
  577.                             echo $sql.' ';
  578.                             print_r($e->getMessage());
  579.                         }
  580.                         $parent = $this->treeCat->getParent($c_id);
  581.                         $c_id = $parent['id'];
  582.                         $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
  583.                         try {
  584.                             $db->query($sql);
  585.                         } catch (Exception $e) {
  586.                             echo $sql.' ';
  587.                             print_r($e->getMessage());
  588.                         }
  589.                         $parent = $this->treeCat->getParent($c_id);
  590.                         $c_id = $parent['id'];
  591.                         $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
  592.                         try {
  593.                             $db->query($sql);
  594.                         } catch (Exception $e) {
  595.                             echo $sql.' ';
  596.                             print_r($e->getMessage());
  597.                         }
  598.                     }
  599.                     if($level==3) {
  600.                         $parent = $this->treeCat->getParent($c_id);
  601.                         $c_id = $parent['id'];
  602.                         $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
  603.                         try {
  604.                             $db->query($sql);
  605.                         } catch (Exception $e) {
  606.                             echo $sql.' ';
  607.                             print_r($e->getMessage());
  608.                         }
  609.                         $parent = $this->treeCat->getParent($c_id);
  610.                         $c_id = $parent['id'];
  611.                         $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
  612.                         try {
  613.                             $db->query($sql);
  614.                         } catch (Exception $e) {
  615.                             echo $sql.' ';
  616.                             print_r($e->getMessage());
  617.                         }
  618.                     }
  619.                     elseif($level==2) {
  620.                         $parent = $this->treeCat->getParent($c_id);
  621.                         $c_id = $parent['id'];
  622.                         $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
  623.                         try {
  624.                             $db->query($sql);
  625.                         } catch (Exception $e) {
  626.                             echo $sql.' ';
  627.                             print_r($e->getMessage());
  628.                         }
  629.                     }
  630.  
  631.                 }
  632.  
  633.  
  634.             }
  635.  
  636.         } catch (Exception $e) {
  637.             print_r($e->getMessage());
  638.         }
  639.         die('import complete without errors');
  640.     }
  641.  
  642.  
  643.     public function connect()
  644.     {
  645.         $link = mysqli_connect("localhost","centr11_test","3t148FsNo0","centr11_test") or die("Error " . mysqli_error($link));
  646.         $link->query("SET NAMES 'utf8'");
  647.         return $link;
  648.     }
  649.  
  650.     public function prodAction(){
  651.         ini_set('display_errors', 1);
  652.  
  653.         $link = $this->connect();
  654.  
  655.         $sql = "SELECT id_manufacturer,name FROM `ps_manufacturer` WHERE active=1 ORDER BY id_manufacturer ASC";
  656.         $result1 = $link->query($sql);
  657.         $i = 0;
  658.         while($row1 = mysqli_fetch_array($result1)) {
  659.  
  660.  
  661.             if(strlen($row1['name'])>1) {
  662.                 $prod = trim($row1['name']);
  663.  
  664.  
  665.                 if($this->objProducers->isExist($prod)){
  666.                     // istnieje
  667.                 } else {
  668.                     // dodaj
  669.                     $data = array();
  670.                     $data['producer_name'] = $prod;
  671.                     $data['producer_desc'] = "";
  672.  
  673.                     $this->objProducers->add($data);
  674.                 }
  675.  
  676.             }
  677.         }
  678.  
  679.         die('import complete without errors');
  680.  
  681.     }
  682.  
  683.     // import kategorii
  684.     public function catAction() {
  685.  
  686.         ini_set('display_errors', 1);
  687.         ini_set('memory_limit', '1024M');
  688.         $lang = 1;
  689.  
  690.         $link = $this->connect();
  691.  
  692.  
  693.         $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
  694. FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
  695.            WHERE c.id_parent='1' AND c.active='1' ORDER BY c.id_category DESC";
  696.         $result1 = $link->query($sql);
  697.  
  698.         while($row1 = mysqli_fetch_array($result1)) {
  699.             // level 1
  700.  
  701.  
  702.             $arr = array();
  703.             //$arr['id'] = $row1['category_id'];
  704.             $arr['name'.$lang] = $row1['name'];
  705.             $arr['google_title'.$lang] = $row1['meta_title'];
  706.             $arr['google_desc'.$lang] =  $row1['meta_description'];
  707.             $arr['google_key_words'.$lang] = $row1['meta_keywords'];
  708.             $arr['campaign_active'] = 0;
  709.  
  710.             $lastID1 = $this->treeCat->add($arr,1);
  711.             $this->treeCat->setup();
  712.  
  713.             $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row1['id_category']."','$lastID1')");
  714.  
  715.             if($row1['description']!='') {
  716.                 $desc = array();
  717.                 $desc['cat_id'] = $lastID1;
  718.                 $desc['cat_desc'] = $row1['description'];
  719.                 $this->objCategoriesDesc->add($desc);
  720.             }
  721.  
  722.  
  723.             $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
  724. FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
  725.                     WHERE c.id_parent='".$row1['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
  726.             $result2 = $link->query($sql);
  727.  
  728.  
  729.             while($row2 = mysqli_fetch_array($result2)) {
  730.                 // level 2
  731.                 $arr = array();
  732.  
  733.                 $arr['name'.$lang] = $row2['name'];
  734.                 $arr['google_title'.$lang] = $row2['meta_title'];
  735.                 $arr['google_desc'.$lang] =  $row2['meta_description'];
  736.                 $arr['google_key_words'.$lang] = $row2['meta_keywords'];
  737.                 $arr['campaign_active'] = 0;
  738.  
  739.  
  740.                 $lastID2 = $this->treeCat->add($arr,$lastID1);
  741.                 $this->treeCat->setup();
  742.  
  743.                 $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row2['id_category']."','$lastID2')");
  744.  
  745.  
  746.                 if($row2['description']!='') {
  747.                     $desc = array();
  748.                     $desc['cat_id'] = $lastID2;
  749.                     $desc['cat_desc'] = $row2['description'];
  750.                     $this->objCategoriesDesc->add($desc);
  751.                 }
  752.  
  753.                 $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
  754. FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
  755.                     WHERE c.id_parent='".$row2['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
  756.                 $result3 = $link->query($sql);
  757.                 while($row3 = mysqli_fetch_array($result3)) {
  758.                     // level 3
  759.                     $arr = array();
  760.                     //  $arr['id'] = $row3['category_id'];
  761.                     $arr['name'.$lang] = $row3['name'];
  762.                     $arr['google_title'.$lang] = $row3['meta_title'];
  763.                     $arr['google_desc'.$lang] =  $row3['meta_description'];
  764.                     $arr['google_key_words'.$lang] = $row3['meta_keywords'];
  765.                     $arr['campaign_active'] = 0;
  766.  
  767.                     $lastID3 = $this->treeCat->add($arr,$lastID2);
  768.                     $this->treeCat->setup();
  769.  
  770.                     $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row3['id_category']."','$lastID3')");
  771.                     if($row3['description']!='') {
  772.                         $desc = array();
  773.                         $desc['cat_id'] = $lastID3;
  774.                         $desc['cat_desc'] = $row3['description'];
  775.                         $this->objCategoriesDesc->add($desc);
  776.                     }
  777.  
  778.                     $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
  779. FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
  780.                     WHERE c.id_parent='".$row3['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
  781.                     $result4 = $link->query($sql);
  782.                     while($row4 = mysqli_fetch_array($result4)) {
  783.                         // level 3
  784.                         $arr = array();
  785.  
  786.                         $arr['name'.$lang] = $row4['name'];
  787.                         $arr['google_title'.$lang] = $row4['meta_title'];
  788.                         $arr['google_desc'.$lang] =  $row4['meta_description'];
  789.                         $arr['google_key_words'.$lang] = $row4['meta_keywords'];
  790.                         $arr['campaign_active'] = 0;
  791.  
  792.                         $lastID4 = $this->treeCat->add($arr,$lastID3);
  793.                         $this->treeCat->setup();
  794.  
  795.                         $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row4['id_category']."','$lastID4')");
  796.  
  797.                         if($row4['description']!='') {
  798.                             $desc = array();
  799.                             $desc['cat_id'] = $lastID4;
  800.                             $desc['cat_desc'] = $row4['description'];
  801.                             $this->objCategoriesDesc->add($desc);
  802.                         }
  803.  
  804.  
  805.                         $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
  806. FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
  807.                     WHERE c.id_parent='".$row4['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
  808.                         $result5 = $link->query($sql);
  809.                         while($row5 = mysqli_fetch_array($result5)) {
  810.                             // level 3
  811.                             $arr = array();
  812.  
  813.                             $arr['name'.$lang] = $row5['name'];
  814.                             $arr['google_title'.$lang] = $row5['meta_title'];
  815.                             $arr['google_desc'.$lang] =  $row5['meta_description'];
  816.                             $arr['google_key_words'.$lang] = $row5['meta_keywords'];
  817.                             $arr['campaign_active'] = 0;
  818.  
  819.                             $lastID5 = $this->treeCat->add($arr,$lastID4);
  820.                             $this->treeCat->setup();
  821.  
  822.                             $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row5['id_category']."','$lastID5')");
  823.  
  824.                             if($row5['description']!='') {
  825.                                 $desc = array();
  826.                                 $desc['cat_id'] = $lastID5;
  827.                                 $desc['cat_desc'] = $row5['description'];
  828.                                 $this->objCategoriesDesc->add($desc);
  829.                             }
  830.  
  831.                         }
  832.  
  833.  
  834.  
  835.                     }
  836.  
  837.  
  838.  
  839.                 }
  840.  
  841.  
  842.             }
  843.  
  844.         }
  845.  
  846.  
  847.  
  848.         pre($cat);
  849.  
  850.         die('import complete without errors');
  851.     }
  852.  
  853.  
  854.  
  855.     public function propertiesShowAction()
  856.     {
  857.         ini_set('display_errors', 1);
  858.         ini_set('memory_limit', '1024M');
  859.         $lang = 1;
  860.  
  861.         $db = Zend_Registry::get('dbAdapter');
  862.         $link = $this->connect();
  863.  
  864.         $res = array();
  865.         $sql = "SELECT GROUP_CONCAT( CAST( id_attribute AS CHAR ) ) as dupa
  866. FROM ps_product_attribute_combination
  867. GROUP BY id_product_attribute
  868. HAVING count( * ) >1";
  869.         $result = $link->query($sql);
  870.         while($row = mysqli_fetch_array($result)) {
  871.             $sql = "SELECT id_attribute_group FROM `ps_attribute` WHERE id_attribute IN (".$row['dupa'].")";
  872.             $result2 = $link->query($sql);
  873.             $a = array();
  874.             while($row2 = mysqli_fetch_array($result2)) {
  875.                 $a[] = $row2['id_attribute_group'];
  876.             }
  877.             $res[implode(",",array_unique($a))] += 1;
  878.         }
  879.  
  880.         pre($res);
  881.  
  882.  
  883.         die("OK");
  884.     }
  885.  
  886.  
  887.     public function importPropertiesValuesAction()
  888.     {
  889.         ini_set('display_errors', 1);
  890.         ini_set('memory_limit', '1024M');
  891.         $lang = 1;
  892.  
  893.         $db = Zend_Registry::get('dbAdapter');
  894.         $link = $this->connect();
  895.  
  896.         try {
  897.             $sql = "SELECT f.id_feature,name FROM `ps_feature` f INNER JOIN ps_feature_lang l ON (f.id_feature=l.id_feature) ORDER BY f.id_feature ASC";
  898.             $result = $link->query($sql);
  899.             while ($row = mysqli_fetch_array($result)) {
  900.                 $id_feature = $row['id_feature'];
  901.  
  902.                 $abc = $link->query("SELECT COUNT(l.value) as ile FROM ps_feature_value f INNER JOIN ps_feature_value_lang l ON
  903.                        (f.id_feature_value=l.id_feature_value) WHERE f.id_feature=$id_feature");
  904.                 while ($row5 = mysqli_fetch_array($abc)) {
  905.                     $jest = $row5['ile'];
  906.                 }
  907.                 if ($jest > 50) {
  908.                     $ind = 2;
  909.                 } else {
  910.                     $ind = 3;
  911.                 }
  912.  
  913.                 $wyn = array();
  914.                 $wyn['p_id'] = $id_feature + 29;
  915.                 $wyn['p_name'] = $row['name'];
  916.                 $wyn['p_iname'] = $row['name'];
  917.                 $wyn['p_model'] = 2;
  918.                 $wyn['p_type'] = $ind;
  919.                 $wyn['p_hide'] = 0;
  920.                 $wyn['p_filter'] = 0;
  921.                 $this->objProperties->add($wyn);
  922.                 $id = $this->objProperties->getLastId();
  923.  
  924.                 if ($ind != 2) {
  925.  
  926.                     $sql2 = "SELECT DISTINCT value FROM ps_feature_value f INNER JOIN ps_feature_value_lang l ON (f.id_feature_value=l.id_feature_value) "
  927.                         . "WHERE id_feature=$id_feature";
  928.                     $result2 = $link->query($sql2);
  929.                     while ($row2 = mysqli_fetch_array($result2)) {
  930.                         $row2['value'] = stripslashes($row2['value']);
  931.  
  932.                         $jest = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$id' AND pv_value1='" . addslashes($row2['value']) . "'");
  933.                         if ($jest < 1) {
  934.                             $this->objPropertiesValues->add($id, $row2['value']);
  935.                         }
  936.                     }
  937.  
  938.                 }
  939.  
  940.             }
  941.         } catch (Exception $e) {
  942.             pre($e->getMessage());
  943.         }
  944.  
  945.         die("ok");
  946.  
  947.     }
  948.  
  949.     public function importGroupsAction()
  950.     {
  951.  
  952.         $db = Zend_Registry::get('dbAdapter');
  953.         $link = $this->connect();
  954. try {
  955.     $sql = "SELECT g.id_attribute_group,name,public_name FROM `ps_attribute_group` g INNER JOIN ps_attribute_group_lang l ON "
  956.         . "(l.id_attribute_group=g.id_attribute_group)  WHERE l.id_lang=3";
  957.     $result = $link->query($sql);
  958.     while ($row = mysqli_fetch_array($result)) {
  959.  
  960.  
  961.         $wyn = array();
  962.         $wyn['pg_id'] = $row['id_attribute_group']+1;
  963.         $wyn['pg_name'] = $row['name'];
  964.         $wyn['super'] = 0;
  965.         $wyn['pg_type'] = 1;
  966.         $this->objPropertiesGroups->add($wyn);
  967.  
  968.         $jest = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='" . $row['name'] . "' AND p_id < 30");
  969.         if ($jest > 0) {
  970.             $w = array();
  971.             $w['pg_id'] = $row['id_attribute_group']+1;
  972.             $w['p_id'] = $jest;
  973.             $w['p_order'] = 0;
  974.             $this->objPropertiesGroupsVal->add($w);
  975.         }
  976.         $data = $db->fetchAll("SELECT p_id FROM properties WHERE p_id > 29");
  977.         foreach ($data as $k => $v) {
  978.             $w = array();
  979.             $w['pg_id'] = $row['id_attribute_group']+1;
  980.             $w['p_id'] = $v['p_id'];
  981.             $w['p_order'] = 1;
  982.             $this->objPropertiesGroupsVal->add($w);
  983.         }
  984.  
  985.     }
  986.  
  987. } catch (Exception $e) {
  988.     pre($e->getMessage());
  989. }
  990.         die("OK");
  991.     }
  992.  
  993.     public function importGroups2Action()
  994.     {
  995.  
  996.         $db = Zend_Registry::get('dbAdapter');
  997.         $link = $this->connect();
  998.  
  999.         $res = array();
  1000.         $sql = "SELECT GROUP_CONCAT( CAST( id_attribute AS CHAR ) ) as dupa
  1001. FROM ps_product_attribute_combination
  1002. GROUP BY id_product_attribute
  1003. HAVING count( * ) >1";
  1004.         $result = $link->query($sql);
  1005.         while($row = mysqli_fetch_array($result)) {
  1006.             $sql = "SELECT id_attribute_group FROM `ps_attribute` WHERE id_attribute IN (".$row['dupa'].")";
  1007.             $result2 = $link->query($sql);
  1008.             $a = array();
  1009.             while($row2 = mysqli_fetch_array($result2)) {
  1010.                 $a[] = $row2['id_attribute_group'];
  1011.             }
  1012.             sort($a);
  1013.             $res[implode(",",array_unique($a))] += 1;
  1014.         }
  1015.  
  1016.  
  1017.  
  1018.         foreach($res as $r=>$r2) {
  1019.             $a = explode(",",$r);
  1020.             if (count($a)==1) continue;
  1021.  
  1022.             $name1 = $name2 = $name3 = '';
  1023.  
  1024.             $sql = "SELECT name FROM `ps_attribute_group_lang` WHERE id_lang=3 AND id_attribute_group=$a[0]";
  1025.             $result = $link->query($sql);
  1026.             while($row = mysqli_fetch_array($result)) {
  1027.                 $name1 = $row['name'];
  1028.             }
  1029.             $sql = "SELECT name FROM `ps_attribute_group_lang` WHERE id_lang=3 AND id_attribute_group=$a[1]";
  1030.             $result = $link->query($sql);
  1031.             while($row = mysqli_fetch_array($result)) {
  1032.                 $name2 = $row['name'];
  1033.             }
  1034.             if (count($a)==3) {
  1035.                 $sql = "SELECT name FROM `ps_attribute_group_lang` WHERE id_lang=3 AND id_attribute_group=$a[2]";
  1036.                 $result = $link->query($sql);
  1037.                 while($row = mysqli_fetch_array($result)) {
  1038.                     $name3 = $row['name'];
  1039.                 }
  1040.                 if ($name3 == '') die("BLAD3");
  1041.             }
  1042.  
  1043.             if($name1=='' OR $name2=='') die("BLAD!");
  1044.  
  1045.             $wyn = array();
  1046.             $wyn['pg_name'] = $name1.' + '.$name2;
  1047.             if ($name3 != '') {
  1048.                 $wyn['pg_name'] = $name1.' + '.$name2.' + '.$name3;
  1049.             }
  1050.             $wyn['super'] = 0;
  1051.             $wyn['pg_type'] = 1;
  1052.             $this->objPropertiesGroups->add($wyn);
  1053.             $id = $this->objPropertiesGroups->getLastId();
  1054.  
  1055.             $jest =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='$name1'  AND p_id < 30");
  1056.             $w = array();
  1057.             $w['pg_id'] = $id;
  1058.             $w['p_id'] = $jest;
  1059.             $w['p_order'] = 0;
  1060.             $this->objPropertiesGroupsVal->add($w);
  1061.  
  1062.             $jest =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='$name2'  AND p_id < 30");
  1063.             $w = array();
  1064.             $w['pg_id'] = $id;
  1065.             $w['p_id'] = $jest;
  1066.             $w['p_order'] = 1;
  1067.             $this->objPropertiesGroupsVal->add($w);
  1068.  
  1069.             if ($name3 != '') {
  1070.                 $jest =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='$name3' AND p_id < 30 ");
  1071.                 $w = array();
  1072.                 $w['pg_id'] = $id;
  1073.                 $w['p_id'] = $jest;
  1074.                 $w['p_order'] = 2;
  1075.                 $this->objPropertiesGroupsVal->add($w);
  1076.             }
  1077.  
  1078.             $data = $db->fetchAll("SELECT p_id FROM properties WHERE p_id > 29");
  1079.             foreach ($data as $k => $v) {
  1080.                 $w = array();
  1081.                 $w['pg_id'] = $id;
  1082.                 $w['p_id'] = $v['p_id'];
  1083.                 $w['p_order'] = 3;
  1084.                 $this->objPropertiesGroupsVal->add($w);
  1085.             }
  1086.  
  1087.         }
  1088.  
  1089.         die("OK!");
  1090.     }
  1091.  
  1092.     public function users2Action(){
  1093.  
  1094.         ini_set('display_errors', 1);
  1095.         // sprawdz czy klient o takim mailu istnieje
  1096.         // jesli nie to dodaj
  1097.         // potem dodaj zamowienie
  1098.         // potem produkty z zamowienia
  1099.  
  1100.  
  1101.         try {
  1102.             $data = $this->objUsers->getAdapter()->fetchAll("SELECT DISTINCT email,c.id_customer,c.firstname,c.lastname,a.address1,a.company,a.phone_mobile,a.city,a.postcode
  1103.                    FROM `ps_customer` c
  1104.                    INNER JOIN ps_address a ON (a.id_customer=c.id_customer) WHERE c.deleted=0 AND a.deleted=0 ORDER BY c.id_customer ASC;");
  1105.  
  1106.             foreach($data as $k=>$v){
  1107.                 $email = $v['email'];
  1108.  
  1109.                 if($this->objUsers->isExist($email))
  1110.                 {
  1111.                     $user = $this->objUsers->getOneByEmail($email);
  1112.                     $u_id = $$user['user_id'];
  1113.                 } else {
  1114.  
  1115.                     $user = array();
  1116.                     $user['user_id'] = $v['id_customer'];
  1117.                     $user['user_type'] = strlen($v['company'])>3 ? 2 : 1;
  1118.                     $user['user_password'] = md5(rand(1000,10000));
  1119.                     if($user['user_type']==2) {
  1120.                         $user['user_firm'] = $v['company'];
  1121.                     } else {
  1122.                         $user['user_firm'] = '';
  1123.                     }
  1124.                     $user['user_name'] = $v['firstname'];
  1125.                     $user['user_surname'] = $v['lastname'];
  1126.                     $user['user_phone'] = trim($v['phone_mobile']);
  1127.                     $user['user_email'] = $email;
  1128.                     $user['user_street'] = $v['address1'];
  1129.                     $user['user_postcode'] = $v['postcode'];
  1130.                     $user['user_city'] = $v['city'];
  1131.                     $user['user_country'] = 'pl';
  1132.                     $user['user_nip'] = '';
  1133.                     $user['user_vat'] = $user['user_type']==2 ? 1 : 0;
  1134.                     $user['user_newsletter'] = 1;
  1135.                     $user['user_activate'] = 1;
  1136.                     $user['user_active'] = 1;
  1137.  
  1138.                     $this->objUsers->add($user);
  1139.                     $u_id = $this->objUsers->getLastId();
  1140.                 }
  1141.  
  1142.  
  1143.             }
  1144.  
  1145.             die('import complete without errors');
  1146.         } catch (Exception $e) {
  1147.             print_r($e->getMessage());
  1148.         }
  1149.  
  1150.  
  1151.     }
  1152.  
  1153.  
  1154.  
  1155.     public function usersAction(){
  1156.  
  1157.         ini_set('display_errors', 1);
  1158.         // sprawdz czy klient o takim mailu istnieje
  1159.         // jesli nie to dodaj
  1160.         // potem dodaj zamowienie
  1161.         // potem produkty z zamowienia
  1162.  
  1163.         $link = $this->connect();
  1164.  
  1165.         try {
  1166.             $result1 = $link->query("SELECT DISTINCT email,c.id_customer,c.firstname,c.lastname,a.address1,a.city,a.postcode,c.newsletter,
  1167.                    a.phone,a.company,a.phone_mobile
  1168.                    FROM `ps_customer` c
  1169.                    LEFT JOIN ps_address a ON (a.id_customer=c.id_customer)
  1170.                    GROUP BY email  ORDER BY c.id_customer ASC  ");
  1171.  
  1172.             while($v = mysqli_fetch_array($result1)) {
  1173.                 $email = $v['email'];
  1174.  
  1175.                 if($this->objUsers->isExist($email))
  1176.                 {
  1177.                     $user = $this->objUsers->getOneByEmail($email);
  1178.                     $u_id = $user['user_id'];
  1179.                 } else {
  1180.  
  1181.                     $user = array();
  1182.                     $user['user_id'] = $v['id_customer'];
  1183.                     $user['user_type'] = strlen($v['company'])>3 ? 2 : 1;
  1184.                     $user['user_password'] = rand(1000,10000);
  1185.                     if($user['user_type']==2) {
  1186.                         $user['user_firm'] = $v['company'];
  1187.                     } else {
  1188.                         $user['user_firm'] = '';
  1189.                     }
  1190.                     $user['user_name'] = $v['firstname'];
  1191.                     $user['user_surname'] = $v['lastname'];
  1192.                     $phone = $v['phone'];
  1193.                     if($phone!='') $v['phone'] = $v['phone_mobile'];
  1194.                     $user['user_phone'] = str_replace(' ','',str_replace('-','',trim($phone) ));
  1195.                     $user['user_email'] = $email;
  1196.                     $user['user_street'] = $v['address1'];
  1197.                     $user['user_postcode'] = $v['postcode'];
  1198.                     $user['user_city'] = $v['city'];
  1199.                     $user['user_country'] = 'pl';
  1200.                     $user['user_nip'] = '';
  1201.                     $user['user_vat'] = $user['user_type']==2 ? 1 : 0;
  1202.                     $user['user_newsletter'] = $v['newsletter'];
  1203.                     $user['user_activate'] = 1;
  1204.                     $user['user_active'] = 1;
  1205.  
  1206.                     $this->objUsers->add($user);
  1207.                     $u_id = $this->objUsers->getLastId();
  1208.                 }
  1209.  
  1210.  
  1211.             }
  1212.  
  1213.             die('import complete without errors');
  1214.         } catch (Exception $e) {
  1215.             print_r($e->getMessage());
  1216.         }
  1217.  
  1218.  
  1219.     }
  1220.  
  1221.     public function ordersAction(){
  1222.         set_time_limit(0);
  1223.         ini_set('memory_limit', '1024M');
  1224.         $lang = 1;
  1225.         ini_set('display_errors', 1);
  1226.         $link = $this->connect();
  1227.  
  1228.  
  1229.         $db = Zend_Registry::get('dbAdapter');
  1230.  
  1231.         $statusy = array();
  1232.         $statusy[10] = 100;
  1233.         $statusy[26] = 1;
  1234.         $statusy[17] = 1;
  1235.         $statusy[5] = 1;
  1236.         $statusy[24] = 1;
  1237.         $statusy[11] = 2;
  1238.         $statusy[21] = 2;
  1239.         $statusy[32] = 2;
  1240.         $statusy[28] = 2;
  1241.         $statusy[14] = 1;
  1242.         $statusy[4] = 1;
  1243.         $statusy[7] = 1;
  1244.         $statusy[30] = 1;
  1245.         $statusy[1] = 1;
  1246.         $statusy[2] = 1;
  1247.         $statusy[15] = 90;
  1248.         $statusy[29] = 1;
  1249.         $statusy[33] = 1;
  1250.         $statusy[13] = 1;
  1251.         $statusy[18] = 9;
  1252.         $statusy[8] = 1;
  1253.         $statusy[25] = 1;
  1254.         $statusy[19] = 1;
  1255.         $statusy[20] = 1;
  1256.         $statusy[31] = 1;
  1257.         $statusy[6] = 1;
  1258.         $statusy[3] = 9;
  1259.         $statusy[22] = 5;
  1260.         $statusy[16] = 9;
  1261.         $statusy[9] = 9;
  1262.         $statusy[27] = 9;
  1263.         $statusy[23] = 2;
  1264.         $statusy[12] = 2;
  1265.  
  1266.         try {
  1267.  
  1268.             $sql = "SELECT * FROM ps_orders ORDER  BY id_order ASC";
  1269.             $result1 = $link->query($sql);
  1270.             $i = 0;
  1271.             while($row = mysqli_fetch_array($result1)) {
  1272.  
  1273.                 $u_id = $row['id_customer'];
  1274.  
  1275.                 $sql1 = "SELECT id_order_state  FROM `ps_order_history` WHERE `id_order` = '".$row['id_order']."' order by id_order_history DESC LIMIT 1";
  1276.                 $res2 = $link->query($sql1);
  1277.                 while($row2 = mysqli_fetch_array($res2)) {
  1278.                     $state = $row2['id_order_state'];
  1279.                 }
  1280.  
  1281.                 $ss = $statusy[$state];
  1282.                 if($ss<1) $ss = 100;
  1283.  
  1284.                 // zamowienie
  1285.                 $order = array();
  1286.                 $order['order_id'] = $row['id_order'];
  1287.                 $order['order_status'] = $ss;
  1288.  
  1289.                 $user = $this->objUsers->getOneById($u_id);
  1290.                 if($user['user_id']>0) {
  1291.                     $order['user_id'] = $u_id;
  1292.                 } else {
  1293.  
  1294.                     $sql4 = "SELECT * FROM ps_customer WHERE id_customer='$u_id'";
  1295.                     $result4 = $link->query($sql4);
  1296.                     while($row4 = mysqli_fetch_array($result4)) {
  1297.  
  1298.                         $email = $row4['email'];
  1299.                     }
  1300.  
  1301.                     $user = $this->objUsers->getOneByEmail($email);
  1302.                     if(!$user) {
  1303.                         $user = array();
  1304.                         $user['user_type'] = 1;
  1305.                         $user['user_email'] = $email;
  1306.                         $user['user_name'] = $row4['firstname'];
  1307.                         $user['user_surname'] = $row4['lastname'];
  1308.                     }
  1309.                     if($user['user_email']=='') {
  1310.                         $user['user_email'] = ' ';
  1311.                     }
  1312.  
  1313.                 }
  1314.  
  1315.                 $order['order_date'] = $row['date_add'];
  1316.                 $order['order_email'] = $user['user_email'];
  1317.                 $order['order_payer'] = $user['user_type'];
  1318.                 $order['order_new'] = 0;
  1319.  
  1320.                 if($user['user_type']==2) {
  1321.                     $who = $user['user_firm'];
  1322.                 } else {
  1323.                     $who = $user['user_name'].' '.$user['user_surname'];
  1324.                 }
  1325.                 $order['order_pay_to'] = $who . "\n" . $user['user_street'].'||'.$user['user_home'].'||'.$user['user_flat'].'||'.$user['user_postcode'].'||'.$user['user_city'].'||Polska';
  1326.                 if ($user['user_nip']!='')
  1327.                     $order['order_pay_to'] .= "\n" . $user['user_nip'];
  1328.                 else
  1329.                     $order['order_pay_to'] .= "\n";
  1330.  
  1331.                 if ($user['user_phone'] != '') {
  1332.                     $order['order_pay_to'] .= "\n" . $user['user_phone'];
  1333.                 } else {
  1334.                     $order['order_pay_to'] .= "\n";
  1335.                 }
  1336.  
  1337.                 $who = $user['user_name'].' '.$user['user_surname'];
  1338.                 $order['order_send_to'] = $who . "\n" . $user['user_street'].'||'.$user['user_home'].'||'.$user['user_flat'].'||'.$user['user_postcode'].'||'.$user['user_city'].'||Polska';
  1339.                 if ( $user['user_phone'] != '') {
  1340.                     $order['order_send_to'] .= "\n\n" .  $user['user_phone'];
  1341.                 }
  1342.  
  1343.                 $order['order_fvat'] = $user['user_type']==2 ? 1:0;
  1344.                 $amount = 0;
  1345.                 $suma = 0;
  1346.                 $positions = $link->query("SELECT * FROM ps_order_detail WHERE id_order='$row[id_order]'");
  1347.  
  1348.                 while($b = mysqli_fetch_array($positions)) {
  1349.                     $amount += $b['product_quantity'];
  1350.  
  1351.                     $cena = $b['product_price'];
  1352.                     $cena2 = $b['product_quantity_discount'];
  1353.                     if($cena2>0) $cena = $cena2;
  1354.  
  1355.                     $suma += ($cena*$b['product_quantity']);
  1356.                 }
  1357.                 $order['order_amount'] = $amount;
  1358.                 $order['order_price'] = $suma;
  1359.                 $order['order_delivery_country_code'] = 'pl';
  1360.                 $order['order_supplier_name'] = 'kurier';
  1361.                 $order['order_payment_name'] = $row['payment'];
  1362.                 $order['order_payment_type'] = $row['module']=='cashondelivery'? 'cod' : 'transfer';
  1363.                 $order['order_delivery_price'] = $row['total_shipping'];
  1364.                 $order['order_topay'] = $row['total_paid'];
  1365.  
  1366.                 $order['order_currency'] = 'PLN';
  1367.                 $order['order_exchange'] = 1;
  1368.                 $order['order_lang'] = 'pl';
  1369.                 $order['order_source'] = 'prestashop';
  1370.                 $this->objOrders->add($order);
  1371.                 $order_id = $this->objOrders->getLastId();
  1372.  
  1373.                 $positions = $link->query("SELECT * FROM ps_order_detail WHERE id_order='$row[id_order]'");
  1374.                 while($b = mysqli_fetch_array($positions)) {
  1375.  
  1376.                     //  $prod = $link->query("SELECT nowe FROM prod WHERE stare='$b[product_id]'");
  1377.                     //   $iii = mysql_fetch_row($prod);
  1378.  
  1379.                     $vat = (int)$b['tax_rate'];
  1380.                     $cena = $b['product_price']*(1+$vat/100);
  1381.                     $cena2 = $b['product_quantity_discount']*(1+$vat/100);
  1382.  
  1383.  
  1384.                     $oi = array();
  1385.                     $item = $this->objItems->getOneById($b[product_id]);
  1386.                     if($b['product_reference']=='') $b['product_reference'] = ' ';
  1387.                     if($item['item_id']>0) {
  1388.                         $oi['oi_item_id'] = $b[product_id];
  1389.                         $oi['oi_item_code'] = $b['product_reference'];
  1390.                         $oi['oi_item_name'] = $b['product_name'];
  1391.                     } else {
  1392.                         $oi['oi_item_id'] = NULL;
  1393.                         $oi['oi_item_code'] = $b['product_reference'];
  1394.                         $oi['oi_item_name'] = $b['product_name'];
  1395.                     }
  1396.                     $oi['order_id'] = $order_id;
  1397.                     $oi['oi_type'] = 1;
  1398.                     $oi['oi_mag'] = 0;
  1399.                     $oi['oi_mag_id'] = NULL;
  1400.                     $oi['oi_item_desc'] = '';
  1401.  
  1402.                     $oi['oi_item_price'] = $cena;
  1403.                     $oi['oi_item_vat'] = (int)$b['tax_rate'];
  1404.  
  1405.                     if($cena2>0) {
  1406.                         $oi['oi_promo'] = 1;
  1407.                         $oi['oi_promo_price'] = $cena2;
  1408.                     }
  1409.  
  1410.                     $oi['oi_amount'] = $b['product_quantity'];
  1411.                     $this->objOrdersItems->add($oi);
  1412.                 }
  1413.  
  1414.                 // Zapisujemy informacje dot. transportu jako pozycje w orders_items
  1415.                 // start : saveTG
  1416.                 $d = '';
  1417.                 $d['order_id'] = $order_id;
  1418.                 $d['oi_type'] = 2; // - transport
  1419.                 $d['oi_item_id'] = null;
  1420.                 $d['oi_mag'] = null;
  1421.                 $d['oi_mag_id'] = null;
  1422.                 $d['oi_item_name'] = "Transport";
  1423.                 $d['oi_item_desc'] = null;
  1424.                 $d['oi_item_code'] = "";
  1425.                 $d['oi_item_price'] = $order['order_delivery_price'];
  1426.                 $d['oi_item_vat'] = 23;
  1427.                 $d['oi_amount'] = 1;
  1428.  
  1429.                 $this->objOrdersItems->saveTG($d);
  1430.                 // end : saveTG
  1431.  
  1432.  
  1433.             }
  1434.  
  1435.             die('import complete without errors');
  1436.         } catch (Exception $e) {
  1437.             print_r($e->getMessage());
  1438.         }
  1439.  
  1440.         die('import WITH errors');
  1441.     }
  1442.  
  1443.  
  1444.     private function _setPropMag($id)
  1445.     {
  1446.         $this->pg_id = 0;
  1447.         $db = Zend_Registry::get('dbAdapter');
  1448.         $link = $this->connect();
  1449.  
  1450.  
  1451.         $sql = "SELECT a.*,c.id_attribute,l.name,p2.id_attribute_group FROM `ps_product_attribute` a INNER JOIN ps_product_attribute_combination c
  1452. ON (c.id_product_attribute=a.id_product_attribute) INNER JOIN ps_attribute_lang l ON (l.id_attribute=c.id_attribute AND l.id_lang=3)
  1453. INNER JOIN ps_attribute p2 ON (p2.id_attribute = c.id_attribute) WHERE a.id_product=$id ORDER BY a.id_product_attribute ASC, p2.id_attribute_group ASC ";
  1454.         $result = $link->query($sql);
  1455.         $i=0;
  1456.         $opt = array();
  1457.         while($row = mysqli_fetch_array($result)) {
  1458.             $opt[] = $row;
  1459.         }
  1460.         if(count($opt)<1) {
  1461.             return 1; // brak cech mag.
  1462.         }
  1463.         if($opt[0]['id_product_attribute']==$opt[1]['id_product_attribute'] && $opt[1]['id_product_attribute']==$opt[2]['id_product_attribute']) {
  1464.             //2 cechy
  1465.  
  1466.             $name = [];
  1467.             $sql = "SELECT name, p.id_attribute_group
  1468.                FROM `ps_attribute_group` a
  1469.                INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
  1470.                INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
  1471.                WHERE   l.id_lang = 3 AND p.id_attribute =".$opt[0]['id_attribute'];
  1472.             $result2 = $link->query($sql);
  1473.             while($row2 = mysqli_fetch_array($result2)) {
  1474.                 $name[$row2['name']] = $row2['id_attribute_group'];
  1475.             }
  1476.  
  1477.             $sql = "SELECT name, p.id_attribute_group
  1478.                FROM `ps_attribute_group` a
  1479.                INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
  1480.                INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
  1481.                WHERE   l.id_lang = 3 AND p.id_attribute =".$opt[1]['id_attribute'];
  1482.             $result2 = $link->query($sql);
  1483.             while($row2 = mysqli_fetch_array($result2)) {
  1484.                 $name[$row2['name']] = $row2['id_attribute_group'];
  1485.             }
  1486.  
  1487.             $sql = "SELECT name, p.id_attribute_group
  1488.                FROM `ps_attribute_group` a
  1489.                INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
  1490.                INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
  1491.                WHERE   l.id_lang = 3 AND p.id_attribute =".$opt[2]['id_attribute'];
  1492.             $result2 = $link->query($sql);
  1493.             while($row2 = mysqli_fetch_array($result2)) {
  1494.                 $name[$row2['name']] = $row2['id_attribute_group'];
  1495.             }
  1496.  
  1497.             asort($name);
  1498.             $names = array_keys($name);
  1499.             $group = substr(implode(" + ", $names),0,32);
  1500.  
  1501.             $pg_id =  $db->fetchOne("SELECT pg_id FROM `properties_groups` WHERE pg_name='".$group."'");
  1502.  
  1503.             if($pg_id>0) {
  1504.                 $this->pg_id = $pg_id;
  1505.  
  1506.                 $pid = [];
  1507.                 $pid[] =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[0]."'  AND p_id < 30");
  1508.                 $pid[] =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[1]."'  AND p_id < 30");
  1509.                 $pid[] =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[2]."'  AND p_id < 30");
  1510.  
  1511.  
  1512.                 if(count($pid) == 2 && $pid[0] != '' && $pid[1] != '' && $pid[2] != '') {
  1513.                     $i=0;
  1514.                     $grupuj = [];
  1515.                     foreach($opt as $k=>$v) {
  1516.                         $grupuj[$v['id_product_attribute']][] = $v;
  1517.                     }
  1518.  
  1519.                     foreach($grupuj as $id_product_attribute=>$z) {
  1520.                         $c = 0;
  1521.                         $pv_id = [];
  1522.                         foreach ($z as $k2 => $v) {
  1523.                             $pv_id[] = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid[$c]'
  1524.                                                    AND pv_value1='" . addslashes($v['name']) . "'");
  1525.                             $c++;
  1526.                         }
  1527.  
  1528.                         $es = array();
  1529.                         $es['item_id'] = $id;
  1530.                         $es['pv_id_1'] = $pv_id[0];
  1531.                         $es['pv_id_2'] = $pv_id[1];
  1532.                         $es['pv_id_3'] = $pv_id[2];
  1533.                         $es['item_code'] = (string)$v['reference'];
  1534.                         $es['item_price'] = 0;
  1535.                         $es['item_weight'] = $v['weight'];
  1536.                      //  $this->objItemsES->add($es);
  1537.                         $aa = $this->objItemsES->getOneByAllId($id, $pv_id[0], $pv_id[1], $pv_id[2]);
  1538.                         if ($aa['es_id'] > 0) {
  1539.                             $amount = array();
  1540.                             $amount['item_id'] = $id;
  1541.                             $amount['depot_id'] = 1;
  1542.                             $amount['mag_id'] = $aa['es_id'];
  1543.                             $amount['ia_amount'] = (int)$v['quantity'];
  1544.                             $amount['ia_nolimit'] = 0;
  1545.                             $this->objAmount->add($amount);
  1546.                         }
  1547.                     }
  1548.  
  1549.                 }
  1550.  
  1551.             }
  1552.  
  1553.         }
  1554.          elseif($opt[0]['id_product_attribute']==$opt[1]['id_product_attribute']) {
  1555.             //2 cechy
  1556.  
  1557.             $name = [];
  1558.             $sql = "SELECT name, p.id_attribute_group
  1559.                FROM `ps_attribute_group` a
  1560.                INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
  1561.                INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
  1562.                WHERE   l.id_lang = 3 AND p.id_attribute =".$opt[0]['id_attribute'];
  1563.             $result2 = $link->query($sql);
  1564.             while($row2 = mysqli_fetch_array($result2)) {
  1565.                 $name[$row2['name']] = $row2['id_attribute_group'];
  1566.             }
  1567.  
  1568.             $sql = "SELECT name, p.id_attribute_group
  1569.                FROM `ps_attribute_group` a
  1570.                INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
  1571.                INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
  1572.                WHERE   l.id_lang = 3 AND p.id_attribute =".$opt[1]['id_attribute'];
  1573.             $result2 = $link->query($sql);
  1574.             while($row2 = mysqli_fetch_array($result2)) {
  1575.                 $name[$row2['name']] = $row2['id_attribute_group'];
  1576.             }
  1577.  
  1578.             asort($name);
  1579.             $names = array_keys($name);
  1580.             $group = substr(implode(" + ", $names),0,32);
  1581.  
  1582.             $pg_id =  $db->fetchOne("SELECT pg_id FROM `properties_groups` WHERE pg_name='".$group."'");
  1583.  
  1584.             if($pg_id>0) {
  1585.                 $this->pg_id = $pg_id;
  1586.  
  1587.                 $pid = [];
  1588.                 $pid[] =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[0]."'  AND p_id < 30");
  1589.                 $pid[] =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[1]."'  AND p_id < 30");
  1590.  
  1591.  
  1592.                 if(count($pid) == 2 && $pid[0] != '' && $pid[1] != '') {
  1593.                     $i=0;
  1594.                     $grupuj = [];
  1595.                     foreach($opt as $k=>$v) {
  1596.                         $grupuj[$v['id_product_attribute']][] = $v;
  1597.                     }
  1598.  
  1599.  
  1600.                     foreach($grupuj as $id_product_attribute=>$z) {
  1601.                         $c = 0;
  1602.                         $pv_id = [];
  1603.                         foreach ($z as $k2 => $v) {
  1604.                             $pv_id[] = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid[$c]'
  1605.                                                    AND pv_value1='" . addslashes($v['name']) . "'");
  1606.                         $c++;
  1607.                         }
  1608.  
  1609.                             $es = array();
  1610.                             $es['item_id'] = $id;
  1611.                             $es['pv_id_1'] = $pv_id[0];
  1612.                             $es['pv_id_2'] = $pv_id[1];
  1613.                             $es['pv_id_3'] = 0;
  1614.                             $es['item_code'] = (string)$v['reference'];
  1615.                             $es['item_price'] = 0;
  1616.                             $es['item_weight'] = $v['weight'];
  1617.                        //     $this->objItemsES->add($es);
  1618.                         $aa = $this->objItemsES->getOneByAllId($id, $pv_id[0], $pv_id[1], 0);
  1619.                         if ($aa['es_id'] > 0) {
  1620.     $amount = array();
  1621.     $amount['item_id'] = $id;
  1622.     $amount['depot_id'] = 1;
  1623.     $amount['mag_id'] = $aa['es_id'];
  1624.     $amount['ia_amount'] = (int)$v['quantity'];
  1625.     $amount['ia_nolimit'] = 0;
  1626.     $this->objAmount->add($amount);
  1627. }
  1628.                     }
  1629.  
  1630.                 }
  1631.  
  1632.             }
  1633.  
  1634.         } else {
  1635.             // 1 cecha
  1636.             $sql = "SELECT name, p.id_attribute_group
  1637.                FROM `ps_attribute_group` a
  1638.                INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
  1639.                INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
  1640.                WHERE  l.id_lang = 3 AND p.id_attribute =".$opt[0]['id_attribute'];
  1641.             $result2 = $link->query($sql);
  1642.             while($row2 = mysqli_fetch_array($result2)) {
  1643.                 $this->pg_id = $row2['id_attribute_group']+1;
  1644.                 $name = $row2['name'];
  1645.             }
  1646.  
  1647.             $pid =  $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$name."' AND p_id < 30");
  1648.             if($pid>0) {
  1649.                 foreach($opt as $k=>$v) {
  1650.  
  1651.                     $pv_id =  $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid' AND pv_value1='".addslashes($v['name'])."'");
  1652.  
  1653.                     $es = array();
  1654.                     $es['item_id'] = $id;
  1655.                     $es['pv_id_1'] = $pv_id;
  1656.                     $es['pv_id_2'] = 0;
  1657.                     $es['pv_id_3'] = 0;
  1658.                     $es['item_code'] = (string)$v['reference'];
  1659.                     $es['item_price'] = 0;
  1660.                     $es['item_weight'] = $v['weight'];
  1661.                 //    $this->objItemsES->add($es);
  1662.                     $aa = $this->objItemsES->getOneByAllId($id, $pv_id[0], 0, 0);
  1663.  
  1664.                     //    $es_id =  $db->fetchOne("SELECT es_id FROM `itemses` WHERE item_id='$id' AND pv_id_1='".$pv_id."'");
  1665.                     //    if($es_id<1) continue;
  1666.                     $atr = $v['id_product_attribute'];
  1667.                     if ($aa['es_id'] > 0) {
  1668.                         $amount = array();
  1669.                         $amount['item_id'] = $id;
  1670.                         $amount['depot_id'] = 1;
  1671.                         $amount['mag_id'] = $aa['es_id'];
  1672.                         $amount['ia_amount'] = (int)$v['quantity'];
  1673.                         $amount['ia_nolimit'] = 0;
  1674.                         $this->objAmount->add($amount);
  1675.                     }
  1676.                 }
  1677.             }
  1678.         }
  1679.  
  1680.  
  1681.     }
  1682.     private function _setPropInf($id)
  1683.     {
  1684.         $lang = 1;
  1685.  
  1686.         $ind = array(0);
  1687.         $db = Zend_Registry::get('dbAdapter');
  1688.         $link = $this->connect();
  1689.  
  1690.  
  1691.         $sql = "SELECT f.id_feature, f.id_feature_value, name, l2.value
  1692. FROM `ps_feature_product` f
  1693. INNER JOIN ps_feature_lang l ON ( f.id_feature = l.id_feature )
  1694. INNER JOIN ps_feature_value v ON ( v.id_feature_value = f.id_feature_value )
  1695. INNER JOIN ps_feature_value_lang l2 ON ( l2.id_feature_value = v.id_feature_value )
  1696. WHERE `id_product` =$id";
  1697.         $result = $link->query($sql);
  1698.         while($row = mysqli_fetch_array($result)) {
  1699.             // id_feature name value
  1700.  
  1701.             $aa =  $db->fetchRow("SELECT p_id,p_type FROM properties WHERE p_iname='".$row['name']."' AND p_id>'29'");
  1702.             $pid = $aa['p_id'];
  1703.             $type = $aa['p_type'];
  1704.             if($pid>0) {
  1705.                 if($type == 2) {
  1706.                     $this->addPropInd($pid,$id,$row['value']);
  1707.                 } else {
  1708.                     $pv_id =  $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid' AND pv_value1='".addslashes($row['value'])."'");
  1709.                     if($pv_id>0) {
  1710.                         $this->addProp($pid,$id,$pv_id);
  1711.                     }
  1712.  
  1713.                 }
  1714.             }
  1715.  
  1716.         }
  1717.  
  1718.     }
  1719.  
  1720.  
  1721.     private function addProp($id,$item_id,$val)
  1722.     {
  1723.         try {
  1724.             $d = array();
  1725.             $d['p_id'] = $id;
  1726.             $d['item_id'] = $item_id;
  1727.             $d['pv_id'] = $val;
  1728.             $this->objPropertiesValMulti->add($d);
  1729.         } catch (Exception $e) {}
  1730.     }
  1731.  
  1732.     private function addPropInd($id,$item_id,$val)
  1733.     {
  1734.         try {
  1735.             $d = array();
  1736.             $d['p_id'] = $id;
  1737.             $d['item_id'] = $item_id;
  1738.             $d['pvi_value'] = $val;
  1739.             $this->objPropertiesValIndividual->add($d);
  1740.         } catch (Exception $e) {}
  1741.     }
  1742.  
  1743.     public function addPropsMagAction()
  1744.     {
  1745.         ini_set('display_errors', 1);
  1746.         ini_set('memory_limit', '1024M');
  1747.         $lang = 1;
  1748.  
  1749.         try {
  1750.             $db = Zend_Registry::get('dbAdapter');
  1751.             $link = $this->connect();
  1752.  
  1753.  
  1754.             $sql = "SELECT g.id_attribute_group,name,public_name FROM `ps_attribute_group` g INNER JOIN ps_attribute_group_lang l ON"
  1755.                 . " (l.id_attribute_group=g.id_attribute_group) WHERE l.id_lang =3";
  1756.             $result = $link->query($sql);
  1757.             while ($row = mysqli_fetch_array($result)) {
  1758.                 $id_attribute = $row['id_attribute_group'];
  1759.  
  1760.                 $wyn = array();
  1761.                 $wyn['p_name'] = $row['public_name'];
  1762.                 $wyn['p_iname'] = $row['name'];
  1763.                 $wyn['p_model'] = 1;
  1764.                 $wyn['p_type'] = 1;
  1765.                 $wyn['p_hide'] = 0;
  1766.                 $wyn['p_filter'] = 0;
  1767.                 $this->objProperties->add($wyn);
  1768.                 $id = $this->objProperties->getLastId();
  1769.  
  1770.                 $sql2 = "SELECT a.id_attribute,l.name FROM `ps_attribute` a INNER JOIN ps_attribute_lang l ON (l.id_attribute=a.id_attribute) "
  1771.                     . " WHERE id_attribute_group='$id_attribute' AND l.id_lang =3";
  1772.                 $result2 = $link->query($sql2);
  1773.                 while ($row2 = mysqli_fetch_array($result2)) {
  1774.                     $row2['name'] = stripslashes($row2['name']);
  1775.  
  1776.                     $jest = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$id' AND pv_value1='" . addslashes($row2['name']) . "'");
  1777.                     if ($jest < 1) {
  1778.                         $this->objPropertiesValues->add($id, $row2['name']);
  1779.                     }
  1780.                 }
  1781.  
  1782.             }
  1783.         } catch (Exception $e) {
  1784.             pre($e->getMessage());
  1785.         }
  1786.  
  1787.         die("ok");
  1788.  
  1789.     }
  1790. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement