/var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin/OrdersController.php (4476B)
paginate = [
'limit' => ADMIN_PAGE_LIMIT,
'contain' => ['Users', 'UserAddresses', 'PaymentMethods', 'Users.Profiles', 'OrderStatuses'],
'conditions' => $conditions,
'sortableFields' => ['Orders.id', 'Orders.user_id', 'Orders.notes', 'Orders.payment_method_id', 'Orders.order_status_id', 'Orders.order_status_date', 'Orders.order_status_comment', 'Orders.email', 'Orders.total', 'Orders.email_sent', 'Orders.is_active', 'Orders.ip', 'Orders.created']
];
$orders = $this->paginate($this->Orders);
$paymentMethods = $this->Orders->PaymentMethods->find('list');
$orderStatuses = $this->Orders->OrderStatuses->find('list');
$this->set(compact('orders', 'paymentMethods', 'orderStatuses'));
}
/**
* View method
*/
public function view($id = null)
{
if (!empty($id) && is_numeric($id)) {
$this->paginate = [
'limit' => ADMIN_PAGE_LIMIT
];
$this->loadModel('OrderProducts');
$orderProducts = $this->paginate($this->OrderProducts->find()
->contain(['Orders', 'Products', 'Orders.UserAddresses', 'Orders.Users', 'Products.Users', 'Products.UserAddresses'])
->where(['OrderProducts.order_id' => $id]));
$orderId = $id;
} else {
$this->Flash->error(__('Oops. Please, try again.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Orders', 'action' => 'index']);
}
$this->set(compact('orderProducts', 'orderId'));
}
/**
* Edit method
*/
public function edit($id = null)
{
if (!empty($id) && is_numeric($id)) {
$order = $this->Orders->get($id, [
'contain' => [],
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$order = $this->Orders->patchEntity($order, $this->request->getData());
if ($this->Orders->save($order)) {
$this->Flash->success(__('The order has been saved.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Orders', 'action' => 'index']);
}
$this->Flash->error(__('The order could not be saved. Please, try again.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Orders', 'action' => 'index']);
}
$users = $this->Orders->Users->find('list', ['limit' => 200]);
$orderStatuses = $this->Orders->OrderStatuses->find('list', ['limit' => 200]);
$paymentMethods = $this->Orders->PaymentMethods->find('list', ['limit' => 200]);
$userAddresses = $this->Orders->UserAddresses->find('list', ['limit' => 200]);
} else {
$this->Flash->error(__('Oops. Please, try again.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Orders', 'action' => 'index']);
}
$this->set(compact('order', 'users', 'orderStatuses', 'paymentMethods', 'userAddresses'));
}
/**
* changeStatusOrder method
*/
public function changeStatusOrder()
{
$this->autoRender = false;
$data = $this->request->getData();
$ids = [];
$ids = explode(',', $data['ids']);
if ($this->request->is(['patch', 'post', 'put'])) {
$this->Orders->updateAll(
[ // fields
'order_status_id' => $data['order_status_id'],
'order_status_date' => FrozenTime::now(),
'order_status_comment' => $data['order_status_comment'],
],
['id IN ' => $ids]
);
$this->Flash->success(__('The new status has been saved.'));
}
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Orders', 'action' => 'index']);
}
/**
* Delete method
*/
// public function delete($id = null)
// {
// if (!empty($id && is_numeric($id))) {
// $this->request->allowMethod(['post', 'get']);
// $order = $this->Orders->get($id);
// $order->is_active = ($order->is_active === true) ? false : true;
// if ($this->Orders->save($order)) {
// $this->Flash->success(__('The user has been modified.'));
// } else {
// $this->Flash->error(__('User The user could not be modified. Please try later modified.'));
// }
//
// }
// return $this->redirect(['action' => 'index']);
// }
}