From cd0cc314f8480e2c3349c5b0d2e56b93849044cf Mon Sep 17 00:00:00 2001 From: sheetalbalpathak <65701479+sheetalbalpathak@users.noreply.github.com> Date: Wed, 19 Jan 2022 12:06:30 +0530 Subject: [PATCH 1/2] Update cart.php Add removeData function to remove data items according to data types. --- src/cart.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cart.php b/src/cart.php index 10d273e..77cf2c1 100644 --- a/src/cart.php +++ b/src/cart.php @@ -75,6 +75,18 @@ public function removeItem( cartItem $item ) : self return $this; } //------------------------------------------------------------------------ + public function removeData( string $type ) : self + { + if( ! $this->hasCartDataType( $type ) ) + { + throw new Exception( 'Invalid cart data type: ' . $type, Exception::invalidDataTypeErrorCode ); + } + + unset( $this->data[ $type ] ); + + return $this; + } + //------------------------------------------------------------------------ public function addProduct( product $product, $qty ) : self { if( $this->hasItemForProductId( $product->getId() ) ) From 16a37a6d3a7eebaed6373171da96b2f8f9acd08f Mon Sep 17 00:00:00 2001 From: sheetalbalpathak <65701479+sheetalbalpathak@users.noreply.github.com> Date: Mon, 24 Jan 2022 11:09:30 +0530 Subject: [PATCH 2/2] Update cart.php change function name as suggested --- src/cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cart.php b/src/cart.php index 77cf2c1..f9118fd 100644 --- a/src/cart.php +++ b/src/cart.php @@ -75,7 +75,7 @@ public function removeItem( cartItem $item ) : self return $this; } //------------------------------------------------------------------------ - public function removeData( string $type ) : self + public function removeDataByType( string $type ) : self { if( ! $this->hasCartDataType( $type ) ) {