Ooworx_StockSort - Version 0.1.1

Version Notes

Check compatibility : 1.6, 1.7, 1.8

Download this release

Release Info

Developer Ooworx
Extension Ooworx_StockSort
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/community/Ooworx/StockSort/Model/Observer.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ Copyright (C) 2015 - Ooworx
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ class Ooworx_StockSort_Model_Observer {
19
+
20
+ public function catalogProductCollectionLoadBefore($observer) {
21
+ // Check is activated
22
+ if (Mage::getStoreConfig('cataloginventory/options/stocksort') == false) {
23
+ return $this;
24
+ }
25
+ $collection = $observer->getCollection();
26
+ // Join inventory table to get product state of stock
27
+ $collection->getSelect()
28
+ ->joinLeft(
29
+ array('_inventory_table' => $collection->getTable('cataloginventory/stock_item')),
30
+ "_inventory_table.product_id = e.entity_id",
31
+ array('is_in_stock', 'manage_stock') // Select attribute for product
32
+ );
33
+ // Create is_outofstock attribute
34
+ $collection->addExpressionAttributeToSelect('is_outofstock', '(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());
35
+ $collection->getSelect()->order('is_outofstock DESC'); // Set to DESC to put at end
36
+ // Make sure on_top is the first order directive
37
+ $order = $collection->getSelect()->getPart('order');
38
+ array_unshift($order, array_pop($order));
39
+ $collection->getSelect()->setPart('order', $order);
40
+ return $this;
41
+ // End
42
+ }
43
+
44
+ }
app/code/community/Ooworx/StockSort/etc/config.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <!-- Ooworx - StockSort - 0.1.1 -->
4
+ <modules>
5
+ <Ooworx_StockSort>
6
+ <version>0.1.1</version>
7
+ </Ooworx_StockSort>
8
+ </modules>
9
+ <!-- GLOBAL -->
10
+ <global>
11
+ <!-- Model -->
12
+ <models>
13
+ <stocksort>
14
+ <class>Ooworx_StockSort_Model</class>
15
+ </stocksort>
16
+ </models>
17
+ </global>
18
+ <!-- FRONTEND -->
19
+ <frontend>
20
+ <events>
21
+ <catalog_product_collection_load_before>
22
+ <observers>
23
+ <stocksort_catalog_product_collection_load_before>
24
+ <type>singleton</type>
25
+ <class>Ooworx_StockSort_Model_Observer</class>
26
+ <method>catalogProductCollectionLoadBefore</method>
27
+ </stocksort_catalog_product_collection_load_before>
28
+ </observers>
29
+ </catalog_product_collection_load_before>
30
+ </events>
31
+ </frontend>
32
+ <!-- DEFAULT -->
33
+ <default>
34
+ <cataloginventory>
35
+ <options>
36
+ <stocksort>1</stocksort>
37
+ </options>
38
+ </cataloginventory>
39
+ </default>
40
+ </config>
app/code/community/Ooworx/StockSort/etc/system.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <cataloginventory translate="label" module="cataloginventory">
5
+ <groups>
6
+ <options translate="label">
7
+ <fields>
8
+ <stocksort translate="label">
9
+ <label>Sort out of stock</label>
10
+ <frontend_type>select</frontend_type>
11
+ <source_model>adminhtml/system_config_source_yesno</source_model>
12
+ <sort_order>4</sort_order>
13
+ <show_in_default>1</show_in_default>
14
+ <show_in_website>1</show_in_website>
15
+ <show_in_store>1</show_in_store>
16
+ <comment>Sort product list with "out of stock" at the end</comment>
17
+ </stocksort>
18
+ </fields>
19
+ </options>
20
+ </groups>
21
+ </cataloginventory>
22
+ </sections>
23
+ </config>
app/etc/modules/Ooworx_StockSort.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Ooworx_StockSort>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Ooworx_StockSort>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Ooworx_StockSort</name>
4
+ <version>0.1.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Sort your product out of stock at the end of search, categories and everywhere in your store.</summary>
10
+ <description>Sort your product out of stock at the end of search, categories and everywhere in your store.</description>
11
+ <notes>Check compatibility : 1.6, 1.7, 1.8</notes>
12
+ <authors><author><name>Ooworx</name><user>ooworx</user><email>support@ooworx.com</email></author></authors>
13
+ <date>2015-09-15</date>
14
+ <time>08:55:45</time>
15
+ <contents><target name="magecommunity"><dir name="Ooworx"><dir name="StockSort"><dir name="Model"><file name="Observer.php" hash="0caef4d871cf3d3b94451d59e7595a14"/></dir><dir name="etc"><file name="config.xml" hash="45e498aa3a0a4b51ce7fc75a55186e55"/><file name="system.xml" hash="9e7984fe3c829d7a4b7c00b6ee053e16"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ooworx_StockSort.xml" hash="9726052585c5279ba743dc9315909165"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Magento_Core_Modules</name><channel>community</channel><min>1.6</min><max>1.9</max></package></required></dependencies>
18
+ </package>