stan fixes, code style fixes - all clean
CI / testsuite (mysql, 8.4, ) (push) Successful in 2m51s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 5m27s
CI / Coding Standard & Static Analysis (push) Failing after 2m34s
CI / testsuite (mysql, 8.2, ) (push) Successful in 6m45s

This commit is contained in:
bs
2026-08-26 01:08:03 -07:00
parent 470a3e76af
commit 7abbb8a5aa
10 changed files with 45 additions and 34 deletions
+1
View File
@@ -8,3 +8,4 @@
/.idea/ /.idea/
tmp tmp
tests/test_app/webroot/images/products/ tests/test_app/webroot/images/products/
tests/test_app/webroot/uploads/
+9 -10
View File
@@ -18,14 +18,12 @@ class ProductCatalogsController extends AppController {
*/ */
public function initialize(): void { public function initialize(): void {
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
// $this->_defaultTable = 'CakeProducts.ProductCatalogs';
// $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
} }
/** /**
* Index method * Index method
* *
* @return \Cake\Http\Response|voidRenders|null view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function index() { public function index() {
$query = $this->ProductCatalogs->find(); $query = $this->ProductCatalogs->find();
@@ -38,8 +36,9 @@ class ProductCatalogsController extends AppController {
* View method * View method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @throws RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return Response|null|void Renders view *
* @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) { public function view($id = null) {
$contain = ['ProductCategories']; $contain = ['ProductCategories'];
@@ -53,7 +52,7 @@ class ProductCatalogsController extends AppController {
/** /**
* Add method * Add method
* *
* @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/ */
public function add() { public function add() {
$productCatalogsTable = $this->ProductCatalogs; $productCatalogsTable = $this->ProductCatalogs;
@@ -78,8 +77,8 @@ class ProductCatalogsController extends AppController {
* Edit method * Edit method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @throws RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) { public function edit($id = null) {
$productCatalogsTable = $this->ProductCatalogs; $productCatalogsTable = $this->ProductCatalogs;
@@ -100,8 +99,8 @@ class ProductCatalogsController extends AppController {
* Delete method * Delete method
* *
* @param string|null $id Product Catalog id. * @param string|null $id Product Catalog id.
* @throws RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return Response|null Redirects to index. * @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) { public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
@@ -85,8 +85,8 @@ class ProductCategoriesController extends AppController {
} }
$this->Flash->error(__('The product category could not be saved. Please, try again.')); $this->Flash->error(__('The product category could not be saved. Please, try again.'));
} }
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all(); $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list', limit: 200)->all();
$parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all(); $parentProductCategories = $this->fetchTable('ProductCategories')->find('list', limit: 200)->all();
$this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories'));
} }
@@ -145,14 +145,14 @@ class ProductCategoriesController extends AppController {
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function select() { public function select() {
$this->ProductCategories->getBehavior('Tree')->setConfig([ $this->ProductCategories->getBehavior('Tree')->setConfig([
'scope' => [ 'scope' => [
'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1),
], ],
]); ]);
$productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ? $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ?
$this->ProductCategories->find('treeList', keyPath: 'internal_id', valuePath: 'name') : $this->ProductCategories->find('treeList', keyPath: 'internal_id', valuePath: 'name') :
$this->ProductCategories->find('treeList'); $this->ProductCategories->find('treeList');
$productCategories = $productCategoriesQ $productCategories = $productCategoriesQ
->orderBy(['ProductCategories.name']) ->orderBy(['ProductCategories.name'])
@@ -122,7 +122,7 @@ class ProductCategoryVariantsController extends AppController {
} }
$productCategories = $this->fetchTable('ProductCategories')->find('list', keyField: 'internal_id', valueField: 'name')->all(); $productCategories = $this->fetchTable('ProductCategories')->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = isset($productCategoryVariant->product_category_id) ? $this->fetchTable('Products')->find('list', limit: 200) $products = isset($productCategoryVariant->product_category_id) ? $this->fetchTable('Products')->find('list', limit: 200)
->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : []; ->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : [];
$this->set(compact('productCategoryVariant', 'productCategories', 'products')); $this->set(compact('productCategoryVariant', 'productCategories', 'products'));
} }
+13 -5
View File
@@ -32,6 +32,7 @@ class ProductPhotosController extends AppController {
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*
* @return \Cake\Http\Response|null|void Renders view * @return \Cake\Http\Response|null|void Renders view
*/ */
public function view($id = null) { public function view($id = null) {
@@ -51,7 +52,7 @@ class ProductPhotosController extends AppController {
if (!$this->request->getData('photo')) { if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.'); $this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$productCategory = $productPhoto->product_category_id ? $this->fetchTable('CakeProducts.ProductCategories')->find() $productCategory = $productPhoto->product_category_id ? $this->fetchTable('CakeProducts.ProductCategories')->find()
->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $this->fetchTable('CakeProducts.ProductCatalogs')->find('list')->toArray(); $productCatalogs = $this->fetchTable('CakeProducts.ProductCatalogs')->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
@@ -70,6 +71,9 @@ class ProductPhotosController extends AppController {
'ProductSkus.id' => $this->request->getData('product_sku_id'), 'ProductSkus.id' => $this->request->getData('product_sku_id'),
]) ])
->first(); ->first();
/**
* @var \CakeProducts\Model\Entity\ProductSku|null $productSku
*/
$path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path; $path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path;
$postData['product_id'] = $productSku->product->id ?? null; $postData['product_id'] = $productSku->product->id ?? null;
@@ -82,6 +86,9 @@ class ProductPhotosController extends AppController {
'Products.id' => $this->request->getData('product_id'), 'Products.id' => $this->request->getData('product_id'),
]) ])
->first(); ->first();
/**
* @var \CakeProducts\Model\Entity\Product|null $product
*/
$path = $product ? $product->id : $path; $path = $product ? $product->id : $path;
$postData['product_category_id'] = $product->product_category->internal_id ?? null; $postData['product_category_id'] = $product->product_category->internal_id ?? null;
@@ -90,7 +97,7 @@ class ProductPhotosController extends AppController {
// @link https://developer.wordpress.org/reference/functions/wp_is_uuid/ // @link https://developer.wordpress.org/reference/functions/wp_is_uuid/
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
$field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id'; $field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id';
$productCategoryPosted = $this->fetchTable('ProductCategories') $productCategoryPosted = $this->fetchTable('CakeProducts.ProductCategories')
->find() ->find()
->where([ ->where([
$field => $categoryId, $field => $categoryId,
@@ -138,7 +145,7 @@ class ProductPhotosController extends AppController {
$this->Flash->error(__('The product photo could not be saved. Please, try again.')); $this->Flash->error(__('The product photo could not be saved. Please, try again.'));
} }
$productCategory = $productPhoto->product_category_id ? $this->fetchTable('ProductCategories')->find() $productCategory = $productPhoto->product_category_id ? $this->fetchTable('ProductCategories')->find()
->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; ->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray(); $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); $this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
} }
@@ -148,7 +155,8 @@ class ProductPhotosController extends AppController {
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return Response|null|void Redirects on successful edit, renders view otherwise. *
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/ */
public function edit($id = null) { public function edit($id = null) {
$productPhoto = $this->fetchTable()->get($id, contain: []); $productPhoto = $this->fetchTable()->get($id, contain: []);
@@ -173,7 +181,7 @@ class ProductPhotosController extends AppController {
* *
* @param string|null $id Product Photo id. * @param string|null $id Product Photo id.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
* @return Response|null Redirects to index. * @return \Cake\Http\Response|null Redirects to index.
*/ */
public function delete($id = null) { public function delete($id = null) {
$this->request->allowMethod(['post', 'delete']); $this->request->allowMethod(['post', 'delete']);
+1 -1
View File
@@ -48,7 +48,7 @@ class ProductVariantsController extends AppController {
if ($this->request->is('post')) { if ($this->request->is('post')) {
$saveOptions = []; $saveOptions = [];
$postData = $this->request->getData(); $postData = $this->request->getData();
/** /**
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $productCategoryVariant * @var \CakeProducts\Model\Entity\ProductCategoryVariant $productCategoryVariant
*/ */
$productCategoryVariant = $this->fetchTable('ProductCategoryVariants')->get($this->request->getData('product_category_variant_id', '-1')); $productCategoryVariant = $this->fetchTable('ProductCategoryVariants')->get($this->request->getData('product_category_variant_id', '-1'));
+6 -3
View File
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace CakeProducts\Controller; namespace CakeProducts\Controller;
use Cake\Log\Log; use Cake\Log\Log;
use CakeProducts\Model\Entity\ProductCategoryVariant;
/** /**
* Products Controller * Products Controller
@@ -77,7 +76,11 @@ class ProductsController extends AppController {
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) { if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
continue; continue;
} }
$existingVariant = $this->fetchTable('ProductCategoryVariants')->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); /**
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $existingVariant
*/
$existingVariant = $this->fetchTable('CakeProducts.ProductCategoryVariants')
->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
$optionsData = []; $optionsData = [];
foreach ($existingVariant->product_category_variant_options as $existingOption) { foreach ($existingVariant->product_category_variant_options as $existingOption) {
$optionsData[] = [ $optionsData[] = [
@@ -124,7 +127,7 @@ class ProductsController extends AppController {
$this->Flash->error(__('The product could not be saved. Please, try again.')); $this->Flash->error(__('The product could not be saved. Please, try again.'));
} }
$productCategory = $product->product_category_id ? $this->fetchTable('ProductCategories')->find() $productCategory = $product->product_category_id ? $this->fetchTable('ProductCategories')->find()
->where(['internal_id' => $product->product_category_id])->first() : null; ->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray(); $productCatalogs = $this->fetchTable('ProductCatalogs')->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory')); $this->set(compact('product', 'productCatalogs', 'productCategory'));
+2 -2
View File
@@ -15,8 +15,8 @@ use Cake\ORM\Entity;
* @property bool $enabled * @property bool $enabled
* @property bool $is_system_variant * @property bool $is_system_variant
* *
* @property ProductCategory|\Cake\Datasource\EntityInterface $product_category * @property ProductCategory $product_category
* @property ProductCategoryVariantOption[]|\Cake\Datasource\EntityInterface[] $product_category_variant_options * @property ProductCategoryVariantOption[] $product_category_variant_options
*/ */
class ProductCategoryVariant extends Entity { class ProductCategoryVariant extends Entity {
+6 -6
View File
@@ -63,7 +63,7 @@ class ProductCategoriesTable extends Table {
]); ]);
$this->belongsTo('ProductCatalogs', [ $this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs', 'className' => 'CakeProducts.ProductCatalogs',
'foreignKey' => 'product_catalog_id', 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER', 'joinType' => 'INNER',
]); ]);
@@ -78,35 +78,35 @@ class ProductCategoriesTable extends Table {
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryAttributes', [ $this->hasMany('ProductCategoryAttributes', [
'className' => 'CakeProducts.ProductCategoryAttributes', 'className' => 'CakeProducts.ProductCategoryAttributes',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductCategoryVariants', [ $this->hasMany('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants', 'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('Products', [ $this->hasMany('Products', [
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasMany('ProductPhotos', [ $this->hasMany('ProductPhotos', [
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'dependent' => true, 'dependent' => true,
'cascadeCallbacks' => true, 'cascadeCallbacks' => true,
]); ]);
$this->hasOne('PrimaryProductPhotos', [ $this->hasOne('PrimaryProductPhotos', [
'className' => 'CakeProducts.ProductPhotos', 'className' => 'CakeProducts.ProductPhotos',
'foreignKey' => 'product_category_id', 'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id', 'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true], 'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
+1 -1
View File
@@ -27,7 +27,7 @@ use Cake\Validation\Validator;
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> saveManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> deleteManyOrFail(iterable $entities, array $options = []) * @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> deleteManyOrFail(iterable $entities, array $options = [])
* *
* @mixin \Cake\ORM\Behavior\TimestampBehavior * @mixin \Cake\ORM\Behavior\TimestampBehavior
*/ */
class ProductPhotosTable extends Table { class ProductPhotosTable extends Table {