Skip to content

Commit

Permalink
create channel service to update channel variant
Browse files Browse the repository at this point in the history
  • Loading branch information
arfenis committed Jun 11, 2024
1 parent 72ad0ed commit c9ab6f3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Domains/Inventory/Channels/Services/ChannelService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Kanvas\Inventory\Channels\Services;

use Kanvas\Inventory\Channels\Repositories\ChannelRepository;
use Kanvas\Inventory\Variants\DataTransferObject\VariantChannel;
use Kanvas\Inventory\Variants\Models\Variants;
use Kanvas\Inventory\Variants\Services\VariantService;
use Kanvas\Inventory\Warehouses\Repositories\WarehouseRepository;

class ChannelService
{
/**
* Update data of variant in a variant channel.
*/
public static function updateChannelVariant(Variants $variant, array $variantsChannels): Variants
{
$variant->variantChannels()->forcedelete();
foreach ($variantsChannels as $variantChannel) {
$warehouse = WarehouseRepository::getById((int) $variantChannel['warehouses_id']);
$channel = ChannelRepository::getById((int) $variantChannel['channels_id'],$variant->product->company()->get()->first());
$variantChannelDto = VariantChannel::from($variantChannel);

VariantService::addVariantChannel(
$variant,
$warehouse,
$channel,
$variantChannelDto
);
}

return $variant;
}

}

0 comments on commit c9ab6f3

Please sign in to comment.