108 private $tableMaintainer;
134 $this->_catalogCategory = $catalogCategory;
147 $this->
_init(
'url_rewrite',
'url_rewrite_id');
158 if ($this->_stores ===
null) {
177 $linkField = $this->getMetadataPool()->getMetadata(CategoryInterface::class)->getLinkField();
178 $identifierFiled = $this->getMetadataPool()->getMetadata(CategoryInterface::class)->getIdentifierField();
185 'entity_type_id' =>
$attribute->getEntityTypeId(),
187 'table' =>
$attribute->getBackend()->getTable(),
194 if (!is_array($categoryIds)) {
195 $categoryIds = [$categoryIds];
198 $attributeTable = $this->_categoryAttributes[
$attributeCode][
'table'];
203 $this->
getTable(
'catalog_category_entity'),
204 [
'value' => $attributeCode,
'entity_id' =>
'entity_id']
211 [
't1' =>$this->
getTable(
'catalog_category_entity')],
214 [
'e' => $attributeTable],
215 "t1.{$linkField} = e.{$linkField}",
218 "t1.{$identifierFiled} IN(?)",
221 'e.attribute_id = :attribute_id' 227 $bind[
'attribute_id'] = $this->_categoryAttributes[
$attributeCode][
'attribute_id'];
229 $valueExpr =
$connection->getCheckSql(
't2.value_id > 0',
't2.value',
't1.value');
231 [
't1' => $attributeTable],
232 [$identifierFiled =>
'e.'.$identifierFiled,
'value' => $valueExpr]
234 [
't2' => $attributeTable],
235 "t1.{$linkField} = t2.{$linkField} AND t1.attribute_id = t2.attribute_id AND t2.store_id = :store_id",
238 [
'e' => $this->
getTable(
'catalog_category_entity')],
239 "e.{$linkField} = t1.{$linkField}",
245 't1.attribute_id = :attribute_id' 249 )->group(
'e.entity_id');
251 $bind[
'attribute_id'] = $this->_categoryAttributes[
$attributeCode][
'attribute_id'];
258 foreach ($rowSet as
$row) {
262 foreach ($categoryIds as $categoryId) {
286 'entity_type_id' =>
$attribute->getEntityTypeId(),
288 'table' =>
$attribute->getBackend()->getTable(),
297 $bind = [
'attribute_id' => $this->_productAttributes[
$attributeCode][
'attribute_id']];
299 $attributeTable = $this->_productAttributes[
$attributeCode][
'table'];
303 [
'entity_id',
'value']
305 'attribute_id = :attribute_id' 314 $valueExpr =
$connection->getCheckSql(
't2.value_id > 0',
't2.value',
't1.value');
316 [
't1' => $attributeTable],
317 [
'entity_id',
'value' => $valueExpr]
319 [
't2' => $attributeTable],
320 't1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=:store_id',
326 't1.attribute_id = :attribute_id' 328 't1.entity_id IN(?)',
337 foreach ($rowSet as
$row) {
359 $split = explode(
'/',
$category->getPath());
360 $category->setParentId($split[count($split) - 2]);
375 $rootCategoryIds = [];
378 $rootCategoryIds[
$store->getRootCategoryId()] =
$store->getRootCategoryId();
380 if ($rootCategoryIds) {
413 $meta = $this->getMetadataPool()->getMetadata(CategoryInterface::class);
414 $linkField = $meta->getLinkField();
416 if (!is_array($categoryIds)) {
417 $categoryIds = [$categoryIds];
419 $isActiveExpr =
$connection->getCheckSql(
'c.value_id > 0',
'c.value',
'c.value');
421 [
'main_table' => $this->
getTable(
'catalog_category_entity')],
423 'main_table.entity_id',
424 'main_table.parent_id',
426 'is_active' => $isActiveExpr,
432 if (
$path ===
null) {
433 $select->where(
'main_table.entity_id IN(?)', $categoryIds);
436 if (substr(
$path, -1) !=
'/') {
440 $select->where(
'main_table.path LIKE ?',
$path .
'%')->order(
'main_table.path');
445 "d.attribute_id = :attribute_id AND d.store_id = 0 AND d.{$linkField} = main_table.{$linkField}",
449 "c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.{$linkField} = main_table.{$linkField}",
455 $rootCategoryPathLength = strlen($rootCategoryPath);
457 $bind = [
'attribute_id' => (int)$isActiveAttribute->getId(),
'store_id' => (int)
$storeId];
460 foreach ($rowSet as
$row) {
464 if (substr(
$row[
'path'], 0, $rootCategoryPathLength) != $rootCategoryPath) {
468 if (strlen(
$row[
'path']) > $rootCategoryPathLength &&
$row[
'path'][$rootCategoryPathLength] !=
'/') {
490 foreach (
$attributes as $categoryId => $attributeValue) {
554 $bind = [
'website_id' => (int)
$websiteId,
'entity_id' => (
int)$entityId];
558 [
'e' => $this->
getTable(
'catalog_product_entity')],
561 [
'w' => $this->
getTable(
'catalog_product_website')],
562 'e.entity_id = w.product_id AND w.website_id = :website_id',
565 'e.entity_id > :entity_id' 576 foreach ($rowSet as
$row) {
590 $this->
getTable(
'catalog_category_product'),
591 [
'product_id',
'category_id']
600 $categoryIds[] =
$category[
'category_id'];
667 $storesProducts = [];
674 [
'i' => $this->tableMaintainer->getMainTable(
$storeId)],
675 [
'product_id',
'store_id',
'visibility']
678 'i.product_id = u.entity_id AND i.store_id = u.store_id' 682 [
'r' => $this->
getTable(
'catalog_url_rewrite_product_category')],
683 'u.url_rewrite_id = r.url_rewrite_id AND r.category_id is NULL',
689 $catId = $this->_storeManager->getStore(
$storeId)->getRootCategoryId();
692 $catBind =
'category_id' . $catId;
694 'i.product_id = :' . $productBind,
695 'i.store_id = :' . $storeBind,
696 'i.category_id = :' . $catBind
698 $cond =
'(' . implode(
' AND ', $bindArray) .
')';
701 $bind[$catBind] = $catId;
706 foreach ($rowSet as
$row) {
708 'store_id' =>
$row[
'store_id'],
709 'visibility' =>
$row[
'visibility'],
710 'url_rewrite' =>
$row[
'request_path'],
721 private function getMetadataPool()
723 if (
null === $this->metadataPool) {
getCategory($categoryId, $storeId)
elseif(isset( $params[ 'redirect_parent']))
_getProductAttribute($attributeCode, $productIds, $storeId)
_init($mainTable, $idFieldName)
_prepareStoreRootCategories($stores)
getRewriteByProductStore(array $products)
_getCategories($categoryIds, $storeId=null, $path=null)
_prepareCategoryParentId(\Magento\Framework\DataObject $category)
getCategories($categoryIds, $storeId)
getProduct($productId, $storeId)
_getCategoryAttribute($attributeCode, $categoryIds, $storeId)
getProductsByStore($storeId, &$lastEntityId)
_getProducts($productIds, $storeId, $entityId, &$lastEntityId)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Eav\Model\Config $eavConfig, Product $productResource, \Magento\Catalog\Model\Category $catalogCategory, \Psr\Log\LoggerInterface $logger, $connectionName=null, TableMaintainer $tableMaintainer=null)