product attributes on edit product

This commit is contained in:
2025-09-19 23:34:04 -07:00
parent f0f9ebeb8c
commit 25cb12d810
3 changed files with 74 additions and 7 deletions

View File

@@ -107,9 +107,16 @@ class ProductsController extends AppController
public function edit($id = null)
{
$productsTable = $this->getTable();
$product = $productsTable->get($id, contain: []);
$product = $productsTable->get($id, contain: [
'ProductAttributes',
'ProductAttributes.ProductCategoryAttributes',
'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions',
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$product = $productsTable->patchEntity($product, $this->request->getData());
$saveOptions = [
'associated' => ['ProductAttributes'],
];
$product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions);
if ($productsTable->save($product)) {
$this->Flash->success(__('The product has been saved.'));
@@ -122,6 +129,7 @@ class ProductsController extends AppController
$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'));
}
/**