only load component if not already loaded

This commit is contained in:
2025-11-07 00:43:39 -08:00
parent 80193e6242
commit 4b45725b33
2 changed files with 15 additions and 10 deletions

View File

@@ -21,11 +21,14 @@ class CartItemsController extends AppController
{ {
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
if (!$this->components()->has('ShoppingCart')) {
$this->loadComponent('CakeCarts.ShoppingCart', [ $this->loadComponent('CakeCarts.ShoppingCart', [
// This is default config. You can modify "actions" as needed to make // This is default config. You can modify "actions" as needed to make
// component work only for specified methods. // component work only for specified methods.
'actions' => ['add'], 'actions' => ['add'],
]); ]);
}
if ($this->components()->has('Authorization')) { if ($this->components()->has('Authorization')) {
$this->Authorization->skipAuthorization(); $this->Authorization->skipAuthorization();
} }

View File

@@ -19,12 +19,14 @@ class CartsController extends AppController
{ {
parent::initialize(); // TODO: Change the autogenerated stub parent::initialize(); // TODO: Change the autogenerated stub
if (!$this->components()->has('ShoppingCart')) {
$this->loadComponent('CakeCarts.ShoppingCart', [ $this->loadComponent('CakeCarts.ShoppingCart', [
// This is default config. You can modify "actions" as needed to make // This is default config. You can modify "actions" as needed to make
// component work only for specified methods. // component work only for specified methods.
'actions' => true, 'actions' => true,
]); ]);
} }
}
/** /**
* Index method * Index method