Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.2] Add clearOptions() method to ShippingManifest #775

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}