Skip to content

Commit

Permalink
Merge pull request #145 from leon-mbs/dev
Browse files Browse the repository at this point in the history
hotfix
  • Loading branch information
leon-mbs authored Apr 6, 2021
2 parents 9409577 + 2e442ab commit 6bfff94
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 151 deletions.
117 changes: 61 additions & 56 deletions www/app/modules/wc/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,73 +261,78 @@ public function onGetItems($sender) {
$common = System::getOptions("common");

$client = \App\Modules\WC\Helper::getClient();


try {
$data = $client->get('products', array('status' => 'publish'));
} catch(\Exception $ee) {
$this->setError($ee->getMessage());
return;
}

// $this->setInfo($json);
$i = 0;
foreach ($data as $product) {

if (strlen($product->sku) == 0) {
continue;
$i = 0;

$page=1;
while(true) {


try {
$data = $client->get('products', array('status' => 'publish','page'=>$page,'per_page'=>100));
} catch(\Exception $ee) {
$this->setError($ee->getMessage());
return;
}
$cnt = Item::findCnt("item_code=" . Item::qstr($product->sku));
if ($cnt > 0) {
continue;
} //уже есть с таким артикулом

$product->name = str_replace('"', '"', $product->name);
$item = new Item();
$item->item_code = $product->sku;
$item->itemname = $product->name;
// $item->description = $product->short_description;
$page++;

$c = count($data) ;
if($c==0) break;
foreach ($data as $product) {

if (strlen($product->sku) == 0) {
continue;
}
$cnt = Item::findCnt("item_code=" . Item::qstr($product->sku));
if ($cnt > 0) {
continue;
} //уже есть с таким артикулом

$product->name = str_replace('"', '"', $product->name);
$item = new Item();
$item->item_code = $product->sku;
$item->itemname = $product->name;
// $item->description = $product->short_description;

if ($modules['wcpricetype'] == 'price1') {
$item->price1 = $product->price;
}
if ($modules['wcpricetype'] == 'price2') {
$item->price2 = $product->price;
}
if ($modules['wcpricetype'] == 'price3') {
$item->price3 = $product->price;
}
if ($modules['wcpricetype'] == 'price4') {
$item->price4 = $product->price;
}
if ($modules['wcpricetype'] == 'price5') {
$item->price5 = $product->price;
}

if ($modules['wcpricetype'] == 'price1') {
$item->price1 = $product->price;
}
if ($modules['wcpricetype'] == 'price2') {
$item->price2 = $product->price;
}
if ($modules['wcpricetype'] == 'price3') {
$item->price3 = $product->price;
}
if ($modules['wcpricetype'] == 'price4') {
$item->price4 = $product->price;
}
if ($modules['wcpricetype'] == 'price5') {
$item->price5 = $product->price;
}

if ($common['useimages'] == 1) {
foreach ($product->images as $im) {

if ($common['useimages'] == 1) {
foreach ($product->images as $im) {
$im = @file_get_contents($im->src);
if (strlen($im) > 0) {
$imagedata = getimagesizefromstring($im);
$image = new \App\Entity\Image();
$image->content = $im;
$image->mime = $imagedata['mime'];

$im = @file_get_contents($im->src);
if (strlen($im) > 0) {
$imagedata = getimagesizefromstring($im);
$image = new \App\Entity\Image();
$image->content = $im;
$image->mime = $imagedata['mime'];
$image->save();
$item->image_id = $image->image_id;
break;
}

$image->save();
$item->image_id = $image->image_id;
break;
}

}
}

$item->save();
$i++;
$item->save();
$i++;
}
}


$this->setSuccess("loaded_items", $i);

}
Expand Down
134 changes: 78 additions & 56 deletions www/app/modules/wc/orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,74 +54,96 @@ public function filterOnSubmit($sender) {
$client = \App\Modules\WC\Helper::getClient();

$this->_neworders = array();
$fields = array(
'status' => 'pending'
);
$page=1;
while(true) {


$fields = array(
'status' => 'pending' ,'per_page'=>100,'page'=>$page
);


try {
$data = $client->get('orders', $fields);
} catch(\Exception $ee) {
$this->setError($ee->getMessage());
return;
}

foreach ($data as $wcorder) {

$isorder = Document::findCnt("meta_name='Order' and content like '%<wcorder>{$wcorder->id}</wcorder>%'");
if ($isorder > 0) { //уже импортирован
continue;
try {
$data = $client->get('orders', $fields);
} catch(\Exception $ee) {
$this->setError($ee->getMessage());
return;
}
$fields = array(
'status' => 'on-hold' ,'per_page'=>100,'page'=>$page
);

$neworder = Document::create('Order');
$neworder->document_number = $neworder->nextNumber();
if (strlen($neworder->document_number) == 0) {
$neworder->document_number = 'WC00001';
}
$neworder->customer_id = $modules['wccustomer_id'];

//товары
$itlist = array();
foreach ($wcorder->line_items as $product) {
//ищем по артикулу
if (strlen($product->sku) == 0) {
try {
$data2 = $client->get('orders', $fields);
} catch(\Exception $ee) {
$this->setError($ee->getMessage());
return;
}
if(is_array($data) && is_array($data2)) {
$data = array_merge($data,$data2) ;
}
$page++;

$c = count($data) ;
if($c==0) break;

foreach ($data as $wcorder) {

$isorder = Document::findCnt("meta_name='Order' and content like '%<wcorder>{$wcorder->id}</wcorder>%'");
if ($isorder > 0) { //уже импортирован
continue;
}
$code = Item::qstr($product->sku);

$tovar = Item::getFirst('item_code=' . $code);
if ($tovar == null) {

$this->setWarn("nofoundarticle_inorder", $product->name, $wcorder->order_id);
continue;
$neworder = Document::create('Order');
$neworder->document_number = $neworder->nextNumber();
if (strlen($neworder->document_number) == 0) {
$neworder->document_number = 'WC00001';
}
$tovar->quantity = $product->quantity;
$tovar->price = round($product->price);

$itlist[] = $tovar;
}
$neworder->packDetails('detaildata', $itlist);

$neworder->headerdata['wcorder'] = $wcorder->id;
$neworder->headerdata['wcorderback'] = 0;
$neworder->headerdata['wcclient'] = $wcorder->shipping->first_name . ' ' . $wcorder->shipping->last_name;
$neworder->amount = round($wcorder->total);
$neworder->document_date = time();
$neworder->notes = "WC номер:{$wcorder->id};";
$neworder->notes .= " Клиент:" . $wcorder->shipping->first_name . ' ' . $wcorder->shipping->last_name . ";";
if (strlen($wcorder->billing->email) > 0) {
$neworder->notes .= " Email:" . $wcorder->billing->email . ";";
}
if (strlen($wcorder->billing->phone) > 0) {
$neworder->notes .= " Тел:" . $wcorder->billing->phone . ";";
}
$neworder->notes .= " Адрес:" . $wcorder->shipping->city . ' ' . $wcorder->shipping->address_1 . ";";
$neworder->notes .= " Комментарий:" . $wcorder->customer_note . ";";
$neworder->customer_id = $modules['wccustomer_id'];

//товары
$itlist = array();
foreach ($wcorder->line_items as $product) {
//ищем по артикулу
if (strlen($product->sku) == 0) {
continue;
}
$code = Item::qstr($product->sku);

$tovar = Item::getFirst('item_code=' . $code);
if ($tovar == null) {

$this->setWarn("nofoundarticle_inorder", $product->name, $wcorder->order_id);
continue;
}
$tovar->quantity = $product->quantity;
$tovar->price = round($product->price);

$itlist[] = $tovar;
}
$neworder->packDetails('detaildata', $itlist);

$neworder->headerdata['wcorder'] = $wcorder->id;
$neworder->headerdata['wcorderback'] = 0;
$neworder->headerdata['wcclient'] = $wcorder->shipping->first_name . ' ' . $wcorder->shipping->last_name;
$neworder->amount = round($wcorder->total);
$neworder->document_date = time();
$neworder->notes = "WC номер:{$wcorder->id};";
$neworder->notes .= " Клиент:" . $wcorder->shipping->first_name . ' ' . $wcorder->shipping->last_name . ";";
if (strlen($wcorder->billing->email) > 0) {
$neworder->notes .= " Email:" . $wcorder->billing->email . ";";
}
if (strlen($wcorder->billing->phone) > 0) {
$neworder->notes .= " Тел:" . $wcorder->billing->phone . ";";
}
$neworder->notes .= " Адрес:" . $wcorder->shipping->city . ' ' . $wcorder->shipping->address_1 . ";";
$neworder->notes .= " Комментарий:" . $wcorder->customer_note . ";";


$this->_neworders[] = $neworder;
$this->_neworders[] = $neworder;
}
}

$this->neworderslist->Reload();

}
Expand Down
Loading

0 comments on commit 6bfff94

Please sign in to comment.