public function testInitVirtualProperty() { $this->auction->shouldReceive('getPrice')->andReturn(10000); $this->auction->shouldReceive('calCustomProfitAndGet')->andReturn(8000); $this->auction->shouldReceive('getRemainProfit')->andReturn(1300); $this->auction->shouldReceive('getStorePercentage')->twice()->andReturn(0.1); $this->auction->shouldReceive('getBsoPercentage')->once()->andReturn(0.1); $auction = Auction::initVirtualProperty($this->auction); $this->assertSame(8000, $this->auction->customProfit); $this->assertSame(650, $this->auction->storeProfit); $this->assertSame(650, $this->auction->bsoProfit); $this->assertTrue($this->auction->hasInitializedVirtualProperty); }
/** * @Route("/auction/sold/{_format}", defaults={"_format"="json"}, name="api_sold_auction", options={"expose"=true}) * @Method("PUT") * * @ApiDoc( * resource=true, * description="BSO auction sold action", * requirements={ * { * "name"="price", * "requirement"="\d+", * "dataType"="integer", * "required"=true, * "description"="The sold price" * }, * { * "name"="mobil", * "dataType"="string", * "required"=false, * "description"="Custom mobil number" * }, * { * "name"="_format", * "dataType"="string", * "required"=false, * "description"="回傳的格式,支援 json, xml, html" * } * } * ) */ public function soldAction(Request $request, $_format) { list($user, $em, $product) = $this->initBaseVar($request); /** * Price * * @var mixed */ $price = $request->request->get('price'); /** * The custom entity * * @var \Woojin\OrderBundle\Entity\Custom */ $custom = $em->getRepository('WoojinOrderBundle:Custom')->findOneBy(array('mobil' => $request->request->get('mobil'), 'store' => $user->getStore())); /** * The auction entity * * @var \Woojin\StoreBundle\Entity\Auction */ $auction = NULL === $product ? NULL : $em->getRepository('WoojinStoreBundle:Auction')->fetchAuctionByProduct($product); /** * Store the valide result * * @var array */ $unValid = $this->execValidaters($this->getSoldActionValidaters(array($product, $auction, $user, $custom, $price))); if (!empty($unValid)) { return $this->_getResponse($unValid, $_format); } /** * The result of service operation * * @var mixed[\Woojin\StoreBundle\Entity\Auction|Exception] */ $result = $this->get('auction.service')->setAuction($auction)->sold(['price' => $price, 'buyer' => $custom, 'bsser' => $user, 'soldAt' => new \DateTime()]); return $this->_genResponseWithServiceReturnAuction(\Woojin\StoreBundle\Entity\Auction::initVirtualProperty($result), $_format); }