From a401e0c7a9745417ba08b435c1ad6c0cfef07621 Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:21:55 -0400 Subject: [PATCH 01/24] Update product varaitns warehouses primary/foreing --- ...035_update_product_variants_warehouses.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php diff --git a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php new file mode 100644 index 000000000..3ac11d005 --- /dev/null +++ b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php @@ -0,0 +1,41 @@ +dropForeign('products_variants_warehouses_warehouses_id_foreign'); + $table->dropForeign('products_variants_warehouses_products_variants_id_foreign'); + + $table->dropPrimary(); + Schema::enableForeignKeyConstraints(); + }); + + Schema::table('products_variants_warehouses', function (Blueprint $table) { + Schema::disableForeignKeyConstraints(); + $table->id()->first(); + $table->foreign('products_variants_id')->references('id')->on('products_variants'); + $table->foreign('warehouses_id')->references('id')->on('warehouses'); + $table->unique(['products_variants_id', 'warehouses_id']); + Schema::enableForeignKeyConstraints(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; From 0641e16670d11d8a0bb171d80011794de8300e1d Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:22:12 -0400 Subject: [PATCH 02/24] Update product varaitns channels primary/foreing --- ...64405_update_product_variants_channels.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php diff --git a/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php b/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php new file mode 100644 index 000000000..13bd9bee4 --- /dev/null +++ b/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php @@ -0,0 +1,46 @@ +dropForeign('products_variants_channels_products_variants_id_foreign'); + $table->dropForeign('products_variants_channels_warehouses_id_foreign'); + $table->dropForeign('products_variants_channels_channels_id_foreign'); + $table->dropPrimary(); + $table->dropColumn(['products_variants_id', 'warehouses_id']); + + Schema::enableForeignKeyConstraints(); + }); + + Schema::table('products_variants_channels', function (Blueprint $table) { + Schema::disableForeignKeyConstraints(); + + $table->bigInteger('product_variants_warehouse_id')->unsigned()->after('channels_id'); + $table->foreign('product_variants_warehouse_id')->references('id')->on('products_variants_warehouses'); + $table->foreign('channels_id')->references('id')->on('channels'); + + $table->unique(['product_variants_warehouse_id', 'channels_id'], 'variants_warehouse_channel'); + Schema::enableForeignKeyConstraints(); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; From 06d05b0aa8867b16bd85f5d225be56ed8f6d0bdb Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:23:43 -0400 Subject: [PATCH 03/24] Change channel relation using variant warehouse --- graphql/schemas/Inventory/variant.graphql | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index 61506a830..c4f46dfb8 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -1,5 +1,5 @@ type Variant { - id: Int + id: ID uuid: String! slug: String! products_id: Int! @@ -19,13 +19,13 @@ type Variant { product: Product warehouses: [WarehouseVariantRelationship] attributes: [VariantsAttributes] - channels: [VariantChannelRelationship] companies: Company } type WarehouseVariantRelationship { - id: Int! - uuid: String! + id: ID! + warehouseinfo: Warehouse @hasMany(relation: "warehouse") + channels: [VariantChannelRelationship] quantity: Float price: Float sku: String @@ -39,14 +39,14 @@ type WarehouseVariantRelationship { can_pre_order: Boolean is_coming_soon: Boolean is_new: Boolean - is_variant_published: Boolean + is_published: Boolean } type VariantsAttributes { name: String! value: Mixed } type VariantChannelRelationship { - warehouses_id: Int + name: String price: Float discounted_price: Float is_published: Boolean @@ -88,6 +88,7 @@ input VariantsInput { price: Float source_id: Mixed attributes: [VariantsAttributesInput] + warehouse_id: Int } input VariantsUpdateInput { products_id: Int From 3e050ac14230c9d0f87be12cbea670adaee72cdf Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:24:32 -0400 Subject: [PATCH 04/24] Get Variantwarehouse on add to channel --- app/GraphQL/Inventory/Mutations/Variants/Variants.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/GraphQL/Inventory/Mutations/Variants/Variants.php b/app/GraphQL/Inventory/Mutations/Variants/Variants.php index a2849ed2d..48af2a000 100644 --- a/app/GraphQL/Inventory/Mutations/Variants/Variants.php +++ b/app/GraphQL/Inventory/Mutations/Variants/Variants.php @@ -14,6 +14,7 @@ use Kanvas\Inventory\Variants\DataTransferObject\Variants as VariantDto; use Kanvas\Inventory\Variants\DataTransferObject\VariantsWarehouses; use Kanvas\Inventory\Variants\Models\Variants as VariantModel; +use Kanvas\Inventory\Variants\Models\VariantsWarehouses as ModelsVariantsWarehouses; use Kanvas\Inventory\Variants\Repositories\VariantsRepository; use Kanvas\Inventory\Warehouses\Repositories\WarehouseRepository; @@ -143,11 +144,15 @@ public function removeAttribute(mixed $root, array $req): VariantModel public function addToChannel(mixed $root, array $req): VariantModel { $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); - $warehouse = WarehouseRepository::getById($req['warehouses_id']); + + $variantWarehouses = ModelsVariantsWarehouses::where('products_variants_id', $variant->getId()) + ->where('warehouses_id', $warehouse->getId()) + ->firstOrFail(); + $channel = ChannelRepository::getById($req['channels_id']); $variantChannel = VariantChannel::from($req['input']); - (new AddVariantToChannel($variant, $channel, $warehouse, $variantChannel))->execute(); + (new AddVariantToChannel($variantWarehouses, $channel, $variantChannel))->execute(); return $variant; } From cd791f1f5e3ffe9f145ac337d6b2767f533fba6b Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:24:56 -0400 Subject: [PATCH 05/24] Add variant warehouse to channel --- .../Variants/Actions/AddVariantToChannel.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Inventory/Variants/Actions/AddVariantToChannel.php b/src/Inventory/Variants/Actions/AddVariantToChannel.php index b20d61648..a309ea497 100644 --- a/src/Inventory/Variants/Actions/AddVariantToChannel.php +++ b/src/Inventory/Variants/Actions/AddVariantToChannel.php @@ -7,39 +7,36 @@ use Kanvas\Inventory\Channels\Models\Channels; use Kanvas\Inventory\Variants\DataTransferObject\VariantChannel; use Kanvas\Inventory\Variants\Models\Variants; -use Kanvas\Inventory\Warehouses\Models\Warehouses; +use Kanvas\Inventory\Variants\Models\VariantsWarehouses; class AddVariantToChannel { public function __construct( - protected Variants $variants, + protected VariantsWarehouses $variantsWarehouses, protected Channels $channel, - protected Warehouses $warehouse, protected VariantChannel $variantChannel ) { } public function execute(): Variants { - if ($this->variants->channels()->find($this->channel->getId())) { - $this->variants->channels()->syncWithoutDetaching([ + if ($this->variantsWarehouses->channels()->find($this->channel->getId())) { + $this->variantsWarehouses->channels()->syncWithoutDetaching([ $this->channel->getId() => [ - 'warehouses_id' => $this->warehouse->getId(), 'price' => $this->variantChannel->price, 'discounted_price' => $this->variantChannel->discounted_price, 'is_published' => $this->variantChannel->is_published, ] ]); } else { - $this->variants->channels()->attach([ + $this->variantsWarehouses->channels()->attach([ $this->channel->getId() => [ - 'warehouses_id' => $this->warehouse->getId(), 'price' => $this->variantChannel->price, 'discounted_price' => $this->variantChannel->discounted_price, 'is_published' => $this->variantChannel->is_published, ] ]); } - return $this->variants; + return $this->variantsWarehouses->variant; } } From 66f8e7ea5a82ee77c319f20322150db72d090f69 Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:25:27 -0400 Subject: [PATCH 06/24] Add warehouse id to variant dto creation --- src/Inventory/Variants/DataTransferObject/Variants.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Inventory/Variants/DataTransferObject/Variants.php b/src/Inventory/Variants/DataTransferObject/Variants.php index e9eb9c206..6308f919a 100644 --- a/src/Inventory/Variants/DataTransferObject/Variants.php +++ b/src/Inventory/Variants/DataTransferObject/Variants.php @@ -14,6 +14,7 @@ public function __construct( public Products $product, public string $name, public string $description, + public int $warehouse_id, public ?string $short_description = null, public ?string $html_description = null, public ?string $sku = null, @@ -31,6 +32,7 @@ public static function viaRequest(array $request): self ProductsRepository::getById($request['products_id'], auth()->user()->getCurrentCompany()), $request['name'], $request['description'] ?? '', + $request['warehouse_id'], $request['short_description'] ?? null, $request['html_description'] ?? null, $request['sku'] ?? null, From d8252f836566fc9ae846fcaeb8f7db4bb0660586 Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:26:33 -0400 Subject: [PATCH 07/24] Renew variant warehouses attributes --- src/Inventory/Variants/Models/Variants.php | 49 ++-------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/src/Inventory/Variants/Models/Variants.php b/src/Inventory/Variants/Models/Variants.php index a2a90602e..cc124e3e9 100644 --- a/src/Inventory/Variants/Models/Variants.php +++ b/src/Inventory/Variants/Models/Variants.php @@ -9,9 +9,9 @@ use Baka\Users\Contracts\UserInterface; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Kanvas\Apps\Models\Apps; use Kanvas\Inventory\Attributes\Models\Attributes; -use Kanvas\Inventory\Channels\Models\Channels; use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributesDto; use Kanvas\Inventory\Attributes\Actions\CreateAttribute; use Kanvas\Inventory\Variants\Actions\AddAttributeAction; @@ -92,33 +92,9 @@ public function product(): BelongsTo return $this->belongsTo(Products::class, 'products_id'); } - /** - * The warehouses that belong to the Variants. - */ - public function warehouses(): BelongsToMany + public function warehouses(): HasMany { - return $this->belongsToMany( - Warehouses::class, - 'products_variants_warehouses', - 'products_variants_id', - 'warehouses_id' - ) - ->withPivot( - 'quantity', - 'price', - 'sku', - 'position', - 'serial_number', - 'is_oversellable', - 'is_default', - 'is_default', - 'is_best_seller', - 'is_on_sale', - 'is_on_promo', - 'can_pre_order', - 'is_new', - 'is_published' - ); + return $this->hasMany(VariantsWarehouses::class, 'products_variants_id'); } /** @@ -135,25 +111,6 @@ public function attributes(): BelongsToMany ->withPivot('value'); } - /** - * channels. - */ - public function channels(): BelongsToMany - { - return $this->belongsToMany( - Channels::class, - VariantsChannels::class, - 'products_variants_id', - 'channels_id' - ) - ->withPivot( - 'price', - 'discounted_price', - 'is_published', - 'warehouses_id' - ); - } - /** * Add/create new attributes from a variant. * From 5b8e14fb39a7827a336715aa168cb068ba1d639a Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:26:52 -0400 Subject: [PATCH 08/24] Change primary and add channel relation --- src/Inventory/Variants/Models/VariantsChannels.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Inventory/Variants/Models/VariantsChannels.php b/src/Inventory/Variants/Models/VariantsChannels.php index a60f724c1..515160f2f 100644 --- a/src/Inventory/Variants/Models/VariantsChannels.php +++ b/src/Inventory/Variants/Models/VariantsChannels.php @@ -5,6 +5,8 @@ namespace Kanvas\Inventory\Variants\Models; use Baka\Traits\HasCompositePrimaryKeyTrait; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Kanvas\Inventory\Channels\Models\Channels; use Kanvas\Inventory\Models\BaseModel; /** @@ -25,12 +27,16 @@ class VariantsChannels extends BaseModel protected $table = 'products_variants_channels'; protected $guarded = [ - 'products_variants_id', + 'product_variants_warehouse_id', 'channels_id', - 'warehouses_id', 'price', 'discount_price' ]; - protected $primaryKey = ['products_variants_id', 'channels_id', 'warehouses_id']; + protected $primaryKey = ['product_variants_warehouse_id', 'channels_id']; + + public function channel(): BelongsTo + { + return $this->belongsTo(Channels::class, 'channels_id'); + } } From 03ad643d6e84120dd113fbc7b380469228033ae0 Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:27:22 -0400 Subject: [PATCH 09/24] Add warehouse to variant creation --- src/Inventory/Variants/Services/Variants.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Inventory/Variants/Services/Variants.php b/src/Inventory/Variants/Services/Variants.php index b7d00dcb9..b80221529 100644 --- a/src/Inventory/Variants/Services/Variants.php +++ b/src/Inventory/Variants/Services/Variants.php @@ -8,6 +8,7 @@ use Kanvas\Inventory\Products\Models\Products; use Kanvas\Inventory\Variants\DataTransferObject\Variants as VariantsDto; use Kanvas\Inventory\Variants\Actions\CreateVariantsAction; +use Kanvas\Inventory\Warehouses\Repositories\WarehouseRepository; class Variants { @@ -34,6 +35,10 @@ public static function createVariantsFromArray(Products $product, array $variant $variantModel->addAttributes($user, $variant['attributes']); } + if (isset($variant['warehouse_id'])) { + WarehouseRepository::getById($variantDto->warehouse_id, $variantDto->product->company()->get()->first()); + $variantModel->warehouses()->attach($variantDto->warehouse_id); + } $variantsData[] = $variantModel; } From e40c4f8213d23d2438895246a9a7a0de4dce931e Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 14:27:40 -0400 Subject: [PATCH 10/24] Set variant and warehouses relations on model --- .../Variants/Models/VariantsWarehouses.php | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/Inventory/Variants/Models/VariantsWarehouses.php b/src/Inventory/Variants/Models/VariantsWarehouses.php index 8e022f728..e5010426a 100644 --- a/src/Inventory/Variants/Models/VariantsWarehouses.php +++ b/src/Inventory/Variants/Models/VariantsWarehouses.php @@ -4,8 +4,12 @@ namespace Kanvas\Inventory\Variants\Models; -use Baka\Traits\HasCompositePrimaryKeyTrait; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Kanvas\Inventory\Channels\Models\Channels; use Kanvas\Inventory\Models\BaseModel; +use Kanvas\Inventory\Warehouses\Models\Warehouses; /** * Class Variants Warehouse. @@ -33,28 +37,34 @@ */ class VariantsWarehouses extends BaseModel { - use HasCompositePrimaryKeyTrait; - protected $table = 'products_variants_warehouses'; - protected $guarded = [ - 'products_variants_id', - 'warehouses_id', - 'quantity', - 'price', - 'sku', - 'position', - 'serial_number', - 'is_default', - 'is_oversellable', - 'is_default', - 'is_best_seller', - 'is_on_sale', - 'is_on_promo', - 'can_pre_order', - 'is_coming_soon', - 'is_new', - 'is_published' - ]; + protected $guarded = []; + + /** + * channels. + */ + public function channels(): BelongsToMany + { + return $this->belongsToMany( + Channels::class, + VariantsChannels::class, + 'product_variants_warehouse_id', + 'channels_id' + ) + ->withPivot( + 'price', + 'discounted_price', + 'is_published' + ); + } + + public function variant(): HasMany + { + return $this->hasMany(Variants::class, 'products_variants_id'); + } - protected $primaryKey = ['products_variants_id', 'warehouses_id']; + public function warehouse(): BelongsTo + { + return $this->belongsTo(Warehouses::class, 'warehouses_id'); + } } From f45fd1a89ac1b8b599e6f0f430e1bab7e8c718d2 Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 17:23:42 -0400 Subject: [PATCH 11/24] Update unique key name on migration --- .../2023_06_22_223035_update_product_variants_warehouses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php index 3ac11d005..f033833d4 100644 --- a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php +++ b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php @@ -26,7 +26,7 @@ public function up(): void $table->id()->first(); $table->foreign('products_variants_id')->references('id')->on('products_variants'); $table->foreign('warehouses_id')->references('id')->on('warehouses'); - $table->unique(['products_variants_id', 'warehouses_id']); + $table->unique(['products_variants_id', 'warehouses_id'],'product_variants_warehouses_unique'); Schema::enableForeignKeyConstraints(); }); } From 0254b7303e4d80ac29df6d911bf87843333e5c4c Mon Sep 17 00:00:00 2001 From: arfenis Date: Mon, 3 Jul 2023 17:24:01 -0400 Subject: [PATCH 12/24] Remove optional isset for warehouse --- src/Inventory/Variants/Services/Variants.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Inventory/Variants/Services/Variants.php b/src/Inventory/Variants/Services/Variants.php index b80221529..a3259233b 100644 --- a/src/Inventory/Variants/Services/Variants.php +++ b/src/Inventory/Variants/Services/Variants.php @@ -35,10 +35,8 @@ public static function createVariantsFromArray(Products $product, array $variant $variantModel->addAttributes($user, $variant['attributes']); } - if (isset($variant['warehouse_id'])) { - WarehouseRepository::getById($variantDto->warehouse_id, $variantDto->product->company()->get()->first()); - $variantModel->warehouses()->attach($variantDto->warehouse_id); - } + WarehouseRepository::getById($variantDto->warehouse_id, $variantDto->product->company()->get()->first()); + $variantModel->warehouses()->attach($variantDto->warehouse_id); $variantsData[] = $variantModel; } From 8031ab0e31d82d1c62ec282e32f45116ca84ff72 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 11:42:46 -0400 Subject: [PATCH 13/24] Change warehouses relations --- src/Inventory/Variants/Models/Variants.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Inventory/Variants/Models/Variants.php b/src/Inventory/Variants/Models/Variants.php index cc124e3e9..5393eafc0 100644 --- a/src/Inventory/Variants/Models/Variants.php +++ b/src/Inventory/Variants/Models/Variants.php @@ -92,11 +92,24 @@ public function product(): BelongsTo return $this->belongsTo(Products::class, 'products_id'); } - public function warehouses(): HasMany + public function variantWarehouses(): HasMany { return $this->hasMany(VariantsWarehouses::class, 'products_variants_id'); } + /** + * warehouses. + */ + public function warehouses(): BelongsToMany + { + return $this->belongsToMany( + Warehouses::class, + VariantsWarehouses::class, + 'products_variants_id', + 'warehouses_id' + ); + } + /** * attributes. */ From 53d86ebe42787ca6b96d98f815ab778e2868aaf8 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 11:43:19 -0400 Subject: [PATCH 14/24] Update warehouses type and null --- graphql/schemas/Inventory/variant.graphql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index c4f46dfb8..577b0ea13 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -17,8 +17,8 @@ type Variant { interactions(visitor: VisitorEntityInput!): Interactions @method(name: "getEntitySocialInteractions") product: Product - warehouses: [WarehouseVariantRelationship] - attributes: [VariantsAttributes] + warehouses: [WarehouseVariantRelationship!]! @hasMany(relation: "variantWarehouses") + attributes: [VariantsAttributes!]! companies: Company } From c77da86bb09d9f8c797e1f40ea0a3160a271c779 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 11:46:24 -0400 Subject: [PATCH 15/24] Stylo --- ...023_06_22_223035_update_product_variants_warehouses.php | 7 +++---- .../2023_06_27_164405_update_product_variants_channels.php | 4 +--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php index f033833d4..9a0b810c3 100644 --- a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php +++ b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ @@ -16,7 +15,7 @@ public function up(): void $table->dropForeign('products_variants_warehouses_warehouses_id_foreign'); $table->dropForeign('products_variants_warehouses_products_variants_id_foreign'); - + $table->dropPrimary(); Schema::enableForeignKeyConstraints(); }); @@ -26,7 +25,7 @@ public function up(): void $table->id()->first(); $table->foreign('products_variants_id')->references('id')->on('products_variants'); $table->foreign('warehouses_id')->references('id')->on('warehouses'); - $table->unique(['products_variants_id', 'warehouses_id'],'product_variants_warehouses_unique'); + $table->unique(['products_variants_id', 'warehouses_id'], 'product_variants_warehouses_unique'); Schema::enableForeignKeyConstraints(); }); } diff --git a/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php b/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php index 13bd9bee4..d2b1a893e 100644 --- a/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php +++ b/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ @@ -22,7 +21,6 @@ public function up(): void Schema::enableForeignKeyConstraints(); }); - Schema::table('products_variants_channels', function (Blueprint $table) { Schema::disableForeignKeyConstraints(); From e620cd037570754c347c2b61962cd376af2486ab Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 11:48:28 -0400 Subject: [PATCH 16/24] stylo 2 --- .../2023_06_22_223035_update_product_variants_warehouses.php | 2 +- .../2023_06_27_164405_update_product_variants_channels.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php index 9a0b810c3..a4b63f769 100644 --- a/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php +++ b/database/migrations/Inventory/2023_06_22_223035_update_product_variants_warehouses.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration { /** * Run the migrations. */ diff --git a/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php b/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php index d2b1a893e..b5678c7d2 100644 --- a/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php +++ b/database/migrations/Inventory/2023_06_27_164405_update_product_variants_channels.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class () extends Migration { /** * Run the migrations. */ @@ -12,7 +12,6 @@ public function up(): void { Schema::table('products_variants_channels', function (Blueprint $table) { Schema::disableForeignKeyConstraints(); - $table->dropForeign('products_variants_channels_products_variants_id_foreign'); $table->dropForeign('products_variants_channels_warehouses_id_foreign'); $table->dropForeign('products_variants_channels_channels_id_foreign'); @@ -31,7 +30,6 @@ public function up(): void $table->unique(['product_variants_warehouse_id', 'channels_id'], 'variants_warehouse_channel'); Schema::enableForeignKeyConstraints(); }); - } /** From 1c2a9ff3500dac3f9d37a119d18e5ffad547af25 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 14:31:48 -0400 Subject: [PATCH 17/24] Update products tests --- .../Inventory/Mutations/Variants/Variants.php | 2 +- graphql/schemas/Inventory/variant.graphql | 4 +- tests/GraphQL/Inventory/ProductsTest.php | 128 ++++++++++++++++-- 3 files changed, 121 insertions(+), 13 deletions(-) diff --git a/app/GraphQL/Inventory/Mutations/Variants/Variants.php b/app/GraphQL/Inventory/Mutations/Variants/Variants.php index 48af2a000..1ae99d676 100644 --- a/app/GraphQL/Inventory/Mutations/Variants/Variants.php +++ b/app/GraphQL/Inventory/Mutations/Variants/Variants.php @@ -60,7 +60,7 @@ public function update(mixed $root, array $req): VariantModel */ public function delete(mixed $root, array $req): bool { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); return $variant->delete(); } diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index 577b0ea13..f92af4b92 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -117,12 +117,12 @@ extend type Mutation @guard { @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@update" ) - deleteVariant(id: Int!): Boolean + deleteVariant(id: ID!): Boolean @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@delete" ) addVariantToWarehouse( - id: Int! + id: ID! warehouse_id: Int! input: VariantsWarehousesInput! ): Variant diff --git a/tests/GraphQL/Inventory/ProductsTest.php b/tests/GraphQL/Inventory/ProductsTest.php index e1996a882..36ff7cbae 100644 --- a/tests/GraphQL/Inventory/ProductsTest.php +++ b/tests/GraphQL/Inventory/ProductsTest.php @@ -162,6 +162,55 @@ public function testDeleteProduct(): void */ public function testAddVariantToProduct(): void { + $region = [ + 'name' => 'Test Region', + 'slug' => 'test-region', + 'short_slug' => 'test-region', + 'is_default' => 1, + 'currency_id' => 1, + ]; + $regionResponse = $this->graphQL(' + mutation($data: RegionInput!) { + createRegion(input: $data) + { + id + name + slug + short_slug + currency_id + is_default + } + } + ', [ + 'data' => $region + ])->assertJson([ + 'data' => ['createRegion' => $region] + ]); + $regionResponse = $regionResponse->decodeResponseJson(); + + $warehouseData = [ + 'regions_id' => $regionResponse['data']['createRegion']['id'], + 'name' => fake()->name, + 'location' => 'Test Location', + 'is_default' => false, + 'is_published' => 1, + ]; + + $warehouseResponse = $this->graphQL(' + mutation($data: WarehouseInput!) { + createWarehouse(input: $data) + { + id + regions_id + name + location + is_default + is_published + } + }', ['data' => $warehouseData])->assertJson([ + 'data' => ['createWarehouse' => $warehouseData] + ]); + $data = [ 'name' => fake()->name, 'description' => fake()->text, @@ -196,19 +245,20 @@ public function testAddVariantToProduct(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $id + 'products_id' => $id, + 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'] ]; - $this->graphQL(' + $variantResponse = $this->graphQL(' mutation($data: VariantsInput!) { createVariant(input: $data) { + id name description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); + }', ['data' => $data]); + $this->assertArrayHasKey('id', $variantResponse->json()['data']['createVariant']); } /** @@ -218,6 +268,55 @@ public function testAddVariantToProduct(): void */ public function testDeleteVariantToProduct(): void { + $region = [ + 'name' => 'Test Region', + 'slug' => 'test-region', + 'short_slug' => 'test-region', + 'is_default' => 1, + 'currency_id' => 1, + ]; + $regionResponse = $this->graphQL(' + mutation($data: RegionInput!) { + createRegion(input: $data) + { + id + name + slug + short_slug + currency_id + is_default + } + } + ', [ + 'data' => $region + ])->assertJson([ + 'data' => ['createRegion' => $region] + ]); + $regionResponse = $regionResponse->decodeResponseJson(); + + $warehouseData = [ + 'regions_id' => $regionResponse['data']['createRegion']['id'], + 'name' => fake()->name, + 'location' => 'Test Location', + 'is_default' => false, + 'is_published' => 1, + ]; + + $warehouseResponse = $this->graphQL(' + mutation($data: WarehouseInput!) { + createWarehouse(input: $data) + { + id + regions_id + name + location + is_default + is_published + } + }', ['data' => $warehouseData])->assertJson([ + 'data' => ['createWarehouse' => $warehouseData] + ]); + $data = [ 'name' => fake()->name, 'description' => fake()->text, @@ -232,6 +331,7 @@ public function testDeleteVariantToProduct(): void }', ['data' => $data])->assertJson([ 'data' => ['createProduct' => $data] ]); + $response = $this->graphQL(' query { products { @@ -242,13 +342,19 @@ public function testDeleteVariantToProduct(): void } } }'); + $this->assertArrayHasKey('data', $response->json()); + $this->assertArrayHasKey('products', $response->json()['data']); + $this->assertArrayHasKey('data', $response->json()['data']['products']); + $this->assertArrayHasKey('id', $response->json()['data']['products']['data'][0]); + $id = $response->json()['data']['products']['data'][0]['id']; $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $id + 'products_id' => $id, + 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'] ]; - $response = $this->graphQL(' + $variantResponse = $this->graphQL(' mutation($data: VariantsInput!) { createVariant(input: $data) { @@ -258,11 +364,13 @@ public function testDeleteVariantToProduct(): void products_id } }', ['data' => $data]); - $id = $response->json()['data']['createVariant']['id']; + $this->assertArrayHasKey('id', $variantResponse->json()['data']['createVariant']); + + $variantResponseId = $variantResponse->json()['data']['createVariant']['id']; $this->graphQL(' - mutation($id: Int!) { + mutation($id: ID!) { deleteVariant(id: $id) - }', ['id' => $id])->assertJson([ + }', ['id' => $variantResponseId])->assertJson([ 'data' => ['deleteVariant' => true] ]); } From 204f5426c15d8c2d4a30d3feba656880face65f4 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 16:18:17 -0400 Subject: [PATCH 18/24] Update viriants test --- .../Inventory/Mutations/Variants/Variants.php | 6 +- graphql/schemas/Inventory/variant.graphql | 2 +- tests/GraphQL/Inventory/VariantTest.php | 90 +++++++++++++++---- 3 files changed, 78 insertions(+), 20 deletions(-) diff --git a/app/GraphQL/Inventory/Mutations/Variants/Variants.php b/app/GraphQL/Inventory/Mutations/Variants/Variants.php index 1ae99d676..1973c72d9 100644 --- a/app/GraphQL/Inventory/Mutations/Variants/Variants.php +++ b/app/GraphQL/Inventory/Mutations/Variants/Variants.php @@ -45,7 +45,7 @@ public function create(mixed $root, array $req): VariantModel */ public function update(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); $variant->update($req['input']); return $variant; } @@ -75,7 +75,7 @@ public function delete(mixed $root, array $req): bool */ public function addToWarehouse(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); $warehouse = WarehouseRepository::getById($req['warehouse_id']); $variantWarehouses = VariantsWarehouses::from($req['input']); @@ -92,7 +92,7 @@ public function addToWarehouse(mixed $root, array $req): VariantModel */ public function removeToWarehouse(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); $warehouse = WarehouseRepository::getById($req['warehouse_id']); $variant->warehouses()->detach($warehouse); diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index f92af4b92..c7a250f7d 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -113,7 +113,7 @@ extend type Mutation @guard { @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@create" ) - updateVariant(input: VariantsUpdateInput!, id: Int!): Variant + updateVariant(input: VariantsUpdateInput!, id: ID!): Variant @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@update" ) diff --git a/tests/GraphQL/Inventory/VariantTest.php b/tests/GraphQL/Inventory/VariantTest.php index 08e99d683..85c4f8687 100644 --- a/tests/GraphQL/Inventory/VariantTest.php +++ b/tests/GraphQL/Inventory/VariantTest.php @@ -15,6 +15,55 @@ class VariantTest extends TestCase */ public function testUpdateVariant(): void { + $region = [ + 'name' => 'Test Region', + 'slug' => 'test-region', + 'short_slug' => 'test-region', + 'is_default' => 1, + 'currency_id' => 1, + ]; + $regionResponse = $this->graphQL(' + mutation($data: RegionInput!) { + createRegion(input: $data) + { + id + name + slug + short_slug + currency_id + is_default + } + } + ', [ + 'data' => $region + ])->assertJson([ + 'data' => ['createRegion' => $region] + ]); + $regionResponse = $regionResponse->decodeResponseJson(); + + $warehouseData = [ + 'regions_id' => $regionResponse['data']['createRegion']['id'], + 'name' => fake()->name, + 'location' => 'Test Location', + 'is_default' => false, + 'is_published' => 1, + ]; + + $warehouseResponse = $this->graphQL(' + mutation($data: WarehouseInput!) { + createWarehouse(input: $data) + { + id + regions_id + name + location + is_default + is_published + } + }', ['data' => $warehouseData])->assertJson([ + 'data' => ['createWarehouse' => $warehouseData] + ]); + $data = [ 'name' => fake()->name, 'description' => fake()->text, @@ -49,27 +98,28 @@ public function testUpdateVariant(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $id + 'products_id' => $id, + 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'] ]; - $response = $this->graphQL(' + $variantResponse = $this->graphQL(' mutation($data: VariantsInput!) { createVariant(input: $data) - { + { id name description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); - $id = $response->json()['data']['createVariant']['id']; + }', ['data' => $data]); + $this->assertArrayHasKey('id', $variantResponse->json()['data']['createVariant']); + + $id = $variantResponse->json()['data']['createVariant']['id']; $data = [ 'name' => fake()->name, 'description' => fake()->text, ]; $this->graphQL(' - mutation($id: Int! $data: VariantsUpdateInput!) { + mutation($id: ID! $data: VariantsUpdateInput!) { updateVariant(id: $id, input: $data) { id @@ -153,7 +203,8 @@ public function testAddVariantToWarehouse(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $productId + 'products_id' => $productId, + 'warehouse_id' => $warehouseId ]; $response = $this->graphQL(' mutation($data: VariantsInput!) { @@ -164,30 +215,37 @@ public function testAddVariantToWarehouse(): void description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); + }', ['data' => $data]); $variantId = $response->json()['data']['createVariant']['id']; - $data = [ + + $data = [ 'price' => rand(1, 1000), 'quantity' => rand(1, 5), 'position' => rand(1, 4), ]; - $this->graphQL(' - mutation($data: VariantsWarehousesInput! $id: Int! $warehouse_id: Int!) { + $warehouseResponse = $this->graphQL(' + mutation($data: VariantsWarehousesInput! $id: ID! $warehouse_id: Int!) { addVariantToWarehouse(input: $data id: $id warehouse_id: $warehouse_id) { id name description products_id + warehouses{ + warehouseinfo{ + id + } + } } }', [ 'data' => $data, 'id' => $variantId, 'warehouse_id' => $warehouseId ]); - $this->assertArrayHasKey('data', $response->json()); + $this->assertEquals( + $warehouseId, + $warehouseResponse['data']['addVariantToWarehouse']['warehouses'][0]['warehouseinfo']['id'] + ); } } From 67c190acf6d4c287a09d79a9b2ab107a064378b1 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 16:41:07 -0400 Subject: [PATCH 19/24] Update variants-attributes tests --- .../Inventory/Mutations/Variants/Variants.php | 8 +- graphql/schemas/Inventory/attributes.graphql | 8 +- graphql/schemas/Inventory/variant.graphql | 6 +- .../RemoveVariantsToWarehouseTest.php | 25 ++-- .../Inventory/VariantAttributeTest.php | 129 ++++++++++++++++-- 5 files changed, 144 insertions(+), 32 deletions(-) diff --git a/app/GraphQL/Inventory/Mutations/Variants/Variants.php b/app/GraphQL/Inventory/Mutations/Variants/Variants.php index 1973c72d9..1928d5623 100644 --- a/app/GraphQL/Inventory/Mutations/Variants/Variants.php +++ b/app/GraphQL/Inventory/Mutations/Variants/Variants.php @@ -109,9 +109,9 @@ public function removeToWarehouse(mixed $root, array $req): VariantModel */ public function addAttribute(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); - $attribute = AttributesRepository::getById($req['attributes_id']); + $attribute = AttributesRepository::getById((int) $req['attributes_id']); (new AddAttributeAction($variant, $attribute, $req['input']['value']))->execute(); return $variant; } @@ -126,9 +126,9 @@ public function addAttribute(mixed $root, array $req): VariantModel */ public function removeAttribute(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); - $attribute = AttributesRepository::getById($req['attributes_id']); + $attribute = AttributesRepository::getById((int) $req['attributes_id']); $variant->attributes()->detach($attribute); return $variant; } diff --git a/graphql/schemas/Inventory/attributes.graphql b/graphql/schemas/Inventory/attributes.graphql index 24463bee0..62e10e588 100644 --- a/graphql/schemas/Inventory/attributes.graphql +++ b/graphql/schemas/Inventory/attributes.graphql @@ -9,7 +9,7 @@ input AttributeUpdateInput { } type Attributes { - id: Int! + id: ID! uuid: String name: String created_at: String @@ -19,7 +19,7 @@ type Attributes { } type AttributesValue { - id: Int! + id: ID! value: Mixed } @@ -28,11 +28,11 @@ extend type Mutation @guard { @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Attributes\\AttributeMutation@create" ) - updateAttribute(id: Int!, input: AttributeUpdateInput!): Attributes! + updateAttribute(id: ID!, input: AttributeUpdateInput!): Attributes! @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Attributes\\AttributeMutation@update" ) - deleteAttribute(id: Int!): Attributes! + deleteAttribute(id: ID!): Attributes! @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Attributes\\AttributeMutation@delete" ) diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index c7a250f7d..df8b5f550 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -134,14 +134,14 @@ extend type Mutation @guard { resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@removeToWarehouse" ) addAttributeToVariant( - id: Int! - attributes_id: Int! + id: ID! + attributes_id: ID! input: VariantsAttributesInput! ): Variant @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@addAttribute" ) - removeAttributeToVariant(id: Int!, attributes_id: Int!): Variant + removeAttributeToVariant(id: ID!, attributes_id: ID!): Variant @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@removeAttribute" ) diff --git a/tests/GraphQL/Inventory/RemoveVariantsToWarehouseTest.php b/tests/GraphQL/Inventory/RemoveVariantsToWarehouseTest.php index 6c1c92a2a..6f3abd1e1 100644 --- a/tests/GraphQL/Inventory/RemoveVariantsToWarehouseTest.php +++ b/tests/GraphQL/Inventory/RemoveVariantsToWarehouseTest.php @@ -80,7 +80,8 @@ public function testRemoveVariantToWarehouse(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $productId + 'products_id' => $productId, + 'warehouse_id' => $warehouseId ]; $response = $this->graphQL(' mutation($data: VariantsInput!) { @@ -91,24 +92,28 @@ public function testRemoveVariantToWarehouse(): void description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); + }', ['data' => $data]); $variantId = $response->json()['data']['createVariant']['id']; - $data = [ - 'price' => 10.00, - 'quantity' => 1, - 'position' => 1, + + $data = [ + 'price' => rand(1, 1000), + 'quantity' => rand(1, 5), + 'position' => rand(1, 4), ]; - $response = $this->graphQL(' - mutation($data: VariantsWarehousesInput! $id: Int! $warehouse_id: Int!) { + $warehouseResponse = $this->graphQL(' + mutation($data: VariantsWarehousesInput! $id: ID! $warehouse_id: Int!) { addVariantToWarehouse(input: $data id: $id warehouse_id: $warehouse_id) { id name description products_id + warehouses{ + warehouseinfo{ + id + } + } } }', [ 'data' => $data, diff --git a/tests/GraphQL/Inventory/VariantAttributeTest.php b/tests/GraphQL/Inventory/VariantAttributeTest.php index 326b8e778..ae76a6320 100644 --- a/tests/GraphQL/Inventory/VariantAttributeTest.php +++ b/tests/GraphQL/Inventory/VariantAttributeTest.php @@ -15,6 +15,52 @@ class VariantAttributeTest extends TestCase */ public function testAddAttributeToVariant(): void { + $dataRegion = [ + 'name' => 'Test Region', + 'slug' => 'test-region', + 'short_slug' => 'test-region', + 'is_default' => 1, + 'currency_id' => 1, + ]; + $response = $this->graphQL(' + mutation($data: RegionInput!) { + createRegion(input: $data) + { + id + name + slug + short_slug + currency_id + is_default + } + }', ['data' => $dataRegion]) + ->assertJson([ + 'data' => ['createRegion' => $dataRegion] + ]); + $idRegion = $response->json()['data']['createRegion']['id']; + $data = [ + 'regions_id' => $idRegion, + 'name' => 'Test Warehouse', + 'location' => 'Test Location', + 'is_default' => false, + 'is_published' => 1, + ]; + + $response = $this->graphQL(' + mutation($data: WarehouseInput!) { + createWarehouse(input: $data) + { + id + regions_id + name + location + is_default + is_published + } + }', ['data' => $data])->assertJson([ + 'data' => ['createWarehouse' => $data] + ]); + $warehouseId = $response->json()['data']['createWarehouse']['id']; $data = [ 'name' => fake()->name, 'description' => fake()->text, @@ -34,7 +80,8 @@ public function testAddAttributeToVariant(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $productId + 'products_id' => $productId, + 'warehouse_id' => $warehouseId ]; $response = $this->graphQL(' mutation($data: VariantsInput!) { @@ -45,9 +92,7 @@ public function testAddAttributeToVariant(): void description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); + }', ['data' => $data]); $variantId = $response->json()['data']['createVariant']['id']; $dataAtribute = [ @@ -67,7 +112,7 @@ public function testAddAttributeToVariant(): void }', ['data' => $dataAtribute]); $attributeId = $response->json()['data']['createAttribute']['id']; $response = $this->graphQL(' - mutation($id: Int! $attributes_id: Int! $input: VariantsAttributesInput!) { + mutation($id: ID! $attributes_id: ID! $input: VariantsAttributesInput!) { addAttributeToVariant(id: $id, attributes_id: $attributes_id, input: $input) { id @@ -92,6 +137,52 @@ public function testAddAttributeToVariant(): void */ public function testRemoveAttributeFromVariant(): void { + $dataRegion = [ + 'name' => 'Test Region', + 'slug' => 'test-region', + 'short_slug' => 'test-region', + 'is_default' => 1, + 'currency_id' => 1, + ]; + $response = $this->graphQL(' + mutation($data: RegionInput!) { + createRegion(input: $data) + { + id + name + slug + short_slug + currency_id + is_default + } + }', ['data' => $dataRegion]) + ->assertJson([ + 'data' => ['createRegion' => $dataRegion] + ]); + $idRegion = $response->json()['data']['createRegion']['id']; + $data = [ + 'regions_id' => $idRegion, + 'name' => 'Test Warehouse', + 'location' => 'Test Location', + 'is_default' => false, + 'is_published' => 1, + ]; + + $response = $this->graphQL(' + mutation($data: WarehouseInput!) { + createWarehouse(input: $data) + { + id + regions_id + name + location + is_default + is_published + } + }', ['data' => $data])->assertJson([ + 'data' => ['createWarehouse' => $data] + ]); + $warehouseId = $response->json()['data']['createWarehouse']['id']; $data = [ 'name' => fake()->name, 'description' => fake()->text, @@ -111,7 +202,8 @@ public function testRemoveAttributeFromVariant(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $productId + 'products_id' => $productId, + 'warehouse_id' => $warehouseId ]; $response = $this->graphQL(' mutation($data: VariantsInput!) { @@ -122,11 +214,26 @@ public function testRemoveAttributeFromVariant(): void description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); + }', ['data' => $data]); $variantId = $response->json()['data']['createVariant']['id']; + $dataAtribute = [ + 'name' => fake()->name, + 'value' => fake()->name + ]; + $response = $this->graphQL(' + mutation($data: AttributeInput!) { + createAttribute(input: $data) + { + id + name + values { + value + } + } + }', ['data' => $dataAtribute]); + $attributeId = $response->json()['data']['createAttribute']['id']; + $dataAtribute = [ 'name' => fake()->name, 'value' => fake()->name @@ -141,7 +248,7 @@ public function testRemoveAttributeFromVariant(): void }', ['data' => $dataAtribute]); $attributeId = $response->json()['data']['createAttribute']['id']; $response = $this->graphQL(' - mutation($id: Int! $attributes_id: Int! $input: VariantsAttributesInput!) { + mutation($id: ID! $attributes_id: ID! $input: VariantsAttributesInput!) { addAttributeToVariant(id: $id, attributes_id: $attributes_id, input: $input) { id @@ -158,7 +265,7 @@ public function testRemoveAttributeFromVariant(): void ]); $this->assertArrayHasKey('data', $response->json()); $response = $this->graphQL(' - mutation($id: Int! $attributesId: Int!) { + mutation($id: ID! $attributesId: ID!) { removeAttributeToVariant(id:$id attributes_id:$attributesId) { id From 4947db83386765938040c8d9ad5d6a5717e11b8a Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 17:33:18 -0400 Subject: [PATCH 20/24] Update variants channels tests --- .../Inventory/Mutations/Variants/Variants.php | 27 ++++++++----- graphql/schemas/Inventory/variant.graphql | 12 ++++-- .../Variants/Models/VariantsWarehouses.php | 4 +- .../Inventory/VariantsChannelsTest.php | 38 +++++++++---------- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/app/GraphQL/Inventory/Mutations/Variants/Variants.php b/app/GraphQL/Inventory/Mutations/Variants/Variants.php index 1928d5623..e619690b1 100644 --- a/app/GraphQL/Inventory/Mutations/Variants/Variants.php +++ b/app/GraphQL/Inventory/Mutations/Variants/Variants.php @@ -32,7 +32,12 @@ public function create(mixed $root, array $req): VariantModel { $variantDto = VariantDto::viaRequest($req['input']); $action = new CreateVariantsAction($variantDto, auth()->user()); - return $action->execute(); + $variantModel = $action->execute(); + + WarehouseRepository::getById($variantDto->warehouse_id, $variantDto->product->company()->get()->first()); + $variantModel->warehouses()->attach($variantDto->warehouse_id); + + return $variantModel; } /** @@ -62,7 +67,7 @@ public function delete(mixed $root, array $req): bool { $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); - return $variant->delete(); + return $variant->softdelete(); } /** @@ -143,14 +148,13 @@ public function removeAttribute(mixed $root, array $req): VariantModel */ public function addToChannel(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); - $warehouse = WarehouseRepository::getById($req['warehouses_id']); - + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); + $warehouse = WarehouseRepository::getById((int) $req['warehouses_id']); $variantWarehouses = ModelsVariantsWarehouses::where('products_variants_id', $variant->getId()) ->where('warehouses_id', $warehouse->getId()) ->firstOrFail(); - $channel = ChannelRepository::getById($req['channels_id']); + $channel = ChannelRepository::getById((int) $req['channels_id']); $variantChannel = VariantChannel::from($req['input']); (new AddVariantToChannel($variantWarehouses, $channel, $variantChannel))->execute(); return $variant; @@ -166,10 +170,13 @@ public function addToChannel(mixed $root, array $req): VariantModel */ public function removeChannel(mixed $root, array $req): VariantModel { - $variant = VariantsRepository::getById($req['id'], auth()->user()->getCurrentCompany()); - - $channel = ChannelRepository::getById($req['channels_id']); - $variant->channels()->detach($channel->id); + $variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany()); + $warehouse = WarehouseRepository::getById((int) $req['warehouses_id']); + $variantWarehouses = ModelsVariantsWarehouses::where('products_variants_id', $variant->getId()) + ->where('warehouses_id', $warehouse->getId()) + ->firstOrFail(); + $channel = ChannelRepository::getById((int) $req['channels_id']); + $variantWarehouses->channels()->where('id', $channel->getId())->detach($channel->id); return $variant; } } diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index df8b5f550..50ee2a8f8 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -146,15 +146,19 @@ extend type Mutation @guard { resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@removeAttribute" ) addVariantToChannel( - id: Int! - channels_id: Int! - warehouses_id: Int! + id: ID! + channels_id: ID! + warehouses_id: ID! input: VariantChannelInput! ): Variant @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@addToChannel" ) - removeVariantChannel(id: Int!, channels_id: Int!): Variant + removeVariantChannel( + id: ID! + channels_id: ID! + warehouses_id: ID! + ): Variant @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Variants\\Variants@removeChannel" ) diff --git a/src/Inventory/Variants/Models/VariantsWarehouses.php b/src/Inventory/Variants/Models/VariantsWarehouses.php index e5010426a..20eea266e 100644 --- a/src/Inventory/Variants/Models/VariantsWarehouses.php +++ b/src/Inventory/Variants/Models/VariantsWarehouses.php @@ -58,9 +58,9 @@ public function channels(): BelongsToMany ); } - public function variant(): HasMany + public function variant(): BelongsTo { - return $this->hasMany(Variants::class, 'products_variants_id'); + return $this->belongsTo(Variants::class, 'products_variants_id'); } public function warehouse(): BelongsTo diff --git a/tests/GraphQL/Inventory/VariantsChannelsTest.php b/tests/GraphQL/Inventory/VariantsChannelsTest.php index a93d87093..f6b8ad773 100644 --- a/tests/GraphQL/Inventory/VariantsChannelsTest.php +++ b/tests/GraphQL/Inventory/VariantsChannelsTest.php @@ -15,7 +15,7 @@ class VariantsChannelsTest extends TestCase */ public function testVariantToChannel(): void { - $data = [ + $dataRegion = [ 'name' => 'Test Region', 'slug' => 'test-region', 'short_slug' => 'test-region', @@ -33,17 +33,13 @@ public function testVariantToChannel(): void currency_id is_default } - } - ', [ - 'data' => $data - ])->assertJson([ - 'data' => ['createRegion' => $data] - ]); - - $response = $response->decodeResponseJson(); - + }', ['data' => $dataRegion]) + ->assertJson([ + 'data' => ['createRegion' => $dataRegion] + ]); + $idRegion = $response->json()['data']['createRegion']['id']; $data = [ - 'regions_id' => $response['data']['createRegion']['id'], + 'regions_id' => $idRegion, 'name' => 'Test Warehouse', 'location' => 'Test Location', 'is_default' => false, @@ -64,7 +60,7 @@ public function testVariantToChannel(): void }', ['data' => $data])->assertJson([ 'data' => ['createWarehouse' => $data] ]); - $warehousesId = $response->json()['data']['createWarehouse']['id']; + $warehouseId = $response->json()['data']['createWarehouse']['id']; $data = [ 'name' => fake()->name, 'description' => fake()->text, @@ -84,7 +80,8 @@ public function testVariantToChannel(): void $data = [ 'name' => fake()->name, 'description' => fake()->text, - 'products_id' => $productId + 'products_id' => $productId, + 'warehouse_id' => $warehouseId ]; $response = $this->graphQL(' mutation($data: VariantsInput!) { @@ -95,9 +92,7 @@ public function testVariantToChannel(): void description products_id } - }', ['data' => $data])->assertJson([ - 'data' => ['createVariant' => $data] - ]); + }', ['data' => $data]); $variantId = $response->json()['data']['createVariant']['id']; $dataChannel = [ @@ -122,7 +117,7 @@ public function testVariantToChannel(): void $channelId = $response->json()['data']['createChannel']['id']; $response = $this->graphQL( ' - mutation addVariantToChannel($id: Int! $channels_id: Int! $warehouses_id: Int! $input: VariantChannelInput!){ + mutation addVariantToChannel($id: ID! $channels_id: ID! $warehouses_id: ID! $input: VariantChannelInput!){ addVariantToChannel(id: $id channels_id:$channels_id warehouses_id:$warehouses_id input:$input){ id } @@ -131,7 +126,7 @@ public function testVariantToChannel(): void [ 'id' => $variantId, 'channels_id' => $channelId, - 'warehouses_id' => $warehousesId, + 'warehouses_id' => $warehouseId, 'input' => [ 'price' => 100, 'discounted_price' => 10, @@ -145,15 +140,16 @@ public function testVariantToChannel(): void ]); $response = $this->graphQL( - 'mutation ($id: Int! $channels_id: Int!) { - removeVariantChannel(id: $id channels_id: $channels_id) + 'mutation ($id: ID! $channels_id: ID! $warehouses_id: ID!) { + removeVariantChannel(id: $id channels_id: $channels_id warehouses_id: $warehouses_id) { id } }', [ 'id' => $variantId, - 'channels_id' => $channelId + 'channels_id' => $channelId, + 'warehouses_id' => $warehouseId, ] ); $response->assertJson([ From 525c6359212e320e87b30fb0759436aaccb46d57 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 5 Jul 2023 17:44:34 -0400 Subject: [PATCH 21/24] update --- graphql/schemas/Inventory/region.graphql | 2 +- tests/GraphQL/Inventory/ProductsTest.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/graphql/schemas/Inventory/region.graphql b/graphql/schemas/Inventory/region.graphql index deeadd19a..8fe96b539 100644 --- a/graphql/schemas/Inventory/region.graphql +++ b/graphql/schemas/Inventory/region.graphql @@ -18,7 +18,7 @@ type Currency { input RegionInput { currency_id: Int! name: String! - slug: String! + slug: String short_slug: String! settings: String is_default: Int! diff --git a/tests/GraphQL/Inventory/ProductsTest.php b/tests/GraphQL/Inventory/ProductsTest.php index 36ff7cbae..9e3d78701 100644 --- a/tests/GraphQL/Inventory/ProductsTest.php +++ b/tests/GraphQL/Inventory/ProductsTest.php @@ -163,9 +163,8 @@ public function testDeleteProduct(): void public function testAddVariantToProduct(): void { $region = [ - 'name' => 'Test Region', - 'slug' => 'test-region', - 'short_slug' => 'test-region', + 'name' => fake()->name, + 'short_slug' => fake()->name, 'is_default' => 1, 'currency_id' => 1, ]; From 0430a512334b8178d8ffc589c276c22045c418af Mon Sep 17 00:00:00 2001 From: arfenis Date: Sun, 9 Jul 2023 13:33:16 -0400 Subject: [PATCH 22/24] Update importer tests with new variant warehouses --- graphql/schemas/Inventory/variant.graphql | 2 +- .../Actions/ProductImporterAction.php | 9 +++++++-- tests/Inventory/Integration/ImporterTest.php | 20 ++++++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index 50ee2a8f8..451948b52 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -88,7 +88,7 @@ input VariantsInput { price: Float source_id: Mixed attributes: [VariantsAttributesInput] - warehouse_id: Int + warehouse_id: Int! } input VariantsUpdateInput { products_id: Int diff --git a/src/Inventory/Importer/Actions/ProductImporterAction.php b/src/Inventory/Importer/Actions/ProductImporterAction.php index 92cf79758..deb84ea86 100644 --- a/src/Inventory/Importer/Actions/ProductImporterAction.php +++ b/src/Inventory/Importer/Actions/ProductImporterAction.php @@ -36,6 +36,7 @@ use Kanvas\Inventory\Variants\Models\Variants as VariantsModel; use Kanvas\Inventory\Warehouses\Actions\CreateWarehouseAction; use Kanvas\Inventory\Warehouses\DataTransferObject\Warehouses; +use Kanvas\Inventory\Variants\Models\VariantsWarehouses as ModelsVariantsWarehouses; use Throwable; class ProductImporterAction @@ -371,10 +372,14 @@ public function addVariantsToLocation(VariantsModel $variantModel): void ]), ))->execute(); + $variantWarehouses = ModelsVariantsWarehouses::where('products_variants_id', $variantModel->getId()) + ->where('warehouses_id', $warehouse->getId()) + ->firstOrFail(); + + (new AddVariantToChannel( - $variantModel, + $variantWarehouses, $channel, - $warehouse, $variantChannel ))->execute(); } diff --git a/tests/Inventory/Integration/ImporterTest.php b/tests/Inventory/Integration/ImporterTest.php index 4420a8c93..7a2309188 100644 --- a/tests/Inventory/Integration/ImporterTest.php +++ b/tests/Inventory/Integration/ImporterTest.php @@ -9,6 +9,8 @@ use Kanvas\Inventory\Importer\DataTransferObjects\ProductImporter; use Kanvas\Inventory\Regions\Repositories\RegionRepository; use Kanvas\Inventory\Support\Setup; +use Kanvas\Inventory\Warehouses\Actions\CreateWarehouseAction; +use Kanvas\Inventory\Warehouses\DataTransferObject\Warehouses as WarehousesDto; use Tests\TestCase; final class ImporterTest extends TestCase @@ -37,6 +39,20 @@ public function testImportAction(): void ], ]; + $region = RegionRepository::getByName('default', $company); + + $warehouse = [ + 'name' => fake()->word(), + 'regions_id' => $region->getId(), + 'is_default' => true, + 'is_published' => 1, + ]; + + $warehouseData = (new CreateWarehouseAction( + WarehousesDto::viaRequest($warehouse), + auth()->user() + ))->execute(); + $productData = ProductImporter::from([ 'name' => fake()->word(), 'description' => fake()->sentence(), @@ -58,6 +74,7 @@ public function testImportAction(): void 'variants' => [ [ 'name' => fake()->word(), + 'warehouse_id' => $warehouseData->getId(), 'description' => fake()->sentence(), 'sku' => fake()->word(), 'price' => fake()->randomNumber(2), @@ -77,6 +94,7 @@ public function testImportAction(): void ], [ 'name' => fake()->word(), + 'warehouse_id' => $warehouseData->getId(), 'description' => fake()->sentence(), 'sku' => fake()->word(), 'price' => fake()->randomNumber(2), @@ -99,7 +117,7 @@ public function testImportAction(): void $productData, $company, auth()->user(), - RegionRepository::getByName('default', $company) + $region ); $this->assertTrue($productImporter->execute()); From c6e22ce494b7964188ed0aaf5af17a6d693a7c0b Mon Sep 17 00:00:00 2001 From: arfenis Date: Sun, 9 Jul 2023 14:53:22 -0400 Subject: [PATCH 23/24] price default --- src/Inventory/Variants/Models/VariantsWarehouses.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Inventory/Variants/Models/VariantsWarehouses.php b/src/Inventory/Variants/Models/VariantsWarehouses.php index 20eea266e..fecff005f 100644 --- a/src/Inventory/Variants/Models/VariantsWarehouses.php +++ b/src/Inventory/Variants/Models/VariantsWarehouses.php @@ -39,6 +39,9 @@ class VariantsWarehouses extends BaseModel { protected $table = 'products_variants_warehouses'; protected $guarded = []; + protected $attributes = [ + 'price' => 0.00 + ]; /** * channels. From 6f8a82adc1b9752392ad913a6d32a564f2d1b7bf Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 9 Jul 2023 23:48:50 -0400 Subject: [PATCH 24/24] feat: add default value for price and position --- ...10_033443_update_variant_channel_price.php | 41 ++++++++++++++++ .../Variants/Models/VariantsWarehouses.php | 3 -- tests/GraphQL/Inventory/ProductsTest.php | 48 +++++++------------ 3 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 database/migrations/Inventory/2023_07_10_033443_update_variant_channel_price.php diff --git a/database/migrations/Inventory/2023_07_10_033443_update_variant_channel_price.php b/database/migrations/Inventory/2023_07_10_033443_update_variant_channel_price.php new file mode 100644 index 000000000..b0d3247bd --- /dev/null +++ b/database/migrations/Inventory/2023_07_10_033443_update_variant_channel_price.php @@ -0,0 +1,41 @@ +double('price', 8, 2)->default(0.00)->change(); + }); + + Schema::table('products_variants_warehouses', function (Blueprint $table) { + $table->double('price', 8, 2)->default(0.00)->change(); + $table->integer('position')->default(0)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('products_variants_channels', function (Blueprint $table) { + $table->double('price', 8, 2)->change(); + }); + + Schema::table('products_variants_warehouses', function (Blueprint $table) { + $table->double('price', 8, 2)->change(); + $table->integer('position')->change(); + }); + } +}; diff --git a/src/Inventory/Variants/Models/VariantsWarehouses.php b/src/Inventory/Variants/Models/VariantsWarehouses.php index fecff005f..20eea266e 100644 --- a/src/Inventory/Variants/Models/VariantsWarehouses.php +++ b/src/Inventory/Variants/Models/VariantsWarehouses.php @@ -39,9 +39,6 @@ class VariantsWarehouses extends BaseModel { protected $table = 'products_variants_warehouses'; protected $guarded = []; - protected $attributes = [ - 'price' => 0.00 - ]; /** * channels. diff --git a/tests/GraphQL/Inventory/ProductsTest.php b/tests/GraphQL/Inventory/ProductsTest.php index 9e3d78701..c6de08a34 100644 --- a/tests/GraphQL/Inventory/ProductsTest.php +++ b/tests/GraphQL/Inventory/ProductsTest.php @@ -10,8 +10,6 @@ class ProductsTest extends TestCase { /** * testSave. - * - * @return void */ public function testSave(): void { @@ -28,14 +26,12 @@ public function testSave(): void description } }', ['data' => $data])->assertJson([ - 'data' => ['createProduct' => $data] + 'data' => ['createProduct' => $data], ]); } /** * test get product. - * - * @return void */ public function testGetProduct(): void { @@ -52,7 +48,7 @@ public function testGetProduct(): void description } }', ['data' => $data])->assertJson([ - 'data' => ['createProduct' => $data] + 'data' => ['createProduct' => $data], ]); $this->graphQL(' @@ -64,14 +60,12 @@ public function testGetProduct(): void } } }')->assertJson([ - 'data' => ['products' => ['data' => [$data]]] + 'data' => ['products' => ['data' => [$data]]], ]); } /** * test update product. - * - * @return void */ public function testUpdateProduct(): void { @@ -87,7 +81,7 @@ public function testUpdateProduct(): void description } }', ['data' => $data])->assertJson([ - 'data' => ['createProduct' => $data] + 'data' => ['createProduct' => $data], ]); $response = $this->graphQL(' @@ -118,14 +112,12 @@ public function testUpdateProduct(): void description } }', ['data' => $data, 'id' => $id])->assertJson([ - 'data' => ['updateProduct' => $data] + 'data' => ['updateProduct' => $data], ]); } /** * testDeleteProduct. - * - * @return void */ public function testDeleteProduct(): void { @@ -144,21 +136,19 @@ public function testDeleteProduct(): void }', ['data' => $data]); $response->assertJson([ - 'data' => ['createProduct' => $data] + 'data' => ['createProduct' => $data], ]); $id = $response->json()['data']['createProduct']['id']; $this->graphQL(' mutation($id: Int!) { deleteProduct(id: $id) }', ['id' => $id])->assertJson([ - 'data' => ['deleteProduct' => true] + 'data' => ['deleteProduct' => true], ]); } /** * testAddVariantToProduct. - * - * @return void */ public function testAddVariantToProduct(): void { @@ -181,9 +171,9 @@ public function testAddVariantToProduct(): void } } ', [ - 'data' => $region + 'data' => $region, ])->assertJson([ - 'data' => ['createRegion' => $region] + 'data' => ['createRegion' => $region], ]); $regionResponse = $regionResponse->decodeResponseJson(); @@ -207,7 +197,7 @@ public function testAddVariantToProduct(): void is_published } }', ['data' => $warehouseData])->assertJson([ - 'data' => ['createWarehouse' => $warehouseData] + 'data' => ['createWarehouse' => $warehouseData], ]); $data = [ @@ -222,7 +212,7 @@ public function testAddVariantToProduct(): void description } }', ['data' => $data])->assertJson([ - 'data' => ['createProduct' => $data] + 'data' => ['createProduct' => $data], ]); $response = $this->graphQL(' @@ -245,7 +235,7 @@ public function testAddVariantToProduct(): void 'name' => fake()->name, 'description' => fake()->text, 'products_id' => $id, - 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'] + 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'], ]; $variantResponse = $this->graphQL(' mutation($data: VariantsInput!) { @@ -262,8 +252,6 @@ public function testAddVariantToProduct(): void /** * testDeleteVariantToProduct. - * - * @return void */ public function testDeleteVariantToProduct(): void { @@ -287,9 +275,9 @@ public function testDeleteVariantToProduct(): void } } ', [ - 'data' => $region + 'data' => $region, ])->assertJson([ - 'data' => ['createRegion' => $region] + 'data' => ['createRegion' => $region], ]); $regionResponse = $regionResponse->decodeResponseJson(); @@ -313,7 +301,7 @@ public function testDeleteVariantToProduct(): void is_published } }', ['data' => $warehouseData])->assertJson([ - 'data' => ['createWarehouse' => $warehouseData] + 'data' => ['createWarehouse' => $warehouseData], ]); $data = [ @@ -328,7 +316,7 @@ public function testDeleteVariantToProduct(): void description } }', ['data' => $data])->assertJson([ - 'data' => ['createProduct' => $data] + 'data' => ['createProduct' => $data], ]); $response = $this->graphQL(' @@ -351,7 +339,7 @@ public function testDeleteVariantToProduct(): void 'name' => fake()->name, 'description' => fake()->text, 'products_id' => $id, - 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'] + 'warehouse_id' => $warehouseResponse['data']['createWarehouse']['id'], ]; $variantResponse = $this->graphQL(' mutation($data: VariantsInput!) { @@ -370,7 +358,7 @@ public function testDeleteVariantToProduct(): void mutation($id: ID!) { deleteVariant(id: $id) }', ['id' => $variantResponseId])->assertJson([ - 'data' => ['deleteVariant' => true] + 'data' => ['deleteVariant' => true], ]); } }