select options for products + skus, photos form
This commit is contained in:
parent
30aad1dea4
commit
9f1959a0ee
|
@ -61,8 +61,9 @@ class ProductPhotosController extends AppController
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
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.');
|
||||||
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||||
$this->set(compact('productPhoto', 'products'));
|
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||||
|
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -107,10 +108,9 @@ class ProductPhotosController extends AppController
|
||||||
// dd(print_r($productPhoto->getErrors(), true));
|
// dd(print_r($productPhoto->getErrors(), true));
|
||||||
$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.'));
|
||||||
}
|
}
|
||||||
$products = $productPhotosTable->Products->find('list', limit: 200)->all();
|
$productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null;
|
||||||
$productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all();
|
$productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||||
|
$this->set(compact('productPhoto', 'productCatalogs', 'productCategory'));
|
||||||
$this->set(compact('productPhoto', 'products', 'productSkus'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -239,4 +239,18 @@ class ProductSkusController extends AppController
|
||||||
|
|
||||||
return $this->redirect(['action' => 'index']);
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,4 +197,22 @@ class ProductsController extends AppController
|
||||||
|
|
||||||
return $this->redirect(['action' => 'index']);
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
$this->setLayout('ajax');
|
$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): ?>
|
<?php foreach ($productCategories as $productCategoryId => $productCategoryName): ?>
|
||||||
<option value="<?= $productCategoryId; ?>" <?= $this->request->getQuery('category_id') == $productCategoryId ? 'selected="selected"' : ''; ?>><?= $productCategoryName; ?></option>
|
<option value="<?= $productCategoryId; ?>" <?= $this->request->getQuery('category_id') == $productCategoryId ? 'selected="selected"' : ''; ?>><?= $productCategoryName; ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
|
@ -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; ?>
|
|
@ -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; ?>
|
|
@ -8,17 +8,53 @@
|
||||||
*/
|
*/
|
||||||
$includeFile = $includeFile ?? false;
|
$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', [
|
echo $this->Form->control('product_id', [
|
||||||
'options' => $products ?? [],
|
'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', [
|
echo $this->Form->control('product_sku_id', [
|
||||||
'options' => $productSkus ?? []
|
'options' => $productSkus ?? [],
|
||||||
|
'empty' => true,
|
||||||
|
'id' => 'product_sku_id',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo $includeFile ? $this->Form->control('photo', [
|
echo $includeFile ? $this->Form->control('photo', [
|
||||||
'type' => 'file',
|
'type' => 'file',
|
||||||
]) : '';
|
]) : '';
|
||||||
echo $this->Form->control('primary_photo');
|
echo $this->Form->control('primary_photo');
|
||||||
|
echo $this->Form->control('primary_category_photo');
|
||||||
echo $this->Form->control('photo_position');
|
echo $this->Form->control('photo_position');
|
||||||
echo $this->Form->control('enabled');
|
echo $this->Form->control('enabled');
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue