attributes form wip

This commit is contained in:
2025-04-02 01:27:25 -07:00
parent 732819ff73
commit 2f80ba1fa3
4 changed files with 48 additions and 70 deletions

View File

@@ -4,7 +4,10 @@
* @var \Cake\Datasource\EntityInterface $productCategory
* @var \Cake\Collection\CollectionInterface|string[] $productCatalogs
* @var \Cake\Collection\CollectionInterface|string[] $parentProductCategories
*
*/
?>
<div class="row">
<aside class="column">

View File

@@ -1,63 +1,36 @@
<?php
/**
* @var \App\View\AppView $this
* @var \Cake\Datasource\EntityInterface $productCategoryAttribute
* @var \Cake\Datasource\EntityInterface[]|ProductCategoryAttribute[] $productCategoryAttributes
*/
use Cake\Utility\Hash;
use CakeProducts\Model\Entity\ProductCategoryAttribute;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
$this->setLayout('ajax');
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Html->link(__('Edit Product Category Attribute'), ['action' => 'edit', $productCategoryAttribute->id], ['class' => 'side-nav-item']) ?>
<?= $this->Form->postLink(__('Delete Product Category Attribute'), ['action' => 'delete', $productCategoryAttribute->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryAttribute->id), 'class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('List Product Category Attributes'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
<?= $this->Html->link(__('New Product Category Attribute'), ['action' => 'add'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column column-80">
<div class="productCategoryAttributes view content">
<h3><?= h($productCategoryAttribute->name) ?></h3>
<table>
<tr>
<th><?= __('Name') ?></th>
<td><?= h($productCategoryAttribute->name) ?></td>
</tr>
<tr>
<th><?= __('Product Category') ?></th>
<td><?= $productCategoryAttribute->hasValue('product_category') ? $this->Html->link($productCategoryAttribute->product_category->name, ['controller' => 'ProductCategories', 'action' => 'view', $productCategoryAttribute->product_category->id]) : '' ?></td>
</tr>
<tr>
<th><?= __('Enabled') ?></th>
<td><?= $productCategoryAttribute->enabled ? __('Yes') : __('No'); ?></td>
</tr>
</table>
<div class="related">
<h4><?= __('Related Product Category Attribute Options') ?></h4>
<?php if (!empty($productCategoryAttribute->product_category_attribute_options)) : ?>
<div class="table-responsive">
<table>
<tr>
<th><?= __('Attribute Value') ?></th>
<th><?= __('Attribute Label') ?></th>
<th><?= __('Enabled') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
<?php foreach ($productCategoryAttribute->product_category_attribute_options as $productCategoryAttributeOptions) : ?>
<tr>
<td><?= h($productCategoryAttributeOptions->attribute_value) ?></td>
<td><?= h($productCategoryAttributeOptions->attribute_label) ?></td>
<td><?= h($productCategoryAttributeOptions->enabled) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'ProductCategoryAttributeOptions', 'action' => 'view', $productCategoryAttributeOptions->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'ProductCategoryAttributeOptions', 'action' => 'edit', $productCategoryAttributeOptions->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'ProductCategoryAttributeOptions', 'action' => 'delete', $productCategoryAttributeOptions->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryAttributeOptions->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
$cnt = 0;
foreach ($productCategoryAttributes 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') :
[];
}
if ($productCategoryAttribute->attribute_type_id === ProductCategoryAttributeTypeId::Integer) {
$inputType = 'number';
}
echo $this->Form->control('product_attributes.' . $cnt . '.product_category_attribute_id', [
'type' => $inputType,
'label' => $productCategoryAttribute->name,
'options' => $options,
]);
}