select options for products + skus, photos form
CI / testsuite (mysql, 8.2, ) (push) Failing after 6m0s Details
CI / testsuite (mysql, 8.4, ) (push) Successful in 10m20s Details
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 5m58s Details
CI / Coding Standard & Static Analysis (push) Failing after 5m39s Details

This commit is contained in:
Brandon Shipley 2025-10-12 02:20:02 -07:00
parent 30aad1dea4
commit 9f1959a0ee
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
7 changed files with 102 additions and 8 deletions

View File

@ -61,8 +61,9 @@ class ProductPhotosController extends AppController
if ($this->request->is('post')) {
if (!$this->request->getData('photo')) {
$this->Flash->error('Photo is required. Nothing was uploaded. Please try again.');
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products'));
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
return;
}
@ -107,10 +108,9 @@ class ProductPhotosController extends AppController
// dd(print_r($productPhoto->getErrors(), true));
$this->Flash->error(__('The product photo could not be saved. Please, try again.'));
}
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
$this->set(compact('productPhoto', 'products', 'productSkus'));
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
}
/**

View File

@ -239,4 +239,18 @@ class ProductSkusController extends AppController
return $this->redirect(['action' => 'index']);
}
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$productSkus = $this->getTable()
->find('list')
->where(['product_id' => $this->request->getQuery('product_id', '-1')])
->orderBy(['sku'])
->toArray();
$this->set(compact('productSkus'));
}
}

View File

@ -197,4 +197,22 @@ class ProductsController extends AppController
return $this->redirect(['action' => 'index']);
}
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$productsTable = $this->getTable();
$productCategory = $productsTable->ProductCategories->find()
->where(['id' => $this->request->getQuery('product_category_id', '-1')])
->first();
$products = $productsTable
->find('list')
->where(['product_category_id' => $productCategory->internal_id ?? '-1'])
->orderBy(['Products.name'])
->toArray();
$this->set(compact('products'));
}
}

View File

@ -7,7 +7,7 @@
$this->setLayout('ajax');
?>
<option value="">Select a <?= $this->request->getQuery('form', 'cataegory') == 'product' ? 'Category ' : 'parent (optional)'; ?></option>
<option value="">Select a <?= $this->request->getQuery('form', 'product') == 'category' ? 'parent (optional) ' : 'Category'; ?></option>
<?php foreach ($productCategories as $productCategoryId => $productCategoryName): ?>
<option value="<?= $productCategoryId; ?>" <?= $this->request->getQuery('category_id') == $productCategoryId ? 'selected="selected"' : ''; ?>><?= $productCategoryName; ?></option>
<?php endforeach; ?>

View File

@ -0,0 +1,13 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $productSkus
*/
$this->setLayout('ajax');
?>
<option value="">Select a SKU</option>
<?php foreach ($productSkus as $productSkuId => $productSku): ?>
<option value="<?= $productSkuId; ?>" <?= $this->request->getQuery('product_sku_id') == $productSkuId ? 'selected="selected"' : ''; ?>><?= $productSku; ?></option>
<?php endforeach; ?>

View File

@ -0,0 +1,13 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\Cake\Datasource\EntityInterface> $products
*/
$this->setLayout('ajax');
?>
<option value="">Select a Product</option>
<?php foreach ($products as $productId => $productName): ?>
<option value="<?= $productId; ?>" <?= $this->request->getQuery('product_id') == $productId ? 'selected="selected"' : ''; ?>><?= $productName; ?></option>
<?php endforeach; ?>

View File

@ -8,17 +8,53 @@
*/
$includeFile = $includeFile ?? false;
echo $this->Form->control('product_catalog_id', [
'empty' => 'Select a Catalog',
'options' => $productCatalogs ?? [],
'hx-trigger' => 'change, load delay:500ms',
'hx-get' => $this->Url->build([
'controller' => 'ProductCategories',
'action' => 'select',
'?' => ['form' => 'product_photo'],
]),
'hx-target' => '#product_category_id',
]);
echo $this->Form->control('product_category_id', [
'options' => [],
'empty' => true,
'id' => 'product_category_id',
'hx-trigger' => 'change, load delay:1s',
'hx-get' => $this->Url->build([
'controller' => 'Products',
'action' => 'select',
'?' => ['form' => 'product_photo'],
]),
'hx-target' => '#product_id',
]);
echo $this->Form->control('product_id', [
'options' => $products ?? [],
'empty' => true,
'hx-trigger' => 'change, load delay:1s',
'id' => 'product_id',
'hx-get' => $this->Url->build([
'controller' => 'ProductSkus',
'action' => 'select',
'?' => ['form' => 'product'],
]),
'hx-target' => '#product_sku_id',
]);
echo $this->Form->control('product_sku_id', [
'options' => $productSkus ?? []
'options' => $productSkus ?? [],
'empty' => true,
'id' => 'product_sku_id',
]);
echo $includeFile ? $this->Form->control('photo', [
'type' => 'file',
]) : '';
echo $this->Form->control('primary_photo');
echo $this->Form->control('primary_category_photo');
echo $this->Form->control('photo_position');
echo $this->Form->control('enabled');
?>