resourceIndex = $resourceIndex; $this->dataProvider = $dataProvider; $this->storeManager = $storeManager; $this->attributeAdapterProvider = $attributeAdapterProvider ?: ObjectManager::getInstance() ->get(AttributeProvider::class); $this->fieldNameResolver = $fieldNameResolver ?: ObjectManager::getInstance() ->get(ResolverInterface::class); } /** * @inheritdoc */ public function getFields(array $productIds, $storeId) { $priceData = $this->dataProvider->getSearchableAttribute('price') ? $this->resourceIndex->getPriceIndexData($productIds, $storeId) : []; $fields = []; foreach ($productIds as $productId) { $fields[$productId] = $this->getProductPriceData($productId, $storeId, $priceData); } return $fields; } /** * Prepare price index for product * * @param int $productId * @param int $websiteId * @param array $priceIndexData * @return array */ private function getProductPriceData($productId, $websiteId, array $priceIndexData) { $result = []; if (array_key_exists($productId, $priceIndexData)) { $productPriceIndexData = $priceIndexData[$productId]; $priceAttribute = $this->attributeAdapterProvider->getByAttributeCode('price'); foreach ($productPriceIndexData as $customerGroupId => $price) { $fieldName = $this->fieldNameResolver->getFieldName( $priceAttribute, ['customerGroupId' => $customerGroupId, 'websiteId' => $websiteId] ); $result[$fieldName] = sprintf('%F', $price); } } return $result; } }