log
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Order as AppOrder;
|
|||||||
use Codexshaper\WooCommerce\Facades\Order;
|
use Codexshaper\WooCommerce\Facades\Order;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
class OrderUpdateGm extends Command
|
class OrderUpdateGm extends Command
|
||||||
{
|
{
|
||||||
@@ -42,35 +43,70 @@ class OrderUpdateGm extends Command
|
|||||||
{
|
{
|
||||||
$all_orderswoo = new Collection();
|
$all_orderswoo = new Collection();
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
$orderupdated = 0;
|
||||||
do{
|
do{
|
||||||
$orderswoo = Order::all($options = ['per_page' => 100, 'page' => $page,'status'=> ["pending","processing","on-hold"]]);
|
$orderswoo = Order::all($options = ['per_page' => 100, 'page' => $page,'status'=> ["pending","processing","on-hold"]]);
|
||||||
$all_orderswoo = $all_orderswoo->merge($orderswoo);
|
$all_orderswoo = $all_orderswoo->merge($orderswoo);
|
||||||
$page++;
|
$page++;
|
||||||
} while($orderswoo->count() > 0);
|
} while($orderswoo->count() > 0);
|
||||||
|
|
||||||
|
|
||||||
foreach($all_orderswoo as $orderwoo ){
|
foreach($all_orderswoo as $orderwoo ){
|
||||||
|
$this->info("Processing order #{$orderwoo->id}...");
|
||||||
$ordergm = AppOrder::where('IdInternet', $orderwoo->id)->latest('DataOra')->first();
|
$ordergm = AppOrder::where('IdInternet', $orderwoo->id)->latest('DataOra')->first();
|
||||||
if($ordergm){
|
if($ordergm){
|
||||||
|
$this->info("Order #{$orderwoo->id} found in GM, checking status...");
|
||||||
if($orderwoo->status == 'processing'){
|
if($orderwoo->status == 'processing'){
|
||||||
if($ordergm->EnabledWoo == 1){
|
$this->info("Order #{$orderwoo->id} is processing, checking if it needs to be completed...");
|
||||||
$data = [
|
if($ordergm->EnabledWoo == 1){
|
||||||
'status' => 'completed',
|
$this->info("Order #{$orderwoo->id} needs to be completed, updating WooCommerce...");
|
||||||
];
|
$data = [
|
||||||
$orderwooupdate = Order::update($orderwoo->id,$data);
|
'status' => 'completed',
|
||||||
}
|
];
|
||||||
}
|
$orderwooupdate = Order::update($orderwoo->id,$data);
|
||||||
elseif ($orderwoo->status == 'on-hold'){
|
|
||||||
|
|
||||||
if($ordergm->FlagSospeso == 0) {
|
// sum the number updated of order to the log
|
||||||
$data = [
|
$orderupdated++;
|
||||||
'status' => 'processing',
|
|
||||||
];
|
}
|
||||||
$orderwooupdate = Order::update($orderwoo->id,$data);
|
|
||||||
}
|
}
|
||||||
|
elseif ($orderwoo->status == 'on-hold'){
|
||||||
|
$this->info("Order #{$orderwoo->id} is on-hold, checking if it needs to be processed...");
|
||||||
|
if($ordergm->FlagSospeso == 0) {
|
||||||
|
$this->info("Order #{$orderwoo->id} needs to be processed, updating WooCommerce...");
|
||||||
|
$data = [
|
||||||
|
'status' => 'processing',
|
||||||
|
];
|
||||||
|
$orderwooupdate = Order::update($orderwoo->id,$data);
|
||||||
|
|
||||||
|
// sum the number updated of order to the log
|
||||||
|
$orderupdated++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
$this->info("Order #{$orderwoo->id} not found in GM, skipping...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the directory actual name and put in the log file
|
||||||
|
$dir = basename(__DIR__);
|
||||||
|
|
||||||
|
$log = $dir . ' Ordini aggiornati' . "\n";
|
||||||
|
|
||||||
|
// check if there are orders to log
|
||||||
|
if($orderupdated > 0) {
|
||||||
|
// Send the email to the admin with the details of the order log
|
||||||
|
Mail::raw($log, function ($message, $orderupdated) {
|
||||||
|
$message->to("log@fioredellavita.it");
|
||||||
|
//$message->bcc('');
|
||||||
|
$message->subject("Ordini Aggiornati su GM:" . $orderupdated);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user