|
|
@@ -10,6 +10,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
use Longyi\Core\Models\ProductVariant as BaseProductVariant;
|
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
|
use Webkul\BagistoApi\Resolver\BaseQueryItemResolver;
|
|
|
+use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
+use Webkul\Product\Models\ProductPriceIndexProxy;
|
|
|
|
|
|
/**
|
|
|
* BagistoApi wrapper around the Longyi1 flexible variant model so that
|
|
|
@@ -19,9 +21,10 @@ use Webkul\BagistoApi\Resolver\BaseQueryItemResolver;
|
|
|
#[ApiResource(
|
|
|
routePrefix: '/api/shop',
|
|
|
shortName: 'ProductVariant',
|
|
|
+ paginationEnabled: false,
|
|
|
operations: [],
|
|
|
graphQlOperations: [
|
|
|
- new Query(resolver: BaseQueryItemResolver::class),
|
|
|
+ new Query(resolver: BaseQueryItemResolver::class, paginationEnabled: false),
|
|
|
]
|
|
|
)]
|
|
|
class ProductVariant extends BaseProductVariant
|
|
|
@@ -31,8 +34,15 @@ class ProductVariant extends BaseProductVariant
|
|
|
'effective_price',
|
|
|
'variant_images',
|
|
|
'option_values',
|
|
|
+ 'price_indices',
|
|
|
];
|
|
|
|
|
|
+
|
|
|
+ public function getMorphClass(): string
|
|
|
+ {
|
|
|
+ return BaseProductVariant::class;
|
|
|
+ }
|
|
|
+
|
|
|
#[ApiProperty(identifier: true, writable: false)]
|
|
|
public function getId(): ?int
|
|
|
{
|
|
|
@@ -122,7 +132,7 @@ class ProductVariant extends BaseProductVariant
|
|
|
*/
|
|
|
public function getEffectivePriceAttribute(): float
|
|
|
{
|
|
|
- return $this->getBasicEffectivePrice();
|
|
|
+ return $this->getEffectivePrice();
|
|
|
}
|
|
|
|
|
|
#[ApiProperty(writable: false, readable: true, required: false)]
|
|
|
@@ -226,4 +236,31 @@ class ProductVariant extends BaseProductVariant
|
|
|
{
|
|
|
return $this->belongsTo(Product::class, 'product_id');
|
|
|
}
|
|
|
+
|
|
|
+ public function getPriceIndicesAttribute(): ?string
|
|
|
+ {
|
|
|
+ if (! $this->relationLoaded('price_indices')) {
|
|
|
+ $this->load('price_indices');
|
|
|
+ }
|
|
|
+ $customerGroupId = app(\Webkul\Customer\Repositories\CustomerRepository::class)
|
|
|
+ ->getCurrentGroup()->id;
|
|
|
+ $channelId = core()->getCurrentChannel()->id;
|
|
|
+
|
|
|
+ $indexs = $this->getRelation('price_indices')
|
|
|
+ ->where('customer_group_id', $customerGroupId)
|
|
|
+ ->where('channel_id', $channelId);
|
|
|
+
|
|
|
+
|
|
|
+ $payload = $indexs
|
|
|
+ ->map(fn ($price_index) => [
|
|
|
+ 'id' => $price_index->id,
|
|
|
+ 'min_price' => $price_index->min_price,
|
|
|
+ 'regular_min_price' => $price_index->regular_min_price,
|
|
|
+ ])
|
|
|
+ ->values()
|
|
|
+ ->all();
|
|
|
+
|
|
|
+ return empty($payload) ? null : json_encode($payload);
|
|
|
+ }
|
|
|
+
|
|
|
}
|