diff --git a/src/Controller/ProductPhotosController.php b/src/Controller/ProductPhotosController.php
index 2311b18..d2f64c1 100644
--- a/src/Controller/ProductPhotosController.php
+++ b/src/Controller/ProductPhotosController.php
@@ -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'));
}
/**
diff --git a/src/Controller/ProductSkusController.php b/src/Controller/ProductSkusController.php
index 96233a4..891ab4b 100644
--- a/src/Controller/ProductSkusController.php
+++ b/src/Controller/ProductSkusController.php
@@ -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'));
+ }
}
diff --git a/src/Controller/ProductsController.php b/src/Controller/ProductsController.php
index fd7cd72..e1c0368 100644
--- a/src/Controller/ProductsController.php
+++ b/src/Controller/ProductsController.php
@@ -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'));
+ }
}
diff --git a/templates/ProductCategories/select.php b/templates/ProductCategories/select.php
index b5e8ab9..278c75a 100644
--- a/templates/ProductCategories/select.php
+++ b/templates/ProductCategories/select.php
@@ -7,7 +7,7 @@
$this->setLayout('ajax');
?>
-
+
$productCategoryName): ?>
\ No newline at end of file
diff --git a/templates/ProductSkus/select.php b/templates/ProductSkus/select.php
new file mode 100644
index 0000000..4b11bb3
--- /dev/null
+++ b/templates/ProductSkus/select.php
@@ -0,0 +1,13 @@
+ $productSkus
+ */
+
+$this->setLayout('ajax');
+
+?>
+
+ $productSku): ?>
+
+
diff --git a/templates/Products/select.php b/templates/Products/select.php
new file mode 100644
index 0000000..aced2db
--- /dev/null
+++ b/templates/Products/select.php
@@ -0,0 +1,13 @@
+ $products
+ */
+
+$this->setLayout('ajax');
+
+?>
+
+ $productName): ?>
+
+
\ No newline at end of file
diff --git a/templates/element/ProductPhotos/form.php b/templates/element/ProductPhotos/form.php
index 1f40879..7857b9f 100644
--- a/templates/element/ProductPhotos/form.php
+++ b/templates/element/ProductPhotos/form.php
@@ -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');
?>