Skip to content
Snippets Groups Projects
Commit aa711a7c authored by Valeriy Nayda's avatar Valeriy Nayda
Browse files

MAGETWO-44237: CategoryLinkManagementInterface->getAssignedProducts() does not...

MAGETWO-44237: CategoryLinkManagementInterface->getAssignedProducts() does not work with flat tables
parent 68b427e7
No related merge requests found
...@@ -36,10 +36,10 @@ class CategoryLinkManagement implements \Magento\Catalog\Api\CategoryLinkManagem ...@@ -36,10 +36,10 @@ class CategoryLinkManagement implements \Magento\Catalog\Api\CategoryLinkManagem
public function getAssignedProducts($categoryId) public function getAssignedProducts($categoryId)
{ {
$category = $this->categoryRepository->get($categoryId); $category = $this->categoryRepository->get($categoryId);
$productsPosition = $category->getProductsPosition();
/** @var \Magento\Framework\Data\Collection\AbstractDb $products */ /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $products */
$products = $category->getProductCollection(); $products = $category->getProductCollection();
$products->addFieldToSelect('position');
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface[] $links */ /** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface[] $links */
$links = []; $links = [];
...@@ -49,7 +49,7 @@ class CategoryLinkManagement implements \Magento\Catalog\Api\CategoryLinkManagem ...@@ -49,7 +49,7 @@ class CategoryLinkManagement implements \Magento\Catalog\Api\CategoryLinkManagem
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface $link */ /** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface $link */
$link = $this->productLinkFactory->create(); $link = $this->productLinkFactory->create();
$link->setSku($product->getSku()) $link->setSku($product->getSku())
->setPosition($productsPosition[$productId]) ->setPosition($product->getData('cat_index_position'))
->setCategoryId($category->getId()); ->setCategoryId($category->getId());
$links[] = $link; $links[] = $link;
} }
......
...@@ -671,4 +671,23 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource ...@@ -671,4 +671,23 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource
return $this->getConnection()->fetchCol($select); return $this->getConnection()->fetchCol($select);
} }
/**
* Get positions of associated to category products
*
* @param \Magento\Catalog\Model\Category $category
* @return array
*/
public function getProductsPosition($category)
{
$select = $this->getConnection()->select()->from(
$this->getTable('catalog_category_product'),
['product_id', 'position']
)->where(
'category_id = :category_id'
);
$bind = ['category_id' => (int)$category->getId()];
return $this->getConnection()->fetchPairs($select, $bind);
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment