phpcbf and added .gitea workflows
This commit is contained in:
@@ -4,10 +4,7 @@ declare(strict_types=1);
|
||||
namespace CakeCarts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Client;
|
||||
use Cake\Log\Log;
|
||||
use CakeCarts\Controller\AppController;
|
||||
|
||||
/**
|
||||
* CartItems Controller
|
||||
@@ -15,148 +12,148 @@ use CakeCarts\Controller\AppController;
|
||||
* @property \CakeCarts\Model\Table\CartItemsTable $CartItems
|
||||
* @property \Authorization\Controller\Component\AuthorizationComponent $Authorization
|
||||
*/
|
||||
class CartItemsController extends AppController
|
||||
{
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
class CartItemsController extends AppController {
|
||||
|
||||
if (!$this->components()->has('ShoppingCart')) {
|
||||
$this->loadComponent('CakeCarts.ShoppingCart', [
|
||||
// This is default config. You can modify "actions" as needed to make
|
||||
// component work only for specified methods.
|
||||
'actions' => ['add'],
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
|
||||
if ($this->components()->has('Authorization')) {
|
||||
$this->Authorization->skipAuthorization();
|
||||
}
|
||||
}
|
||||
if (!$this->components()->has('ShoppingCart')) {
|
||||
$this->loadComponent('CakeCarts.ShoppingCart', [
|
||||
// This is default config. You can modify "actions" as needed to make
|
||||
// component work only for specified methods.
|
||||
'actions' => ['add'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
if ($this->components()->has('Authorization')) {
|
||||
$this->Authorization->skipAuthorization();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||
public function add() {
|
||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||
|
||||
Log::debug(print_r('$this->request->getData()', true));
|
||||
Log::debug(print_r($this->request->getData(), true));
|
||||
$cart = $this->viewBuilder()->getVar('cart');
|
||||
$postData = $this->request->getData();
|
||||
$postData['cart_id'] = $cart->id;
|
||||
// get product skus with variants
|
||||
$price = $this->request->getData('price');
|
||||
$qty = $this->request->getData('qty', 1);
|
||||
$postData['price'] = $price;
|
||||
$postData['subtotal'] = isset($price) ? bcmul("$price", "$qty", 5) : null;
|
||||
Log::debug(print_r('$this->request->getData()', true));
|
||||
Log::debug(print_r($this->request->getData(), true));
|
||||
$cart = $this->viewBuilder()->getVar('cart');
|
||||
$postData = $this->request->getData();
|
||||
$postData['cart_id'] = $cart->id;
|
||||
// get product skus with variants
|
||||
$price = $this->request->getData('price');
|
||||
$qty = $this->request->getData('qty', 1);
|
||||
$postData['price'] = $price;
|
||||
$postData['subtotal'] = isset($price) ? bcmul("$price", "$qty", 5) : null;
|
||||
|
||||
$newCartItem = $this->CartItems->newEntity($postData, [
|
||||
'validate' => Configure::readOrFail('CakeCarts.CartItems.requirePricing') ? 'requirePricing' : 'default',
|
||||
]);
|
||||
$newCartItem = $this->CartItems->newEntity($postData, [
|
||||
'validate' => Configure::readOrFail('CakeCarts.CartItems.requirePricing') ? 'requirePricing' : 'default',
|
||||
]);
|
||||
|
||||
if ($this->CartItems->save($newCartItem)) {
|
||||
$this->Flash->success('Added to cart');
|
||||
if ($this->CartItems->save($newCartItem)) {
|
||||
$this->Flash->success('Added to cart');
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
]));
|
||||
}
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
// Log::debug(print_r('$newCartItem->getErrors()', true));
|
||||
// Log::debug(print_r($newCartItem->getErrors(), true));
|
||||
$this->Flash->error('Failed to add to cart.');
|
||||
$this->Flash->error('Failed to add to cart.');
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
]));
|
||||
}
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Cart Item id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||
public function edit($id = null) {
|
||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||
|
||||
$cartItem = $this->CartItems->find()
|
||||
->where(['CartItems.id' => $id])
|
||||
->contain(['Carts'])
|
||||
->firstOrFail();
|
||||
$cartItem = $this->CartItems->find()
|
||||
->where(['CartItems.id' => $id])
|
||||
->contain(['Carts'])
|
||||
->firstOrFail();
|
||||
|
||||
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
||||
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
||||
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$qty = $this->request->getData('qty', 1);
|
||||
$price = $this->request->getData('price', null);
|
||||
$subtotal = isset($price) ? bcmul("$qty", "$price", 5) : null;
|
||||
$postData['subtotal'] = $subtotal;
|
||||
$cartItem = $this->CartItems->patchEntity($cartItem, $postData, [
|
||||
'validate' => Configure::readOrFail('CakeCarts.CartItems.requirePricing') ? 'requiresPricing' : 'default',
|
||||
]);
|
||||
if ($this->CartItems->save($cartItem)) {
|
||||
$this->Flash->success(__('The cart item has been saved.'));
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$qty = $this->request->getData('qty', 1);
|
||||
$price = $this->request->getData('price', null);
|
||||
$subtotal = isset($price) ? bcmul("$qty", "$price", 5) : null;
|
||||
$postData['subtotal'] = $subtotal;
|
||||
$cartItem = $this->CartItems->patchEntity($cartItem, $postData, [
|
||||
'validate' => Configure::readOrFail('CakeCarts.CartItems.requirePricing') ? 'requiresPricing' : 'default',
|
||||
]);
|
||||
if ($this->CartItems->save($cartItem)) {
|
||||
$this->Flash->success(__('The cart item has been saved.'));
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
]));
|
||||
}
|
||||
Log::debug(print_r('$cartItem->getErrors()', true));
|
||||
Log::debug(print_r($cartItem->getErrors(), true));
|
||||
$this->Flash->error(__('The cart item could not be saved. Please, try again.'));
|
||||
}
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
Log::debug(print_r('$cartItem->getErrors()', true));
|
||||
Log::debug(print_r($cartItem->getErrors(), true));
|
||||
$this->Flash->error(__('The cart item could not be saved. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
]));
|
||||
}
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Cart Item id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$identity = $this->getRequest()->getAttribute('identity');
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$identity = $this->getRequest()->getAttribute('identity');
|
||||
|
||||
// $cart = $this->viewBuilder()->getVar('cart');
|
||||
$cartItem = $this->CartItems->find()
|
||||
->where(['CartItems.id' => $id])
|
||||
->contain(['Carts'])
|
||||
->firstOrFail();
|
||||
$cartItem = $this->CartItems->find()
|
||||
->where(['CartItems.id' => $id])
|
||||
->contain(['Carts'])
|
||||
->firstOrFail();
|
||||
|
||||
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
||||
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
||||
|
||||
unset($cartItem->cart);
|
||||
if ($this->CartItems->delete($cartItem)) {
|
||||
$this->Flash->success(__('The cart item has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The cart item could not be deleted. Please, try again.'));
|
||||
}
|
||||
unset($cartItem->cart);
|
||||
if ($this->CartItems->delete($cartItem)) {
|
||||
$this->Flash->success(__('The cart item has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The cart item could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user