/** * {@inheritdoc} */ public function build(DataProviderInterface $dataProvider, array $dimensions, RequestBucketInterface $bucket, Table $entityIdsTable) { /** @var DynamicBucket $bucket */ $algorithm = $this->algorithmRepository->get($bucket->getMethod()); $data = $algorithm->getItems($bucket, $dimensions, $this->entityStorageFactory->create($entityIdsTable)); $resultData = $this->prepareData($data); return $resultData; }
public function testBuild() { $expectedResult = ['count' => 'count(main_table.value)']; $this->requestBucket->expects($this->once())->method('getMetrics')->willReturn([$this->metric]); $this->metric->expects($this->once())->method('getType')->willReturn('count'); $metrics = $this->metrics->build($this->requestBucket); $this->assertEquals($expectedResult, $metrics); }
/** * Test for method "build" */ public function testBuild() { $fetchResult = ['name' => ['some', 'result']]; $documents = [['product_id' => 1, 'sku' => 'Product']]; $this->bucket->expects($this->once())->method('getName')->willReturn('name'); $this->entityMetadata->expects($this->once())->method('getEntityId')->willReturn('product_id'); $this->request->expects($this->once())->method('getAggregation')->willReturn([$this->bucket]); $this->request->expects($this->once())->method('getDimensions')->willReturn([]); $this->bucketBuilder->expects($this->once())->method('build')->willReturn($fetchResult['name']); $result = $this->builder->build($this->request, $documents); $this->assertEquals($result, $fetchResult); }
/** * Build metrics for Select->columns * * @param RequestBucketInterface $bucket * @return string[] */ public function build(RequestBucketInterface $bucket) { $selectAggregations = []; /** @var \Magento\Framework\Search\Request\Aggregation\Metric[] $metrics */ $metrics = $bucket->getMetrics(); foreach ($metrics as $metric) { $metricType = $metric->getType(); if (in_array($metricType, $this->mapMetrics)) { $selectAggregations[$metricType] = "{$metricType}(main_table.value)"; } } return $selectAggregations; }
/** * Test for method "build" */ public function testBuild() { $this->metricsBuilder->expects($this->once())->method('build')->willReturn(['metrics']); $this->bucket->expects($this->once())->method('getRanges')->willReturn([$this->range, $this->range, $this->range]); $this->range->expects($this->at(0))->method('getFrom')->willReturn(''); $this->range->expects($this->at(1))->method('getTo')->willReturn(50); $this->range->expects($this->at(2))->method('getFrom')->willReturn(50); $this->range->expects($this->at(3))->method('getTo')->willReturn(100); $this->range->expects($this->at(4))->method('getFrom')->willReturn(100); $this->range->expects($this->at(5))->method('getTo')->willReturn(''); $this->adapter->expects($this->once())->method('getCaseSql')->withConsecutive([''], [['`value` < 50' => "'*_50'", '`value` BETWEEN 50 AND 100' => "'50_100'", '`value` >= 100' => "'100_*'"]]); $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select); $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select); $result = $this->builder->build($this->dataProvider, [], $this->bucket, [1, 2, 3]); $this->assertEquals($this->select, $result); }
/** * @param \Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject * @param callable $proceed * @param BucketInterface $bucket * @param Dimension[] $dimensions * * @return Select * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetDataSet(\Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject, \Closure $proceed, BucketInterface $bucket, array $dimensions) { if ($bucket->getField() == 'category_ids') { $currentScope = $dimensions['scope']->getValue(); $currentScopeId = $this->scopeResolver->getScope($currentScope)->getId(); $currenCategory = $this->layer->getCurrentCategory(); $derivedTable = $this->getSelect(); $derivedTable->from(['main_table' => $this->resource->getTableName('catalog_category_product_index')], ['entity_id' => 'product_id', 'value' => 'category_id'])->where('main_table.store_id = ?', $currentScopeId); if (!empty($currenCategory)) { $derivedTable->join(['category' => $this->resource->getTableName('catalog_category_entity')], 'main_table.category_id = category.entity_id', [])->where('`category`.`path` LIKE ?', $currenCategory->getPath() . '%')->where('`category`.`level` > ?', $currenCategory->getLevel()); } $select = $this->getSelect(); $select->from(['main_table' => $derivedTable]); return $select; } return $proceed($bucket, $dimensions); }
/** * Test for method "build" */ public function testBuild() { $this->metricsBuilder->expects($this->once())->method('build')->willReturn(['metrics']); $this->bucket->expects($this->once())->method('getRanges')->willReturn([$this->range, $this->range, $this->range]); $this->range->expects($this->at(0))->method('getFrom')->willReturn(''); $this->range->expects($this->at(1))->method('getTo')->willReturn(50); $this->range->expects($this->at(2))->method('getFrom')->willReturn(50); $this->range->expects($this->at(3))->method('getTo')->willReturn(100); $this->range->expects($this->at(4))->method('getFrom')->willReturn(100); $this->range->expects($this->at(5))->method('getTo')->willReturn(''); $this->connectionMock->expects($this->once())->method('getCaseSql')->withConsecutive([''], [['`value` < 50' => "'*_50'", '`value` BETWEEN 50 AND 100' => "'50_100'", '`value` >= 100' => "'100_*'"]]); $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select); $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select); /** @var \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject $table */ $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $result = $this->builder->build($this->dataProvider, [], $this->bucket, $table); $this->assertEquals($this->select, $result); }
/** * Test for method "build" */ public function testBuild() { $fetchResult = ['name' => ['some', 'result']]; $documents = [1 => 'document_1', 2 => 'document_2']; $this->aggregationResolver->expects($this->once())->method('resolve')->with($this->request, array_keys($documents))->willReturn([$this->bucket]); $this->bucket->expects($this->once())->method('getName')->willReturn('name'); $this->request->expects($this->once())->method('getDimensions')->willReturn([]); $this->bucketBuilder->expects($this->once())->method('build')->willReturn($fetchResult['name']); $result = $this->builder->build($this->request, $this->table, $documents); $this->assertEquals($fetchResult, $result); }
/** * {@inheritdoc} */ public function getDataSet(BucketInterface $bucket, array $dimensions) { $currentScope = $dimensions['scope']->getValue(); $attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField()); if ($attribute->getAttributeCode() == 'price') { /** @var \Magento\Store\Model\Store $store */ $store = $this->scopeResolver->getScope($currentScope); if (!$store instanceof \Magento\Store\Model\Store) { throw new \RuntimeException('Illegal scope resolved'); } $table = $this->resource->getTableName('catalog_product_index_price'); $select = $this->getSelect(); $select->from(['main_table' => $table], null)->columns([BucketInterface::FIELD_VALUE => 'main_table.min_price'])->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('main_table.website_id = ?', $store->getWebsiteId()); } else { $currentScopeId = $this->scopeResolver->getScope($currentScope)->getId(); $select = $this->getSelect(); $table = $this->resource->getTableName('catalog_product_index_eav' . ($attribute->getBackendType() == 'decimal' ? '_decimal' : '')); $select->from(['main_table' => $table], ['value'])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ? ', $currentScopeId); } return $select; }
/** * Test for method "build" */ public function testBuild() { $fetchResult = ['name' => ['some', 'result']]; /** @var \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject $table */ $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $this->bucket->expects($this->once())->method('getName')->willReturn('name'); $this->request->expects($this->once())->method('getAggregation')->willReturn([$this->bucket]); $this->request->expects($this->once())->method('getDimensions')->willReturn([]); $this->bucketBuilder->expects($this->once())->method('build')->willReturn($fetchResult['name']); $result = $this->builder->build($this->request, $table); $this->assertEquals($result, $fetchResult); }