Ejemplo n.º 1
0
 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @return string
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
 {
     $currentStoreId = $this->scopeResolver->getScope()->getId();
     $attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
     $select = $this->getSelect();
     $table = $attribute->getBackendTable();
     if ($filter->getField() == 'price') {
         $query = str_replace('price', 'min_price', $query);
         $select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
     } elseif ($filter->getField() == 'category_ids') {
         return 'category_index.category_id = ' . $filter->getValue();
     } else {
         if ($attribute->isStatic()) {
             $select->from(['main_table' => $table], 'entity_id')->where($query);
         } else {
             if ($filter->getType() == FilterInterface::TYPE_TERM) {
                 $field = $filter->getField();
                 $mapper = function ($value) use($field, $isNegation) {
                     return ($isNegation ? '-' : '') . $this->attributePrefix . $field . '_' . $value;
                 };
                 if (is_array($filter->getValue())) {
                     $value = implode(' ', array_map($mapper, $filter->getValue()));
                 } else {
                     $value = $mapper($filter->getValue());
                 }
                 return 'MATCH (data_index) AGAINST (' . $this->getConnection()->quote($value) . ' IN BOOLEAN MODE)';
             }
             $ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
             $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
         }
     }
     return 'search_index.product_id IN (
         select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
 }
Ejemplo n.º 2
0
 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @param QueryContainer $queryContainer
  * @return string
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
 {
     $currentStoreId = $this->scopeResolver->getScope()->getId();
     $attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
     $select = $this->getConnection()->select();
     $table = $attribute->getBackendTable();
     if ($filter->getField() == 'price') {
         $query = str_replace('price', 'min_price', $query);
         $select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
     } elseif ($filter->getField() == 'category_ids') {
         return 'category_index.category_id = ' . $filter->getValue();
     } else {
         if ($attribute->isStatic()) {
             $select->from(['main_table' => $table], 'entity_id')->where($query);
         } else {
             if ($filter->getType() == FilterInterface::TYPE_TERM) {
                 if (is_array($filter->getValue())) {
                     $value = sprintf('%s IN (%s)', $isNegation ? 'NOT' : '', implode(',', $filter->getValue()));
                 } else {
                     $value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
                 }
                 $filterQuery = sprintf('cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s', $this->scopeResolver->getScope()->getId(), $attribute->getId(), $value);
                 $queryContainer->addFilter($filterQuery);
                 return '';
             }
             $ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
             $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
         }
     }
     return 'search_index.entity_id IN (
         select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
 }
Ejemplo n.º 3
0
 /**
  * Load customer log data by customer id
  *
  * @param int $customerId
  * @return array
  */
 protected function loadLogData($customerId)
 {
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
     $adapter = $this->resource->getConnection('read');
     $select = $adapter->select()->from(['cl' => $this->resource->getTableName('customer_log')])->joinLeft(['cv' => $this->resource->getTableName('customer_visitor')], 'cv.customer_id = cl.customer_id', ['last_visit_at'])->where('cl.customer_id = ?', $customerId)->order('cv.visitor_id DESC')->limit(1);
     return $adapter->fetchRow($select);
 }
Ejemplo n.º 4
0
 /**
  * @magentoDataFixture Magento/Bundle/_files/product.php
  * @covers \Magento\Indexer\Model\Indexer::reindexAll
  * @covers \Magento\Bundle\Model\Product\Type::getSearchableData
  */
 public function testPrepareProductIndexForBundleProduct()
 {
     $this->indexer->reindexAll();
     $select = $this->adapter->select()->from($this->resource->getTableName('catalogsearch_fulltext_scope1'))->where('`data_index` LIKE ?', '%' . 'Bundle Product Items' . '%');
     $result = $this->adapter->fetchAll($select);
     $this->assertCount(1, $result);
 }
