/** * @param ProductGridWidgetRenderEvent $event */ public function onWidgetRender(ProductGridWidgetRenderEvent $event) { $params = $event->getWidgetRouteParameters(); $params[PriceListRequestHandler::PRICE_LIST_KEY] = $this->priceListRequestHandler->getPriceList()->getId(); $params[PriceListRequestHandler::PRICE_LIST_CURRENCY_KEY] = $this->priceListRequestHandler->getPriceListSelectedCurrencies(); $params[PriceListRequestHandler::TIER_PRICES_KEY] = $this->priceListRequestHandler->getShowTierPrices(); $event->setWidgetRouteParameters($params); }
/** * @param OrmFilterDatasourceAdapter $ds * @param string $unit */ protected function qbPrepare(OrmFilterDatasourceAdapter $ds, $unit) { $qb = $ds->getQueryBuilder(); $rootAliasCollection = $qb->getRootAliases(); $rootAlias = reset($rootAliasCollection); $joinAlias = $this->getJoinAlias(); $currency = $this->get('data_name'); $qb->innerJoin('OroB2BPricingBundle:ProductPrice', $joinAlias, Join::WITH, $rootAlias . '.id = IDENTITY(' . $joinAlias . '.product)'); $this->addEqExpr($ds, $joinAlias . '.priceList', $ds->generateParameterName('priceList'), $this->priceListRequestHandler->getPriceList()); $this->addEqExpr($ds, $joinAlias . '.currency', $ds->generateParameterName('currency'), $currency); $this->addEqExpr($ds, $joinAlias . '.quantity', $ds->generateParameterName('quantity'), 1); $this->addEqExpr($ds, 'IDENTITY(' . $joinAlias . '.unit)', $ds->generateParameterName('unit'), $unit); }
public function testOnWidgetRender() { $priceList = $this->getPriceList(42); $currencies = ['UAH']; $showTierPrices = false; /** @var \PHPUnit_Framework_MockObject_MockObject|ProductGridWidgetRenderEvent $event */ $event = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Event\\ProductGridWidgetRenderEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('getWidgetRouteParameters')->willReturn([]); $this->priceListRequestHandler->expects($this->once())->method('getPriceList')->willReturn($priceList); $this->priceListRequestHandler->expects($this->once())->method('getPriceListSelectedCurrencies')->willReturn($currencies); $this->priceListRequestHandler->expects($this->once())->method('getShowTierPrices')->willReturn($showTierPrices); $event->expects($this->once())->method('setWidgetRouteParameters')->with($this->logicalAnd($this->isType('array'), $this->arrayHasKey('priceListId'), $this->arrayHasKey('priceCurrencies'), $this->arrayHasKey('showTierPrices'), $this->contains($priceList->getId()), $this->contains($currencies), $this->contains($showTierPrices))); $this->listener->onWidgetRender($event); }
/** * @param int|null $priceListId * @param array $priceCurrencies * @param array $sourceResults * @param ProductPrice[] $prices * @param array $expectedResults * @dataProvider onResultAfterDataProvider */ public function testOnResultAfter($priceListId = null, array $priceCurrencies = [], array $sourceResults = [], array $prices = [], array $expectedResults = []) { $priceRepository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with('OroB2BPricingBundle:ProductPrice')->willReturn($priceRepository); $sourceResultRecords = []; $productIds = []; foreach ($sourceResults as $sourceResult) { $sourceResultRecords[] = new ResultRecord($sourceResult); $productIds[] = $sourceResult['id']; } if ($priceListId && $priceCurrencies) { $this->priceListRequestHandler->expects($this->any())->method('getPriceList')->willReturn($this->getPriceList($priceListId)); $this->priceListRequestHandler->expects($this->any())->method('getPriceListSelectedCurrencies')->will($this->returnCallback(function () use($priceCurrencies) { return array_intersect(['USD', 'EUR'], $priceCurrencies); })); $this->priceListRequestHandler->expects($this->any())->method('getShowTierPrices')->willReturn(true); $priceRepository->expects($this->any())->method('findByPriceListIdAndProductIds')->with($priceListId, $productIds)->willReturn($prices); } /** @var \PHPUnit_Framework_MockObject_MockObject|DatagridInterface $datagrid */ $datagrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface'); $event = new OrmResultAfter($datagrid, $sourceResultRecords); $this->listener->onResultAfter($event); $actualResults = $event->getRecords(); $this->assertSameSize($expectedResults, $actualResults); foreach ($expectedResults as $key => $expectedResult) { $actualResult = $actualResults[$key]; foreach ($expectedResult as $name => $value) { $this->assertEquals($value, $actualResult->getValue($name)); } } }
/** * @param mixed $value * @param bool|int $expected * * @dataProvider priceListIdDataProvider */ public function testGetPriceListId($value, $expected) { /** @var \PHPUnit_Framework_MockObject_MockObject|Request $request */ $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $request->expects($this->atLeastOnce())->method('get')->willReturn($value); $this->handler->setRequest($request); $this->assertEquals($expected, $this->handler->getPriceListId()); }
/** * @return array */ protected function getCurrencies() { return $this->priceListRequestHandler->getPriceListSelectedCurrencies(); }