clean up
This commit is contained in:
@@ -8,7 +8,7 @@ use Cake\Log\Log;
|
||||
/**
|
||||
* ProductVariants Controller
|
||||
*
|
||||
* @property CakeProducts\Model\Table\ProductVariantsTable $ProductVariants
|
||||
* @property \CakeProducts\Model\Table\ProductVariantsTable $ProductVariants
|
||||
*/
|
||||
class ProductVariantsController extends AppController {
|
||||
|
||||
@@ -18,7 +18,7 @@ class ProductVariantsController extends AppController {
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index() {
|
||||
$query = $this->ProductVariants->find()
|
||||
$query = $this->fetchTable()->find()
|
||||
->contain(['ProductCategoryVariants', 'Products']);
|
||||
$productVariants = $this->paginate($query);
|
||||
|
||||
@@ -33,7 +33,7 @@ class ProductVariantsController extends AppController {
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function view($id = null) {
|
||||
$productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']);
|
||||
$productVariant = $this->fetchTable()->get($id, contain: ['ProductCategoryVariants', 'Products']);
|
||||
$this->set(compact('productVariant'));
|
||||
}
|
||||
|
||||
@@ -43,16 +43,19 @@ class ProductVariantsController extends AppController {
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add($productId) {
|
||||
$product = $this->ProductVariants->Products->get($productId);
|
||||
$productVariant = $this->ProductVariants->newEmptyEntity();
|
||||
$product = $this->fetchTable()->Products->get($productId);
|
||||
$productVariant = $this->fetchTable()->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$saveOptions = [];
|
||||
$postData = $this->request->getData();
|
||||
$productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1'));
|
||||
/**
|
||||
* @var \CakeProducts\Model\Entity\ProductCategoryVariant $productCategoryVariant
|
||||
*/
|
||||
$productCategoryVariant = $this->fetchTable('ProductCategoryVariants')->get($this->request->getData('product_category_variant_id', '-1'));
|
||||
$postData['name'] = $productCategoryVariant->name;
|
||||
$postData['product_id'] = $productId;
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $postData);
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$productVariant = $this->fetchTable()->patchEntity($productVariant, $postData);
|
||||
if ($this->fetchTable()->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
@@ -62,7 +65,7 @@ class ProductVariantsController extends AppController {
|
||||
Log::debug(print_r($productVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants
|
||||
$productCategoryVariants = $this->fetchTable('ProductCategoryVariants')
|
||||
->find('list', limit: 200)
|
||||
->where(['product_category_id' => $product->product_category_id])
|
||||
->toArray();
|
||||
@@ -77,18 +80,18 @@ class ProductVariantsController extends AppController {
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null) {
|
||||
$productVariant = $this->ProductVariants->get($id, contain: []);
|
||||
$productVariant = $this->fetchTable()->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData());
|
||||
if ($this->ProductVariants->save($productVariant)) {
|
||||
$productVariant = $this->fetchTable()->patchEntity($productVariant, $this->request->getData());
|
||||
if ($this->fetchTable()->save($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
$this->Flash->error(__('The product variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all();
|
||||
$products = $this->ProductVariants->Products->find('list', limit: 200)->all();
|
||||
$productCategoryVariants = $this->fetchTable('ProductCategoryVariants')->find('list', limit: 200)->all();
|
||||
$products = $this->fetchTable('Products')->find('list', limit: 200)->all();
|
||||
$this->set(compact('productVariant', 'productCategoryVariants', 'products'));
|
||||
}
|
||||
|
||||
@@ -101,8 +104,8 @@ class ProductVariantsController extends AppController {
|
||||
*/
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productVariant = $this->ProductVariants->get($id);
|
||||
if ($this->ProductVariants->delete($productVariant)) {
|
||||
$productVariant = $this->fetchTable()->get($id);
|
||||
if ($this->fetchTable()->delete($productVariant)) {
|
||||
$this->Flash->success(__('The product variant has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product variant could not be deleted. Please, try again.'));
|
||||
|
||||
Reference in New Issue
Block a user