Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $path = 'Lieferavis/out';
- $fileName = '50051-2023-01-24-B105529.csv'; // need to change
- $fileContent = $this->FtpService->getFileToFtp($path, $fileName);
- $delimiter = ';';
- $product_arr = app(\App\Services\Marketplace\ProductService::class)->generateStringToArray($fileContent,$delimiter);
- $csv_ean_stock = collect($product_arr)->pluck('geliefert','ean')->toArray();
- $csv_ean_stock = array_map('intval', $csv_ean_stock);
- foreach(array_chunk(array_keys($csv_ean_stock),1500) as $ean){
- $local_mp_products = Product::with(['drmProducts','stockSendLog'])
- ->select('internel_stock','ean','id','old_internel_stock','internel_stock_updated_at','shipping_method')
- ->whereIn('ean',$ean)
- ->where('shipping_method',2)
- ->get();
- foreach($local_mp_products as $product){
- if($product->internel_stock != $csv_ean_stock[$product->ean] ){
- $old_stock = $product->internel_stock;
- $product->atw = 0;
- $product->internel_stock = $csv_ean_stock[$product->ean];
- $product->old_internel_stock = $old_stock;
- $product->internel_stock_updated_at = \Carbon\Carbon::now();
- $product->status = ProductStatus::ACTIVE;
- $product->internel_sync_status = ProductStatus::INTERNAL_SYNC_APPROVED;
- $drm_products = $product->drmProducts;
- if(count($drm_products) > 0){
- $data['stock'] = $csv_ean_stock[$product->ean];
- app(\App\Services\Marketplace\ProductService::class)->syncDrmProduct($drm_products,$data);
- info("plush API DRM product sync-".$product->ean);
- }
- $fullfillmentLog = $product->stockSendLog;
- if($fullfillmentLog->send_stock>$csv_ean_stock[$product->ean]){
- $fullfillmentLog->update([
- $fullfillmentLog->recived_stock = $csv_ean_stock[$product->ean],
- $fullfillmentLog->is_left = $fullfillmentLog->send_stock - $csv_ean_stock[$product->ean]
- ]);
- }
- else{
- $fullfillmentLog->update([
- $fullfillmentLog->recived_stock = $csv_ean_stock[$product->ean],
- $fullfillmentLog->is_left = null
- ]);
- }
- $product->update();
- info("plush API product sync-".$product->ean);
- dd('done');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement