Skip to content

Commit

Permalink
428. FillPhotoAndUrlInOneCProducts command & minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Aug 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5dc71bb commit b2704c3
Showing 8 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion formaters/pint.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
},
"new_with_parentheses": {
"named_class": true,
"anonymous_class": true
"anonymous_class": false
},
"not_operator_with_successor_space": false,
"nullable_type_declaration_for_default_null_value": {
54 changes: 54 additions & 0 deletions src/app/Console/Commands/OneRun/FillPhotoAndUrlInOneCProducts.php
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();
}
}
14 changes: 14 additions & 0 deletions src/app/Models/OneC/AbstractOneCModel.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,20 @@ abstract class AbstractOneCModel extends Model
*/
protected $connection = 'sqlsrv';

/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'ROW_ID';

/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;

/**
* Auto Trim Field From Database
*
2 changes: 2 additions & 0 deletions src/app/Models/Stock.php
Original file line number Diff line number Diff line change
@@ -24,8 +24,10 @@
* @property string $internal_name
* @property string|null $description
* @property string|null $address
* @property string|null $address_zip Индекс
* @property string|null $worktime Рабочее время
* @property string|null $phone
* @property string|null $contact_person Контактное лицо
* @property bool $has_pickup
* @property float|null $geo_latitude
* @property float|null $geo_longitude
2 changes: 1 addition & 1 deletion src/app/Models/Url.php
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public function filters()
}

/**
* Return ralation model
* Return relation model
*/
public function getFilterModel(): Model
{
3 changes: 3 additions & 0 deletions src/app/Models/User/User.php
Original file line number Diff line number Diff line change
@@ -47,6 +47,9 @@
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Orders\Order[] $orders
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Feedback[] $reviews
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Logs\SmsLog[] $mailings
* @property-read \App\Models\User\UserBlacklist|null $blacklist
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User\UserBlacklist[] $blacklistLogs
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Payments\OnlinePayment[] $payments
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User\UserPromocode[] $usedPromocodes
*
* @mixin \Illuminate\Database\Eloquent\Builder
2 changes: 1 addition & 1 deletion src/app/Models/User/UserBlacklist.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

/**
* @property int $id
* @property int $user_id
* @property int $user_id ID пользователя
* @property string|null $comment Комментарий
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
1 change: 1 addition & 0 deletions src/config/model-doc.php
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
// Ignore models by FQCN
'ignore' => [
\App\Models\OneC\OfflineOrder::class,
\App\Models\OneC\Product::class,
],

'custom_tags' => [

0 comments on commit b2704c3

Please sign in to comment.