Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#212 import order client to customer table #213

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
namespace Nicelizhi\Manage\Console\Commands\Customers;

use Illuminate\Console\Command;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Event;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Sales\Models\Order;


class ImportOrderCustomer extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'manage:customers:import:order';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Impoty the customer from orders';

public function __construct(
protected CustomerRepository $customerRepository
)
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{

$count = Order::count();
$max = 100;
$offset = 0;
$pages = ceil($count / $max);

for($i=0; $i< $pages; $i++) {
$offset = $i * $max;
$items = Order::select(['id'])->offset($offset)->limit($max)->get();

foreach($items as $item) {



// var_dump($item->shipping_address);

$shipping_address = $item->shipping_address;

$this->info("import the customer: ".$shipping_address->email);

//check the email exist
$customer = $this->customerRepository->findOneByField('email', $shipping_address->email);

if($customer) {
continue;
}


$data = [];
$data['email'] = $shipping_address->email;
$data['customer_group_id'] = 2;
$data['first_name'] = $shipping_address->first_name;
$data['last_name'] = $shipping_address->last_name;
$data['gender'] = $shipping_address->gender;
$data['phone'] = $shipping_address->phone;

//var_dump($data);

$this->createCuster($data);
//exit;


}

}

//exit;









// $data = array_merge(request()->only([
// 'first_name',
// 'last_name',
// 'gender',
// 'email',
// 'date_of_birth',
// 'phone',
// 'customer_group_id',
// ]), [
// 'password' => bcrypt($password),
// 'is_verified' => 1,
// ]);




}

public function createCuster($data) {
$password = rand(100000, 10000000);
Event::dispatch('customer.registration.before');

$data = array_merge($data, [
'password' => bcrypt($password),
'is_verified' => 1,
]);

//var_dump($data);exit;

$this->customerRepository->create($data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ protected function createACL()
protected function registerCommands() {
if ($this->app->runningInConsole()) {
$this->commands([
\Nicelizhi\Manage\Console\Commands\Customers\ImportOrderCustomer::class,
]);
}
}
Expand Down
Loading