feat(product): display attributes
This commit is contained in:
@@ -9,6 +9,7 @@ use Registry;
|
||||
/**
|
||||
* @property Loader $load
|
||||
* @property Cart $cart
|
||||
* @property \ModelCatalogProduct $model_catalog_product
|
||||
*/
|
||||
class OcRegistryDecorator
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Handlers;
|
||||
|
||||
use App\Adapters\OcModelCatalogProductAdapter;
|
||||
use App\Decorators\OcRegistryDecorator;
|
||||
use Cart\Currency;
|
||||
use Cart\Tax;
|
||||
use Openguru\OpenCartFramework\Config\Settings;
|
||||
@@ -23,6 +24,7 @@ class ProductsHandler
|
||||
private Settings $settings;
|
||||
private OcModelCatalogProductAdapter $ocModelCatalogProduct;
|
||||
private ImageToolInterface $ocImageTool;
|
||||
private OcRegistryDecorator $oc;
|
||||
|
||||
public function __construct(
|
||||
Builder $queryBuilder,
|
||||
@@ -30,7 +32,8 @@ class ProductsHandler
|
||||
Tax $tax,
|
||||
Settings $settings,
|
||||
OcModelCatalogProductAdapter $ocModelCatalogProduct,
|
||||
ImageToolInterface $ocImageTool
|
||||
ImageToolInterface $ocImageTool,
|
||||
OcRegistryDecorator $registry
|
||||
) {
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->currency = $currency;
|
||||
@@ -38,6 +41,7 @@ class ProductsHandler
|
||||
$this->settings = $settings;
|
||||
$this->ocModelCatalogProduct = $ocModelCatalogProduct;
|
||||
$this->ocImageTool = $ocImageTool;
|
||||
$this->oc = $registry;
|
||||
}
|
||||
|
||||
public function handle(Request $request): JsonResponse
|
||||
@@ -185,7 +189,6 @@ class ProductsHandler
|
||||
$product = $this->queryBuilder->newQuery()
|
||||
->select([
|
||||
'products.product_id' => 'product_id',
|
||||
'products.quantity' => 'product_quantity',
|
||||
'product_description.name' => 'product_name',
|
||||
'product_description.description' => 'product_description',
|
||||
'products.price' => 'price',
|
||||
@@ -264,6 +267,7 @@ class ProductsHandler
|
||||
'quantity' => $product['quantity'],
|
||||
'images' => $images,
|
||||
'options' => $this->loadProductOptions($product),
|
||||
'attributes' => $this->loadProductAttributes($product['product_id']),
|
||||
];
|
||||
|
||||
return new JsonResponse([
|
||||
@@ -323,4 +327,11 @@ class ProductsHandler
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function loadProductAttributes(int $productId): array
|
||||
{
|
||||
$this->oc->load->model('catalog/product');
|
||||
|
||||
return $this->oc->model_catalog_product->getProductAttributes($productId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,28 @@
|
||||
<p class="text-base" v-html="product.description"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<h3 class="font-bold mb-2">Характеристики</h3>
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-xs">
|
||||
<tbody>
|
||||
<template v-for="attrGroup in product.attributes" :key="attrGroup.attribute_group_id">
|
||||
<tr class="bg-base-200 font-semibold">
|
||||
<td colspan="2">{{ attrGroup.name }}</td>
|
||||
</tr>
|
||||
<tr v-for="attr in attrGroup.attribute" :key="attr.attribute_id">
|
||||
<td class="w-1/3">{{ attr.name }}</td>
|
||||
<td>{{ attr.text }}</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user