diff --git a/src/Controller/ProductCategoryAttributesController.php b/src/Controller/ProductCategoryAttributesController.php index 20a5ae7..5f9679e 100644 --- a/src/Controller/ProductCategoryAttributesController.php +++ b/src/Controller/ProductCategoryAttributesController.php @@ -167,6 +167,9 @@ class ProductCategoryAttributesController extends AppController return $this->redirect(['action' => 'index']); } + /** + * @return void + */ public function form() { $productCategoryAttributes = $this->getTable()->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1')); diff --git a/src/Model/Table/ProductCategoryAttributesTable.php b/src/Model/Table/ProductCategoryAttributesTable.php index 58bd032..5336f39 100644 --- a/src/Model/Table/ProductCategoryAttributesTable.php +++ b/src/Model/Table/ProductCategoryAttributesTable.php @@ -113,8 +113,11 @@ class ProductCategoryAttributesTable extends Table public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) { - $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); - $categories = $this->ProductCategories->find('path', for: $category->id)->all(); + $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->first(); + $categories = []; + if ($category) { + $categories = $this->ProductCategories->find('path', for: $category->id)->all(); + } return $categories; }