Skip to content

Commit

Permalink
Merge pull request #193 from dystcz/feature/update-product-option-values
Browse files Browse the repository at this point in the history
Update product option values
  • Loading branch information
repl6669 authored Oct 29, 2024
2 parents 423c044 + f553ef9 commit 30e6d3e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Domain/CartLines/JsonApi/V1/CartLineSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function includePaths(): iterable
'purchasable.product.images',
'purchasable.product.thumbnail',
'purchasable.product_option_values',
'purchasable.product_option_values.images',
'purchasable.product_option_values.product_option',

...parent::includePaths(),
Expand Down
3 changes: 3 additions & 0 deletions src/Domain/Orders/JsonApi/V1/OrderSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function includePaths(): iterable
'product_lines.purchasable.thumbnail',
'product_lines.purchasable.product',
'product_lines.purchasable.product.thumbnail',
'product_lines.purchasable.product_option_values',
'product_lines.purchasable.product_option_values.images',
'product_lines.purchasable.product_option_values.product_option',

// Shipping lines
'shipping_lines',
Expand Down
15 changes: 15 additions & 0 deletions src/Domain/ProductOptionValues/Concerns/InteractsWithLunarApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace Dystcz\LunarApi\Domain\ProductOptionValues\Concerns;

use Dystcz\LunarApi\Domain\ProductOptionValues\Factories\ProductOptionValueFactory;
use Dystcz\LunarApi\Domain\ProductOptionValues\Models\ProductOptionValue;
use Dystcz\LunarApi\Hashids\Traits\HashesRouteKey;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Facades\Config;

trait InteractsWithLunarApi
{
Expand All @@ -16,4 +19,16 @@ protected static function newFactory(): ProductOptionValueFactory
{
return ProductOptionValueFactory::new();
}

public function images(): MorphMany
{
/** @var ProductOptionValue $this */

return $this
->media()
->where(
'collection_name',
Config::get('lunar.media.collection'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Dystcz\LunarApi\Domain\JsonApi\Eloquent\Schema;
use Dystcz\LunarApi\Support\Models\Actions\SchemaType;
use LaravelJsonApi\Eloquent\Fields\Relations\BelongsTo;
use LaravelJsonApi\Eloquent\Fields\Relations\HasMany;
use LaravelJsonApi\Eloquent\Fields\Str;
use Lunar\Models\Contracts\ProductOption;
use Lunar\Models\Contracts\ProductOptionValue;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class ProductOptionValueSchema extends Schema
{
Expand All @@ -22,6 +24,7 @@ class ProductOptionValueSchema extends Schema
public function includePaths(): iterable
{
return [
'images',
'product_option',

...parent::includePaths(),
Expand Down Expand Up @@ -49,6 +52,11 @@ public function fields(): iterable
static fn ($relation) => $relation->withoutLinks()
),

HasMany::make('images', 'images')
->type(SchemaType::get(Media::class))
->canCount()
->countAs('images_count'),

...parent::fields(),
];
}
Expand Down
3 changes: 3 additions & 0 deletions src/Domain/ProductOptions/JsonApi/V1/ProductOptionSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class ProductOptionSchema extends Schema
public function includePaths(): iterable
{
return [
'product_option_values',
'product_option_values.images',

...parent::includePaths(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function includePaths(): iterable
'urls',
'values',

'product_option_values',
'product_option_values.images',
'product_option_values.product_option',

...parent::includePaths(),
];
}
Expand Down
7 changes: 7 additions & 0 deletions src/Domain/Products/JsonApi/V1/ProductSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public function includePaths(): iterable
'collections.default_url',
'collections.group',

'product_option.product_option_values',
'product_option.product_option_values.images',

'product_option_values',
'product_option_values.images',
'product_option_values.product_option',

'product_type',
'tags',

Expand Down

0 comments on commit 30e6d3e

Please sign in to comment.