feat: update ProductController and ProductResource to include attribute options in product loading
This commit is contained in:
@@ -24,6 +24,7 @@ class ProductController extends Controller
|
|||||||
'attachments' => fn ($query) => $query->orderBy('attachments.id')->limit(1),
|
'attachments' => fn ($query) => $query->orderBy('attachments.id')->limit(1),
|
||||||
'brand',
|
'brand',
|
||||||
'category',
|
'category',
|
||||||
|
'attributes.options',
|
||||||
])
|
])
|
||||||
->latest()
|
->latest()
|
||||||
->paginateFromRequest()
|
->paginateFromRequest()
|
||||||
@@ -45,8 +46,7 @@ class ProductController extends Controller
|
|||||||
'attachments',
|
'attachments',
|
||||||
'brand',
|
'brand',
|
||||||
'category',
|
'category',
|
||||||
'variants.definitions.attribute.options',
|
'attributes.options',
|
||||||
'variants.attachments',
|
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ProductResource extends JsonResource
|
|||||||
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
|
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
|
||||||
->values()
|
->values()
|
||||||
),
|
),
|
||||||
'variants' => ProductVariantResource::collection($this->whenLoaded('variants')),
|
'attributes' => AttributeResource::collection($this->whenLoaded('attributes')),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class ProductService
|
|||||||
$this->syncProductImages($product, $images);
|
$this->syncProductImages($product, $images);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $product->load(['attributes', 'attachments', 'brand', 'category']);
|
return $product->load(['attributes.options', 'attachments', 'brand', 'category']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class ProductService
|
|||||||
$this->syncProductImages($product, $images);
|
$this->syncProductImages($product, $images);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $product->load(['attributes', 'attachments', 'brand', 'category']);
|
return $product->load(['attributes.options', 'attachments', 'brand', 'category']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user