-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get disable products in product collection in magento2.2 #13411
Comments
Got a solution for the above issue via below trick -
Above process works for me. Hope it helps ... :) |
@developer-vtnetzwelt, thank you for your report. |
Hi @shikhamis11. Thank you for working on this issue.
|
Hi @shikhamis11 @magento-engcom-team |
hi @developer-vtnetzwelt |
@sdzhepa Thank you for verifying the issue. Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:
Once all required information is added, please add label |
@shikhamis11 Thank you for verifying the issue. Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:
Once all required information is added, please add label |
✅ Confirmed by @shikhamis11 Issue Available: @shikhamis11, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself. |
I am working on this at #dmcdindia19 |
Hi @abhi-ranosys. Thank you for working on this issue.
|
The same issue is present in magento 2.3.1 . |
Hi @magento-engcom-team I have get same issure in magento 2.3.1.
print collection sql to log : |
@abhi-ranosys, @developer-vtnetzwelt, @magento-engcom-team I think the issue is inside of the following class: To reproduce -> In admin filter products by Status = Disabled The following function is missing an attribute_id condition: Original: /**
* Add attribute to filter by all stores
*
* @param Attribute $attributeModel
* @param array $condition
* @return void
*/
private function addAttributeToFilterAllStores(Attribute $attributeModel, array $condition)
{
$tableName = $this->getTable($attributeModel->getBackendTable());
$entity = $this->getEntity();
$fKey = 'e.' . $this->getEntityPkName($entity);
$pKey = $tableName . '.' . $this->getEntityPkName($entity);
$condition = "({$pKey} = {$fKey}) AND ("
. $this->_getConditionSql("{$tableName}.value", $condition)
. ')';
$selectExistsInAllStores = $this->getConnection()->select()->from($tableName);
$this->getSelect()->exists($selectExistsInAllStores, $condition);
} SELECT `e`.*, `at_qty`.`qty` FROM `catalog_product_entity` AS `e`
LEFT JOIN `cataloginventory_stock_item` AS `at_qty` ON (at_qty.`product_id`=e.entity_id) AND (at_qty.stock_id=1)
LEFT JOIN `catalog_product_entity_int` AS `status_t1` ON e.row_id=status_t1.row_id AND status_t1.attribute_id='94' AND status_t1.store_id='0'
LEFT JOIN `catalog_product_entity_int` AS `status_t2` ON e.row_id=status_t2.row_id AND status_t2.attribute_id='94' AND status_t2.store_id='0'
WHERE ((EXISTS (SELECT 1 FROM `catalog_product_entity_int` WHERE
((catalog_product_entity_int.row_id = e.row_id) AND (catalog_product_entity_int.value = '2')))))
AND (e.created_in <= '1559361600') AND (e.updated_in > '1559361600') ORDER BY IF(status_t2.value_id > 0, status_t2.value, status_t1.value) ASC
LIMIT 20 Working version: /**
* Add attribute to filter by all stores
*
* @param Attribute $attributeModel
* @param array $condition
* @return void
*/
private function addAttributeToFilterAllStores(Attribute $attributeModel, array $condition)
{
$tableName = $this->getTable($attributeModel->getBackendTable());
$entity = $this->getEntity();
$fKey = 'e.' . $this->getEntityPkName($entity);
$pKey = $tableName . '.' . $this->getEntityPkName($entity);
$condition = "({$pKey} = {$fKey}) AND ("
. $this->_getConditionSql("{$tableName}.value", $condition)
. ' AND '
. "{$tableName}.attribute_id = '{$attributeModel->getId()}'"
. ')';
$selectExistsInAllStores = $this->getConnection()->select()->from($tableName);
$this->getSelect()->exists($selectExistsInAllStores, $condition);
} SELECT `e`.*, `at_qty`.`qty` FROM `catalog_product_entity` AS `e`
LEFT JOIN `cataloginventory_stock_item` AS `at_qty` ON (at_qty.`product_id`=e.entity_id) AND (at_qty.stock_id=1)
LEFT JOIN `catalog_product_entity_int` AS `status_t1` ON e.row_id=status_t1.row_id AND status_t1.attribute_id='94' AND status_t1.store_id='0'
LEFT JOIN `catalog_product_entity_int` AS `status_t2` ON e.row_id=status_t2.row_id AND status_t2.attribute_id='94' AND status_t2.store_id='0'
WHERE ((EXISTS (SELECT 1 FROM `catalog_product_entity_int` WHERE
((catalog_product_entity_int.row_id = e.row_id) AND (catalog_product_entity_int.value = '2' AND catalog_product_entity_int.attribute_id = '94')))))
AND (e.created_in <= '1559361600') AND (e.updated_in > '1559361600') ORDER BY IF(status_t2.value_id > 0, status_t2.value, status_t1.value) ASC
LIMIT 20
|
Hi @developer-vtnetzwelt, @abhi-ranosys. Thank you for your report and collaboration! The related internal Jira ticket But if you still run into this problem please update or provide additional information/steps/preconditions in the Description section and reopen this issue. |
I am trying to get product collection with all enabled/disabled products. It works fine until I upgrade Magento to 2.2.2. Now It's not fetching disabled products in collection.
Preconditions
Magento v2.2.2
Cache enabled
Steps to reproduce
Here is my code that I have applied -
`class Index extends \Magento\Framework\App\Action\Action
{
protected $_productCollectionFactory;
}`
here filter
->addAttributeToFilter('status', array('in'=>array(1,2)))
, I applied after up-gradation.In this I also tried with -
$collection->getSelect()->where('stock_status_index.stock_status IN(1,0)');
But its not making any effect.
Expected result
Actual result
In Admin - Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stock Products-> If I set this to yes then it fetching all 'Enable/Disable' products but I don't want to set this setting to 'Yes'.
Plz help me in this to sort it out, stucked in this problem more than 2 days. Need help. Thank you.
The text was updated successfully, but these errors were encountered: