diff --git a/src/Controller/ProductsController.php b/src/Controller/ProductsController.php index 48e169c..08d4111 100644 --- a/src/Controller/ProductsController.php +++ b/src/Controller/ProductsController.php @@ -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')); } diff --git a/templates/ProductCategoryAttributes/form.php b/templates/ProductCategoryAttributes/form.php index f20fbda..d13a78e 100644 --- a/templates/ProductCategoryAttributes/form.php +++ b/templates/ProductCategoryAttributes/form.php @@ -13,24 +13,35 @@ $this->setLayout('ajax'); 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, - ]); -} \ No newline at end of file +} diff --git a/templates/Products/view.php b/templates/Products/view.php index 009f119..e9ac6d3 100644 --- a/templates/Products/view.php +++ b/templates/Products/view.php @@ -32,5 +32,26 @@ +