コード例 #1
0
 /**
  * @param OrmResultAfter $event
  */
 public function onResultAfter(OrmResultAfter $event)
 {
     $currencies = $this->getCurrencies();
     if (!$currencies) {
         return;
     }
     /** @var ResultRecord[] $records */
     $records = $event->getRecords();
     $productIds = [];
     foreach ($records as $record) {
         $productIds[] = $record->getValue('id');
     }
     /** @var ProductPriceRepository $priceRepository */
     $priceRepository = $this->doctrineHelper->getEntityRepository('OroB2BPricingBundle:ProductPrice');
     $priceList = $this->getPriceList();
     $showTierPrices = $this->priceListRequestHandler->getShowTierPrices();
     $prices = $priceRepository->findByPriceListIdAndProductIds($priceList->getId(), $productIds, $showTierPrices);
     $groupedPrices = $this->groupPrices($prices);
     foreach ($records as $record) {
         $record->addData(['showTierPrices' => $showTierPrices]);
         $productId = $record->getValue('id');
         $priceContainer = [];
         foreach ($currencies as $currencyIsoCode) {
             $columnName = $this->buildColumnName($currencyIsoCode);
             if (isset($groupedPrices[$productId][$currencyIsoCode])) {
                 $priceContainer[$columnName] = $groupedPrices[$productId][$currencyIsoCode];
             } else {
                 $priceContainer[$columnName] = [];
             }
         }
         if ($priceContainer) {
             $record->addData($priceContainer);
         }
     }
 }