Skip to content
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

Fixed Mage_Catalog_Model_Product_Status::addSaleableFilterToCollection() does nothing #2603

Merged
merged 7 commits into from
Oct 14, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ protected function _prepareCollection()
->setStore($this->getStore())
->addAttributeToSelect($attributes)
->addAttributeToSelect('sku')
->addAttributeToSelect('gift_message_available')
->addStoreFilter()
->addAttributeToFilter('type_id', array_keys(
Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
))
->addAttributeToSelect('gift_message_available');

Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()
]);

$this->setCollection($collection);
return parent::_prepareCollection();
Expand Down
10 changes: 6 additions & 4 deletions app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ protected function _getCustomers()
protected function _getProducts()
{
if (!$this->_productCollection) {
$this->_productCollection= Mage::getResourceModel('catalog/product_collection');
//$this->_productCollection->getEntity()->setStore($this->_getStore());
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
$this->_productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
$this->_productCollection->addAttributeToSelect('name')
$this->_productCollection
->addAttributeToSelect('name')
->addAttributeToSelect('sku')
->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds()
])
->load();
}
return $this->_productCollection->getItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ protected function _prepareCollection()
->addAttributeToSelect('attribute_set_id')
->addAttributeToFilter('type_id', ['in' => $this->getAllowedSelectionTypes()])
->addFilterByRequiredOptions()
->addStoreFilter();
->addStoreFilter()
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()
]);

if ($products = $this->_getProducts()) {
$collection->addIdFilter($this->_getProducts(), true);
Expand All @@ -80,8 +83,6 @@ protected function _prepareCollection()
$this->setEmptyText($this->__('Please enter search conditions to view products.'));
}

Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);

$this->setCollection($collection);

return parent::_prepareCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ protected function _prepareData()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToSort('position', 'asc')
->addStoreFilter()
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()
])
->addMinimalPrice()

->joinTable('bundle/option', 'parent_id=entity_id', ['option_id' => 'option_id'])
->joinTable('bundle/selection', 'option_id=option_id', ['product_id' => 'product_id'], '{{table}}.product_id='.$this->getProduct()->getId());

Expand All @@ -53,7 +55,6 @@ protected function _prepareData()
$collection->addIdFilter(Mage::getSingleton('checkout/cart')->getProductIds(), true);
}

Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$collection->getSelect()->group('entity_id');

Expand Down
16 changes: 8 additions & 8 deletions app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ class Mage_Catalog_Block_Seo_Sitemap_Product extends Mage_Catalog_Block_Seo_Site
*/
protected function _prepareLayout()
{
$collection = Mage::getModel('catalog/product')->getCollection();
/** @var Mage_Catalog_Model_Resource_Product_Collection $collection */

$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('url_key');
$collection->addStoreFilter();

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addStoreFilter()
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds()
]);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

$this->setCollection($collection);

return $this;
}

Expand Down
7 changes: 4 additions & 3 deletions app/code/core/Mage/Catalog/Model/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ public function prepareProductCollection($collection)
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addPriceData()
->addTaxPercents()
->addUrlRewrite($this->getCurrentCategory()->getId());

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
->addUrlRewrite($this->getCurrentCategory()->getId())
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds()
]);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/CatalogIndex/Model/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function plainReindex($products = null, $attributes = null, $stores = nul
$collection = $this->_getProductCollection($store, $products);
$collection->addAttributeToFilter(
'status',
['in'=>Mage::getModel('catalog/product_status')->getSaleableStatusIds()]
['in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()]
);
$collection->addFieldToFilter('type_id', $type);
$this->_walkCollection($collection, $store, [], $priceAttributeCodes);
Expand Down
8 changes: 5 additions & 3 deletions app/code/core/Mage/CatalogSearch/Model/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ public function prepareProductCollection($collection)
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addTaxPercents()
->addStoreFilter();

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
->addStoreFilter()
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds()
]);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);

return $this;
}
}
7 changes: 4 additions & 3 deletions app/code/core/Mage/CatalogSearch/Model/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public function prepareProductCollection($collection)
->addPriceData()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
->addUrlRewrite()
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds()
]);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);

return $this;
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Checkout/Block/Cart/Crosssell.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ protected function _getCollection()
->getProductCollection()
->setStoreId(Mage::app()->getStore()->getId())
->addStoreFilter()
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()
])
->setPageSize($this->_maxItemCount);
$this->_addProductAttributesAndPrices($collection);

Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);

Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Tag/Block/Product/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ protected function _getProductCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addTagFilter($this->getTag()->getId())
->addStoreFilter(Mage::app()->getStore()->getId())
->addAttributeToFilter('status', [
'in' => Mage::getSingleton('catalog/product_status')->getSaleableStatusIds()
])
->addMinimalPrice()
->addUrlRewrite()
->setActiveFilter();
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection(
$this->_productCollection
);
Expand Down