Skip to content

Commit f88df18

Browse files
committed
Add attributeValueGroup relationship to AttributeValue model and include group and label in product variations
This commit introduces a new relationship in the AttributeValue model to link it with the AttributeValueGroup model. Additionally, it updates the Product model to include the 'group' and 'label' fields in the product variations, enhancing the information available for each product attribute.
1 parent 60027f1 commit f88df18

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

app/Models/AttributeValue.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\Product;
66
use App\Models\Attribute;
7+
use App\Models\AttributeValueGroup;
78
use App\Models\ProductAttributesValue;
89
use Illuminate\Database\Eloquent\Model;
910
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -28,4 +29,8 @@ public function attributes()
2829
public function productAttributesValues():HasMany{
2930
return $this->hasMany(ProductAttributesValue::class);
3031
}
32+
33+
public function attributeValueGroup(){
34+
return $this->belongsTo(AttributeValueGroup::class);
35+
}
3136
}

app/Models/Product.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public function getVariations()
111111
"id" => $attr->id,
112112
"name" => $attr->attributeValue->attribute->name ?? null,
113113
"value" => $attr->attributeValue->value ?? null,
114+
"group"=>$attr->attributeValue->attributeValueGroup->label ?? null,
115+
"label"=>$attr->attributeValue->label ?? null,
114116
"quantity" => $attr->quantity ?? null,
115117
"price" => $attr->price ?? null,
116118
];

0 commit comments

Comments
 (0)