|
|
@@ -445,6 +445,9 @@ class Product extends BaseProduct
|
|
|
'color' => ['id' => 23],
|
|
|
'size' => ['id' => 24],
|
|
|
'brand' => ['id' => 25],
|
|
|
+ 'video' => ['id' => 49],
|
|
|
+ 'alone' => ['id' => 36],
|
|
|
+ 'feature' => ['id' => 37],
|
|
|
];
|
|
|
|
|
|
#[ApiProperty(identifier: true, writable: false)]
|
|
|
@@ -504,71 +507,66 @@ class Product extends BaseProduct
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get all custom attribute values for this product.
|
|
|
- *
|
|
|
- * Aggregates every `attribute_values` row into a flat list of
|
|
|
- * `{ code, label, value }` entries (resolved for the current
|
|
|
- * locale/channel). Exposed to GraphQL/REST as `attributes` so any
|
|
|
- * attribute added later in the Attributes table is surfaced
|
|
|
- * automatically without code changes.
|
|
|
- *
|
|
|
- * @return \Webkul\BagistoApi\Dto\ProductDetail\ProductAttributeDto[]
|
|
|
+ * Get the "video" attribute value (text).
|
|
|
*/
|
|
|
- public function getAttributesAttribute(): array
|
|
|
+ public function getVideoAttribute(): ?string
|
|
|
{
|
|
|
- if (! $this->relationLoaded('attribute_values')) {
|
|
|
- $this->load('attribute_values.attribute');
|
|
|
- } elseif (! $this->attribute_values->first()?->relationLoaded('attribute')) {
|
|
|
- $this->load('attribute_values.attribute');
|
|
|
- }
|
|
|
-
|
|
|
- $currentLocale = $this->locale ?? app()->getLocale();
|
|
|
- $currentChannel = $this->channel ?? (core()->getCurrentChannel()->code ?? 'default');
|
|
|
-
|
|
|
- $localeVariants = array_values(array_unique(array_filter([
|
|
|
- $currentLocale,
|
|
|
- core()->getCurrentChannel()->default_locale?->code,
|
|
|
- null,
|
|
|
- ])));
|
|
|
+ $value = $this->getSystemAttributeValue('video');
|
|
|
|
|
|
- $channelVariants = [$currentChannel, null];
|
|
|
+ return $value === '' ? null : (string) $value;
|
|
|
+ }
|
|
|
|
|
|
- $seen = [];
|
|
|
- $result = [];
|
|
|
+ #[ApiProperty(writable: true, readable: true)]
|
|
|
+ public function getVideo(): ?string
|
|
|
+ {
|
|
|
+ return $this->getVideoAttribute();
|
|
|
+ }
|
|
|
|
|
|
- foreach ($this->attribute_values as $av) {
|
|
|
- $code = $av->attribute?->code;
|
|
|
+ public function setVideo(?string $value): void
|
|
|
+ {
|
|
|
+ $this->setSystemAttributeValue('video', $value);
|
|
|
+ }
|
|
|
|
|
|
- if (! $code) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Get the "alone" attribute value (boolean).
|
|
|
+ */
|
|
|
+ public function getAloneAttribute(): ?bool
|
|
|
+ {
|
|
|
+ $value = $this->getSystemAttributeValue('alone');
|
|
|
|
|
|
- // Only keep the best (most specific) match per attribute code.
|
|
|
- if (isset($seen[$code])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ return $value === '' || $value === null ? null : (bool) $value;
|
|
|
+ }
|
|
|
|
|
|
- $locale = $av->locale;
|
|
|
- $channel = $av->channel;
|
|
|
+ #[ApiProperty(writable: true, readable: true)]
|
|
|
+ public function getAlone(): ?bool
|
|
|
+ {
|
|
|
+ return $this->getAloneAttribute();
|
|
|
+ }
|
|
|
|
|
|
- $localeRank = array_search($locale, $localeVariants, true);
|
|
|
- $channelRank = array_search($channel, $channelVariants, true);
|
|
|
+ public function setAlone(?bool $value): void
|
|
|
+ {
|
|
|
+ $this->setSystemAttributeValue('alone', $value);
|
|
|
+ }
|
|
|
|
|
|
- // Ignore rows that don't match the current locale/channel scope.
|
|
|
- if ($localeRank === false || $channelRank === false) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Get the "feature" attribute value (textarea / HTML).
|
|
|
+ */
|
|
|
+ public function getFeatureAttribute(): ?string
|
|
|
+ {
|
|
|
+ $value = $this->getSystemAttributeValue('feature');
|
|
|
|
|
|
- $seen[$code] = true;
|
|
|
+ return $value === '' ? null : (string) $value;
|
|
|
+ }
|
|
|
|
|
|
- $result[] = new \Webkul\BagistoApi\Dto\ProductDetail\ProductAttributeDto(
|
|
|
- code: $code,
|
|
|
- label: $av->attribute?->admin_name ?? $av->attribute?->name ?? $code,
|
|
|
- value: $av->value,
|
|
|
- );
|
|
|
- }
|
|
|
+ #[ApiProperty(writable: true, readable: true)]
|
|
|
+ public function getFeature(): ?string
|
|
|
+ {
|
|
|
+ return $this->getFeatureAttribute();
|
|
|
+ }
|
|
|
|
|
|
- return $result;
|
|
|
+ public function setFeature(?string $value): void
|
|
|
+ {
|
|
|
+ $this->setSystemAttributeValue('feature', $value);
|
|
|
}
|
|
|
|
|
|
/**
|