Magento2: Not in value Category ids product collection issue
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Product collection issue
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
products = $productCollection->addAttributeToSelect('*')
->addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
->setOrder('price', 'ASC')
->load();
magento2 category-products
add a comment |Â
up vote
1
down vote
favorite
Product collection issue
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
products = $productCollection->addAttributeToSelect('*')
->addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
->setOrder('price', 'ASC')
->load();
magento2 category-products
What issue you are facing here?
– aman
1 hour ago
@aman going to php session close function
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Product collection issue
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
products = $productCollection->addAttributeToSelect('*')
->addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
->setOrder('price', 'ASC')
->load();
magento2 category-products
Product collection issue
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
products = $productCollection->addAttributeToSelect('*')
->addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
->setOrder('price', 'ASC')
->load();
magento2 category-products
magento2 category-products
edited 1 hour ago


Amit Bera♦
54k1366157
54k1366157
asked 1 hour ago
Masud Shaikh
7810
7810
What issue you are facing here?
– aman
1 hour ago
@aman going to php session close function
– Masud Shaikh
1 hour ago
add a comment |Â
What issue you are facing here?
– aman
1 hour ago
@aman going to php session close function
– Masud Shaikh
1 hour ago
What issue you are facing here?
– aman
1 hour ago
What issue you are facing here?
– aman
1 hour ago
@aman going to php session close function
– Masud Shaikh
1 hour ago
@aman going to php session close function
– Masud Shaikh
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
To fetch product collection by categories you can try this code:
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$categories = [2,3,5];//category ids array
$collection = $productCollection ->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['nin' => $categories]);
$collection->setPageSize(10)
print_r($collection->getData());
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
1
down vote
First, you to have to check why the parameter is not working
If you check addCategoriesFilter function definition, then you will find it support a parameter which is an array. the parameter is a one-dimensional array which supports index as condition Type and value as filter value.Like
$categoriesFilter =
[
'in' => [10,15],
'nin' => [12,18]
]
So,you have to change
addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
to
addCategoriesFilter(array('nin' => $currentCategoryId))
public function addCategoriesFilter(array $categoriesFilter)
foreach ($categoriesFilter as $conditionType => $values)
$categorySelect = $this->getConnection()->select()->from(
['cat' => $this->getTable('catalog_category_product')],
'cat.product_id'
)->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
$selectCondition = [
$this->mapConditionType($conditionType) => $categorySelect
];
$this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
return $this;
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
To fetch product collection by categories you can try this code:
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$categories = [2,3,5];//category ids array
$collection = $productCollection ->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['nin' => $categories]);
$collection->setPageSize(10)
print_r($collection->getData());
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
3
down vote
accepted
To fetch product collection by categories you can try this code:
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$categories = [2,3,5];//category ids array
$collection = $productCollection ->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['nin' => $categories]);
$collection->setPageSize(10)
print_r($collection->getData());
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
To fetch product collection by categories you can try this code:
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$categories = [2,3,5];//category ids array
$collection = $productCollection ->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['nin' => $categories]);
$collection->setPageSize(10)
print_r($collection->getData());
To fetch product collection by categories you can try this code:
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
$categories = [2,3,5];//category ids array
$collection = $productCollection ->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['nin' => $categories]);
$collection->setPageSize(10)
print_r($collection->getData());
edited 1 hour ago
answered 1 hour ago
aman
55525
55525
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
add a comment |Â
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
I have tried this code got the error message Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 400592896 bytes) in Unknown on line 0
– Masud Shaikh
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Try the updated answer, as I limit the item to 10, seems it is printing lots of data so it went out of memory
– aman
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
Its worked thanks @aman
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
1
down vote
First, you to have to check why the parameter is not working
If you check addCategoriesFilter function definition, then you will find it support a parameter which is an array. the parameter is a one-dimensional array which supports index as condition Type and value as filter value.Like
$categoriesFilter =
[
'in' => [10,15],
'nin' => [12,18]
]
So,you have to change
addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
to
addCategoriesFilter(array('nin' => $currentCategoryId))
public function addCategoriesFilter(array $categoriesFilter)
foreach ($categoriesFilter as $conditionType => $values)
$categorySelect = $this->getConnection()->select()->from(
['cat' => $this->getTable('catalog_category_product')],
'cat.product_id'
)->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
$selectCondition = [
$this->mapConditionType($conditionType) => $categorySelect
];
$this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
return $this;
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
1
down vote
First, you to have to check why the parameter is not working
If you check addCategoriesFilter function definition, then you will find it support a parameter which is an array. the parameter is a one-dimensional array which supports index as condition Type and value as filter value.Like
$categoriesFilter =
[
'in' => [10,15],
'nin' => [12,18]
]
So,you have to change
addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
to
addCategoriesFilter(array('nin' => $currentCategoryId))
public function addCategoriesFilter(array $categoriesFilter)
foreach ($categoriesFilter as $conditionType => $values)
$categorySelect = $this->getConnection()->select()->from(
['cat' => $this->getTable('catalog_category_product')],
'cat.product_id'
)->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
$selectCondition = [
$this->mapConditionType($conditionType) => $categorySelect
];
$this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
return $this;
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
First, you to have to check why the parameter is not working
If you check addCategoriesFilter function definition, then you will find it support a parameter which is an array. the parameter is a one-dimensional array which supports index as condition Type and value as filter value.Like
$categoriesFilter =
[
'in' => [10,15],
'nin' => [12,18]
]
So,you have to change
addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
to
addCategoriesFilter(array('nin' => $currentCategoryId))
public function addCategoriesFilter(array $categoriesFilter)
foreach ($categoriesFilter as $conditionType => $values)
$categorySelect = $this->getConnection()->select()->from(
['cat' => $this->getTable('catalog_category_product')],
'cat.product_id'
)->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
$selectCondition = [
$this->mapConditionType($conditionType) => $categorySelect
];
$this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
return $this;
First, you to have to check why the parameter is not working
If you check addCategoriesFilter function definition, then you will find it support a parameter which is an array. the parameter is a one-dimensional array which supports index as condition Type and value as filter value.Like
$categoriesFilter =
[
'in' => [10,15],
'nin' => [12,18]
]
So,you have to change
addCategoriesFilter('category_id', array(
array('nin' => $currentCategoryId),
))
to
addCategoriesFilter(array('nin' => $currentCategoryId))
public function addCategoriesFilter(array $categoriesFilter)
foreach ($categoriesFilter as $conditionType => $values)
$categorySelect = $this->getConnection()->select()->from(
['cat' => $this->getTable('catalog_category_product')],
'cat.product_id'
)->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
$selectCondition = [
$this->mapConditionType($conditionType) => $categorySelect
];
$this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
return $this;
edited 35 mins ago
answered 1 hour ago


Amit Bera♦
54k1366157
54k1366157
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
add a comment |Â
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
It is worked fine Thanks! @amit
– Masud Shaikh
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242234%2fmagento2-not-in-value-category-ids-product-collection-issue%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What issue you are facing here?
– aman
1 hour ago
@aman going to php session close function
– Masud Shaikh
1 hour ago