Sonata\Component\Basket\BasketEntityFactory::reset PHP Method

reset() public method

public reset ( Sonata\Component\Basket\BasketInterface $basket, $full = true )
$basket Sonata\Component\Basket\BasketInterface
    public function reset(BasketInterface $basket, $full = true)
    {
        if ($full && $basket->getCustomerId()) {
            $this->basketManager->delete($basket);
        } else {
            $basket->reset($full);
            $this->save($basket);
        }
    }

Usage Example

 public function testReset()
 {
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $basket->expects($this->once())->method('getCustomerId')->will($this->returnValue(1));
     $basketManager = $this->getMock('Sonata\\Component\\Basket\\BasketManagerInterface');
     $basketManager->expects($this->once())->method('delete');
     $basketBuilder = $this->getMock('Sonata\\Component\\Basket\\BasketBuilderInterface');
     $session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\Session');
     $currencyDetector = $this->getMock('Sonata\\Component\\Currency\\CurrencyDetectorInterface');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $currencyDetector->expects($this->any())->method('getCurrency')->will($this->returnValue($currency));
     $factory = new BasketEntityFactory($basketManager, $basketBuilder, $currencyDetector, $session);
     $factory->reset($basket);
 }
BasketEntityFactory