Skip to content

Commit

Permalink
369. product stub for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Jun 2, 2024

Verified

This commit was signed with the committer’s verified signature.
dchassin David P. Chassin
1 parent 8adf0f8 commit 5b06077
Showing 4 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/app/Http/Controllers/DebugController.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Jobs\OneC\UpdateOfflineOrdersJob;
use App\Models\Orders\OfflineOrder;
use App\Models\Orders\Order;
use App\Models\User\User;
use App\Services\Order\OrderItemInventoryService;
@@ -16,7 +17,7 @@ public function index()
{
// (new OrderItemInventoryService)->outOfStock(1426);

// UpdateOfflineOrdersJob::dispatchSync();
// (new UpdateOfflineOrdersJob)->notify(OfflineOrder::query()->find(26167));

return 'ok';
}
Original file line number Diff line number Diff line change
@@ -338,6 +338,7 @@ protected function updateAvailableSizesFromOrders(array &$availableSizes): int
$productsInOrdersDebug = [];
$sizesCount = OrderItem::query()
->whereIn('status_key', ['new', 'reserved', 'confirmed', 'collect', 'pickup'])
->whereHas('statusLog')
->with('statusLog:order_item_id,stock_id')
->get(['id', 'product_id', 'size_id', 'count'])
->each(function (OrderItem $orderItem) use (&$productsInOrders, &$productsInOrdersDebug) {
25 changes: 20 additions & 5 deletions src/app/Jobs/OneC/UpdateOfflineOrdersJob.php
Original file line number Diff line number Diff line change
@@ -4,10 +4,12 @@

use App\Jobs\AbstractJob;
use App\Models\Bots\Telegram\TelegramChat;
use App\Models\Brand;
use App\Models\Logs\OrderItemStatusLog;
use App\Models\OneC\OfflineOrder as OfflineOrder1C;
use App\Models\Orders\OfflineOrder;
use App\Models\Orders\OrderItem;
use App\Models\Product;
use App\Models\Stock;
use App\Models\User\User;
use App\Notifications\OrderItemInventoryNotification;
@@ -178,11 +180,9 @@ private function notify(OfflineOrder $offlineOrder): void
}

$notification = new OrderItemStatusLog(['stock_id' => $offlineOrder->stock_id]);
$orderItem = (new OrderItem([
'product_id' => $offlineOrder->product_id,
'size_id' => $offlineOrder->size_id,
'status_key' => 'complete',
]))->setRelation('inventoryNotification', $notification);
$orderItem = (new OrderItem(['size_id' => $offlineOrder->size_id, 'status_key' => 'complete']))
->setRelation('product', $this->getProductFromOfflineOrder($offlineOrder))
->setRelation('inventoryNotification', $notification);

$chat->notifyNow(new OrderItemInventoryNotification($orderItem));
}
@@ -204,4 +204,19 @@ private function getChatByStockId(int $stockId): ?TelegramChat
{
return $this->stocks[$stockId]?->groupChat;
}

private function getProductFromOfflineOrder(OfflineOrder $offlineOrder): Product
{
if ($offlineOrder->product) {
return $offlineOrder->product;
}

$product = new Product([
'id' => $offlineOrder->one_c_product_id,
'sku' => $offlineOrder->sku,
]);
$product->setRelation('brand', new Brand(['name' => 'Нет на сайте -']));

return $product;
}
}
12 changes: 12 additions & 0 deletions src/app/Models/Product.php
Original file line number Diff line number Diff line change
@@ -291,6 +291,18 @@ public function getFallbackMediaUrl(string $collectionName = 'default', string $
};
}

/**
* Get the fallback media path.
*/
public function getFallbackMediaPath(string $collectionName = 'default', string $conversionName = ''): string
{
return match ($conversionName) {
'thumb' => public_path('/images/no-image-100.png'),
'catalog' => public_path('/images/no-image-300.png'),
default => public_path('/images/no-image.png'),
};
}

/**
* Сортировка товаров
*

0 comments on commit 5b06077

Please sign in to comment.