From 4b45725b33eaf30147f04740a43464b79f08061d Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Fri, 7 Nov 2025 00:43:39 -0800 Subject: [PATCH] only load component if not already loaded --- src/Controller/CartItemsController.php | 13 ++++++++----- src/Controller/CartsController.php | 12 +++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Controller/CartItemsController.php b/src/Controller/CartItemsController.php index 1b1ef1a..d4b0001 100644 --- a/src/Controller/CartItemsController.php +++ b/src/Controller/CartItemsController.php @@ -21,11 +21,14 @@ class CartItemsController extends AppController { parent::initialize(); // TODO: Change the autogenerated stub - $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('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(); } diff --git a/src/Controller/CartsController.php b/src/Controller/CartsController.php index d0de855..74e87d0 100644 --- a/src/Controller/CartsController.php +++ b/src/Controller/CartsController.php @@ -19,11 +19,13 @@ class CartsController extends AppController { parent::initialize(); // TODO: Change the autogenerated stub - $this->loadComponent('CakeCarts.ShoppingCart', [ - // This is default config. You can modify "actions" as needed to make - // component work only for specified methods. - 'actions' => true, - ]); + 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' => true, + ]); + } } /**