diff --git a/src/Controller/ProductCategoriesController.php b/src/Controller/ProductCategoriesController.php index 8a2a168..0229d5d 100644 --- a/src/Controller/ProductCategoriesController.php +++ b/src/Controller/ProductCategoriesController.php @@ -60,7 +60,9 @@ class ProductCategoriesController extends AppController 'ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions', ]); - $this->set(compact('productCategory')); + + $productCategoryAttributes = $this->getTable()->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id); + $this->set(compact('productCategory', 'productCategoryAttributes')); } /** diff --git a/src/Controller/ProductCategoryAttributesController.php b/src/Controller/ProductCategoryAttributesController.php index 58adeac..d142643 100644 --- a/src/Controller/ProductCategoryAttributesController.php +++ b/src/Controller/ProductCategoryAttributesController.php @@ -61,6 +61,7 @@ class ProductCategoryAttributesController extends AppController 'ProductCategories', 'ProductCategoryAttributeOptions', ]); + $this->set(compact('productCategoryAttribute')); } @@ -165,4 +166,11 @@ class ProductCategoryAttributesController extends AppController return $this->redirect(['action' => 'index']); } + + public function form($categoryId = null) + { + $productCategoryAttributes = $this->getTable()->getAllCategoryAttributesForCategoryId($categoryId); + + $this->set(compact('productCategoryAttributes')); + } } diff --git a/src/Controller/ProductsController.php b/src/Controller/ProductsController.php index 684ee15..f54c288 100644 --- a/src/Controller/ProductsController.php +++ b/src/Controller/ProductsController.php @@ -77,8 +77,9 @@ class ProductsController extends AppController Log::debug(print_r($product->getErrors(), true)); $this->Flash->error(__('The product could not be saved. Please, try again.')); } - $productCategories = $productsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name' )->all(); - $this->set(compact('product', 'productCategories')); + $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null; + $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); + $this->set(compact('product', 'productCatalogs', 'productCategory')); } /** diff --git a/src/Model/Table/ProductCategoryAttributesTable.php b/src/Model/Table/ProductCategoryAttributesTable.php index a2f3cf8..58bd032 100644 --- a/src/Model/Table/ProductCategoryAttributesTable.php +++ b/src/Model/Table/ProductCategoryAttributesTable.php @@ -110,4 +110,12 @@ class ProductCategoryAttributesTable extends Table return $rules; } + + public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) + { + $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); + $categories = $this->ProductCategories->find('path', for: $category->id)->all(); + + return $categories; + } } diff --git a/templates/Products/add.php b/templates/Products/add.php index 39bf6b0..08c3a0e 100644 --- a/templates/Products/add.php +++ b/templates/Products/add.php @@ -17,11 +17,7 @@ = $this->Form->create($product) ?>
= $this->Form->button(__('Submit')) ?> = $this->Form->end() ?> diff --git a/templates/Products/edit.php b/templates/Products/edit.php index 5d49a17..ed9457b 100644 --- a/templates/Products/edit.php +++ b/templates/Products/edit.php @@ -22,11 +22,7 @@ = $this->Form->create($product) ?> = $this->Form->button(__('Submit')) ?> = $this->Form->end() ?> diff --git a/templates/element/ExternalProductCatalogs/form.php b/templates/element/ExternalProductCatalogs/form.php index d8bcffc..646aab0 100644 --- a/templates/element/ExternalProductCatalogs/form.php +++ b/templates/element/ExternalProductCatalogs/form.php @@ -19,7 +19,6 @@ echo $this->Form->control('api_url'); ?>