Пример #1
0
 /**
  * Filter category ids by store
  *
  * @param int[] $ids
  * @param \Magento\Store\Model\Store $store
  * @return int[]
  */
 protected function filterIdsByStore(array $ids, $store)
 {
     $rootId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
     $rootIdExpr = $this->getReadAdapter()->quote((string) $rootId);
     $rootCatIdExpr = $this->getReadAdapter()->quote("{$rootId}/{$store->getRootCategoryId()}");
     $catIdExpr = $this->getReadAdapter()->quote("{$rootId}/{$store->getRootCategoryId()}/%");
     $select = $this->getReadAdapter()->select()->from($this->getTableName('catalog_category_entity'), array('entity_id'))->where("path = {$rootIdExpr} OR path = {$rootCatIdExpr} OR path like {$catIdExpr}")->where('entity_id IN (?)', $ids);
     $resultIds = array();
     foreach ($this->getReadAdapter()->fetchAll($select) as $category) {
         $resultIds[] = $category['entity_id'];
     }
     return $resultIds;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function getRootCategoryId()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getRootCategoryId');
     if (!$pluginInfo) {
         return parent::getRootCategoryId();
     } else {
         return $this->___callPlugins('getRootCategoryId', func_get_args(), $pluginInfo);
     }
 }
Пример #3
0
 /**
  * Get select for all products
  *
  * @param \Magento\Store\Model\Store $store
  * @return \Magento\Framework\DB\Select
  */
 protected function getAllProducts(\Magento\Store\Model\Store $store)
 {
     if (!isset($this->productsSelects[$store->getId()])) {
         $statusAttributeId = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId();
         $visibilityAttributeId = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'visibility')->getId();
         $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
         $linkField = $metadata->getLinkField();
         $select = $this->connection->select()->from(['cp' => $this->getTable('catalog_product_entity')], [])->joinInner(['cpw' => $this->getTable('catalog_product_website')], 'cpw.product_id = cp.entity_id', [])->joinInner(['cpsd' => $this->getTable('catalog_product_entity_int')], 'cpsd.' . $linkField . ' = cp.' . $linkField . ' AND cpsd.store_id = 0' . ' AND cpsd.attribute_id = ' . $statusAttributeId, [])->joinLeft(['cpss' => $this->getTable('catalog_product_entity_int')], 'cpss.' . $linkField . ' = cp.' . $linkField . ' AND cpss.attribute_id = cpsd.attribute_id' . ' AND cpss.store_id = ' . $store->getId(), [])->joinInner(['cpvd' => $this->getTable('catalog_product_entity_int')], 'cpvd.' . $linkField . ' = cp.' . $linkField . ' AND cpvd.store_id = 0' . ' AND cpvd.attribute_id = ' . $visibilityAttributeId, [])->joinLeft(['cpvs' => $this->getTable('catalog_product_entity_int')], 'cpvs.' . $linkField . ' = cp.' . $linkField . ' AND cpvs.attribute_id = cpvd.attribute_id ' . ' AND cpvs.store_id = ' . $store->getId(), [])->joinLeft(['ccp' => $this->getTable('catalog_category_product')], 'ccp.product_id = cp.entity_id', [])->where('cpw.website_id = ?', $store->getWebsiteId())->where($this->connection->getIfNullSql('cpss.value', 'cpsd.value') . ' = ?', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->where($this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)', [\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH])->group('cp.entity_id')->columns(['category_id' => new \Zend_Db_Expr($store->getRootCategoryId()), 'product_id' => 'cp.entity_id', 'position' => new \Zend_Db_Expr($this->connection->getCheckSql('ccp.product_id IS NOT NULL', 'ccp.position', '0')), 'is_parent' => new \Zend_Db_Expr($this->connection->getCheckSql('ccp.product_id IS NOT NULL', '1', '0')), 'store_id' => new \Zend_Db_Expr($store->getId()), 'visibility' => new \Zend_Db_Expr($this->connection->getIfNullSql('cpvs.value', 'cpvd.value'))]);
         $this->productsSelects[$store->getId()] = $select;
     }
     return $this->productsSelects[$store->getId()];
 }
Пример #4
0
 /**
  * Gets the absolute preview URL to a given store's category page.
  * The category is the first one found in the database for the store.
  * The preview url includes "nostodebug=true" parameter.
  *
  * @param Store $store the store to get the url for.
  *
  * @return string the url.
  */
 public function getPreviewUrlCategory(Store $store)
 {
     $rootCatId = (int) $store->getRootCategoryId();
     /** @noinspection PhpUndefinedNamespaceInspection */
     /** @noinspection PhpUndefinedClassInspection */
     /** @var \Magento\Catalog\Model\Resource\Category\Collection $collection */
     $collection = $this->_categoryCollectionFactory->create();
     $collection->addAttributeToFilter('is_active', ['eq' => 1]);
     $collection->addAttributeToFilter('path', ['like' => "1/{$rootCatId}/%"]);
     $collection->setCurPage(1);
     $collection->setPageSize(1);
     $collection->load();
     foreach ($collection->getItems() as $category) {
         /** @var \Magento\Catalog\Model\Category $category */
         $url = $category->getUrl();
         $url = $this->replaceQueryParamsInUrl(array('___store' => $store->getCode()), $url);
         return $this->addNostoDebugParamToUrl($url);
     }
     return '';
 }