diff --git a/app/GraphQL/Inventory/Builders/Variants/VariantChannelBuilder.php b/app/GraphQL/Inventory/Builders/Variants/VariantChannelBuilder.php index 3d8306798a..3409d62108 100644 --- a/app/GraphQL/Inventory/Builders/Variants/VariantChannelBuilder.php +++ b/app/GraphQL/Inventory/Builders/Variants/VariantChannelBuilder.php @@ -6,6 +6,7 @@ use GraphQL\Type\Definition\ResolveInfo; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\DB; use Kanvas\Inventory\Channels\Models\Channels; @@ -75,7 +76,29 @@ public function getChannel(mixed $root, array $req): array } /** - * Get channel prices history + * Get filter variant by channel + * + * @param mixed $root + * @param array $req + * @return Collection + */ + public function getHasChannel(mixed $root, array $req): Collection + { + if (empty($req['HAS']['condition']['value'])) { + return collect(); + } + $channelUuid = $req['HAS']['condition']['value']; + + return $root->with(['channels' => function ($query) use ($channelUuid) { + $query->where('uuid', $channelUuid); + }])->get(); + } + + /** + * Get channel price history + * + * @param mixed $root + * @return array */ public function getChannelHistory(mixed $root): array { diff --git a/graphql/schemas/Inventory/variant.graphql b/graphql/schemas/Inventory/variant.graphql index 6087e7b4c6..7b71af57f7 100644 --- a/graphql/schemas/Inventory/variant.graphql +++ b/graphql/schemas/Inventory/variant.graphql @@ -24,6 +24,7 @@ type Variant { @hasMany(relation: "variantWarehouses") attributes: [VariantsAttributes!]! companies: Company + channels: [VariantChannelRelationship!]! } input VariantsAttributesInput { @@ -119,6 +120,12 @@ extend type Query @guard { relation: "attributeValues" columns: ["products_variants_id", "value", "attributes_id"] ) + hasChannel: _ + @whereHasConditions( + relation: "channels" + columns: ["uuid"] + handler: "App\\GraphQL\\Inventory\\Builders\\Variants\\VariantChannelBuilder@getHasChannel" + ) orderBy: _ @orderBy( columns: [ diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index 9e6f7e4073..af54d686de 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -171,7 +171,7 @@ public function channels(): BelongsToMany 'products_variants_id', 'channels_id' ) - ->withPivot('price', 'discounted_price', 'is_published'); + ->withPivot('price', 'discounted_price', 'is_published', 'warehouses_id'); } /**