public function testApplyPriceListLimitationsNotApplied()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|QueryBuilder $qb */
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $this->priceListTreeHandler->expects($this->never())->method($this->anything());
     $this->modifier->applyPriceListLimitations($qb);
 }
 public function testDefaultIfNotFound()
 {
     $accountUser = new AccountUser();
     $accountUser->setAccount($this->getAccount('account.level_1'));
     $this->websiteManager->expects($this->once())->method('getCurrentWebsite')->willReturn(null);
     $this->assertTrue($this->handler->getPriceList($accountUser)->isDefault());
 }
 /**
  * {@inheritDoc}
  */
 public function getPriceList()
 {
     $priceList = $this->priceListTreeHandler->getPriceList($this->getAccountUser());
     if (!$priceList) {
         throw new \RuntimeException('PriceList not found');
     }
     return $priceList;
 }
 public function testGetPriceListCurrenciesWithRequestAndSaveState()
 {
     $this->handler->setRequest($this->request);
     $this->request->expects($this->exactly(2))->method('get')->willReturnMap([[FrontendPriceListRequestHandler::PRICE_LIST_CURRENCY_KEY, null, false, 'EUR'], [FrontendPriceListRequestHandler::SAVE_STATE_KEY, null, false, true]]);
     $this->priceListTreeHandler->expects($this->once())->method('getPriceList')->willReturn($this->getPriceList(42, ['EUR', 'USD']));
     $this->session->expects($this->once())->method('set')->with(FrontendPriceListRequestHandler::PRICE_LIST_CURRENCY_KEY, 'EUR');
     $this->assertEquals(['EUR'], $this->handler->getPriceListSelectedCurrencies());
 }
 /**
  * @param QueryBuilder $queryBuilder
  * @param string|null $currency
  */
 public function applyPriceListLimitations(QueryBuilder $queryBuilder, $currency = null)
 {
     $token = $this->tokenStorage->getToken();
     /** @var AccountUser $user */
     if ($token && ($user = $token->getUser()) instanceof AccountUser) {
         $priceList = $this->priceListTreeHandler->getPriceList($user);
         if ($priceList) {
             $rootAliases = $queryBuilder->getRootAliases();
             $rootAlias = $rootAliases[0];
             // Select only products that are in specific price list
             $limitationQb = $queryBuilder->getEntityManager()->createQueryBuilder();
             $limitationQb->from('OroB2BPricingBundle:ProductPrice', '_productPrice')->select('IDENTITY(_productPrice.product)')->where($limitationQb->expr()->eq('_productPrice.priceList', ':_priceList'))->andWhere($limitationQb->expr()->eq('_productPrice.product', $rootAlias));
             if ($currency) {
                 $limitationQb->andWhere($queryBuilder->expr()->eq('_productPrice.currency', ':currency'));
                 $queryBuilder->setParameter('currency', strtoupper($currency));
             }
             $queryBuilder->andWhere($queryBuilder->expr()->exists($limitationQb))->setParameter('_priceList', $priceList);
         }
     }
 }