Version Notes
Fast work on stores with a huge quantity of products
Download this release
Release Info
Developer | Kinex |
Extension | Kinex_AutoRelated |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- app/code/community/Kinex/AutoRelated/Block/Related.php +39 -0
- app/code/community/Kinex/AutoRelated/Helper/Data.php +5 -0
- app/code/community/Kinex/AutoRelated/Model/Collection.php +52 -0
- app/code/community/Kinex/AutoRelated/etc/config.xml +61 -0
- app/code/community/Kinex/AutoRelated/etc/system.xml +50 -0
- app/etc/modules/Kinex_AutoRelated.xml +1 -1
- package.xml +3 -3
app/code/community/Kinex/AutoRelated/Block/Related.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Kinex_AutoRelated_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('autorelated/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('autorelated/general/enabled');
|
30 |
+
if ($_enabled && count($this->getItems()) == 0){
|
31 |
+
$_products = Mage::getModel('autorelated/collection')->getRelatedProducts();
|
32 |
+
if ($_products){
|
33 |
+
$this->_itemCollection = $_products;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
return $this;
|
38 |
+
}
|
39 |
+
}
|
app/code/community/Kinex/AutoRelated/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Kinex_AutoRelated_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
5 |
+
|
app/code/community/Kinex/AutoRelated/Model/Collection.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Kinex_AutoRelated_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('autorelated/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/Kinex/AutoRelated/etc/config.xml
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Kinex_AutoRelated>
|
5 |
+
<version>1.0.3</version>
|
6 |
+
</Kinex_AutoRelated>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<blocks>
|
10 |
+
<autorelated>
|
11 |
+
<class>Kinex_AutoRelatedproducts_Block</class>
|
12 |
+
</autorelated>
|
13 |
+
<catalog>
|
14 |
+
<rewrite>
|
15 |
+
<product_list_related>Kinex_AutoRelated_Block_Related</product_list_related>
|
16 |
+
</rewrite>
|
17 |
+
</catalog>
|
18 |
+
</blocks>
|
19 |
+
<models>
|
20 |
+
<autorelated>
|
21 |
+
<class>Kinex_AutoRelated_Model</class>
|
22 |
+
</autorelated>
|
23 |
+
</models>
|
24 |
+
|
25 |
+
<helpers>
|
26 |
+
<autorelated>
|
27 |
+
<class>Kinex_AutoRelated_Helper</class>
|
28 |
+
</autorelated>
|
29 |
+
</helpers>
|
30 |
+
</global>
|
31 |
+
<adminhtml>
|
32 |
+
<acl>
|
33 |
+
<resources>
|
34 |
+
<admin>
|
35 |
+
<children>
|
36 |
+
<system>
|
37 |
+
<children>
|
38 |
+
<config>
|
39 |
+
<children>
|
40 |
+
<autorelated translate="title" module="autorelated">
|
41 |
+
<title>Related Products</title>
|
42 |
+
</autorelated>
|
43 |
+
</children>
|
44 |
+
</config>
|
45 |
+
</children>
|
46 |
+
</system>
|
47 |
+
</children>
|
48 |
+
</admin>
|
49 |
+
</resources>
|
50 |
+
</acl>
|
51 |
+
</adminhtml>
|
52 |
+
<default>
|
53 |
+
<autorelated>
|
54 |
+
<general>
|
55 |
+
<enabled>1</enabled>
|
56 |
+
<limit>3</limit>
|
57 |
+
<cache_lifetime>3600</cache_lifetime>
|
58 |
+
</general>
|
59 |
+
</autorelated>
|
60 |
+
</default>
|
61 |
+
</config>
|
app/code/community/Kinex/AutoRelated/etc/system.xml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<kinex translate="label">
|
5 |
+
<label>kinex</label>
|
6 |
+
<sort_order>100</sort_order>
|
7 |
+
</kinex>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<autorelated translate="label" module="autorelated">
|
11 |
+
<label>Auto Related Products</label>
|
12 |
+
<tab>kinex</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 |
+
<limit translate="label">
|
37 |
+
<label>Limit</label>
|
38 |
+
<frontend_type>text</frontend_type>
|
39 |
+
<validate>validate-digits</validate>
|
40 |
+
<sort_order>10</sort_order>
|
41 |
+
<show_in_default>1</show_in_default>
|
42 |
+
<show_in_website>1</show_in_website>
|
43 |
+
<show_in_store>1</show_in_store>
|
44 |
+
</limit>
|
45 |
+
</fields>
|
46 |
+
</general>
|
47 |
+
</groups>
|
48 |
+
</autorelated>
|
49 |
+
</sections>
|
50 |
+
</config>
|
app/etc/modules/Kinex_AutoRelated.xml
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
<Kinex_AutoRelated>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
-
<version>1.0.
|
8 |
</Kinex_AutoRelated>
|
9 |
</modules>
|
10 |
</config>
|
4 |
<Kinex_AutoRelated>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
+
<version>1.0.3</version>
|
8 |
</Kinex_AutoRelated>
|
9 |
</modules>
|
10 |
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Kinex_AutoRelated</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -11,8 +11,8 @@
|
|
11 |
<notes>Fast work on stores with a huge quantity of products</notes>
|
12 |
<authors><author><name>Kinex</name><user>kinextoronto</user><email>kinexmedia48@gmail.com</email></author><author><name>harpreet</name><user>harpreet</user><email>harpreetsinghphp@gmail.com</email></author></authors>
|
13 |
<date>2015-10-06</date>
|
14 |
-
<time>
|
15 |
-
<contents><target name="magecommunity"><dir name="Kinex"><
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Kinex_AutoRelated</name>
|
4 |
+
<version>1.0.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
11 |
<notes>Fast work on stores with a huge quantity of products</notes>
|
12 |
<authors><author><name>Kinex</name><user>kinextoronto</user><email>kinexmedia48@gmail.com</email></author><author><name>harpreet</name><user>harpreet</user><email>harpreetsinghphp@gmail.com</email></author></authors>
|
13 |
<date>2015-10-06</date>
|
14 |
+
<time>15:06:38</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Kinex"><dir name="AutoRelated"><dir name="Block"><file name="Related.php" hash="3318c1997981258fcf4376faa69c20aa"/></dir><dir name="Helper"><file name="Data.php" hash="cb207ce44709289d5526ac22908d7b5b"/></dir><dir name="Model"><file name="Collection.php" hash="9118fb8854044f2e10b9db437bddcc39"/></dir><dir name="etc"><file name="config.xml" hash="6e1607e8ed8dcc733db50e38214e12a6"/><file name="system.xml" hash="7c3e6aff64a68b06783384d76c6012d9"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Kinex_AutoRelated.xml" hash="3eae4925bf06f06cc9a2ec79f12c3e54"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|