Ejemplo n.º 5
0
 /**
  * Execute full indexation
  *
  * @return void
  */
 public function executeFull()
 {
     $results = [];
     foreach ($this->getTables() as $table => $columns) {
         if (!count($columns)) {
             continue;
         }
         foreach ($columns as $idx => $col) {
             $columns[$idx] = '`' . $col . '`';
         }
         $select = $this->connection->select();
         $fromColumns = new \Zend_Db_Expr('CONCAT(' . implode(",' ',", $columns) . ') as data_index');
         $select->from($table, $fromColumns);
         $result = $this->connection->query($select);
         while ($row = $result->fetch()) {
             $data = $row['data_index'];
             $this->split($data, $results);
         }
     }
     $indexTable = $this->resource->getTableName('mst_misspell_index');
     $this->connection->delete($indexTable);
     $rows = [];
     foreach ($results as $word => $freq) {
         $rows[] = ['keyword' => $word, 'trigram' => $this->text->getTrigram($word), 'frequency' => $freq / count($results)];
         if (count($rows) > 1000) {
             $this->connection->insertArray($indexTable, ['keyword', 'trigram', 'frequency'], $rows);
             $rows = [];
         }
     }
     if (count($rows) > 0) {
         $this->connection->insertArray($indexTable, ['keyword', 'trigram', 'frequency'], $rows);
     }
     $this->connection->delete($this->resource->getTableName('mst_misspell_suggest'));
 }
Ejemplo n.º 6
0
 /**
  * Get table name (validated by db adapter) by table placeholder
  *
  * @param string|array $tableName
  * @return string
  */
 public function getTable($tableName)
 {
     $cacheKey = $this->_getTableCacheName($tableName);
     if (!isset($this->tables[$cacheKey])) {
         $this->tables[$cacheKey] = $this->resourceModel->getTableName($tableName);
     }
     return $this->tables[$cacheKey];
 }
