Skip to content

Commit 6ab0545

Browse files
committed
Add getAttributeValueByAttributeId method and corresponding API route
This commit introduces a new method in the ListCategoryController to retrieve attribute values based on a given attribute ID, enhancing the functionality for managing category attributes. Additionally, a new route is added to the API for accessing this method, improving the overall attribute management capabilities.
1 parent 553c0eb commit 6ab0545

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

app/Http/Controllers/ListCategoryController.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,40 @@ public function getCategoriesWithAttributes(){
113113
return $categoriesWithAttributes;
114114
}
115115

116+
public function getAttributeValueByAttributeId($attributeId){
117+
118+
$categoryAttributeLink = DB::table('category_atributes')
119+
->where('attribute_id', $attributeId)
120+
->first();
121+
122+
if (!$categoryAttributeLink) {
123+
return response()->json(['error' => 'No link found between this category and attribute.'], 404);
124+
}
125+
126+
// On trouve tous les groupes de valeurs liés à cette combinaison de catégorie et d'attribut.
127+
$groups = DB::table('category_atribute_group_links')
128+
->where('category_attribute_id', $categoryAttributeLink->id)
129+
->join('attribute_value_groups', 'category_atribute_group_links.attribute_value_group_id', '=', 'attribute_value_groups.id')
130+
->select('attribute_value_groups.id', 'attribute_value_groups.label')
131+
->get();
132+
133+
$result = [];
134+
135+
// Pour chaque groupe trouvé, on récupère les valeurs correspondantes.
136+
foreach ($groups as $group) {
137+
$values = DB::table('attribute_values')
138+
->where('attribute_value_group_id', $group->id)
139+
->where('attribute_id',$attributeId)
140+
->select('id as value_id', 'value', 'hex_color')
141+
->get();
142+
143+
$result[] = [
144+
'group_id' => $group->id,
145+
'group_label' => $group->label,
146+
'values' => $values,
147+
];
148+
}
149+
150+
return response()->json($result);
151+
}
116152
}

routes/api.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
Route::get("/attributes/value/{id}", [GetAttributesController::class, 'getValue']);
165165
Route::get("/all/genders", [CurrentGenderController::class, "all"]);
166166

167+
Route::get('/attributes/value/by/group/{id}',[ListCategoryController::class,"getAttributeValueByAttributeId"]);
168+
Route::get('/categories/attributes',[ListCategoryController::class,"getCategoriesWithAttributes"]);
169+
167170
Route::middleware(['auth:api', 'scopes:seller', "isSeller"])->prefix('v1')->group(function () {
168171
Route::post("init/payment/subscription/product", [SubscribeProductController::class, "initPay"]);
169172
Route::post('init/payment/subscription/product/pending/{membership_id}/{product_id}/{transaction_ref}', [SubscribeProductController::class, 'initPaymentPending']);
@@ -179,7 +182,7 @@
179182
Route::post('update/images',[UpdateSellerController::class,'updateGalerieImages']);
180183
Route::post("/boost/shop",[BoostShopController::class,'boost']);
181184

182-
Route::get('/categories/attributes',[ListCategoryController::class,"getCategoriesWithAttributes"]);
185+
183186

184187
// Routes pour la gestion des commandes du vendeur
185188
Route::get('/seller/orders', [OrderListController::class, 'listOrders']);

0 commit comments

Comments
 (0)