public restoreFromSession ( ) |
public function restoreFromSession()
{
$data = unserialize(Yii::app()->getUser()->getState($this->cartId));
if (is_array($data) || $data instanceof Traversable) {
foreach ($data as $key => $product) {
parent::add($key, $product);
}
}
}
function testRestoreFromSession() { $this->setUp(); $cart = new EShoppingCart(); $book = Book::model()->findByPk(1); $cart->put($book); $newCart = new EShoppingCart(); $newCart->restoreFromSession(); $this->assertEquals(1, $newCart->getItemsCount()); }