Advertisement
ridwan100

plushUpdate

Jun 12th, 2023 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. $path        = 'Lieferavis/out';
  2.         $fileName    = '50051-2023-01-24-B105529.csv'; // need to change
  3.         $fileContent = $this->FtpService->getFileToFtp($path, $fileName);
  4.         $delimiter   = ';';
  5.         $product_arr = app(\App\Services\Marketplace\ProductService::class)->generateStringToArray($fileContent,$delimiter);
  6.  
  7.         $csv_ean_stock = collect($product_arr)->pluck('geliefert','ean')->toArray();
  8.         $csv_ean_stock = array_map('intval', $csv_ean_stock);  
  9.         foreach(array_chunk(array_keys($csv_ean_stock),1500) as $ean){
  10.  
  11.             $local_mp_products = Product::with(['drmProducts','stockSendLog'])
  12.             ->select('internel_stock','ean','id','old_internel_stock','internel_stock_updated_at','shipping_method')
  13.             ->whereIn('ean',$ean)
  14.             ->where('shipping_method',2)
  15.             ->get();
  16.             foreach($local_mp_products as $product){
  17.  
  18.                 if($product->internel_stock !=  $csv_ean_stock[$product->ean] ){
  19.  
  20.                     $old_stock = $product->internel_stock;
  21.                     $product->atw = 0; 
  22.                     $product->internel_stock             = $csv_ean_stock[$product->ean];
  23.                     $product->old_internel_stock         = $old_stock;
  24.                     $product->internel_stock_updated_at  = \Carbon\Carbon::now();
  25.                     $product->status = ProductStatus::ACTIVE;
  26.                     $product->internel_sync_status = ProductStatus::INTERNAL_SYNC_APPROVED;
  27.                     $drm_products = $product->drmProducts;
  28.                     if(count($drm_products) > 0){
  29.                         $data['stock'] = $csv_ean_stock[$product->ean];
  30.                         app(\App\Services\Marketplace\ProductService::class)->syncDrmProduct($drm_products,$data);
  31.                         info("plush API DRM product sync-".$product->ean);
  32.                     }
  33.                     $fullfillmentLog = $product->stockSendLog;
  34.                     if($fullfillmentLog->send_stock>$csv_ean_stock[$product->ean]){
  35.                         $fullfillmentLog->update([
  36.                             $fullfillmentLog->recived_stock = $csv_ean_stock[$product->ean],
  37.                             $fullfillmentLog->is_left = $fullfillmentLog->send_stock - $csv_ean_stock[$product->ean]
  38.                         ]);
  39.                     }
  40.                      
  41.                     else{
  42.                         $fullfillmentLog->update([
  43.                             $fullfillmentLog->recived_stock = $csv_ean_stock[$product->ean],
  44.                             $fullfillmentLog->is_left = null
  45.                         ]);
  46.                     }    
  47.                     $product->update();
  48.                     info("plush API product sync-".$product->ean);
  49.                     dd('done');
  50.                 }
  51.             }
  52.        
  53.  
  54.        
  55.  
  56.  
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement