/** * Tries to initialize cart if there is data in storage. * If not, returns new instance from resourceFactory * * @return CartInterface */ private function provideCart() { $cartIdentifier = $this->cartContext->getCurrentCartIdentifier(); if ($cartIdentifier !== null) { $cart = $this->cartRepository->find($cartIdentifier); if ($cart !== null) { return $cart; } } $cart = $this->cartFactory->createNew(); $this->cartContext->setCurrentCartIdentifier($cart); return $cart; }
function it_sets_current_cart_identifier_when_setting_cart(CartContextInterface $cartContext, CartInterface $cart) { $cartContext->setCurrentCartIdentifier($cart)->shouldBeCalled(); $this->setCart($cart); }
/** * {@inheritdoc} */ public function setCart(CartInterface $cart) { $this->cart = $cart; $this->context->setCurrentCartIdentifier($cart); }