From bd11126a124da8789681be6cb45a9bd36d726698 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 7 Jul 2020 00:19:13 -0500 Subject: [PATCH] bug fixes and new interface for cart data make cart data an interface that is used on the base class. make interface the type that is specified on func calls. remove unused reflection bug fixes --- README.md | 10 +++++++--- src/cart.php | 4 ++-- src/cartData.php | 4 ++-- src/cartStorageSession.php | 4 +++- src/iCartData.php | 11 +++++++++++ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/iCartData.php diff --git a/README.md b/README.md index 2ce637e..3bdd190 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,14 @@ After creating your implementation of this interface, you must supply it to your ```php interface cartStorageInterface { - public function init( cart $cart ) : cartStorageInterface; - public function saveCartItem( cartItem $item ) : cartStorageInterface; - public function saveCartData( cartData $data ) : cartStorageInterface; public function loadCart( cart $cart ) : cartStorageInterface; + public function emptyCart( cart $cart ) : cartStorageInterface; + + public function saveItems( array $items ) : cartStorageInterface; + public function saveData( array $data ) : cartStorageInterface; + + // used to clean up after all storage is complete + public function finalize( cart $cart ) : cartStorageInterface; } ``` diff --git a/src/cart.php b/src/cart.php index 07badef..035a4fd 100644 --- a/src/cart.php +++ b/src/cart.php @@ -218,10 +218,10 @@ public function save() $this->storageHandler->saveItems( $this->items ); $this->storageHandler->saveData( $this->data ); - $this->storageHandler->finalize(); + $this->storageHandler->finalize( $this ); } //------------------------------------------------------------------------ - public function addData( cartData $data ) : self + public function addData( iCartData $data ) : self { $this->data[$data->getType()] = $data; diff --git a/src/cartData.php b/src/cartData.php index 11abc9f..24dc6ef 100644 --- a/src/cartData.php +++ b/src/cartData.php @@ -1,7 +1,7 @@ items as $item ) + foreach( $items as $item ) { $_SESSION['cart_items'][] = ['id' => $item->getProduct()->getId(), 'qty' => $item->getQty()]; } @@ -51,6 +51,8 @@ public function saveData( array $data ) public function finalize( cart $cart ) : cartStorageInterface { // do nothing + + return $this; } //------------------------------------------------------------------------ public function loadCart( cart $cart ) : cartStorageInterface diff --git a/src/iCartData.php b/src/iCartData.php new file mode 100644 index 0000000..7251634 --- /dev/null +++ b/src/iCartData.php @@ -0,0 +1,11 @@ +