Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package Panel
- */
- class Panel_ImportController extends IberoBasicController {
- public function indexAction(){
- die('...');
- }
- private function getPvVal($id)
- {
- $p1 = $this->objPropertiesValues->getAllById($id);
- foreach ($p1 as $k => $v) {
- $v['pv_value'] = str_replace(',', '.', $v['pv_value']);
- $v['pv_value'] = str_replace('+', '', $v['pv_value']);
- $c1[(string)$v['pv_value']] = $v['pv_id'];
- }
- return $c1;
- }
- public function stanyAction()
- {
- $row = 1;
- if (($uchwyt = fopen ("items.csv","r")) !== FALSE) {
- while (($data = fgetcsv($uchwyt, 1000, ";")) !== FALSE) {
- $itemId = $data[0];
- $amount = (int)$data[3];
- if ($itemId > 0) {
- $d = [];
- $d['item_id'] = $itemId;
- $d['depot_id'] = 1;
- $d['mag_id'] = NULL;
- $d['ia_amount'] = (int)$amount;
- $d['ia_nolimit'] = 0;
- $this->objAmount->add($d);
- pre($d);
- }
- }
- fclose ($uchwyt);
- }
- die('1');
- }
- public function stany2Action()
- {
- $row = 1;
- if (($uchwyt = fopen ("items2.csv","r")) !== FALSE) {
- while (($data = fgetcsv($uchwyt, 1000, ";")) !== FALSE) {
- $itemId = $data[0];
- $magId = $data[1];
- $amount = (int)$data[4];
- if ($itemId > 0 && $magId > 0) {
- $d = [];
- $d['item_id'] = $itemId;
- $d['depot_id'] = 1;
- $d['mag_id'] = $magId;
- $d['ia_amount'] = (int)$amount;
- $d['ia_nolimit'] = 0;
- try {
- $this->objAmount->add($d);
- pre($d);
- } catch (Exception $e) {}
- }
- }
- fclose ($uchwyt);
- }
- die('1');
- }
- public function rozmiaryAction()
- {
- set_time_limit(0);
- ini_set('memory_limit', '1024M');
- $c1 = $this->getPvVal(153);
- $c2 = $this->getPvVal(146);
- $c3 = $this->getPvVal(147);
- $res = [];
- $k = 0;
- $array = str_getcsv(file_get_contents('plik.csv'));
- foreach ($array as $val) {
- if (substr($val,0,5) == 'barts') {
- $k++;
- $val = trim(substr($val,5));
- }
- $res[$k][] = $val;
- }
- for ($i = 0; $i <= 17; $i++) {
- $item_id = $res[$i][0];
- $item = $this->objItems->getOneByid($item_id);
- if ($item['item_id'] > 0 && $item['pg_id'] == 23) {
- // $this->objItemsES->delAllByItemId($item_id);
- // continue;
- $res[$i][2] = str_replace(',', '.', $res[$i][2]);
- $res[$i][3] = str_replace(',', '.', $res[$i][3]);
- $res[$i][4] = str_replace(',', '.', $res[$i][4]);
- $moc = explode("\n", $res[$i][2]);
- $cylinder = explode(";", $res[$i][3]);
- $os = explode(";", $res[$i][4]);
- if (substr($res[$i][4], 0,2) == 'od') {
- $os = [];
- $a = explode(" ", $res[$i][4]);
- foreach (range($a[1], $a[3], $a[5]) as $number) {
- $os[] = $number;
- }
- }
- foreach ($moc as $moc1) {
- $a = explode(" ", $moc1);
- foreach (range($a[1], $a[3], $a[5]) as $number) {
- $number = (string)$number;
- if (strpos($number, '.') === false) {
- $number .= '.0';
- }
- if ($number == '0.0') {
- $number = '0.00';
- }
- foreach ($cylinder as $cy) {
- $cy = trim($cy);
- if ($cy == '') {
- continue;
- }
- foreach ($os as $o) {
- $o = trim($o);
- if ($o == '') {
- continue;
- }
- $itemses = [];
- $itemses['item_id'] = $item_id;
- $itemses['pv_id_1'] = $c1[$number];
- $itemses['pv_id_2'] = $c2[$cy];
- $itemses['pv_id_3'] = $c3[$o];
- $itemses['item_code'] = '';
- $itemses['item_price'] = 0;
- $itemses['item_weight'] = 0;
- if ($itemses['pv_id_1'] < 1 || $itemses['pv_id_2'] < 1 || $itemses['pv_id_3'] < 1) {
- pre($itemses, '1:'.$number.' 2:'.$cy.' 3:'.$o);
- exit;
- }
- $this->objItemsES->add($itemses);
- $amount = array();
- $amount['item_id'] = $item_id;
- $amount['depot_id'] = 1001;
- $amount['mag_id'] = $this->objItemsES->getLastId();
- $amount['ia_amount'] = 0;
- $amount['ia_nolimit'] = 1;
- $this->objAmount->add($amount);
- }
- }
- }
- }
- } else {
- pre($item_id,'bad item');
- }
- }
- die('1');
- }
- public function rozmiary2Action()
- {
- set_time_limit(0);
- ini_set('memory_limit', '1024M');
- $c1 = $this->getPvVal(153);
- $c2 = $this->getPvVal(150);
- $c3 = $this->getPvVal(149);
- $res = [];
- $k = 0;
- $array = str_getcsv(file_get_contents('plik.csv'));
- foreach ($array as $val) {
- if (substr($val,0,5) == 'barts') {
- $k++;
- $val = trim(substr($val,5));
- }
- $res[$k][] = $val;
- }
- $i = 0;
- $item_id = $res[0][0];
- $item = $this->objItems->getOneByid($item_id);
- if ($item['item_id'] > 0 && $item['pg_id'] == 27) {
- // $this->objItemsES->delAllByItemId($item_id);
- // continue;
- $res[$i][2] = str_replace(',', '.', $res[$i][2]);
- $res[$i][3] = str_replace(',', '.', $res[$i][3]);
- $res[$i][4] = str_replace(',', '.', $res[$i][4]);
- $moc = explode("\n", $res[$i][2]);
- $cylinder = explode(";", $res[$i][3]);
- $os = explode(";", $res[$i][4]);
- if (substr($res[$i][4], 0,2) == 'od') {
- $os = [];
- $a = explode(" ", $res[$i][4]);
- foreach (range($a[1], $a[3], $a[5]) as $number) {
- if (strpos($number, '.') === false) {
- $number .= '.0';
- }
- $os[] = $number;
- }
- }
- if (substr($res[$i][3], 0,2) == 'od') {
- $cylinder = [];
- $a = explode(" ", $res[$i][3]);
- foreach (range($a[1], $a[3], $a[5]) as $number) {
- if (strpos($number, '.') === false) {
- $number .= '.0';
- }
- $cylinder[] = $number;
- }
- }
- foreach ($moc as $moc1) {
- $a = explode(" ", $moc1);
- foreach (range($a[1], $a[3], $a[5]) as $number) {
- $number = (string)$number;
- if (strpos($number, '.') === false) {
- $number .= '.0';
- }
- if ($number == '0.0') {
- $number = '0.00';
- }
- foreach ($cylinder as $cy) {
- $cy = trim($cy);
- if ($cy == '') {
- continue;
- }
- foreach ($os as $o) {
- $o = trim($o);
- if ($o == '') {
- continue;
- }
- $itemses = [];
- $itemses['item_id'] = $item_id;
- $itemses['pv_id_1'] = $c1[$number];
- $itemses['pv_id_2'] = $c2[$cy];
- $itemses['pv_id_3'] = $c3[$o];
- $itemses['item_code'] = '';
- $itemses['item_price'] = 0;
- $itemses['item_weight'] = 0;
- if ($itemses['pv_id_1'] < 1 || $itemses['pv_id_2'] < 1 || $itemses['pv_id_3'] < 1) {
- pre($itemses, '1:'.$number.' 2:'.$cy.' 3:'.$o);
- exit;
- }
- $this->objItemsES->add($itemses);
- $amount = array();
- $amount['item_id'] = $item_id;
- $amount['depot_id'] = 1001;
- $amount['mag_id'] = $this->objItemsES->getLastId();
- $amount['ia_amount'] = 0;
- $amount['ia_nolimit'] = 1;
- $this->objAmount->add($amount);
- }
- }
- }
- }
- } else {
- pre($item_id,'bad item');
- }
- die('1');
- }
- public function amountAction(){
- ini_set('display_errors', 1);
- set_time_limit(0);
- try {
- $link = mysqli_connect("localhost","bartek","passwd123","bartek") or die("Error " . mysqli_error($link));
- $link->query("SET NAMES 'utf8'");
- $db = Zend_Registry::get('dbAdapter');
- $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
- ON (p.id_product=l.id_product AND l.id_lang='7') ORDER BY p.id_product ASC");
- while($v = mysqli_fetch_array($result1)) {
- $item_id = $v['id_product'];
- $this->_setPropMag($item_id);
- if($this->pg_id>1) {
- } else {
- $amount1 = 0;
- $sql3 = "SELECT * FROM `ps_stock_available` WHERE `id_product` = $item_id ";
- $result3 = $link->query($sql3);
- while($row3 = mysqli_fetch_array($result3)) {
- $amount1 = (int)$row3['quantity'];
- break;
- }
- try {
- $db->query("INSERT INTO items_amount (item_id,depot_id,ia_amount,ia_nolimit) VALUES('$item_id','1','$amount1','0')");
- } catch (Exception $e) {
- }
- }
- }
- die("OK!");
- } catch (Exception $e) {
- print_r($e->getMessage());
- }
- die("error!");
- }
- public function availabilityAction()
- {
- $link = $this->connect();
- $pair = [];
- $pair[1] = 1;
- $pair[2] = 4;
- $pair[3] = 5;
- $pair[5] = 6;
- $pair[6] = 7;
- $pair[8] = 2;
- $pair[10] = 3;
- $result1 = $link->query("SELECT id_product,id_availability FROM `ps_product` order by id_product ASC");
- while($v = mysqli_fetch_array($result1)) {
- $item_id = $v['id_product'];
- $time = 0;
- if (isset($pair[$v['id_availability']])) {
- $time = $pair[$v['id_availability']];
- }
- $d = [];
- $d['item_shipping_time'] = $time;
- $this->objItems->save($item_id, $d);
- }
- die("ok");
- }
- public function itemsAction(){
- ini_set('display_errors', 1);
- ini_set('memory_limit', '2048M');
- set_time_limit(0);
- try {
- $link = $this->connect();
- $db = Zend_Registry::get('dbAdapter');
- $path = '/home/ftbzrr/domains/fitbay.ebexo.com.pl/public_html/images/items/';
- $type = array('_big','_top','_medium','_small','_micro','_prop');
- $sql = "SELECT id_manufacturer,name FROM `ps_manufacturer` WHERE active=1 ORDER BY id_manufacturer ASC";
- $result1 = $link->query($sql);
- $i = 0;
- while($row1 = mysqli_fetch_array($result1)) {
- if(strlen($row1['name'])>1) {
- $prod = trim($row1['name']);
- $producers[$row1['id_manufacturer']] = $prod;
- }
- }
- $olddir = '/home/ftbzrr/domains/fitbay.ebexo.com.pl/public_html/p/';
- $lastID=0;
- $abc = 0;
- $nowe = 0;
- $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
- ON (p.id_product=l.id_product AND l.id_lang='3') WHERE p.id_product > 0 ORDER BY p.id_product ASC");
- while($v = mysqli_fetch_array($result1)) {
- try {
- $item_id = $v['id_product'];
- if ($item_id <= 14730) continue;
- $one1 = $this->objItems->getOneById($item_id);
- if ($one1['item_id'] < 1) continue;
- $item = array();
- $item['item_buy_price'] = $v['wholesale_price'];
- $item['item_id'] = $item_id;
- $item['item_name'] = $v['name'];
- $item['item_desc_short'] = $v['description_short'];
- $item['item_desc'] = $v['description'];
- switch ($v['id_tax']) {
- case 1:
- $tax = 0;
- break;
- case 2:
- $tax = 8;
- break;
- case 3:
- $tax = 23;
- break;
- case 4:
- $tax = 5;
- break;
- }
- $item['item_vat'] = $tax;
- $item['item_weight'] = $v['weight'];
- $item['item_active'] = $v['active'];
- $item['item_shipping_time'] = 1;
- $item['item_exp_store'] = 0;
- $item['pg_id'] = 1;
- $producent = $producers[$v['id_manufacturer']];
- if ($producent != '') {
- $p = $this->objProducers->getOneByName($producent);
- if ($p['producer_id'] > 1) {
- $item['producer_id'] = $p['producer_id'];
- } else {
- $item['producer_id'] = 1;
- }
- } else {
- $item['producer_id'] = 1;
- }
- $item['item_code'] = (string)$v['reference'];
- $item['item_ean'] = (string)$v['ean13'];
- $item['item_new'] = 0;
- $priceBrutto = $v['price'] * (1 + $item['item_vat'] / 100);
- if ($v['reduction_price'] > 0) {
- $price = $priceBrutto - $v['reduction_price'];
- if ($v['reduction_from'] == $v['reduction_to']) {
- $item['item_promo_price_from'] = '2017-10-03';
- $item['item_promo_price_to'] = '2020-12-31';
- } else {
- $item['item_promo_price_from'] = $v['reduction_from'];
- $item['item_promo_price_to'] = $v['reduction_to'];
- }
- $item['item_price'] = $v['price'];
- $item['item_promo'] = 1;
- $item['item_promo_price'] = $price;
- $item['item_real_promo'] = 1;
- $item['item_actual_price'] = $item['item_promo_price'];
- } else {
- $item['item_promo'] = 0;
- $item['item_price'] = $v['price'];
- $item['item_actual_price'] = $priceBrutto;
- }
- // dodanie produktu
- //////// $this->objItems->add($item);
- $lastID = $item_id;
- $this->_setPropMag($item_id);
- if ($this->pg_id > 0) {
- // $item2 = array();
- // $item2['item_exp_store'] = 1;
- // $item2['pg_id'] = $this->pg_id;
- // $this->objItems->save($item_id,$item2);
- } else {
- // magazyn - to dla produktow bez cech mag.
- $amount = (int)$v['quantity'];
- $db->query("INSERT INTO items_amount (item_id,depot_id,ia_amount,ia_nolimit) VALUES('$lastID','1','$amount','0')");
- }
- } catch (Exception $e) {
- print_r($e->getMessage());
- }
- continue;
- $this->_setPropInf($item_id);
- // foto
- @mkdir("{$path}{$lastID}");
- $result2 = $link->query("SELECT * FROM `ps_image` where id_product='".$lastID."' order by position ASC");
- while($foto = mysqli_fetch_array($result2)) {
- // 10779-19481.jpg
- $img = $lastID.'-'.$foto['id_image'].'.jpg';
- if($img != '' && file_exists($olddir.$img) ){
- file_put_contents($path.$lastID.'/'.$foto['id_product'].'-'.$foto['id_image'].'_big.jpg', file_get_contents($olddir.$img));
- $base = $foto['id_product'].'-'.$foto['id_image'].'.jpg';
- foreach($type as $ftype) {
- $fname = $foto['id_product'].'-'.$foto['id_image'].$ftype.'.jpg';
- if($foto['cover']==1) {
- $if_root = 1;
- } else {
- $if_root = 0;
- }
- $db->query("INSERT INTO items_foto (item_id,if_root,if_base_name,if_name,if_type,prop)
- VALUES('$lastID','$if_root','$base','$fname','$ftype','0');");
- }
- }
- }
- // end foto
- continue;
- // kategorie
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('1','$lastID')";
- $db->query($sql);
- $i_id = $lastID;
- $sql6 = "SELECT nowa FROM `ps_category_product` p INNER JOIN kategorie k ON (k.stara=p.id_category) WHERE id_product='$item_id'";
- $res6 = $link->query($sql6);
- while($row6 = mysqli_fetch_array($res6)) {
- $c_id = $cat = $row6['nowa'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$cat','$lastID')";
- $db->query($sql);
- $level = $this->treeCat->getLevel($cat);
- if($level==4) {
- $parent = $this->treeCat->getParent($c_id);
- $c_id = $parent['id'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
- try {
- $db->query($sql);
- } catch (Exception $e) {
- echo $sql.' ';
- print_r($e->getMessage());
- }
- $parent = $this->treeCat->getParent($c_id);
- $c_id = $parent['id'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
- try {
- $db->query($sql);
- } catch (Exception $e) {
- echo $sql.' ';
- print_r($e->getMessage());
- }
- $parent = $this->treeCat->getParent($c_id);
- $c_id = $parent['id'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
- try {
- $db->query($sql);
- } catch (Exception $e) {
- echo $sql.' ';
- print_r($e->getMessage());
- }
- }
- if($level==3) {
- $parent = $this->treeCat->getParent($c_id);
- $c_id = $parent['id'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
- try {
- $db->query($sql);
- } catch (Exception $e) {
- echo $sql.' ';
- print_r($e->getMessage());
- }
- $parent = $this->treeCat->getParent($c_id);
- $c_id = $parent['id'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
- try {
- $db->query($sql);
- } catch (Exception $e) {
- echo $sql.' ';
- print_r($e->getMessage());
- }
- }
- elseif($level==2) {
- $parent = $this->treeCat->getParent($c_id);
- $c_id = $parent['id'];
- $sql = "INSERT INTO cat_items (cat_id,item_id) VALUES ('$c_id','$i_id')";
- try {
- $db->query($sql);
- } catch (Exception $e) {
- echo $sql.' ';
- print_r($e->getMessage());
- }
- }
- }
- }
- } catch (Exception $e) {
- print_r($e->getMessage());
- }
- die('import complete without errors');
- }
- public function connect()
- {
- $link = mysqli_connect("localhost","centr11_test","3t148FsNo0","centr11_test") or die("Error " . mysqli_error($link));
- $link->query("SET NAMES 'utf8'");
- return $link;
- }
- public function prodAction(){
- ini_set('display_errors', 1);
- $link = $this->connect();
- $sql = "SELECT id_manufacturer,name FROM `ps_manufacturer` WHERE active=1 ORDER BY id_manufacturer ASC";
- $result1 = $link->query($sql);
- $i = 0;
- while($row1 = mysqli_fetch_array($result1)) {
- if(strlen($row1['name'])>1) {
- $prod = trim($row1['name']);
- if($this->objProducers->isExist($prod)){
- // istnieje
- } else {
- // dodaj
- $data = array();
- $data['producer_name'] = $prod;
- $data['producer_desc'] = "";
- $this->objProducers->add($data);
- }
- }
- }
- die('import complete without errors');
- }
- // import kategorii
- public function catAction() {
- ini_set('display_errors', 1);
- ini_set('memory_limit', '1024M');
- $lang = 1;
- $link = $this->connect();
- $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
- FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
- WHERE c.id_parent='1' AND c.active='1' ORDER BY c.id_category DESC";
- $result1 = $link->query($sql);
- while($row1 = mysqli_fetch_array($result1)) {
- // level 1
- $arr = array();
- //$arr['id'] = $row1['category_id'];
- $arr['name'.$lang] = $row1['name'];
- $arr['google_title'.$lang] = $row1['meta_title'];
- $arr['google_desc'.$lang] = $row1['meta_description'];
- $arr['google_key_words'.$lang] = $row1['meta_keywords'];
- $arr['campaign_active'] = 0;
- $lastID1 = $this->treeCat->add($arr,1);
- $this->treeCat->setup();
- $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row1['id_category']."','$lastID1')");
- if($row1['description']!='') {
- $desc = array();
- $desc['cat_id'] = $lastID1;
- $desc['cat_desc'] = $row1['description'];
- $this->objCategoriesDesc->add($desc);
- }
- $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
- FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
- WHERE c.id_parent='".$row1['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- // level 2
- $arr = array();
- $arr['name'.$lang] = $row2['name'];
- $arr['google_title'.$lang] = $row2['meta_title'];
- $arr['google_desc'.$lang] = $row2['meta_description'];
- $arr['google_key_words'.$lang] = $row2['meta_keywords'];
- $arr['campaign_active'] = 0;
- $lastID2 = $this->treeCat->add($arr,$lastID1);
- $this->treeCat->setup();
- $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row2['id_category']."','$lastID2')");
- if($row2['description']!='') {
- $desc = array();
- $desc['cat_id'] = $lastID2;
- $desc['cat_desc'] = $row2['description'];
- $this->objCategoriesDesc->add($desc);
- }
- $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
- FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
- WHERE c.id_parent='".$row2['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
- $result3 = $link->query($sql);
- while($row3 = mysqli_fetch_array($result3)) {
- // level 3
- $arr = array();
- // $arr['id'] = $row3['category_id'];
- $arr['name'.$lang] = $row3['name'];
- $arr['google_title'.$lang] = $row3['meta_title'];
- $arr['google_desc'.$lang] = $row3['meta_description'];
- $arr['google_key_words'.$lang] = $row3['meta_keywords'];
- $arr['campaign_active'] = 0;
- $lastID3 = $this->treeCat->add($arr,$lastID2);
- $this->treeCat->setup();
- $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row3['id_category']."','$lastID3')");
- if($row3['description']!='') {
- $desc = array();
- $desc['cat_id'] = $lastID3;
- $desc['cat_desc'] = $row3['description'];
- $this->objCategoriesDesc->add($desc);
- }
- $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
- FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
- WHERE c.id_parent='".$row3['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
- $result4 = $link->query($sql);
- while($row4 = mysqli_fetch_array($result4)) {
- // level 3
- $arr = array();
- $arr['name'.$lang] = $row4['name'];
- $arr['google_title'.$lang] = $row4['meta_title'];
- $arr['google_desc'.$lang] = $row4['meta_description'];
- $arr['google_key_words'.$lang] = $row4['meta_keywords'];
- $arr['campaign_active'] = 0;
- $lastID4 = $this->treeCat->add($arr,$lastID3);
- $this->treeCat->setup();
- $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row4['id_category']."','$lastID4')");
- if($row4['description']!='') {
- $desc = array();
- $desc['cat_id'] = $lastID4;
- $desc['cat_desc'] = $row4['description'];
- $this->objCategoriesDesc->add($desc);
- }
- $sql = "SELECT c.*, l.name, l.seo_description as description,l.meta_description,l.meta_keywords,l.meta_title
- FROM `ps_category` c INNER JOIN ps_category_lang l ON (l.id_category=c.id_category AND l.id_lang=3)
- WHERE c.id_parent='".$row4['id_category']."' AND c.active='1' ORDER BY c.id_category DESC";
- $result5 = $link->query($sql);
- while($row5 = mysqli_fetch_array($result5)) {
- // level 3
- $arr = array();
- $arr['name'.$lang] = $row5['name'];
- $arr['google_title'.$lang] = $row5['meta_title'];
- $arr['google_desc'.$lang] = $row5['meta_description'];
- $arr['google_key_words'.$lang] = $row5['meta_keywords'];
- $arr['campaign_active'] = 0;
- $lastID5 = $this->treeCat->add($arr,$lastID4);
- $this->treeCat->setup();
- $link->query("INSERT INTO kategorie (stara,nowa) VALUES('".$row5['id_category']."','$lastID5')");
- if($row5['description']!='') {
- $desc = array();
- $desc['cat_id'] = $lastID5;
- $desc['cat_desc'] = $row5['description'];
- $this->objCategoriesDesc->add($desc);
- }
- }
- }
- }
- }
- }
- pre($cat);
- die('import complete without errors');
- }
- public function propertiesShowAction()
- {
- ini_set('display_errors', 1);
- ini_set('memory_limit', '1024M');
- $lang = 1;
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- $res = array();
- $sql = "SELECT GROUP_CONCAT( CAST( id_attribute AS CHAR ) ) as dupa
- FROM ps_product_attribute_combination
- GROUP BY id_product_attribute
- HAVING count( * ) >1";
- $result = $link->query($sql);
- while($row = mysqli_fetch_array($result)) {
- $sql = "SELECT id_attribute_group FROM `ps_attribute` WHERE id_attribute IN (".$row['dupa'].")";
- $result2 = $link->query($sql);
- $a = array();
- while($row2 = mysqli_fetch_array($result2)) {
- $a[] = $row2['id_attribute_group'];
- }
- $res[implode(",",array_unique($a))] += 1;
- }
- pre($res);
- die("OK");
- }
- public function importPropertiesValuesAction()
- {
- ini_set('display_errors', 1);
- ini_set('memory_limit', '1024M');
- $lang = 1;
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- try {
- $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";
- $result = $link->query($sql);
- while ($row = mysqli_fetch_array($result)) {
- $id_feature = $row['id_feature'];
- $abc = $link->query("SELECT COUNT(l.value) as ile FROM ps_feature_value f INNER JOIN ps_feature_value_lang l ON
- (f.id_feature_value=l.id_feature_value) WHERE f.id_feature=$id_feature");
- while ($row5 = mysqli_fetch_array($abc)) {
- $jest = $row5['ile'];
- }
- if ($jest > 50) {
- $ind = 2;
- } else {
- $ind = 3;
- }
- $wyn = array();
- $wyn['p_id'] = $id_feature + 29;
- $wyn['p_name'] = $row['name'];
- $wyn['p_iname'] = $row['name'];
- $wyn['p_model'] = 2;
- $wyn['p_type'] = $ind;
- $wyn['p_hide'] = 0;
- $wyn['p_filter'] = 0;
- $this->objProperties->add($wyn);
- $id = $this->objProperties->getLastId();
- if ($ind != 2) {
- $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) "
- . "WHERE id_feature=$id_feature";
- $result2 = $link->query($sql2);
- while ($row2 = mysqli_fetch_array($result2)) {
- $row2['value'] = stripslashes($row2['value']);
- $jest = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$id' AND pv_value1='" . addslashes($row2['value']) . "'");
- if ($jest < 1) {
- $this->objPropertiesValues->add($id, $row2['value']);
- }
- }
- }
- }
- } catch (Exception $e) {
- pre($e->getMessage());
- }
- die("ok");
- }
- public function importGroupsAction()
- {
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- try {
- $sql = "SELECT g.id_attribute_group,name,public_name FROM `ps_attribute_group` g INNER JOIN ps_attribute_group_lang l ON "
- . "(l.id_attribute_group=g.id_attribute_group) WHERE l.id_lang=3";
- $result = $link->query($sql);
- while ($row = mysqli_fetch_array($result)) {
- $wyn = array();
- $wyn['pg_id'] = $row['id_attribute_group']+1;
- $wyn['pg_name'] = $row['name'];
- $wyn['super'] = 0;
- $wyn['pg_type'] = 1;
- $this->objPropertiesGroups->add($wyn);
- $jest = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='" . $row['name'] . "' AND p_id < 30");
- if ($jest > 0) {
- $w = array();
- $w['pg_id'] = $row['id_attribute_group']+1;
- $w['p_id'] = $jest;
- $w['p_order'] = 0;
- $this->objPropertiesGroupsVal->add($w);
- }
- $data = $db->fetchAll("SELECT p_id FROM properties WHERE p_id > 29");
- foreach ($data as $k => $v) {
- $w = array();
- $w['pg_id'] = $row['id_attribute_group']+1;
- $w['p_id'] = $v['p_id'];
- $w['p_order'] = 1;
- $this->objPropertiesGroupsVal->add($w);
- }
- }
- } catch (Exception $e) {
- pre($e->getMessage());
- }
- die("OK");
- }
- public function importGroups2Action()
- {
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- $res = array();
- $sql = "SELECT GROUP_CONCAT( CAST( id_attribute AS CHAR ) ) as dupa
- FROM ps_product_attribute_combination
- GROUP BY id_product_attribute
- HAVING count( * ) >1";
- $result = $link->query($sql);
- while($row = mysqli_fetch_array($result)) {
- $sql = "SELECT id_attribute_group FROM `ps_attribute` WHERE id_attribute IN (".$row['dupa'].")";
- $result2 = $link->query($sql);
- $a = array();
- while($row2 = mysqli_fetch_array($result2)) {
- $a[] = $row2['id_attribute_group'];
- }
- sort($a);
- $res[implode(",",array_unique($a))] += 1;
- }
- foreach($res as $r=>$r2) {
- $a = explode(",",$r);
- if (count($a)==1) continue;
- $name1 = $name2 = $name3 = '';
- $sql = "SELECT name FROM `ps_attribute_group_lang` WHERE id_lang=3 AND id_attribute_group=$a[0]";
- $result = $link->query($sql);
- while($row = mysqli_fetch_array($result)) {
- $name1 = $row['name'];
- }
- $sql = "SELECT name FROM `ps_attribute_group_lang` WHERE id_lang=3 AND id_attribute_group=$a[1]";
- $result = $link->query($sql);
- while($row = mysqli_fetch_array($result)) {
- $name2 = $row['name'];
- }
- if (count($a)==3) {
- $sql = "SELECT name FROM `ps_attribute_group_lang` WHERE id_lang=3 AND id_attribute_group=$a[2]";
- $result = $link->query($sql);
- while($row = mysqli_fetch_array($result)) {
- $name3 = $row['name'];
- }
- if ($name3 == '') die("BLAD3");
- }
- if($name1=='' OR $name2=='') die("BLAD!");
- $wyn = array();
- $wyn['pg_name'] = $name1.' + '.$name2;
- if ($name3 != '') {
- $wyn['pg_name'] = $name1.' + '.$name2.' + '.$name3;
- }
- $wyn['super'] = 0;
- $wyn['pg_type'] = 1;
- $this->objPropertiesGroups->add($wyn);
- $id = $this->objPropertiesGroups->getLastId();
- $jest = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='$name1' AND p_id < 30");
- $w = array();
- $w['pg_id'] = $id;
- $w['p_id'] = $jest;
- $w['p_order'] = 0;
- $this->objPropertiesGroupsVal->add($w);
- $jest = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='$name2' AND p_id < 30");
- $w = array();
- $w['pg_id'] = $id;
- $w['p_id'] = $jest;
- $w['p_order'] = 1;
- $this->objPropertiesGroupsVal->add($w);
- if ($name3 != '') {
- $jest = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='$name3' AND p_id < 30 ");
- $w = array();
- $w['pg_id'] = $id;
- $w['p_id'] = $jest;
- $w['p_order'] = 2;
- $this->objPropertiesGroupsVal->add($w);
- }
- $data = $db->fetchAll("SELECT p_id FROM properties WHERE p_id > 29");
- foreach ($data as $k => $v) {
- $w = array();
- $w['pg_id'] = $id;
- $w['p_id'] = $v['p_id'];
- $w['p_order'] = 3;
- $this->objPropertiesGroupsVal->add($w);
- }
- }
- die("OK!");
- }
- public function users2Action(){
- ini_set('display_errors', 1);
- // sprawdz czy klient o takim mailu istnieje
- // jesli nie to dodaj
- // potem dodaj zamowienie
- // potem produkty z zamowienia
- try {
- $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
- FROM `ps_customer` c
- 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;");
- foreach($data as $k=>$v){
- $email = $v['email'];
- if($this->objUsers->isExist($email))
- {
- $user = $this->objUsers->getOneByEmail($email);
- $u_id = $$user['user_id'];
- } else {
- $user = array();
- $user['user_id'] = $v['id_customer'];
- $user['user_type'] = strlen($v['company'])>3 ? 2 : 1;
- $user['user_password'] = md5(rand(1000,10000));
- if($user['user_type']==2) {
- $user['user_firm'] = $v['company'];
- } else {
- $user['user_firm'] = '';
- }
- $user['user_name'] = $v['firstname'];
- $user['user_surname'] = $v['lastname'];
- $user['user_phone'] = trim($v['phone_mobile']);
- $user['user_email'] = $email;
- $user['user_street'] = $v['address1'];
- $user['user_postcode'] = $v['postcode'];
- $user['user_city'] = $v['city'];
- $user['user_country'] = 'pl';
- $user['user_nip'] = '';
- $user['user_vat'] = $user['user_type']==2 ? 1 : 0;
- $user['user_newsletter'] = 1;
- $user['user_activate'] = 1;
- $user['user_active'] = 1;
- $this->objUsers->add($user);
- $u_id = $this->objUsers->getLastId();
- }
- }
- die('import complete without errors');
- } catch (Exception $e) {
- print_r($e->getMessage());
- }
- }
- public function usersAction(){
- ini_set('display_errors', 1);
- // sprawdz czy klient o takim mailu istnieje
- // jesli nie to dodaj
- // potem dodaj zamowienie
- // potem produkty z zamowienia
- $link = $this->connect();
- try {
- $result1 = $link->query("SELECT DISTINCT email,c.id_customer,c.firstname,c.lastname,a.address1,a.city,a.postcode,c.newsletter,
- a.phone,a.company,a.phone_mobile
- FROM `ps_customer` c
- LEFT JOIN ps_address a ON (a.id_customer=c.id_customer)
- GROUP BY email ORDER BY c.id_customer ASC ");
- while($v = mysqli_fetch_array($result1)) {
- $email = $v['email'];
- if($this->objUsers->isExist($email))
- {
- $user = $this->objUsers->getOneByEmail($email);
- $u_id = $user['user_id'];
- } else {
- $user = array();
- $user['user_id'] = $v['id_customer'];
- $user['user_type'] = strlen($v['company'])>3 ? 2 : 1;
- $user['user_password'] = rand(1000,10000);
- if($user['user_type']==2) {
- $user['user_firm'] = $v['company'];
- } else {
- $user['user_firm'] = '';
- }
- $user['user_name'] = $v['firstname'];
- $user['user_surname'] = $v['lastname'];
- $phone = $v['phone'];
- if($phone!='') $v['phone'] = $v['phone_mobile'];
- $user['user_phone'] = str_replace(' ','',str_replace('-','',trim($phone) ));
- $user['user_email'] = $email;
- $user['user_street'] = $v['address1'];
- $user['user_postcode'] = $v['postcode'];
- $user['user_city'] = $v['city'];
- $user['user_country'] = 'pl';
- $user['user_nip'] = '';
- $user['user_vat'] = $user['user_type']==2 ? 1 : 0;
- $user['user_newsletter'] = $v['newsletter'];
- $user['user_activate'] = 1;
- $user['user_active'] = 1;
- $this->objUsers->add($user);
- $u_id = $this->objUsers->getLastId();
- }
- }
- die('import complete without errors');
- } catch (Exception $e) {
- print_r($e->getMessage());
- }
- }
- public function ordersAction(){
- set_time_limit(0);
- ini_set('memory_limit', '1024M');
- $lang = 1;
- ini_set('display_errors', 1);
- $link = $this->connect();
- $db = Zend_Registry::get('dbAdapter');
- $statusy = array();
- $statusy[10] = 100;
- $statusy[26] = 1;
- $statusy[17] = 1;
- $statusy[5] = 1;
- $statusy[24] = 1;
- $statusy[11] = 2;
- $statusy[21] = 2;
- $statusy[32] = 2;
- $statusy[28] = 2;
- $statusy[14] = 1;
- $statusy[4] = 1;
- $statusy[7] = 1;
- $statusy[30] = 1;
- $statusy[1] = 1;
- $statusy[2] = 1;
- $statusy[15] = 90;
- $statusy[29] = 1;
- $statusy[33] = 1;
- $statusy[13] = 1;
- $statusy[18] = 9;
- $statusy[8] = 1;
- $statusy[25] = 1;
- $statusy[19] = 1;
- $statusy[20] = 1;
- $statusy[31] = 1;
- $statusy[6] = 1;
- $statusy[3] = 9;
- $statusy[22] = 5;
- $statusy[16] = 9;
- $statusy[9] = 9;
- $statusy[27] = 9;
- $statusy[23] = 2;
- $statusy[12] = 2;
- try {
- $sql = "SELECT * FROM ps_orders ORDER BY id_order ASC";
- $result1 = $link->query($sql);
- $i = 0;
- while($row = mysqli_fetch_array($result1)) {
- $u_id = $row['id_customer'];
- $sql1 = "SELECT id_order_state FROM `ps_order_history` WHERE `id_order` = '".$row['id_order']."' order by id_order_history DESC LIMIT 1";
- $res2 = $link->query($sql1);
- while($row2 = mysqli_fetch_array($res2)) {
- $state = $row2['id_order_state'];
- }
- $ss = $statusy[$state];
- if($ss<1) $ss = 100;
- // zamowienie
- $order = array();
- $order['order_id'] = $row['id_order'];
- $order['order_status'] = $ss;
- $user = $this->objUsers->getOneById($u_id);
- if($user['user_id']>0) {
- $order['user_id'] = $u_id;
- } else {
- $sql4 = "SELECT * FROM ps_customer WHERE id_customer='$u_id'";
- $result4 = $link->query($sql4);
- while($row4 = mysqli_fetch_array($result4)) {
- $email = $row4['email'];
- }
- $user = $this->objUsers->getOneByEmail($email);
- if(!$user) {
- $user = array();
- $user['user_type'] = 1;
- $user['user_email'] = $email;
- $user['user_name'] = $row4['firstname'];
- $user['user_surname'] = $row4['lastname'];
- }
- if($user['user_email']=='') {
- $user['user_email'] = ' ';
- }
- }
- $order['order_date'] = $row['date_add'];
- $order['order_email'] = $user['user_email'];
- $order['order_payer'] = $user['user_type'];
- $order['order_new'] = 0;
- if($user['user_type']==2) {
- $who = $user['user_firm'];
- } else {
- $who = $user['user_name'].' '.$user['user_surname'];
- }
- $order['order_pay_to'] = $who . "\n" . $user['user_street'].'||'.$user['user_home'].'||'.$user['user_flat'].'||'.$user['user_postcode'].'||'.$user['user_city'].'||Polska';
- if ($user['user_nip']!='')
- $order['order_pay_to'] .= "\n" . $user['user_nip'];
- else
- $order['order_pay_to'] .= "\n";
- if ($user['user_phone'] != '') {
- $order['order_pay_to'] .= "\n" . $user['user_phone'];
- } else {
- $order['order_pay_to'] .= "\n";
- }
- $who = $user['user_name'].' '.$user['user_surname'];
- $order['order_send_to'] = $who . "\n" . $user['user_street'].'||'.$user['user_home'].'||'.$user['user_flat'].'||'.$user['user_postcode'].'||'.$user['user_city'].'||Polska';
- if ( $user['user_phone'] != '') {
- $order['order_send_to'] .= "\n\n" . $user['user_phone'];
- }
- $order['order_fvat'] = $user['user_type']==2 ? 1:0;
- $amount = 0;
- $suma = 0;
- $positions = $link->query("SELECT * FROM ps_order_detail WHERE id_order='$row[id_order]'");
- while($b = mysqli_fetch_array($positions)) {
- $amount += $b['product_quantity'];
- $cena = $b['product_price'];
- $cena2 = $b['product_quantity_discount'];
- if($cena2>0) $cena = $cena2;
- $suma += ($cena*$b['product_quantity']);
- }
- $order['order_amount'] = $amount;
- $order['order_price'] = $suma;
- $order['order_delivery_country_code'] = 'pl';
- $order['order_supplier_name'] = 'kurier';
- $order['order_payment_name'] = $row['payment'];
- $order['order_payment_type'] = $row['module']=='cashondelivery'? 'cod' : 'transfer';
- $order['order_delivery_price'] = $row['total_shipping'];
- $order['order_topay'] = $row['total_paid'];
- $order['order_currency'] = 'PLN';
- $order['order_exchange'] = 1;
- $order['order_lang'] = 'pl';
- $order['order_source'] = 'prestashop';
- $this->objOrders->add($order);
- $order_id = $this->objOrders->getLastId();
- $positions = $link->query("SELECT * FROM ps_order_detail WHERE id_order='$row[id_order]'");
- while($b = mysqli_fetch_array($positions)) {
- // $prod = $link->query("SELECT nowe FROM prod WHERE stare='$b[product_id]'");
- // $iii = mysql_fetch_row($prod);
- $vat = (int)$b['tax_rate'];
- $cena = $b['product_price']*(1+$vat/100);
- $cena2 = $b['product_quantity_discount']*(1+$vat/100);
- $oi = array();
- $item = $this->objItems->getOneById($b[product_id]);
- if($b['product_reference']=='') $b['product_reference'] = ' ';
- if($item['item_id']>0) {
- $oi['oi_item_id'] = $b[product_id];
- $oi['oi_item_code'] = $b['product_reference'];
- $oi['oi_item_name'] = $b['product_name'];
- } else {
- $oi['oi_item_id'] = NULL;
- $oi['oi_item_code'] = $b['product_reference'];
- $oi['oi_item_name'] = $b['product_name'];
- }
- $oi['order_id'] = $order_id;
- $oi['oi_type'] = 1;
- $oi['oi_mag'] = 0;
- $oi['oi_mag_id'] = NULL;
- $oi['oi_item_desc'] = '';
- $oi['oi_item_price'] = $cena;
- $oi['oi_item_vat'] = (int)$b['tax_rate'];
- if($cena2>0) {
- $oi['oi_promo'] = 1;
- $oi['oi_promo_price'] = $cena2;
- }
- $oi['oi_amount'] = $b['product_quantity'];
- $this->objOrdersItems->add($oi);
- }
- // Zapisujemy informacje dot. transportu jako pozycje w orders_items
- // start : saveTG
- $d = '';
- $d['order_id'] = $order_id;
- $d['oi_type'] = 2; // - transport
- $d['oi_item_id'] = null;
- $d['oi_mag'] = null;
- $d['oi_mag_id'] = null;
- $d['oi_item_name'] = "Transport";
- $d['oi_item_desc'] = null;
- $d['oi_item_code'] = "";
- $d['oi_item_price'] = $order['order_delivery_price'];
- $d['oi_item_vat'] = 23;
- $d['oi_amount'] = 1;
- $this->objOrdersItems->saveTG($d);
- // end : saveTG
- }
- die('import complete without errors');
- } catch (Exception $e) {
- print_r($e->getMessage());
- }
- die('import WITH errors');
- }
- private function _setPropMag($id)
- {
- $this->pg_id = 0;
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- $sql = "SELECT a.*,c.id_attribute,l.name,p2.id_attribute_group FROM `ps_product_attribute` a INNER JOIN ps_product_attribute_combination c
- 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)
- 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 ";
- $result = $link->query($sql);
- $i=0;
- $opt = array();
- while($row = mysqli_fetch_array($result)) {
- $opt[] = $row;
- }
- if(count($opt)<1) {
- return 1; // brak cech mag.
- }
- if($opt[0]['id_product_attribute']==$opt[1]['id_product_attribute'] && $opt[1]['id_product_attribute']==$opt[2]['id_product_attribute']) {
- //2 cechy
- $name = [];
- $sql = "SELECT name, p.id_attribute_group
- FROM `ps_attribute_group` a
- INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
- INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
- WHERE l.id_lang = 3 AND p.id_attribute =".$opt[0]['id_attribute'];
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- $name[$row2['name']] = $row2['id_attribute_group'];
- }
- $sql = "SELECT name, p.id_attribute_group
- FROM `ps_attribute_group` a
- INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
- INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
- WHERE l.id_lang = 3 AND p.id_attribute =".$opt[1]['id_attribute'];
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- $name[$row2['name']] = $row2['id_attribute_group'];
- }
- $sql = "SELECT name, p.id_attribute_group
- FROM `ps_attribute_group` a
- INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
- INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
- WHERE l.id_lang = 3 AND p.id_attribute =".$opt[2]['id_attribute'];
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- $name[$row2['name']] = $row2['id_attribute_group'];
- }
- asort($name);
- $names = array_keys($name);
- $group = substr(implode(" + ", $names),0,32);
- $pg_id = $db->fetchOne("SELECT pg_id FROM `properties_groups` WHERE pg_name='".$group."'");
- if($pg_id>0) {
- $this->pg_id = $pg_id;
- $pid = [];
- $pid[] = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[0]."' AND p_id < 30");
- $pid[] = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[1]."' AND p_id < 30");
- $pid[] = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[2]."' AND p_id < 30");
- if(count($pid) == 2 && $pid[0] != '' && $pid[1] != '' && $pid[2] != '') {
- $i=0;
- $grupuj = [];
- foreach($opt as $k=>$v) {
- $grupuj[$v['id_product_attribute']][] = $v;
- }
- foreach($grupuj as $id_product_attribute=>$z) {
- $c = 0;
- $pv_id = [];
- foreach ($z as $k2 => $v) {
- $pv_id[] = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid[$c]'
- AND pv_value1='" . addslashes($v['name']) . "'");
- $c++;
- }
- $es = array();
- $es['item_id'] = $id;
- $es['pv_id_1'] = $pv_id[0];
- $es['pv_id_2'] = $pv_id[1];
- $es['pv_id_3'] = $pv_id[2];
- $es['item_code'] = (string)$v['reference'];
- $es['item_price'] = 0;
- $es['item_weight'] = $v['weight'];
- // $this->objItemsES->add($es);
- $aa = $this->objItemsES->getOneByAllId($id, $pv_id[0], $pv_id[1], $pv_id[2]);
- if ($aa['es_id'] > 0) {
- $amount = array();
- $amount['item_id'] = $id;
- $amount['depot_id'] = 1;
- $amount['mag_id'] = $aa['es_id'];
- $amount['ia_amount'] = (int)$v['quantity'];
- $amount['ia_nolimit'] = 0;
- $this->objAmount->add($amount);
- }
- }
- }
- }
- }
- elseif($opt[0]['id_product_attribute']==$opt[1]['id_product_attribute']) {
- //2 cechy
- $name = [];
- $sql = "SELECT name, p.id_attribute_group
- FROM `ps_attribute_group` a
- INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
- INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
- WHERE l.id_lang = 3 AND p.id_attribute =".$opt[0]['id_attribute'];
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- $name[$row2['name']] = $row2['id_attribute_group'];
- }
- $sql = "SELECT name, p.id_attribute_group
- FROM `ps_attribute_group` a
- INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
- INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
- WHERE l.id_lang = 3 AND p.id_attribute =".$opt[1]['id_attribute'];
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- $name[$row2['name']] = $row2['id_attribute_group'];
- }
- asort($name);
- $names = array_keys($name);
- $group = substr(implode(" + ", $names),0,32);
- $pg_id = $db->fetchOne("SELECT pg_id FROM `properties_groups` WHERE pg_name='".$group."'");
- if($pg_id>0) {
- $this->pg_id = $pg_id;
- $pid = [];
- $pid[] = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[0]."' AND p_id < 30");
- $pid[] = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$names[1]."' AND p_id < 30");
- if(count($pid) == 2 && $pid[0] != '' && $pid[1] != '') {
- $i=0;
- $grupuj = [];
- foreach($opt as $k=>$v) {
- $grupuj[$v['id_product_attribute']][] = $v;
- }
- foreach($grupuj as $id_product_attribute=>$z) {
- $c = 0;
- $pv_id = [];
- foreach ($z as $k2 => $v) {
- $pv_id[] = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid[$c]'
- AND pv_value1='" . addslashes($v['name']) . "'");
- $c++;
- }
- $es = array();
- $es['item_id'] = $id;
- $es['pv_id_1'] = $pv_id[0];
- $es['pv_id_2'] = $pv_id[1];
- $es['pv_id_3'] = 0;
- $es['item_code'] = (string)$v['reference'];
- $es['item_price'] = 0;
- $es['item_weight'] = $v['weight'];
- // $this->objItemsES->add($es);
- $aa = $this->objItemsES->getOneByAllId($id, $pv_id[0], $pv_id[1], 0);
- if ($aa['es_id'] > 0) {
- $amount = array();
- $amount['item_id'] = $id;
- $amount['depot_id'] = 1;
- $amount['mag_id'] = $aa['es_id'];
- $amount['ia_amount'] = (int)$v['quantity'];
- $amount['ia_nolimit'] = 0;
- $this->objAmount->add($amount);
- }
- }
- }
- }
- } else {
- // 1 cecha
- $sql = "SELECT name, p.id_attribute_group
- FROM `ps_attribute_group` a
- INNER JOIN ps_attribute_group_lang l ON ( l.id_attribute_group = a.id_attribute_group )
- INNER JOIN ps_attribute p ON ( p.id_attribute_group = a.id_attribute_group )
- WHERE l.id_lang = 3 AND p.id_attribute =".$opt[0]['id_attribute'];
- $result2 = $link->query($sql);
- while($row2 = mysqli_fetch_array($result2)) {
- $this->pg_id = $row2['id_attribute_group']+1;
- $name = $row2['name'];
- }
- $pid = $db->fetchOne("SELECT p_id FROM properties WHERE p_iname='".$name."' AND p_id < 30");
- if($pid>0) {
- foreach($opt as $k=>$v) {
- $pv_id = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid' AND pv_value1='".addslashes($v['name'])."'");
- $es = array();
- $es['item_id'] = $id;
- $es['pv_id_1'] = $pv_id;
- $es['pv_id_2'] = 0;
- $es['pv_id_3'] = 0;
- $es['item_code'] = (string)$v['reference'];
- $es['item_price'] = 0;
- $es['item_weight'] = $v['weight'];
- // $this->objItemsES->add($es);
- $aa = $this->objItemsES->getOneByAllId($id, $pv_id[0], 0, 0);
- // $es_id = $db->fetchOne("SELECT es_id FROM `itemses` WHERE item_id='$id' AND pv_id_1='".$pv_id."'");
- // if($es_id<1) continue;
- $atr = $v['id_product_attribute'];
- if ($aa['es_id'] > 0) {
- $amount = array();
- $amount['item_id'] = $id;
- $amount['depot_id'] = 1;
- $amount['mag_id'] = $aa['es_id'];
- $amount['ia_amount'] = (int)$v['quantity'];
- $amount['ia_nolimit'] = 0;
- $this->objAmount->add($amount);
- }
- }
- }
- }
- }
- private function _setPropInf($id)
- {
- $lang = 1;
- $ind = array(0);
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- $sql = "SELECT f.id_feature, f.id_feature_value, name, l2.value
- FROM `ps_feature_product` f
- INNER JOIN ps_feature_lang l ON ( f.id_feature = l.id_feature )
- INNER JOIN ps_feature_value v ON ( v.id_feature_value = f.id_feature_value )
- INNER JOIN ps_feature_value_lang l2 ON ( l2.id_feature_value = v.id_feature_value )
- WHERE `id_product` =$id";
- $result = $link->query($sql);
- while($row = mysqli_fetch_array($result)) {
- // id_feature name value
- $aa = $db->fetchRow("SELECT p_id,p_type FROM properties WHERE p_iname='".$row['name']."' AND p_id>'29'");
- $pid = $aa['p_id'];
- $type = $aa['p_type'];
- if($pid>0) {
- if($type == 2) {
- $this->addPropInd($pid,$id,$row['value']);
- } else {
- $pv_id = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$pid' AND pv_value1='".addslashes($row['value'])."'");
- if($pv_id>0) {
- $this->addProp($pid,$id,$pv_id);
- }
- }
- }
- }
- }
- private function addProp($id,$item_id,$val)
- {
- try {
- $d = array();
- $d['p_id'] = $id;
- $d['item_id'] = $item_id;
- $d['pv_id'] = $val;
- $this->objPropertiesValMulti->add($d);
- } catch (Exception $e) {}
- }
- private function addPropInd($id,$item_id,$val)
- {
- try {
- $d = array();
- $d['p_id'] = $id;
- $d['item_id'] = $item_id;
- $d['pvi_value'] = $val;
- $this->objPropertiesValIndividual->add($d);
- } catch (Exception $e) {}
- }
- public function addPropsMagAction()
- {
- ini_set('display_errors', 1);
- ini_set('memory_limit', '1024M');
- $lang = 1;
- try {
- $db = Zend_Registry::get('dbAdapter');
- $link = $this->connect();
- $sql = "SELECT g.id_attribute_group,name,public_name FROM `ps_attribute_group` g INNER JOIN ps_attribute_group_lang l ON"
- . " (l.id_attribute_group=g.id_attribute_group) WHERE l.id_lang =3";
- $result = $link->query($sql);
- while ($row = mysqli_fetch_array($result)) {
- $id_attribute = $row['id_attribute_group'];
- $wyn = array();
- $wyn['p_name'] = $row['public_name'];
- $wyn['p_iname'] = $row['name'];
- $wyn['p_model'] = 1;
- $wyn['p_type'] = 1;
- $wyn['p_hide'] = 0;
- $wyn['p_filter'] = 0;
- $this->objProperties->add($wyn);
- $id = $this->objProperties->getLastId();
- $sql2 = "SELECT a.id_attribute,l.name FROM `ps_attribute` a INNER JOIN ps_attribute_lang l ON (l.id_attribute=a.id_attribute) "
- . " WHERE id_attribute_group='$id_attribute' AND l.id_lang =3";
- $result2 = $link->query($sql2);
- while ($row2 = mysqli_fetch_array($result2)) {
- $row2['name'] = stripslashes($row2['name']);
- $jest = $db->fetchOne("SELECT pv_id FROM `properties_values` WHERE p_id='$id' AND pv_value1='" . addslashes($row2['name']) . "'");
- if ($jest < 1) {
- $this->objPropertiesValues->add($id, $row2['name']);
- }
- }
- }
- } catch (Exception $e) {
- pre($e->getMessage());
- }
- die("ok");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement