/** * @param Quote $quote * @param array $offerData * @return Order|null */ protected function onSuccess(Quote $quote, array $offerData) { $order = $this->converter->convert($quote, $this->user, $offerData); $this->manager->persist($order); $this->manager->flush(); return $order; }
public function testProcessValidPost() { $offerData = ['offer', 'data']; $quote = new Quote(); $order = new Order(); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->willReturn(true); $this->form->expects($this->once())->method('getData')->willReturn($offerData); $this->converter->expects($this->once())->method('convert')->with($quote, $this->accountUser, $offerData)->willReturn($order); $this->manager->expects($this->once())->method('persist')->with($order); $this->manager->expects($this->once())->method('flush'); $this->assertEquals($order, $this->handler->process($quote)); }
public function testConvertFromSelectedOffers() { $sku = 'sku1'; $unit = 'kg'; $qty = 55.5; $price = 555; $subtotalAmount = 25355.5; $quoteProduct = $this->createQuoteProduct($sku, true); $quoteProduct->setProduct((new Product())->setSku('test sku')); $quote = $this->createMainEntity(self::ACCOUNT_NAME, self::ACCOUNT_USER_FIRST_NAME, self::ACCOUNT_USER_LAST_NAME); $order = $this->createMainEntity(self::ACCOUNT_NAME, self::ACCOUNT_USER_FIRST_NAME, self::ACCOUNT_USER_LAST_NAME, true)->setCurrency(self::CURRENCY)->addLineItem($this->createOrderLineItem($sku, $unit, $qty, OrderLineItem::PRICE_TYPE_UNIT, $price, self::CURRENCY))->setSubtotal($subtotalAmount); $offer = $this->createQuoteProductOffer($unit, 1000, QuoteProductOffer::PRICE_TYPE_UNIT, $price, self::CURRENCY); $this->createQuoteProduct($sku, true)->addQuoteProductOffer($offer); $this->assertCalculateSubtotalsCalled($subtotalAmount); $this->assertEquals($order, $this->converter->convert($quote, null, [['offer' => $offer, 'quantity' => $qty]])); }