feat(product): display attributes
This commit is contained in:
@@ -9,6 +9,7 @@ use Registry;
|
|||||||
/**
|
/**
|
||||||
* @property Loader $load
|
* @property Loader $load
|
||||||
* @property Cart $cart
|
* @property Cart $cart
|
||||||
|
* @property \ModelCatalogProduct $model_catalog_product
|
||||||
*/
|
*/
|
||||||
class OcRegistryDecorator
|
class OcRegistryDecorator
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Handlers;
|
namespace App\Handlers;
|
||||||
|
|
||||||
use App\Adapters\OcModelCatalogProductAdapter;
|
use App\Adapters\OcModelCatalogProductAdapter;
|
||||||
|
use App\Decorators\OcRegistryDecorator;
|
||||||
use Cart\Currency;
|
use Cart\Currency;
|
||||||
use Cart\Tax;
|
use Cart\Tax;
|
||||||
use Openguru\OpenCartFramework\Config\Settings;
|
use Openguru\OpenCartFramework\Config\Settings;
|
||||||
@@ -23,6 +24,7 @@ class ProductsHandler
|
|||||||
private Settings $settings;
|
private Settings $settings;
|
||||||
private OcModelCatalogProductAdapter $ocModelCatalogProduct;
|
private OcModelCatalogProductAdapter $ocModelCatalogProduct;
|
||||||
private ImageToolInterface $ocImageTool;
|
private ImageToolInterface $ocImageTool;
|
||||||
|
private OcRegistryDecorator $oc;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Builder $queryBuilder,
|
Builder $queryBuilder,
|
||||||
@@ -30,7 +32,8 @@ class ProductsHandler
|
|||||||
Tax $tax,
|
Tax $tax,
|
||||||
Settings $settings,
|
Settings $settings,
|
||||||
OcModelCatalogProductAdapter $ocModelCatalogProduct,
|
OcModelCatalogProductAdapter $ocModelCatalogProduct,
|
||||||
ImageToolInterface $ocImageTool
|
ImageToolInterface $ocImageTool,
|
||||||
|
OcRegistryDecorator $registry
|
||||||
) {
|
) {
|
||||||
$this->queryBuilder = $queryBuilder;
|
$this->queryBuilder = $queryBuilder;
|
||||||
$this->currency = $currency;
|
$this->currency = $currency;
|
||||||
@@ -38,6 +41,7 @@ class ProductsHandler
|
|||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->ocModelCatalogProduct = $ocModelCatalogProduct;
|
$this->ocModelCatalogProduct = $ocModelCatalogProduct;
|
||||||
$this->ocImageTool = $ocImageTool;
|
$this->ocImageTool = $ocImageTool;
|
||||||
|
$this->oc = $registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Request $request): JsonResponse
|
public function handle(Request $request): JsonResponse
|
||||||
@@ -185,7 +189,6 @@ class ProductsHandler
|
|||||||
$product = $this->queryBuilder->newQuery()
|
$product = $this->queryBuilder->newQuery()
|
||||||
->select([
|
->select([
|
||||||
'products.product_id' => 'product_id',
|
'products.product_id' => 'product_id',
|
||||||
'products.quantity' => 'product_quantity',
|
|
||||||
'product_description.name' => 'product_name',
|
'product_description.name' => 'product_name',
|
||||||
'product_description.description' => 'product_description',
|
'product_description.description' => 'product_description',
|
||||||
'products.price' => 'price',
|
'products.price' => 'price',
|
||||||
@@ -264,6 +267,7 @@ class ProductsHandler
|
|||||||
'quantity' => $product['quantity'],
|
'quantity' => $product['quantity'],
|
||||||
'images' => $images,
|
'images' => $images,
|
||||||
'options' => $this->loadProductOptions($product),
|
'options' => $this->loadProductOptions($product),
|
||||||
|
'attributes' => $this->loadProductAttributes($product['product_id']),
|
||||||
];
|
];
|
||||||
|
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
@@ -323,4 +327,11 @@ class ProductsHandler
|
|||||||
|
|
||||||
return $result;
|
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>
|
<p class="text-base" v-html="product.description"></p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user