AutoRelatedProducts - Version 0.0.1

Version Notes

Auto related products first release 0.0.1

Download this release

Release Info

Developer EvoPin
Extension AutoRelatedProducts
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

app/code/community/EvoPin/AutoRelatedProducts/Block/Adminhtml/Catalog/Product/Edit/Tab/Related.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class EvoPin_AutoRelatedProducts_Block_Adminhtml_Catalog_Product_Edit_Tab_Related extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related
3
+ {
4
+ /**
5
+ * Retrieve related products
6
+ *
7
+ * @return array
8
+ */
9
+ public function getSelectedRelatedProducts()
10
+ {
11
+ $_enabled = Mage::getStoreConfig('autorelatedproducts/general/enabled');
12
+ if(!$_enabled)
13
+ return parent::getSelectedRelatedProducts();
14
+
15
+ $_backend_enabled = Mage::getStoreConfig('autorelatedproducts/general/backend_enabled');
16
+ if(!$_backend_enabled)
17
+ return parent::getSelectedRelatedProducts();
18
+
19
+ $products = array();
20
+ foreach (Mage::registry('current_product')->getRelatedProducts() as $product) {
21
+ $products[$product->getId()] = array('position' => $product->getPosition());
22
+ }
23
+
24
+ $product = Mage::registry('current_product');
25
+
26
+ if ($category = Mage::registry('current_category')) {
27
+
28
+ } elseif ($product) {
29
+ $ids = $product->getCategoryIds();
30
+
31
+ if (!empty($ids)) {
32
+ $category = Mage::getModel('catalog/category')->load($ids[0]);
33
+ }
34
+ }
35
+
36
+ if ($category) {
37
+
38
+ $related_products = Mage::getResourceModel('reports/product_collection')
39
+ ->addAttributeToFilter('visibility', array(
40
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
41
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
42
+ ))
43
+ ->addAttributeToFilter('status', 1)
44
+ ->addCategoryFilter($category)
45
+ ->addAttributeToSelect('*');
46
+
47
+ if ($product) {
48
+ $related_products->addAttributeToFilter('entity_id', array(
49
+ 'neq' => Mage::registry('current_product')->getId())
50
+ );
51
+ }
52
+
53
+ Mage::getModel('cataloginventory/stock')->addInStockFilterToCollection($related_products);
54
+
55
+ $related_products_ids = array();
56
+ foreach ($related_products as $product) {
57
+ $related_products_ids[$product->getId()] = array('position' => $product->getPosition());
58
+ }
59
+
60
+ return $products + $related_products_ids;
61
+
62
+ } else {
63
+ return $products;
64
+ }
65
+
66
+ }
67
+
68
+ }
app/code/community/EvoPin/AutoRelatedProducts/Block/Related.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class EvoPin_AutoRelatedProducts_Block_Related extends Mage_Catalog_Block_Product_List_Related
4
+ {
5
+ protected function _construct() {
6
+ // Only cache if we have something thats keyable..
7
+ $_time = (int)Mage::getStoreConfig('autorelatedproducts/general/cache_lifetime');
8
+ if($_time > 0 && $cacheKey = $this->_cacheKey()) {
9
+ $this->addData(array(
10
+ 'cache_lifetime' => $_time,
11
+ 'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG),
12
+ 'cache_key' => $cacheKey,
13
+ ));
14
+ }
15
+ }
16
+
17
+ protected function _cacheKey(){
18
+ $product = Mage::registry('current_product');
19
+ if($product) {
20
+ return get_class() . '::' . Mage::app()->getStore()->getCode() . '::' . $product->getId();
21
+ }
22
+
23
+ return false;
24
+ }
25
+
26
+ protected function _prepareData (){
27
+ parent::_prepareData();
28
+
29
+ $_enabled = Mage::getStoreConfig('autorelatedproducts/general/enabled');
30
+ if ($_enabled && count($this->getItems()) == 0){
31
+ $_products = Mage::getModel('autorelatedproducts/collection')->getRelatedProducts();
32
+ if ($_products){
33
+ $this->_itemCollection = $_products;
34
+ }
35
+ }
36
+
37
+ return $this;
38
+ }
39
+ }
app/code/community/EvoPin/AutoRelatedProducts/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class EvoPin_AutoRelatedProducts_Helper_Data extends Mage_Catalog_Helper_Product
4
+ {
5
+
6
+ }
app/code/community/EvoPin/AutoRelatedProducts/Model/Collection.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class EvoPin_AutoRelatedProducts_Model_Collection extends Mage_Core_Model_Abstract
4
+ {
5
+ public function getRelatedProducts($limit = false) {
6
+ $products = $this->getData('related_products');
7
+ if (!$products) {
8
+ $product = Mage::registry('current_product');
9
+
10
+ if ($category = Mage::registry('current_category')) {
11
+
12
+ } elseif ($product) {
13
+ $ids = $product->getCategoryIds();
14
+
15
+ if (!empty($ids)) {
16
+ $category = Mage::getModel('catalog/category')->load($ids[0]);
17
+ }
18
+ }
19
+
20
+ if ($category) {
21
+ if ($limit === false) {
22
+ $limit = Mage::getStoreConfig('autorelatedproducts/general/limit');
23
+ }
24
+
25
+ $products = Mage::getResourceModel('reports/product_collection')
26
+ ->addAttributeToFilter('visibility', array(
27
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
28
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
29
+ ))
30
+ ->addAttributeToFilter('status', 1)
31
+ ->addCategoryFilter($category)
32
+ ->addAttributeToSelect('*')
33
+ ->setPageSize($limit);
34
+
35
+ if ($product) {
36
+ $products->addAttributeToFilter('entity_id', array(
37
+ 'neq' => Mage::registry('current_product')->getId())
38
+ );
39
+ }
40
+
41
+ $products->getSelect()->order(new Zend_Db_Expr('RAND()'));
42
+ Mage::getModel('cataloginventory/stock')->addInStockFilterToCollection($products);
43
+
44
+ $this->setData('related_products', $products);
45
+ } else {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ return $products;
51
+ }
52
+ }
app/code/community/EvoPin/AutoRelatedProducts/etc/config.xml ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <EvoPin_AutoRelatedProducts>
5
+ <version>0.0.1</version>
6
+ </EvoPin_AutoRelatedProducts>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <autorelatedproducts>
11
+ <class>EvoPin_Autorelatedproducts_Block</class>
12
+ </autorelatedproducts>
13
+ <catalog>
14
+ <rewrite>
15
+ <product_list_related>EvoPin_AutoRelatedProducts_Block_Related</product_list_related>
16
+ </rewrite>
17
+ </catalog>
18
+ <adminhtml>
19
+ <rewrite>
20
+ <catalog_product_edit_tab_related>EvoPin_AutoRelatedProducts_Block_Adminhtml_Catalog_Product_Edit_Tab_Related</catalog_product_edit_tab_related>
21
+ </rewrite>
22
+ </adminhtml>
23
+ </blocks>
24
+ <models>
25
+ <autorelatedproducts>
26
+ <class>EvoPin_AutoRelatedProducts_Model</class>
27
+ </autorelatedproducts>
28
+ </models>
29
+ <helpers>
30
+ <autorelatedproducts>
31
+ <class>EvoPin_AutoRelatedProducts_Helper</class>
32
+ </autorelatedproducts>
33
+ </helpers>
34
+ </global>
35
+ <adminhtml>
36
+ <acl>
37
+ <resources>
38
+ <admin>
39
+ <children>
40
+ <system>
41
+ <children>
42
+ <config>
43
+ <children>
44
+ <autorelatedproducts translate="title" module="autorelatedproducts">
45
+ <title>Related Products</title>
46
+ </autorelatedproducts>
47
+ </children>
48
+ </config>
49
+ </children>
50
+ </system>
51
+ </children>
52
+ </admin>
53
+ </resources>
54
+ </acl>
55
+ </adminhtml>
56
+ <default>
57
+ <autorelatedproducts>
58
+ <general>
59
+ <enabled>1</enabled>
60
+ <backend_enabled>1</backend_enabled>
61
+ <limit>3</limit>
62
+ <cache_lifetime>3600</cache_lifetime>
63
+ </general>
64
+ </autorelatedproducts>
65
+ </default>
66
+ </config>
app/code/community/EvoPin/AutoRelatedProducts/etc/system.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <evopin translate="label">
5
+ <label>EvoPin Extensions</label>
6
+ <sort_order>100</sort_order>
7
+ </evopin>
8
+ </tabs>
9
+ <sections>
10
+ <autorelatedproducts translate="label" module="autorelatedproducts">
11
+ <label>Auto Related Products</label>
12
+ <tab>evopin</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>300</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general translate="label">
20
+ <label>Settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>10</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <enabled translate="label">
28
+ <label>Enable Auto Related Products</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>5</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </enabled>
36
+ <backend_enabled translate="label">
37
+ <label>Enable on the backend</label>
38
+ <frontend_type>select</frontend_type>
39
+ <comment><![CDATA[Show the related products selected on the backend as well]]></comment>
40
+ <source_model>adminhtml/system_config_source_yesno</source_model>
41
+ <sort_order>10</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </backend_enabled>
46
+ <limit translate="label">
47
+ <label>Limit</label>
48
+ <frontend_type>text</frontend_type>
49
+ <validate>validate-digits</validate>
50
+ <comment><![CDATA[Number of related products to show (e.g. 3)]]></comment>
51
+ <sort_order>15</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ </limit>
56
+ <cache_lifetime translate="label">
57
+ <label>Cache Time</label>
58
+ <frontend_type>text</frontend_type>
59
+ <validate>validate-digits</validate>
60
+ <comment><![CDATA[How long to cache the results (seconds)]]></comment>
61
+ <sort_order>20</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ </cache_lifetime>
66
+ </fields>
67
+ </general>
68
+ </groups>
69
+ </autorelatedproducts>
70
+ </sections>
71
+ </config>
app/etc/modules/EvoPin_AutoRelatedProducts.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <EvoPin_AutoRelatedProducts>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </EvoPin_AutoRelatedProducts>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>AutoRelatedProducts</name>
4
+ <version>0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>MIT</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Auto related products first release 0.0.1</summary>
10
+ <description>Auto related products first release 0.0.1</description>
11
+ <notes>Auto related products first release 0.0.1</notes>
12
+ <authors><author><name>EvoPin</name><user>EvoPin</user><email>evopin@gmail.com</email></author></authors>
13
+ <date>2014-03-11</date>
14
+ <time>23:04:03</time>
15
+ <contents><target name="magecommunity"><dir name="EvoPin"><dir name="AutoRelatedProducts"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><file name="Related.php" hash="61575f9b07bb08379c7175c08b2de506"/></dir></dir></dir></dir></dir><file name="Related.php" hash="9d07c40f5efc40c3214c8e317756f72d"/></dir><dir name="Helper"><file name="Data.php" hash="320c5e4b5dd82f2e32331f336932ad1d"/></dir><dir name="Model"><file name="Collection.php" hash="5e48e0131418139e4455417bd3abb342"/></dir><dir name="etc"><file name="config.xml" hash="424bc68c60ce3d0e1f9b715e6e947f8f"/><file name="system.xml" hash="be967f4a5bf7c51ff1554cc25a12d79e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="EvoPin_AutoRelatedProducts.xml" hash="48d56933b5f4e60a310fd57b64a8d20c"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>