From e1ed7db7043316f360c12d580553e22b0a75e510 Mon Sep 17 00:00:00 2001 From: Michiel Loncke <56675+webcraft@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:52:16 +0100 Subject: [PATCH] Add clearOptions() method to ShippingManifest --- packages/core/src/Base/ShippingManifest.php | 10 +++++++++ .../src/Base/ShippingManifestInterface.php | 7 ++++++ .../tests/Unit/Base/ShippingManifestTest.php | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/packages/core/src/Base/ShippingManifest.php b/packages/core/src/Base/ShippingManifest.php index f64e88818c..ee8945a3f2 100644 --- a/packages/core/src/Base/ShippingManifest.php +++ b/packages/core/src/Base/ShippingManifest.php @@ -41,6 +41,16 @@ public function addOption(ShippingOption $option) return $this; } + /** + * {@inheritDoc} + */ + public function clearOptions() + { + $this->options = collect(); + + return $this; + } + /** * {@inheritDoc} */ diff --git a/packages/core/src/Base/ShippingManifestInterface.php b/packages/core/src/Base/ShippingManifestInterface.php index 383bbb7aa8..1e0dfac294 100644 --- a/packages/core/src/Base/ShippingManifestInterface.php +++ b/packages/core/src/Base/ShippingManifestInterface.php @@ -16,6 +16,13 @@ interface ShippingManifestInterface */ public function addOption(ShippingOption $shippingOption); + /** + * Remove all shipping options + * + * @return self + */ + public function clearOptions(); + /** * Return available options for a given cart. * diff --git a/packages/core/tests/Unit/Base/ShippingManifestTest.php b/packages/core/tests/Unit/Base/ShippingManifestTest.php index a486b656f1..aa305826c6 100644 --- a/packages/core/tests/Unit/Base/ShippingManifestTest.php +++ b/packages/core/tests/Unit/Base/ShippingManifestTest.php @@ -115,4 +115,26 @@ public function cannot_add_the_same_option_identifier_more_than_once() $this->assertCount(1, ShippingManifest::getOptions($this->cart)); } + + /** @test */ + public function can_clear_options() + { + $taxClass = TaxClass::factory()->create(); + + ShippingManifest::addOption( + new ShippingOption( + name: 'Basic Delivery', + description: 'Basic Delivery', + identifier: 'BASDEL', + price: new Price(500, $this->cart->currency, 1), + taxClass: $taxClass + ) + ); + + $this->assertCount(1, ShippingManifest::getOptions($this->cart)); + + ShippingManifest::clearOptions(); + + $this->assertCount(0, ShippingManifest::getOptions($this->cart)); + } }