Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Jobs;
- use App\Entities\ProductImages;
- use Illuminate\Bus\Queueable;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use App\Entities\Product;
- class SendProductsToShopJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- protected $username;
- protected $password;
- protected $url;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->username = config('integration.shop.username');
- $this->password = config('integration.shop.password');
- $this->url = config('integration.shop.url');
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- try {
- $client = \DreamCommerce\ShopAppstoreLib\Client::factory(
- \DreamCommerce\ShopAppstoreLib\Client::ADAPTER_BASIC_AUTH,
- array(
- 'entrypoint' => $this->url,
- 'username' => $this->username,
- 'password' => $this->password
- )
- );
- $resource = new \DreamCommerce\ShopAppstoreLib\Resource\Product($client);
- $products = $this->getProducts();
- $i = 1;
- foreach ($products as $product) {
- if ($product->shop_product_id !== null) {
- $item = $resource->get($product->shop_product_id);
- $i++;
- var_dump($i . ' :' . $product->shop_product_id);
- continue;
- }
- if (isset($item)) {
- if (isset($item->special_offer)) {
- var_dump($i . ' :' . $product->shop_product_id);
- continue;
- }
- if (isset($item->stock)) {
- if ($item->stock->price < $product->price_standard) {
- $data = array(
- 'category_id' => 350,
- 'producer_id' => 35,
- 'translations' => array(
- 'pl_PL' => array(
- 'name' => $product->name,
- 'description' => $product->description,
- 'short_description' => $product->description,
- 'active' => true
- ),
- ),
- 'stock' => array(
- 'price' => $product->price_standard,
- 'price_wholesale' => $product->price_wholesale,
- 'price_special' => $product->price_wholesale2,
- 'warn_level' => '1',
- 'delivery_id' => $product->quantity > 0 ? '1' : '',
- 'active' => 0,
- 'stock' => $product->quantity
- ),
- );
- $result = $resource->put($product->shop_product_id, $data);
- var_dump($product->shop_product_id);
- } else {
- var_dump($i . ' :' . $product->shop_product_id);
- continue;
- }
- } else {
- var_dump($i . ' :' . $product->shop_product_id);
- continue;
- }
- } else {
- if (isset($product->ean)) {
- $ean = substr($product->ean, 0, 13);
- if (strlen($ean) == 12) {
- $ean = 5907589890983;
- }
- $data = array(
- 'category_id' => 350,
- 'producer_id' => 35,
- 'translations' => array(
- 'pl_PL' => array(
- 'name' => $product->name,
- 'description' => $product->description,
- 'short_description' => $product->description,
- 'active' => true
- )
- ),
- 'stock' => array(
- 'price' => $product->price_standard,
- 'price_wholesale' => $product->price_wholesale,
- 'price_special' => $product->price_wholesale2,
- 'warn_level' => '1',
- 'delivery_id' => $product->quantity > 0 ? '1' : '',
- 'active' => 0,
- 'stock' => $product->quantity
- ),
- 'tax_id' => 1,
- 'code' => $product->sku,
- 'additional_producer' => $product->sku,
- 'ean' => $ean != null ? $ean : '5907589890983',
- 'unit_id' => 1,
- );
- var_dump($ean);
- $result = $resource->post($data);
- Product::where('sku', $product->sku)->update([
- 'shop_product_id' => $result,
- 'ean' => $ean
- ]);
- // $resources = new \DreamCommerce\ShopAppstoreLib\Resource\ProductImage($client);
- // $productImages = ProductImages::where('product_id', $product->id)->get();
- // $data = array(
- // 'product_id' => $result,
- // 'file' => $productImages->first->id->filename,
- // 'url' => $productImages->first->id->url,
- // );
- // $status = $resources->post($data);
- }
- }
- }
- } catch (\DreamCommerce\ShopAppstoreLib\Exception\Exception $ex) {
- die($ex->getMessage());
- }
- }
- public
- function getProducts()
- {
- $products = Product::all()->where('wholesaler_id', '=', '1');
- return $products;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement