product attributes increment was missing on form, view product attributes on view product page
CI / testsuite (mysql, 8.1, ) (push) Failing after 1s Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 1s Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 1s Details
CI / Coding Standard & Static Analysis (push) Failing after 0s Details

This commit is contained in:
Brandon Shipley 2025-04-05 02:37:53 -07:00
parent bb1dab1f43
commit b5926c260e
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
3 changed files with 57 additions and 20 deletions

View File

@ -53,7 +53,12 @@ class ProductsController extends AppController
*/
public function view($id = null)
{
$product = $this->getTable()->get($id, contain: ['ProductCategories']);
$product = $this->getTable()->get($id, contain: [
'ProductCategories',
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributeOptions',
]);
$this->set(compact('product'));
}

View File

@ -13,24 +13,35 @@ $this->setLayout('ajax');
<?php
$cnt = 0;
foreach ($productCategoryAttributes as $productCategoryAttribute) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.product_category_attribute_id', [
foreach ($productCategories as $productCategory) {
foreach ($productCategory->product_category_attributes as $productCategoryAttribute) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.product_category_attribute_id', [
'value' => $productCategoryAttribute->id,
]);
$inputType = 'text';
$options = [];
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Constrained) {
$inputType = 'select';
$options = !empty($productCategoryAttribute->product_category_attribute_options) ?
Hash::combine($productCategoryAttribute->product_category_attribute_options, '{n}.id', '{n}.attribute_label') :
[];
]);
$inputType = 'text';
$options = [];
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Integer) {
$inputType = 'number';
}
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Constrained) {
echo $this->Form->hidden('product_attributes.' . $cnt . '.attribute_value', [
'value' => '',
]);
$options = !empty($productCategoryAttribute->product_category_attribute_options) ?
Hash::combine($productCategoryAttribute->product_category_attribute_options, '{n}.id', '{n}.attribute_label') :
[];
echo $this->Form->control('product_attributes.' . $cnt . '.product_category_attribute_option_id', [
'type' => 'select',
'label' => $productCategoryAttribute->name,
'options' => $options,
]);
} else {
echo $this->Form->control('product_attributes.' . $cnt . '.attribute_value', [
'type' => $inputType,
'label' => $productCategoryAttribute->name,
'options' => $options,
]);
}
$cnt++;
}
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Integer) {
$inputType = 'number';
}
echo $this->Form->control('product_attributes.' . $cnt . '.attribute_value', [
'type' => $inputType,
'label' => $productCategoryAttribute->name,
'options' => $options,
]);
}
}

View File

@ -32,5 +32,26 @@
</tr>
</table>
</div>
<div class="related">
<h4><?= __('Product Attributes') ?></h4>
<?php if (!empty($product->product_attributes)) : ?>
<div class="table-responsive">
<table>
<?php foreach ($product->product_attributes as $productAttribute) : ?>
<?php if (!$productAttribute->hasValue('product_category_attribute')) {
continue;
} ?>
<tr>
<th><?= h($productAttribute->product_category_attribute->name) ?></th>
<td>
<?= $productAttribute->hasValue('product_category_attribute_option') ? h($productAttribute->product_category_attribute_option->attribute_label) : ''; ?>
<?= !$productAttribute->hasValue('product_category_attribute_option') ? h($productAttribute->attribute_value) : ''; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>