Ejemplo n.º 7
0
 /**
  * Build index query
  *
  * @param RequestInterface $request
  * @return Select
  */
 public function build(RequestInterface $request)
 {
     $select = $this->getSelect()->from(['search_index' => $this->resource->getTableName($request->getIndex())], ['entity_id' => 'search_index.product_id'])->joinLeft(['category_index' => $this->resource->getTableName('catalog_category_product_index')], 'search_index.product_id = category_index.product_id' . ' AND search_index.store_id = category_index.store_id', []);
     $isShowOutOfStock = $this->config->isSetFlag('cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE);
     if ($isShowOutOfStock === false) {
         $select->joinLeft(['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.product_id = stock_index.product_id' . $this->getReadConnection()->quoteInto(' AND stock_index.website_id = ?', $this->storeManager->getWebsite()->getId()), [])->where('stock_index.stock_status = ?', 1);
     }
     return $select;
 }
Ejemplo n.º 8
0
 /**
  * @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
  */
 public function testAggregate()
 {
     $rating = $this->reviewCollection->getFirstItem();
     $this->reviewResource->aggregate($rating);
     $select = $this->adapter->select()->from($this->resource->getTableName('review_entity_summary'));
     $result = $this->adapter->fetchRow($select);
     $this->assertEquals(1, $result['reviews_count']);
     $this->assertEquals(40, $result['rating_summary']);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getAggregations(array $entityIds)
 {
     $aggregation = ['count' => 'count(DISTINCT entity_id)', 'max' => 'MAX(min_price)', 'min' => 'MIN(min_price)', 'std' => 'STDDEV_SAMP(min_price)'];
     $select = $this->getSelect();
     $tableName = $this->resource->getTableName('catalog_product_index_price');
     $select->from($tableName, [])->where('entity_id IN (?)', $entityIds)->columns($aggregation);
     $select = $this->setCustomerGroupId($select);
     $result = $this->getConnection()->fetchRow($select);
     return $result;
 }
Ejemplo n.º 10
0
 public function testGetTableName()
 {
     $tablePrefix = 'prefix_';
     $tableSuffix = 'suffix';
     $tableNameOrig = 'store_website';
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Resource', array('tablePrefix' => 'prefix_'));
     $tableName = $this->_model->getTableName(array($tableNameOrig, $tableSuffix));
     $this->assertContains($tablePrefix, $tableName);
     $this->assertContains($tableSuffix, $tableName);
     $this->assertContains($tableNameOrig, $tableName);
 }
Ejemplo n.º 11
0
 protected function mockBuild($index, $tableSuffix)
 {
     $this->request->expects($this->once())->method('getIndex')->will($this->returnValue($index));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($index) {
         return is_array($index) ? $index[0] . $index[1] : $index;
     }));
     $this->select->expects($this->once())->method('from')->with(['search_index' => $index . $tableSuffix], ['entity_id' => 'product_id'])->will($this->returnSelf());
     $this->select->expects($this->at(1))->method('joinLeft')->with(['category_index' => 'catalog_category_product_index'], 'search_index.product_id = category_index.product_id' . ' AND search_index.store_id = category_index.store_id', [])->will($this->returnSelf());
     $this->select->expects($this->at(2))->method('joinLeft')->with(['cea' => 'catalog_eav_attribute'], 'search_index.attribute_id = cea.attribute_id', ['search_weight'])->will($this->returnSelf());
     $this->select->expects($this->at(3))->method('joinLeft')->with(['cpie' => $this->resource->getTableName('catalog_product_index_eav')], 'search_index.product_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id', [])->willReturnSelf();
 }
Ejemplo n.º 12
0
 /**
  * @param int $n
  * @return void
  */
 public function generateSequences($n = 10)
 {
     $connection = $this->appResource->getConnection('write');
     for ($i = 0; $i < $n; $i++) {
         foreach ($this->entities as $entityName) {
             $sequenceName = $this->appResource->getTableName(sprintf('sequence_%s_%s', $entityName, $i));
             if (!$connection->isTableExists($sequenceName)) {
                 $connection->query($this->ddlSequence->getCreateSequenceDdl($sequenceName));
             }
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Retrieves information about log tables
  *
  * @return string[]
  */
 public function getTablesInfo()
 {
     $tables = ['log_customer', 'log_visitor', 'log_visitor_info', 'log_url_table', 'log_url_info_table', 'log_quote_table', 'reports_viewed_product_index', 'reports_compared_product_index', 'reports_event', 'catalog_compare_item'];
     $result = [];
     foreach ($tables as $table) {
         $info = $this->_resourceHelper->getTableInfo($this->_resource->getTableName($table));
         if (!$info) {
             continue;
         }
         $result[] = $info;
     }
     return $result;
 }
Ejemplo n.º 14
0
 /**
  * @param string $index
  * @param Dimension[] $dimensions
  * @return string
  */
 public function resolve($index, array $dimensions)
 {
     $tableNameParts = [$index];
     foreach ($dimensions as $dimension) {
         switch ($dimension->getName()) {
             case 'scope':
                 $tableNameParts[] = $dimension->getName() . $this->getScopeId($dimension);
                 break;
             default:
                 $tableNameParts[] = $dimension->getName() . $dimension->getValue();
         }
     }
     return $this->resource->getTableName(implode('_', $tableNameParts));
 }
Ejemplo n.º 15
0
 /**
  * Build index query
  *
  * @param RequestInterface $request
  * @return Select
  */
 public function build(RequestInterface $request)
 {
     $searchIndexTable = $this->scopeResolver->resolve($request->getIndex(), $request->getDimensions());
     $select = $this->getSelect()->from(['search_index' => $searchIndexTable], ['entity_id' => 'entity_id'])->joinLeft(['cea' => $this->resource->getTableName('catalog_eav_attribute')], 'search_index.attribute_id = cea.attribute_id', []);
     if ($this->isNeedToAddFilters($request)) {
         $select->joinLeft(['category_index' => $this->resource->getTableName('catalog_category_product_index')], 'search_index.entity_id = category_index.product_id', [])->joinLeft(['cpie' => $this->resource->getTableName('catalog_product_index_eav')], 'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id', []);
     }
     $select = $this->processDimensions($request, $select);
     $isShowOutOfStock = $this->config->isSetFlag('cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE);
     if ($isShowOutOfStock === false) {
         $select->joinLeft(['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.entity_id = stock_index.product_id' . $this->getReadConnection()->quoteInto(' AND stock_index.website_id = ?', $this->storeManager->getWebsite()->getId()), []);
         $select->where('stock_index.stock_status = ?', 1);
     }
     return $select;
 }
Ejemplo n.º 16
0
 /**
  * Cleanup old logs so that the database table foggyline_sentinel_log does not get cluttered.
  *
  * @return $this
  */
 public function cleanup()
 {
     try {
         /* Here we do a fast cleanup, directly on database, no individual objects */
         $connection = $this->resource->getConnection();
         $connection->beginTransaction();
         $condition = ['created_at < (NOW() - INTERVAL ? HOUR)' => $this->helper->getCleanAfterHours()];
         $connection->delete($this->resource->getTableName('foggyline_sentinel_log'), $condition);
         $connection->commit();
         $this->logger->info('Cron job foggyline_sentinel_cleanup executed');
     } catch (\Exception $e) {
         $connection->rollBack();
         $this->logger->critical($e);
     }
     return $this;
 }
Ejemplo n.º 17
0
 /**
  * Obtain select for categories with attributes.
  * By default everything from entity table is selected
  * + name, is_active and is_anchor
  * Also the correct product_count is selected, depending on is the category anchor or not.
  *
  * @param bool $sorted
  * @param array $optionalAttributes
  * @return \Zend_Db_Select
  */
 protected function _createCollectionDataSelect($sorted = true, $optionalAttributes = array())
 {
     $select = $this->_getDefaultCollection($sorted ? $this->_orderField : false)->getSelect();
     // add attributes to select
     $attributes = array('name', 'is_active', 'is_anchor');
     if ($optionalAttributes) {
         $attributes = array_unique(array_merge($attributes, $optionalAttributes));
     }
     $resource = $this->_catalogCategory;
     foreach ($attributes as $attributeCode) {
         /* @var $attribute \Magento\Eav\Model\Entity\Attribute */
         $attribute = $resource->getAttribute($attributeCode);
         // join non-static attribute table
         if (!$attribute->getBackend()->isStatic()) {
             $tableDefault = sprintf('d_%s', $attributeCode);
             $tableStore = sprintf('s_%s', $attributeCode);
             $valueExpr = $this->_conn->getCheckSql("{$tableStore}.value_id > 0", "{$tableStore}.value", "{$tableDefault}.value");
             $select->joinLeft(array($tableDefault => $attribute->getBackend()->getTable()), sprintf('%1$s.entity_id=e.entity_id AND %1$s.attribute_id=%2$d' . ' AND %1$s.entity_type_id=e.entity_type_id AND %1$s.store_id=%3$d', $tableDefault, $attribute->getId(), \Magento\Store\Model\Store::DEFAULT_STORE_ID), array($attributeCode => 'value'))->joinLeft(array($tableStore => $attribute->getBackend()->getTable()), sprintf('%1$s.entity_id=e.entity_id AND %1$s.attribute_id=%2$d' . ' AND %1$s.entity_type_id=e.entity_type_id AND %1$s.store_id=%3$d', $tableStore, $attribute->getId(), $this->getStoreId()), array($attributeCode => $valueExpr));
         }
     }
     // count children products qty plus self products qty
     $categoriesTable = $this->_coreResource->getTableName('catalog_category_entity');
     $categoriesProductsTable = $this->_coreResource->getTableName('catalog_category_product');
     $subConcat = $this->_conn->getConcatSql(array('e.path', $this->_conn->quote('/%')));
     $subSelect = $this->_conn->select()->from(array('see' => $categoriesTable), null)->joinLeft(array('scp' => $categoriesProductsTable), 'see.entity_id=scp.category_id', array('COUNT(DISTINCT scp.product_id)'))->where('see.entity_id = e.entity_id')->orWhere('see.path LIKE ?', $subConcat);
     $select->columns(array('product_count' => $subSelect));
     $subSelect = $this->_conn->select()->from(array('cp' => $categoriesProductsTable), 'COUNT(cp.product_id)')->where('cp.category_id = e.entity_id');
     $select->columns(array('self_product_count' => $subSelect));
     return $select;
 }
Ejemplo n.º 18
0
 /**
  * Check attribute lock state
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @param null $attributeSet
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return void
  */
 public function validate(\Magento\Framework\Model\AbstractModel $object, $attributeSet = null)
 {
     $adapter = $this->resource->getConnection('read');
     $attrTable = $this->resource->getTableName('catalog_product_super_attribute');
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $bind = ['attribute_id' => $object->getAttributeId()];
     $select = clone $adapter->select();
     $select->reset()->from(['main_table' => $attrTable], ['psa_count' => 'COUNT(product_super_attribute_id)'])->join(['entity' => $productTable], 'main_table.product_id = entity.entity_id')->where('main_table.attribute_id = :attribute_id')->group('main_table.attribute_id')->limit(1);
     if ($attributeSet !== null) {
         $bind['attribute_set_id'] = $attributeSet;
         $select->where('entity.attribute_set_id = :attribute_set_id');
     }
     if ($adapter->fetchOne($select, $bind)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('This attribute is used in configurable products.'));
     }
 }
Ejemplo n.º 19
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\App\Resource $resource
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\App\Resource $resource)
 {
     $this->_setIdFieldName('primary_id');
     parent::__construct($entityFactory, $logger, $fetchStrategy, $resource->getConnection('review_read'));
     $this->_summaryTable = $resource->getTableName('review_entity_summary');
     $this->_select->from($this->_summaryTable);
     $this->setItemObjectClass('Magento\\Review\\Model\\Review\\Summary');
 }
Ejemplo n.º 20
0
 /**
  * Returns the list of tables which data should not be backed up
  *
  * @return string[]
  */
 public function getIgnoreDataTablesList()
 {
     $result = [];
     foreach ($this->_ignoreDataTablesList as $table) {
         $result[] = $this->_resource->getTableName($table);
     }
     return $result;
 }
Ejemplo n.º 21
0
 /**
  * Reindex affected products
  *
  * @param int $storeId
  * @param string $attrCode
  * @param \Zend_Db_Expr $attrConditionValue
  * @return void
  */
 protected function _refreshSpecialPriceByStore($storeId, $attrCode, $attrConditionValue)
 {
     $attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attrCode);
     $attributeId = $attribute->getAttributeId();
     $connection = $this->_getWriteConnection();
     $select = $connection->select()->from($this->_resource->getTableName(array('catalog_product_entity', 'datetime')), array('entity_id'))->where('attribute_id = ?', $attributeId)->where('store_id = ?', $storeId)->where('value = ?', $attrConditionValue);
     $this->_processor->getIndexer()->reindexList($connection->fetchCol($select, array('entity_id')));
 }
Ejemplo n.º 22
0
 /**
  * @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);
 }
Ejemplo n.º 23
0
 public function testGetTableNameWithPrefix()
 {
     $this->setConnection();
     $modelEntity = ['modelEntity', 'tableSuffix'];
     $expected = 'tablename';
     $tablePrefix = 'tablePrefix';
     $this->_resorce->setTablePrefix($tablePrefix);
     $this->_connection->expects($this->once())->method('getTableName')->with($tablePrefix . $modelEntity[0] . '_' . $modelEntity[1])->will($this->returnValue($expected));
     $this->assertEquals($expected, $this->_resorce->getTableName($modelEntity));
 }
Ejemplo n.º 24
0
 /**
  * Build adapter dependent query
  *
  * @param RequestInterface $request
  * @return Select
  */
 public function buildQuery(RequestInterface $request)
 {
     /** @var ScoreBuilder $scoreBuilder */
     $scoreBuilder = $this->scoreBuilderFactory->create();
     $select = $this->processQuery($scoreBuilder, $request->getQuery(), $this->getSelect(), self::BOOL_MUST);
     $select = $this->processDimensions($request, $select);
     $tableName = $this->resource->getTableName($request->getIndex());
     $select->from($tableName)->columns($scoreBuilder->build())->order($scoreBuilder->getScoreAlias() . ' ' . Select::SQL_DESC);
     return $select;
 }
Ejemplo n.º 25
0
 /**
  * Delete options and selections.
  *
  * @param array $productIds
  *
  * @return \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
  */
 protected function deleteOptionsAndSelections($productIds)
 {
     $optionTable = $this->_resource->getTableName('catalog_product_bundle_option');
     $optionValueTable = $this->_resource->getTableName('catalog_product_bundle_option_value');
     $valuesIds = $this->connection->fetchAssoc($this->connection->select()->from(['bov' => $optionValueTable], ['value_id'])->joinLeft(['bo' => $optionTable], 'bo.option_id = bov.option_id', ['option_id'])->where('parent_id IN (?)', $productIds));
     $this->connection->delete($optionTable, $this->connection->quoteInto('value_id IN (?)', array_keys($valuesIds)));
     $productIdsInWhere = $this->connection->quoteInto('parent_id IN (?)', $productIds);
     $this->connection->delete($optionTable, $this->connection->quoteInto('parent_id IN (?)', $productIdsInWhere));
     $this->connection->delete($optionTable, $this->connection->quoteInto('parent_product_id IN (?)', $productIdsInWhere));
     return $this;
 }
Ejemplo n.º 26
0
 /**
  * Build trigger statement for INSER, UPDATE, DELETE events
  *
  * @param string $event
  * @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
  * @return string
  */
 protected function buildStatement($event, $changelog)
 {
     switch ($event) {
         case \Magento\Framework\DB\Ddl\Trigger::EVENT_INSERT:
         case \Magento\Framework\DB\Ddl\Trigger::EVENT_UPDATE:
             return sprintf("INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);", $this->write->quoteIdentifier($this->resource->getTableName($changelog->getName())), $this->write->quoteIdentifier($changelog->getColumnName()), $this->write->quoteIdentifier($this->getColumnName()));
         case \Magento\Framework\DB\Ddl\Trigger::EVENT_DELETE:
             return sprintf("INSERT IGNORE INTO %s (%s) VALUES (OLD.%s);", $this->write->quoteIdentifier($this->resource->getTableName($changelog->getName())), $this->write->quoteIdentifier($changelog->getColumnName()), $this->write->quoteIdentifier($this->getColumnName()));
         default:
             return '';
     }
 }
Ejemplo n.º 27
0
 /**
  * {@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;
 }
Ejemplo n.º 28
0
 /**
  * Populate ACL with roles from external storage
  *
  * @param \Magento\Framework\Acl $acl
  * @return void
  */
 public function populateAcl(\Magento\Framework\Acl $acl)
 {
     $roleTableName = $this->_resource->getTableName('authorization_role');
     $adapter = $this->_resource->getConnection('core_read');
     $select = $adapter->select()->from($roleTableName)->order('tree_level');
     foreach ($adapter->fetchAll($select) as $role) {
         $parent = $role['parent_id'] > 0 ? $role['parent_id'] : null;
         switch ($role['role_type']) {
             case RoleGroup::ROLE_TYPE:
                 $acl->addRole($this->_groupFactory->create(['roleId' => $role['role_id']]), $parent);
                 break;
             case RoleUser::ROLE_TYPE:
                 if (!$acl->hasRole($role['role_id'])) {
                     $acl->addRole($this->_roleFactory->create(['roleId' => $role['role_id']]), $parent);
                 } else {
                     $acl->addRoleParent($role['role_id'], $parent);
                 }
                 break;
         }
     }
 }
Ejemplo n.º 29
0
 /**
  * Get options for database backend type
  *
  * @return array
  */
 protected function _getDbAdapterOptions()
 {
     $options['adapter_callback'] = function () {
         return $this->_resource->getConnection('core_write');
     };
     $options['data_table_callback'] = function () {
         return $this->_resource->getTableName('cache');
     };
     $options['tags_table_callback'] = function () {
         return $this->_resource->getTableName('cache_tag');
     };
     return $options;
 }
Ejemplo n.º 30
0
 /**
  * Get maximum version_id from changelog
  *
  * @return int
  * @throws \Exception
  */
 public function getVersion()
 {
     $changelogTableName = $this->resource->getTableName($this->getName());
     if (!$this->write->isTableExists($changelogTableName)) {
         throw new \Exception("Table {$changelogTableName} does not exist");
     }
     $row = $this->write->fetchRow('SHOW TABLE STATUS LIKE ?', [$changelogTableName]);
     if (isset($row['Auto_increment'])) {
         return (int) $row['Auto_increment'] - 1;
     } else {
         throw new \Exception("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id.");
     }
 }