Skip to content

Instantly share code, notes, and snippets.

@ViniciusAugusto
Created January 5, 2016 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ViniciusAugusto/ed211ab575256014aa04 to your computer and use it in GitHub Desktop.
Save ViniciusAugusto/ed211ab575256014aa04 to your computer and use it in GitHub Desktop.
Sem estoque, por ultimo na listagem de produtos - Magento 1.7.0.0 +
// insira o codigo abaixo para colocar os produtos sem estoque por ultimo na listagem de produtos do magento
// depois de
if ($attribute == 'price' && $storeId != 0) {
//no arquivo app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php se a versão do Magento 1.7.0.0 +
//alteração
$this->getSelect()->joinLeft(
array('_inventory_table'=>$this->getTable('cataloginventory/stock_item')),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock', 'manage_stock')
);
$this->addExpressionAttributeToSelect('on_top',
'(CASE WHEN (((_inventory_table.use_config_manage_stock = 1) AND (_inventory_table.is_in_stock = 1)) OR ((_inventory_table.use_config_manage_stock = 0) AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1))) THEN 1 ELSE 0 END)',
array());
$this->getSelect()->order('on_top DESC');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment