Commit af08b763 authored by Kulya's avatar Kulya 😊

Upd alvbx add prods15

parent fe8a0e54
......@@ -16,6 +16,10 @@ class AloVoiceRest
$this->config = $config;
}
public function lasttimefile() {
return __DIR__.'/billzlasttime';
}
public function consoleMethod($r) {
if(!empty($_SERVER['argv'][1])){
$runMethod = strtolower($_SERVER['argv'][1]);
......@@ -308,7 +312,7 @@ class AloVoiceRest
private function bx_process_product($data=[],$full=false) {
$data = json_decode('{
$datasss = json_decode('{
"ID": 1261574,
"name": "*Tahorat va namoz",
"sku": "Q001",
......@@ -434,26 +438,17 @@ class AloVoiceRest
}
}
// if(!empty($data["imageUrls"])){
// 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){
// $arNewProductParams["property100"] = $arPic;
// }
// }
// }
// }
$section_id = (!empty($data["properties"]["CATEGORY"])) ? $this->process_product_section($data["properties"]["CATEGORY"]) : false;
if(!empty($data["properties"]["SUB_CATEGORY"])){
$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);
if(empty($arProduct)){
......@@ -463,17 +458,12 @@ class AloVoiceRest
}
}
else {
echo '--------------------';
var_dump($arProduct);
echo '--------------------';
$arUpdRes = BxRest::call('catalog.product.update',["id"=>$arProduct["id"] ,"fields"=>$arNewProductParams]);
echo '**********************';
var_dump($arUpdRes);
echo '*********************';
if(!empty($arUpdRes["result"]["element"])){
$arProduct = $arUpdRes["result"]["element"];
}
}
if(!empty($arProduct["id"]) && !empty($data["price"])){
$arProdPrice = [
"product" => [
......@@ -489,7 +479,7 @@ class AloVoiceRest
];
$priceRes = BxRest::call('catalog.price.modify',["fields"=>$arProdPrice]);
var_dump($priceRes);
}
}
......@@ -514,46 +504,41 @@ class AloVoiceRest
return $return;
}
private function billz_products_all_synch($r=false) {
$tms["0_begin"] = time();
$return = ["result"=>false];
$date = "2017-01-01T00:00:00Z";
echo "\nBegin loading billz products [date_from:".$date."]...";
$allProds = BillzRest::getProducts($date);
echo "\n Billz products loaded done!";
if(!empty($allProds["answer"]["result"])){
echo "\n Billz begin product saving...";
$tms["1_saving"] = time();
$jsProducts = json_encode($allProds);
$return["count"] = count($allProds["answer"]["result"]);
$return["result"] = file_put_contents(__DIR__."/billz_allproducts.json",$jsProducts);
$tms["2_saved"] = time();
echo "\n Billz products saved!";
}
$tms["3_end"] = time();
$tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"];
echo "\n DONE!!";
$return["times"] = $tms;
return $return;
}
// private function billz_products_all_synch($r=false) {
// $tms["0_begin"] = time();
// $return = ["result"=>false];
// $date = "2017-01-01T00:00:00Z";
// echo "\nBegin loading billz products [date_from:".$date."]...";
// $allProds = BillzRest::getProducts($date);
// echo "\n Billz products loaded done!";
// if(!empty($allProds["answer"]["result"])){
// echo "\n Billz begin product saving...";
// $tms["1_saving"] = time();
// $jsProducts = json_encode($allProds);
// $return["count"] = count($allProds["answer"]["result"]);
// $return["result"] = file_put_contents(__DIR__."/billz_allproducts.json",$jsProducts);
// $tms["2_saved"] = time();
// echo "\n Billz products saved!";
// }
// $tms["3_end"] = time();
// $tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"];
// echo "\n DONE!!";
// $return["times"] = $tms;
// return $return;
// }
private function get_byinn($r=false) {
return ALVC::requesTaxInn($r["inn"]);
}
private function billz_catalog_infos_synch($r=false) {
$p=1;
$ps=10;
$loadedCnt = 0;
$bxlang = 'Ru';
$tms["0_begin"] = time();
$arSections = [];
$arSubSections = [];
$arTrdSections = [];
$newProductsCnt = 0;
$arOffices = [];
$arAllProperties = [
......@@ -578,8 +563,7 @@ class AloVoiceRest
];
// $sdata = date("Y-m-d")."T".date("H").":00:00Z";
$sdata = "2017-01-01T00:00:00Z";
$sdata = self::get_products_last_update(); //"2017-01-01T00:00:00Z";
$first = BillzRest::getProducts($sdata);
......@@ -591,39 +575,45 @@ class AloVoiceRest
}
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"];
// }
}
$this->bx_process_product($prd);
$newProductsCnt++;
}
self::set_products_last_update();
// 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"])){
$sid = $this->process_product_section($prd["properties"]["SUB_CATEGORY"],$rpid);
// if(!in_array($prd["properties"]["SUB_CATEGORY"],$arSubSections)){
// $arSubSections[] = $prd["properties"]["SUB_CATEGORY"];
// }
}
// if(!empty($prd["properties"]["SUB_CATEGORY"])){
// $sid = $this->process_product_section($prd["properties"]["SUB_CATEGORY"],$rpid);
// // if(!in_array($prd["properties"]["SUB_CATEGORY"],$arSubSections)){
// // $arSubSections[] = $prd["properties"]["SUB_CATEGORY"];
// // }
// }
if(!empty($prd["properties"]["ПОДКАТЕГОРИЯ2"])){
$this->process_product_section($prd["properties"]["SUB_CATEGORY"],$sid);
// if(!in_array($prd["properties"]["ПОДКАТЕГОРИЯ2"],$arTrdSections)){
// $arTrdSections[] = $prd["properties"]["ПОДКАТЕГОРИЯ2"];
// }
}
// if(!empty($prd["properties"]["ПОДКАТЕГОРИЯ2"])){
// $this->process_product_section($prd["properties"]["SUB_CATEGORY"],$sid);
// // if(!in_array($prd["properties"]["ПОДКАТЕГОРИЯ2"],$arTrdSections)){
// // $arTrdSections[] = $prd["properties"]["ПОДКАТЕГОРИЯ2"];
// // }
// }
// process offices
if(!empty($prd["offices"])){
foreach($prd["offices"] as $ofc){
if(!empty($ofc["officeID"]) && !empty($ofc["officeName"]) && empty($arOffices[$ofc["officeID"]])){
$arOffices[$ofc["officeID"]] = $ofc["officeName"];
}
}
}
// // process offices
// if(!empty($prd["offices"])){
// foreach($prd["offices"] as $ofc){
// if(!empty($ofc["officeID"]) && !empty($ofc["officeName"]) && empty($arOffices[$ofc["officeID"]])){
// $arOffices[$ofc["officeID"]] = $ofc["officeName"];
// }
// }
// }
}
// }
}
$arConf = self::get_billzconf();
......@@ -631,14 +621,31 @@ class AloVoiceRest
self::save_billzconf(["conf"=>$arConf]);
$tms["2_end"] = time();
$tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"];
$return = ["billzprops"=>count($arAllProperties), "categories"=>$arSections, "subcats"=>$arSubSections, "trdcats"=>$arTrdSections, "offices"=>$arOffices, "times"=>$tms];
$alltime = $tms["3_end"]-$tms["0_begin"];
$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!");
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) {
$sid = false;
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