EShoppingCart::restoreFromSession PHP Method

restoreFromSession() public method

Restores the shopping cart from the session
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);
            }
        }
    }

Usage Example

Esempio n. 1
0
 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());
 }