Skip to content

Commit

Permalink
fix: variant update
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jun 13, 2024
1 parent d83041b commit 8d96789
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions graphql/schemas/Inventory/variant.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type Variant {
html_description: String
sku: String
ean: String
barcode: String
serial_number: String
status: Status
files: [Filesystem]
@paginate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function execute(): Variants

$search = [
'products_id' => $this->variantDto->product->getId(),
'slug' => $this->variantDto->slug ?? Str::slug($this->variantDto->name),
'sku' => $this->variantDto->sku,
'companies_id' => $this->variantDto->product->companies_id,
'apps_id' => $this->variantDto->product->apps_id,
Expand All @@ -56,6 +55,7 @@ public function execute(): Variants
[
'name' => $this->variantDto->name,
'users_id' => $this->user->getId(),
'slug' => $this->variantDto->slug ?? Str::slug($this->variantDto->name),
'description' => $this->variantDto->description,
'short_description' => $this->variantDto->short_description,
'html_description' => $this->variantDto->html_description,
Expand Down
10 changes: 9 additions & 1 deletion src/Domains/Inventory/Variants/Services/VariantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Kanvas\Inventory\Variants\Actions\CreateVariantsAction;
use Kanvas\Inventory\Variants\Actions\UpdateToChannelAction;
use Kanvas\Inventory\Variants\Actions\UpdateToWarehouseAction;
use Kanvas\Inventory\Variants\Actions\UpdateVariantsAction;
use Kanvas\Inventory\Variants\DataTransferObject\VariantChannel as VariantChannelDto;
use Kanvas\Inventory\Variants\DataTransferObject\Variants as VariantsDto;
use Kanvas\Inventory\Variants\DataTransferObject\VariantsWarehouses;
Expand All @@ -41,7 +42,14 @@ public static function createVariantsFromArray(Products $product, array $variant
...$variant,
]);

$variantModel = (new CreateVariantsAction($variantDto, $user))->execute();
$existVariantUpdate = Variants::fromCompany($product->company)->fromApp($product->app)->where('sku', $variantDto->sku)->first();

if (! $existVariantUpdate) {
$variantModel = (new CreateVariantsAction($variantDto, $user))->execute();
} else {
$variantModel = (new UpdateVariantsAction($existVariantUpdate, $variantDto, $user))->execute();
}

$company = $variantDto->product->company;

if (isset($variant['custom_fields']) && ! empty($variant['custom_fields'])) {
Expand Down

0 comments on commit 8d96789

Please sign in to comment.