-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
428.
FillPhotoAndUrlInOneCProducts
command & minor improvements
- Loading branch information
1 parent
5dc71bb
commit b2704c3
Showing
8 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/app/Console/Commands/OneRun/FillPhotoAndUrlInOneCProducts.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\OneRun; | ||
|
||
use App\Models\OneC\Product as ProductFromOneC; | ||
use App\Models\Product; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class FillPhotoAndUrlInOneCProducts extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'one-run:fill-photo-and-url-in-one-c-products'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Fills in images and links to products in 1C'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$productsQuery = Product::withTrashed()->whereNotNull('one_c_id'); | ||
|
||
$bar = $this->output->createProgressBar($productsQuery->count()); | ||
|
||
$productsQuery | ||
->with(['category', 'productFromOneC', 'media']) | ||
->select(['id', 'one_c_id', 'slug', 'category_id']) | ||
->chunk(200, function (Collection $chunk) use ($bar) { | ||
$chunk->each(function (Product $product) use ($bar) { | ||
/** @var ProductFromOneC $productFromOneC */ | ||
if ($productFromOneC = $product->productFromOneC) { | ||
$productFromOneC->update([ | ||
'SP6111' => url($product->getUrl()), | ||
'SP6116' => $product->getFirstMediaUrl(conversionName: 'catalog'), | ||
]); | ||
} | ||
$bar->advance(); | ||
}); | ||
}); | ||
|
||
$bar->finish(); | ||
$this->output->newLine(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters