Commit 24eefdb3 authored by Thomas Bilk ن's avatar Thomas Bilk ن Committed by GitHub

Merge pull request #2 from thomasbilk/master

Added Clearing Functions
parents d04ba1ed e8e3ef2a
......@@ -275,7 +275,7 @@ class Cart implements Jsonable, \JsonSerializable, Arrayable{
}
/**
* clear cart
* clears cart items, all attributes and condisions remain
*/
public function clear() {
$this->events->fire($this->getInstanceName() . '.clearing', array($this));
......@@ -288,6 +288,15 @@ class Cart implements Jsonable, \JsonSerializable, Arrayable{
$this->events->fire($this->getInstanceName() . '.cleared', array($this));
}
/**
* clears alls cart items, attributes and conditions
*/
public function clearAll() {
$this->clear();
$this->clearCartAttributes();
$this->clearCartConditions();
}
/**
* add a condition on the cart
*
......@@ -434,6 +443,16 @@ class Cart implements Jsonable, \JsonSerializable, Arrayable{
);
}
/**
* clears all attributes on the cart
*/
public function clearCartAttributes() {
$this->session->put(
$this->sessionKeyCartAttributes,
array()
);
}
/**
* get cart sub total
*
......@@ -743,7 +762,7 @@ EOF;
* @param Collection $attributes
*/
protected function saveAttributes(Collection $attributes) {
$this->session->set($this->sessionKeyCartAttributes, $attributes);
$this->session->put($this->sessionKeyCartAttributes, $attributes);
}
}
......@@ -447,6 +447,17 @@ class CartTest extends PHPUnit_Framework_TestCase {
$this->assertTrue($this->cart->isEmpty(), 'cart should now be empty');
}
public function test_clearing_cart_attributes() {
$customer_email = 'customer@shop.com';
$this->cart->addAttribute('customer_email', $customer_email);
$this->assertEquals($customer_email, $this->cart->getAttribute('customer_email'), 'prove first that cart attribute was set');
$this->cart->clearCartAttributes();
$this->assertEmpty($this->cart->attributes(), 'cart should not have attributes');
}
public function test_cart_get_total_quantity() {
$items = array(
array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment