-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4802 from magento-epam/EPAM-PR-74
- fixed Category with invalid data loses new products assignment after validation - fixed Catalog product collection filters produce errors and cause inconsistent behavior - fixed Exported customer without modification can not be imported
- Loading branch information
Showing
7 changed files
with
206 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,15 @@ | |
* | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Model\ResourceModel; | ||
|
||
use Magento\Catalog\Model\Indexer\Category\Product\Processor; | ||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\DataObject; | ||
use Magento\Framework\EntityManager\EntityManager; | ||
use Magento\Catalog\Model\Category as CategoryEntity; | ||
use Magento\Catalog\Setup\CategorySetup; | ||
|
||
/** | ||
* Resource model for category entity | ||
|
@@ -92,6 +94,7 @@ class Category extends AbstractResource | |
* @var Processor | ||
*/ | ||
private $indexerProcessor; | ||
|
||
/** | ||
* Category constructor. | ||
* @param \Magento\Eav\Model\Entity\Context $context | ||
|
@@ -275,7 +278,7 @@ protected function _beforeSave(\Magento\Framework\DataObject $object) | |
if ($object->getPosition() === null) { | ||
$object->setPosition($this->_getMaxPosition($object->getPath()) + 1); | ||
} | ||
$path = explode('/', $object->getPath()); | ||
$path = explode('/', (string)$object->getPath()); | ||
$level = count($path) - ($object->getId() ? 1 : 0); | ||
$toUpdateChild = array_diff($path, [$object->getId()]); | ||
|
||
|
@@ -314,7 +317,7 @@ protected function _afterSave(\Magento\Framework\DataObject $object) | |
/** | ||
* Add identifier for new category | ||
*/ | ||
if (substr($object->getPath(), -1) == '/') { | ||
if (substr((string)$object->getPath(), -1) == '/') { | ||
$object->setPath($object->getPath() . $object->getId()); | ||
$this->_savePath($object); | ||
} | ||
|
@@ -352,7 +355,7 @@ protected function _getMaxPosition($path) | |
{ | ||
$connection = $this->getConnection(); | ||
$positionField = $connection->quoteIdentifier('position'); | ||
$level = count(explode('/', $path)); | ||
$level = count(explode('/', (string)$path)); | ||
$bind = ['c_level' => $level, 'c_path' => $path . '/%']; | ||
$select = $connection->select()->from( | ||
$this->getTable('catalog_category_entity'), | ||
|
@@ -717,7 +720,7 @@ public function getCategories($parent, $recursionLevel = 0, $sorted = false, $as | |
*/ | ||
public function getParentCategories($category) | ||
{ | ||
$pathIds = array_reverse(explode(',', $category->getPathInStore())); | ||
$pathIds = array_reverse(explode(',', (string)$category->getPathInStore())); | ||
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categories */ | ||
$categories = $this->_categoryCollectionFactory->create(); | ||
return $categories->setStore( | ||
|
@@ -1134,4 +1137,44 @@ private function getAggregateCount() | |
} | ||
return $this->aggregateCount; | ||
} | ||
|
||
/** | ||
* Get category with children. | ||
* | ||
* @param int $categoryId | ||
* @return array | ||
*/ | ||
public function getCategoryWithChildren(int $categoryId): array | ||
{ | ||
$connection = $this->getConnection(); | ||
|
||
$selectAttributeCode = $connection->select() | ||
->from( | ||
['eav_attribute' => $this->getTable('eav_attribute')], | ||
['attribute_id'] | ||
)->where('entity_type_id = ?', CategorySetup::CATEGORY_ENTITY_TYPE_ID) | ||
->where('attribute_code = ?', 'is_anchor') | ||
->limit(1); | ||
$isAnchorAttributeCode = $connection->fetchOne($selectAttributeCode); | ||
if (empty($isAnchorAttributeCode) || (int)$isAnchorAttributeCode <= 0) { | ||
return []; | ||
} | ||
|
||
$select = $connection->select() | ||
->from( | ||
['cce' => $this->getTable('catalog_category_entity')], | ||
['entity_id', 'parent_id', 'path'] | ||
)->join( | ||
['cce_int' => $this->getTable('catalog_category_entity_int')], | ||
'cce.entity_id = cce_int.entity_id', | ||
['is_anchor' => 'cce_int.value'] | ||
)->where( | ||
'cce_int.attribute_id = ?', | ||
$isAnchorAttributeCode | ||
)->where( | ||
"cce.path LIKE '%/{$categoryId}' OR cce.path LIKE '%/{$categoryId}/%'" | ||
)->order('path'); | ||
|
||
return $connection->fetchAll($select); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.