Commit af08b763 authored by Kulya's avatar Kulya 😊

Upd alvbx add prods15

parent fe8a0e54
...@@ -16,6 +16,10 @@ class AloVoiceRest ...@@ -16,6 +16,10 @@ class AloVoiceRest
$this->config = $config; $this->config = $config;
} }
public function lasttimefile() {
return __DIR__.'/billzlasttime';
}
public function consoleMethod($r) { public function consoleMethod($r) {
if(!empty($_SERVER['argv'][1])){ if(!empty($_SERVER['argv'][1])){
$runMethod = strtolower($_SERVER['argv'][1]); $runMethod = strtolower($_SERVER['argv'][1]);
...@@ -308,7 +312,7 @@ class AloVoiceRest ...@@ -308,7 +312,7 @@ class AloVoiceRest
private function bx_process_product($data=[],$full=false) { private function bx_process_product($data=[],$full=false) {
$data = json_decode('{ $datasss = json_decode('{
"ID": 1261574, "ID": 1261574,
"name": "*Tahorat va namoz", "name": "*Tahorat va namoz",
"sku": "Q001", "sku": "Q001",
...@@ -434,25 +438,16 @@ class AloVoiceRest ...@@ -434,25 +438,16 @@ class AloVoiceRest
} }
} }
// if(!empty($data["imageUrls"])){ $section_id = (!empty($data["properties"]["CATEGORY"])) ? $this->process_product_section($data["properties"]["CATEGORY"]) : false;
// foreach($data["imageUrls"] as $ik=>$img){
// $arImage = $this->get_image_by_url($img["url"]);
// if(!empty($arImage["name"]) && !empty($arImage["base64"])){
// $arPic = [
// "value" => [
// "fileData" => [
// $arImage["name"],
// $arImage["base64"]
// ]
// ]
// ];
// if($ik==0){ if(!empty($data["properties"]["SUB_CATEGORY"])){
// $arNewProductParams["property100"] = $arPic; $section_id = $this->process_product_section($data["properties"]["SUB_CATEGORY"],$section_id);
// } }
// } if(!empty($data["properties"]["ПОДКАТЕГОРИЯ2"])){
// } $section_id = $this->process_product_section($data["properties"]["ПОДКАТЕГОРИЯ2"],$section_id);
// } }
$arNewProductParams["iblockSectionId"] = (!empty($section_id)) ? $section_id : 0;
BillzRest::setLog($arNewProductParams); BillzRest::setLog($arNewProductParams);
...@@ -463,16 +458,11 @@ class AloVoiceRest ...@@ -463,16 +458,11 @@ class AloVoiceRest
} }
} }
else { else {
echo '--------------------';
var_dump($arProduct);
echo '--------------------';
$arUpdRes = BxRest::call('catalog.product.update',["id"=>$arProduct["id"] ,"fields"=>$arNewProductParams]); $arUpdRes = BxRest::call('catalog.product.update',["id"=>$arProduct["id"] ,"fields"=>$arNewProductParams]);
if(!empty($arUpdRes["result"]["element"])){
echo '**********************'; $arProduct = $arUpdRes["result"]["element"];
var_dump($arUpdRes); }
echo '*********************';
} }
if(!empty($arProduct["id"]) && !empty($data["price"])){ if(!empty($arProduct["id"]) && !empty($data["price"])){
$arProdPrice = [ $arProdPrice = [
...@@ -489,7 +479,7 @@ class AloVoiceRest ...@@ -489,7 +479,7 @@ class AloVoiceRest
]; ];
$priceRes = BxRest::call('catalog.price.modify',["fields"=>$arProdPrice]); $priceRes = BxRest::call('catalog.price.modify',["fields"=>$arProdPrice]);
var_dump($priceRes);
} }
} }
...@@ -514,46 +504,41 @@ class AloVoiceRest ...@@ -514,46 +504,41 @@ class AloVoiceRest
return $return; return $return;
} }
private function billz_products_all_synch($r=false) { // private function billz_products_all_synch($r=false) {
$tms["0_begin"] = time(); // $tms["0_begin"] = time();
$return = ["result"=>false]; // $return = ["result"=>false];
$date = "2017-01-01T00:00:00Z"; // $date = "2017-01-01T00:00:00Z";
echo "\nBegin loading billz products [date_from:".$date."]..."; // echo "\nBegin loading billz products [date_from:".$date."]...";
$allProds = BillzRest::getProducts($date); // $allProds = BillzRest::getProducts($date);
echo "\n Billz products loaded done!"; // echo "\n Billz products loaded done!";
if(!empty($allProds["answer"]["result"])){ // if(!empty($allProds["answer"]["result"])){
echo "\n Billz begin product saving..."; // echo "\n Billz begin product saving...";
$tms["1_saving"] = time(); // $tms["1_saving"] = time();
$jsProducts = json_encode($allProds); // $jsProducts = json_encode($allProds);
$return["count"] = count($allProds["answer"]["result"]); // $return["count"] = count($allProds["answer"]["result"]);
$return["result"] = file_put_contents(__DIR__."/billz_allproducts.json",$jsProducts); // $return["result"] = file_put_contents(__DIR__."/billz_allproducts.json",$jsProducts);
$tms["2_saved"] = time(); // $tms["2_saved"] = time();
echo "\n Billz products saved!"; // echo "\n Billz products saved!";
} // }
$tms["3_end"] = time(); // $tms["3_end"] = time();
$tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"]; // $tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"];
echo "\n DONE!!"; // echo "\n DONE!!";
$return["times"] = $tms; // $return["times"] = $tms;
return $return; // return $return;
} // }
private function get_byinn($r=false) { private function get_byinn($r=false) {
return ALVC::requesTaxInn($r["inn"]); return ALVC::requesTaxInn($r["inn"]);
} }
private function billz_catalog_infos_synch($r=false) { private function billz_catalog_infos_synch($r=false) {
$p=1;
$ps=10;
$loadedCnt = 0;
$bxlang = 'Ru';
$tms["0_begin"] = time(); $tms["0_begin"] = time();
$arSections = []; $newProductsCnt = 0;
$arSubSections = [];
$arTrdSections = [];
$arOffices = []; $arOffices = [];
$arAllProperties = [ $arAllProperties = [
...@@ -578,8 +563,7 @@ class AloVoiceRest ...@@ -578,8 +563,7 @@ class AloVoiceRest
]; ];
// $sdata = date("Y-m-d")."T".date("H").":00:00Z"; $sdata = self::get_products_last_update(); //"2017-01-01T00:00:00Z";
$sdata = "2017-01-01T00:00:00Z";
$first = BillzRest::getProducts($sdata); $first = BillzRest::getProducts($sdata);
...@@ -591,39 +575,45 @@ class AloVoiceRest ...@@ -591,39 +575,45 @@ class AloVoiceRest
} }
foreach($first["answer"]["result"] as $prd){ foreach($first["answer"]["result"] as $prd){
$prid = false; $this->bx_process_product($prd);
$sid = false; $newProductsCnt++;
if(!empty($prd["properties"]["CATEGORY"])){ }
$rpid = $this->process_product_section($prd["properties"]["CATEGORY"]); self::set_products_last_update();
// if(!in_array($prd["properties"]["CATEGORY"],$arSections)){
// $arSections[] = $prd["properties"]["CATEGORY"]; // foreach($first["answer"]["result"] as $prd){
// $prid = false;
// $sid = false;
// if(!empty($prd["properties"]["CATEGORY"])){
// $rpid = $this->process_product_section($prd["properties"]["CATEGORY"]);
// // if(!in_array($prd["properties"]["CATEGORY"],$arSections)){
// // $arSections[] = $prd["properties"]["CATEGORY"];
// // }
// } // }
}
if(!empty($prd["properties"]["SUB_CATEGORY"])){ // if(!empty($prd["properties"]["SUB_CATEGORY"])){
$sid = $this->process_product_section($prd["properties"]["SUB_CATEGORY"],$rpid); // $sid = $this->process_product_section($prd["properties"]["SUB_CATEGORY"],$rpid);
// if(!in_array($prd["properties"]["SUB_CATEGORY"],$arSubSections)){ // // if(!in_array($prd["properties"]["SUB_CATEGORY"],$arSubSections)){
// $arSubSections[] = $prd["properties"]["SUB_CATEGORY"]; // // $arSubSections[] = $prd["properties"]["SUB_CATEGORY"];
// // }
// } // }
}
if(!empty($prd["properties"]["ПОДКАТЕГОРИЯ2"])){ // if(!empty($prd["properties"]["ПОДКАТЕГОРИЯ2"])){
$this->process_product_section($prd["properties"]["SUB_CATEGORY"],$sid); // $this->process_product_section($prd["properties"]["SUB_CATEGORY"],$sid);
// if(!in_array($prd["properties"]["ПОДКАТЕГОРИЯ2"],$arTrdSections)){ // // if(!in_array($prd["properties"]["ПОДКАТЕГОРИЯ2"],$arTrdSections)){
// $arTrdSections[] = $prd["properties"]["ПОДКАТЕГОРИЯ2"]; // // $arTrdSections[] = $prd["properties"]["ПОДКАТЕГОРИЯ2"];
// // }
// } // }
}
// process offices // // process offices
if(!empty($prd["offices"])){ // if(!empty($prd["offices"])){
foreach($prd["offices"] as $ofc){ // foreach($prd["offices"] as $ofc){
if(!empty($ofc["officeID"]) && !empty($ofc["officeName"]) && empty($arOffices[$ofc["officeID"]])){ // if(!empty($ofc["officeID"]) && !empty($ofc["officeName"]) && empty($arOffices[$ofc["officeID"]])){
$arOffices[$ofc["officeID"]] = $ofc["officeName"]; // $arOffices[$ofc["officeID"]] = $ofc["officeName"];
} // }
} // }
} // }
} // }
} }
$arConf = self::get_billzconf(); $arConf = self::get_billzconf();
...@@ -631,14 +621,31 @@ class AloVoiceRest ...@@ -631,14 +621,31 @@ class AloVoiceRest
self::save_billzconf(["conf"=>$arConf]); self::save_billzconf(["conf"=>$arConf]);
$tms["2_end"] = time(); $tms["2_end"] = time();
$tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"]; $alltime = $tms["3_end"]-$tms["0_begin"];
$return = ["billzprops"=>count($arAllProperties), "categories"=>$arSections, "subcats"=>$arSubSections, "trdcats"=>$arTrdSections, "offices"=>$arOffices, "times"=>$tms]; $return = ["newproducts"=>$newProductsCnt,"billzprops"=>count($arAllProperties), "time"=>$alltime."sec."]; //"categories"=>$arSections, "subcats"=>$arSubSections, "trdcats"=>$arTrdSections, "offices"=>$arOffices,
ALVC::eLog($return,"------ AloVoiceRest :: billz_catalog_infos_synch CRON Done!"); ALVC::eLog($return,"------ AloVoiceRest :: billz_catalog_infos_synch CRON Done!");
return $return; return $return;
} }
private function get_products_last_update() {
$timeFile = self::lasttimefile();
$lastDateTime = "2018-01-01T00:00:00Z";
if(file_exists($timeFile)){
$strTime = file_get_contents($timeFile);
if(!empty($strTime)){
$lastDateTime = $strTime;
}
}
return $lastDateTime;
}
private function set_products_last_update() {
$ldatetime = date("Y-m-d")."T".date("H:i:s")."Z";
$timeFile = self::lasttimefile();
file_put_contents($timeFile,$ldatetime);
}
private function process_product_section($name='',$parent_id=false) { private function process_product_section($name='',$parent_id=false) {
$sid = false; $sid = false;
if(!$sid = $this->bx_get_product_section($name)){ if(!$sid = $this->bx_get_product_section($name)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment