Skip to content

Commit

Permalink
Add clearOptions() method to ShippingManifest (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
webcraft authored Dec 21, 2022
1 parent f0e6d74 commit 7b9ab44
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/Base/ShippingManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public function addOption(ShippingOption $option)
return $this;
}

/**
* {@inheritDoc}
*/
public function clearOptions()
{
$this->options = collect();

return $this;
}

/**
* {@inheritDoc}
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/Base/ShippingManifestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
22 changes: 22 additions & 0 deletions packages/core/tests/Unit/Base/ShippingManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 7b9ab44

Please sign in to comment.