default product type id on categories table

This commit is contained in:
2025-07-05 23:18:54 -07:00
parent 59a38758e9
commit 9d777f12b2
7 changed files with 68 additions and 8 deletions

View File

@@ -37,7 +37,7 @@ class ProductCategoryVariantsController extends AppController
public function index()
{
$query = $this->getTable()->find()
->contain(['ProductCategories', 'Products']);
->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
$productCategoryVariants = $this->paginate($query);
$this->set(compact('productCategoryVariants'));
@@ -52,7 +52,7 @@ class ProductCategoryVariantsController extends AppController
*/
public function view($id = null)
{
$productCategoryVariant = $this->getTable()->get($id, contain: ['ProductCategories', 'Products']);
$productCategoryVariant = $this->getTable()->get($id, contain: ['ProductCategories', 'Products', 'ProductCategoryVariantOptions']);
$this->set(compact('productCategoryVariant'));
}
@@ -77,7 +77,7 @@ class ProductCategoryVariantsController extends AppController
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);
@@ -103,8 +103,17 @@ class ProductCategoryVariantsController extends AppController
$productCategoryVariantsTable = $this->getTable();
$productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
$postData = $this->request->getData();
// if ($this->request->getSession()->read('Auth.User.id')) {
// $postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
// }
$saveOptions = [
'associated' => [
'ProductCategoryVariantOptions'
],
];
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) {
$this->Flash->success(__('The product category variant has been saved.'));
return $this->redirect(['action' => 'index']);

View File

@@ -5,6 +5,7 @@ namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/**
* Product Entity
@@ -12,11 +13,13 @@ use Cake\ORM\Entity;
* @property string $id
* @property string $name
* @property string $product_category_id
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
* @property ProductProductTypeId $product_type_id
* @property DateTime|null $deleted
*
* @property \CakeProducts\Model\Entity\ProductCategory $product_category
* @property \CakeProducts\Model\Entity\ProductAttribute[] $product_attributes
* @property ProductCategory $product_category
* @property ProductAttribute[] $product_attributes
* @property ProductCategoryVariant[] $product_category_variants
*
*/
class Product extends Entity
{
@@ -37,5 +40,6 @@ class Product extends Entity
// entities
'product_category' => false,
'product_attributes' => true,
'product_category_variants' => false,
];
}

View File

@@ -5,6 +5,7 @@ namespace CakeProducts\Model\Entity;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
use CakeProducts\Model\Enum\ProductProductTypeId;
/**
* ProductCategory Entity
@@ -19,6 +20,7 @@ use Cake\ORM\Entity;
* @property int $rght
* @property bool $enabled
* @property DateTime|null $deleted
* @property ProductProductTypeId|null $default_product_type_id
*
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
@@ -40,6 +42,7 @@ class ProductCategory extends Entity
'internal_id' => true,
'name' => true,
'category_description' => true,
'default_product_type_id' => true,
'parent_id' => true,
'lft' => true,
'rght' => true,

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Type\EnumType;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
@@ -14,6 +15,7 @@ use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
@@ -99,6 +101,8 @@ class ProductCategoriesTable extends Table
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash');
}
@@ -137,6 +141,10 @@ class ProductCategoriesTable extends Table
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->integer('default_product_type_id')
->allowEmptyString('default_product_type_id');
return $validator;
}