Exemplo n.º 1
0
 /**
  * Populates temporary table
  *
  * @param Table $table
  * @param array $data
  * @return Table
  * @throws \Zend_Db_Exception
  */
 private function populateTemporaryTable(Table $table, $data)
 {
     if (count($data)) {
         $this->getConnection()->insertArray($table->getName(), [self::FIELD_ENTITY_ID, self::FIELD_SCORE], $data);
     }
     return $table;
 }
Exemplo n.º 2
0
 /**
  * Executes query and return raw response
  *
  * @param Table $table
  * @return array
  * @throws \Zend_Db_Exception
  */
 private function getDocuments(Table $table)
 {
     $connection = $this->getConnection();
     $select = $connection->select();
     $select->from($table->getName(), ['entity_id', 'score']);
     return $connection->fetchAssoc($select);
 }
Exemplo n.º 3
0
 /**
  * @param \Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject
  * @param callable|\Closure $proceed
  * @param BucketInterface $bucket
  * @param Dimension[] $dimensions
  *
  * @param Table $entityIdsTable
  * @return Select
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetDataSet(\Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject, \Closure $proceed, BucketInterface $bucket, array $dimensions, Table $entityIdsTable)
 {
     if ($bucket->getField() == 'category_ids') {
         $currentScopeId = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
         $currentCategory = $this->layer->getCurrentCategory();
         $derivedTable = $this->resource->getConnection()->select();
         $derivedTable->from(['main_table' => $this->resource->getTableName('catalog_category_product_index')], ['value' => 'category_id'])->where('main_table.store_id = ?', $currentScopeId);
         $derivedTable->joinInner(['entities' => $entityIdsTable->getName()], 'main_table.product_id  = entities.entity_id', []);
         if (!empty($currentCategory)) {
             $derivedTable->join(['category' => $this->resource->getTableName('catalog_category_entity')], 'main_table.category_id = category.entity_id', [])->where('`category`.`path` LIKE ?', $currentCategory->getPath() . '%')->where('`category`.`level` > ?', $currentCategory->getLevel());
         }
         $select = $this->resource->getConnection()->select();
         $select->from(['main_table' => $derivedTable]);
         return $select;
     }
     return $proceed($bucket, $dimensions, $entityIdsTable);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getDataSet(BucketInterface $bucket, array $dimensions, Table $entityIdsTable)
 {
     $currentScope = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
     $attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField());
     $select = $this->getSelect();
     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->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();
         $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);
     }
     $select->joinInner(['entities' => $entityIdsTable->getName()], 'main_table.entity_id  = entities.entity_id', []);
     return $select;
 }
Exemplo n.º 5
0
 /**
  * @param \Magento\Framework\DB\Ddl\Table $table
  * @return $this
  */
 public function prepareTemporaryTable($table)
 {
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     /** @var \Mirasvit\Search\Model\IndexFactory $indexFactory */
     $indexFactory = $objectManager->get('Mirasvit\\Search\\Model\\IndexFactory');
     $index = $indexFactory->create()->load('catalogsearch_fulltext');
     if (!$index->hasProperty('only_active_categories')) {
         return $this;
     }
     /** @var \Magento\Catalog\Model\Category\Tree $tree */
     $tree = $objectManager->get('Magento\\Catalog\\Model\\Category\\Tree');
     $root = $tree->getTree($tree->getRootNode())->getChildrenData();
     $ids = $this->getActiveCategories($root);
     /** @var \Magento\Framework\App\ResourceConnection $resource */
     $resource = $objectManager->get('Magento\\Framework\\App\\ResourceConnection');
     $connection = $resource->getConnection();
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $prods */
     $prods = $objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection');
     $prods->addCategoriesFilter(['eq' => $ids]);
     $select = $prods->getSelect()->reset('columns')->columns(['entity_id']);
     $connection->delete($table->getName(), ['entity_id NOT IN(' . new \Zend_Db_Expr($select) . ')']);
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Get document ids
  *
  * @param Table $documentsTable
  * @return array
  * @deprecated Added for backward compatibility
  */
 private function getDocumentIds(Table $documentsTable)
 {
     $select = $this->getConnection()->select()->from($documentsTable->getName(), TemporaryStorage::FIELD_ENTITY_ID);
     return $this->getConnection()->fetchCol($select);
 }
Exemplo n.º 7
0
 /**
  * @param Table $tableDdl
  * @return void
  */
 public function createTableByDdl($tableDdl)
 {
     $this->resourceAdapter->dropTable($tableDdl->getName());
     $this->resourceAdapter->createTable($tableDdl);
     $this->resourceAdapter->resetDdlCache($tableDdl->getName());
 }
Exemplo n.º 8
0
 /**
  * @param Select $query
  * @param Table $previousResultTable
  * @param ScoreBuilder $scoreBuilder
  * @return Select
  * @throws \Zend_Db_Exception
  */
 private function joinPreviousResultToSelect(Select $query, Table $previousResultTable, ScoreBuilder $scoreBuilder)
 {
     $query->joinInner(['previous_results' => $previousResultTable->getName()], 'previous_results.entity_id = search_index.entity_id', []);
     $scoreBuilder->addCondition('previous_results.score', false);
     $query->columns($scoreBuilder->build());
     $query = $this->createAroundSelect($query, $scoreBuilder);
     return $query;
 }
 /**
  * @param string $mode
  * @param Table $table
  * @param array|int $modifyColumns
  * @throws \Zend_Db_Exception
  */
 private function migrateTable($mode, Table $table, $modifyColumns)
 {
     if ($mode === 'remove' && is_array($modifyColumns)) {
         $describedTable = $this->describeTable($table->getName());
         foreach ($modifyColumns as $column) {
             if (isset($describedTable[$column])) {
                 $cd = $this->getColumnCreateByDescribe($describedTable[$column]);
                 $this->changeColumn($table->getName(), $column, 'z_' . $column, $cd);
             }
         }
         return;
     }
     $modifyColumns = array_flip($modifyColumns);
     // values are now keys
     $modifyColumns = array_change_key_case($modifyColumns, CASE_UPPER);
     $position = '';
     foreach ($table->getColumns() as $name => $column) {
         if (isset($modifyColumns[$name])) {
             $column['AFTER'] = $position;
             switch ($mode) {
                 case 'add':
                     $this->addColumn($table->getName(), $column['COLUMN_NAME'], $column);
                     break;
                 case 'change':
                     $this->changeColumn($table->getName(), $column['COLUMN_NAME'], $column['COLUMN_NAME'], $column);
                     break;
                 default:
                     throw new \InvalidArgumentException('Not implemented in migrateColumn method');
             }
         }
         $position = $column['COLUMN_NAME'];
     }
     return;
 }
 protected function createMemoryTable()
 {
     $this->memoryTable = $this->createTable([['COLUMN_NAME' => 'entity_id', 'DATA_TYPE' => 'int', 'DEFAULT' => null, 'NULLABLE' => false, 'LENGTH' => null, 'SCALE' => null, 'PRECISION' => null, 'UNSIGNED' => true, 'PRIMARY' => true, 'PRIMARY_POSITION' => 0, 'IDENTITY' => false]]);
     return $this->memoryTable->getName();
 }