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 @@ +