Skip to content

Commit

Permalink
Merge pull request #792 from bakaphp/channel-search-by-attribute
Browse files Browse the repository at this point in the history
Allow to search by channel on where
  • Loading branch information
arfenis authored Jan 10, 2024
2 parents 24ccffa + 26a4998 commit ed01edb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions graphql/schemas/Inventory/variant.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Variant {
@hasMany(relation: "variantWarehouses")
attributes: [VariantsAttributes!]!
companies: Company
channels: [VariantChannelRelationship!]!
}

input VariantsAttributesInput {
Expand Down Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion src/Domains/Inventory/Variants/Models/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit ed01edb

Please sign in to comment.