| <?php |
| <?php |
| |
| |
| namespace App\Jobs; |
| namespace App\Jobs; |
| |
| |
| require_once(dirname(__FILE__).'/../../vendor/autoload.php'); |
| require_once(dirname(__FILE__).'/../../vendor/autoload.php'); |
| |
| |
| use Illuminate\Bus\Queueable; |
| use Illuminate\Bus\Queueable; |
| use Illuminate\Queue\SerializesModels; |
| use Illuminate\Queue\SerializesModels; |
| use Illuminate\Queue\InteractsWithQueue; |
| use Illuminate\Queue\InteractsWithQueue; |
| use Illuminate\Contracts\Queue\ShouldQueue; |
| use Illuminate\Contracts\Queue\ShouldQueue; |
| use Illuminate\Foundation\Bus\Dispatchable; |
| use Illuminate\Foundation\Bus\Dispatchable; |
| use Illuminate\Support\Facades\File; |
| use Illuminate\Support\Facades\File; |
| use Config; |
| use Config; |
| use Log; |
| use Log; |
| |
| |
| use OhMyBrew\BasicShopifyAPI; |
| use OhMyBrew\BasicShopifyAPI; |
| |
| |
| |
| |
| class CreateShopifyCustomerJob implements ShouldQueue |
| class CreateShopifyCustomerJob implements ShouldQueue |
| { |
| { |
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
| |
| |
| public $email; |
| public $email; |
| public $userName; |
| public $userName; |
| . | |
| public $shopify_api_version; |
| /** |
| /** |
| * Create a new job instance. |
| * Create a new job instance. |
| * |
| * |
| * @return void |
| * @return void |
| */ |
| */ |
| public function __construct($email, $userName) |
| public function __construct($email, $userName) |
| { |
| { |
| // |
| // |
| $this->email = $email; |
| $this->email = $email; |
| $this->userName = $userName; |
| $this->userName = $userName; |
| . | |
| $this->shopify_api_version = env('SHOPIFY_API_VERSION', true); |
| } |
| } |
| |
| |
| /** |
| /** |
| * Execute the job. |
| * Execute the job. |
| * @return void |
| * @return void |
| */ |
| */ |
| public function handle() |
| public function handle() |
| { |
| { |
| |
| |
| $api = new BasicShopifyAPI(); |
| $api = new BasicShopifyAPI(); |
| |
| |
| $password = Config::get('shopify.password'); |
| $password = Config::get('shopify.password'); |
| $shopDomain = Config::get('shopify.shopDomain'); |
| $shopDomain = Config::get('shopify.shopDomain'); |
| |
| |
| $api->setShop($shopDomain); |
| $api->setShop($shopDomain); |
| $api->setAccessToken($password); |
| $api->setAccessToken($password); |
| |
| |
| $params = array( |
| $params = array( |
| 'customer' => array( |
| 'customer' => array( |
| 'email' => $this->email, |
| 'email' => $this->email, |
| 'first_name' => $this->userName |
| 'first_name' => $this->userName |
| ) |
| ) |
| ); |
| ); |
| |
| |
| // Log::info(print_r($params)); |
| // Log::info(print_r($params)); |
| |
| |
| . | $result = $api->rest('POST', '/admin/customers.json', $params); |
| $result = $api->rest('POST', '/admin/api/'.$this->shopify_api_version.'/customers.json', $params); |
| |
| |
| if(empty($result->errors)) //success |
| if(empty($result->errors)) //success |
| { |
| { |
| // TO DO |
| // TO DO |
| } |
| } |
| else //error |
| else //error |
| { |
| { |
| // TO DO |
| // TO DO |
| } |
| } |
| |
| |
| } |
| } |
| } |
| } |
| |
| |