Cart\Cart::restore PHP Method

restore() public method

Restore the cart from its saved state.
public restore ( )
    public function restore()
    {
        $state = $this->store->get($this->id);
        if ($state == '') {
            return;
        }
        $data = @unserialize($state);
        // suppress unserializable error
        $this->restoreCheckType($data);
        $this->restoreCheckContents($data);
        $this->restoreCheckContentsType($data);
        $this->id = $data['id'];
        $this->items = array();
        foreach ($data['items'] as $itemArr) {
            $this->items[] = new CartItem($itemArr);
        }
    }

Usage Example

Beispiel #1
0
 public function testRestoreExceptions()
 {
     $exceptionCounter = 0;
     $store = m::mock('Cart\\Storage\\Store');
     $store->shouldReceive('get')->times(6)->andReturn('!foo!', serialize('bar'), serialize(array('id' => 'foo')), serialize(array('items' => array())), serialize(array('id' => array(), 'items' => array())), serialize(array('items' => 'foo', 'id' => 'foo')));
     $cart = new Cart('foo', $store);
     for ($i = 1; $i <= 6; $i++) {
         try {
             $cart->restore();
         } catch (CartRestoreException $e) {
             $exceptionCounter++;
         }
     }
     $this->assertEquals($exceptionCounter, 6);
 }