AdvertiseRelatedProducts - Version 1.1.2

Version Notes

v1.1.1 - This version has removed some common product code into the community package 1.2.0

v.1.1.2 - Improved performance when no remote results available

Download this release

Release Info

Developer Michael
Extension AdvertiseRelatedProducts
Version 1.1.2
Comparing to
See all releases


Code changes from version 1.1.1 to 1.1.2

app/code/community/Advertise/RelatedProducts/Block/Related.php CHANGED
@@ -108,12 +108,31 @@ class Advertise_RelatedProducts_Block_Related extends Mage_Catalog_Block_Product
108
  // Still haven't got the required number of related products so fill up with random products
109
  $numRandomsToGet = $relatedCount - count($this->_itemCollection);
110
 
111
- // Get random products
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  $randCollection = Mage::getResourceModel('catalog/product_collection');
113
  Mage::getModel('catalog/layer')->prepareProductCollection($randCollection);
114
- $randCollection->getSelect()->order('rand()');
 
115
  $randCollection->addStoreFilter();
116
- $randCollection->setPage(1, $numRandomsToGet);
 
 
117
  // Don't get items we already have
118
  $exclude = $this->_itemCollection->getAllIds();
119
  $toexclude = array();
@@ -131,6 +150,7 @@ class Advertise_RelatedProducts_Block_Related extends Mage_Catalog_Block_Product
131
  $toexclude[] = $item->getProductId();
132
  }
133
  $randCollection->addIdFilter($toexclude, true);
 
134
  foreach($randCollection as $randProduct)
135
  {
136
  $this->_itemCollection->addItem($randProduct);
108
  // Still haven't got the required number of related products so fill up with random products
109
  $numRandomsToGet = $relatedCount - count($this->_itemCollection);
110
 
111
+ // Get a list of 100 random product IDs
112
+ // (To execute SQL query directly: 1. Get the resource model, 2. Retrieve the read connection, 3. Execute the query)
113
+ $resource = Mage::getSingleton('core/resource');
114
+ $readConnection = $resource->getConnection('core_read');
115
+ $query = 'SELECT MAX(entity_id) AS maxid FROM ' . $resource->getTableName('catalog/product');
116
+ $maxid = $readConnection->fetchOne($query);
117
+ if (!$maxid) {
118
+ $maxid = $prodid;
119
+ }
120
+ $randids = array();
121
+ for ($i = 0; $i <= 100; $i++) {
122
+ array_push($randids , rand(1,$maxid));
123
+ }
124
+
125
+ // Select random products
126
+ // DO NOT USE $randCollection->getSelect()->order('rand()');
127
+ // AS VERY INEFFICIENT; TOO LONG FOR LARGE PRODUCT COLLECTIONS
128
  $randCollection = Mage::getResourceModel('catalog/product_collection');
129
  Mage::getModel('catalog/layer')->prepareProductCollection($randCollection);
130
+ // Select from the 100 random IDs
131
+ $randCollection->addIdFilter($randids, false);
132
  $randCollection->addStoreFilter();
133
+ $randCollection->getSelect()->limit($numRandomsToGet);
134
+ //$randCollection->setPage(1, $numRandomsToGet);
135
+
136
  // Don't get items we already have
137
  $exclude = $this->_itemCollection->getAllIds();
138
  $toexclude = array();
150
  $toexclude[] = $item->getProductId();
151
  }
152
  $randCollection->addIdFilter($toexclude, true);
153
+ // Mage::log('RANDOM RELATED ITEM SELECT QUERY:' . $randCollection->getSelect());
154
  foreach($randCollection as $randProduct)
155
  {
156
  $this->_itemCollection->addItem($randProduct);
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AdvertiseRelatedProducts</name>
4
- <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
@@ -10,11 +10,13 @@
10
  <description>With Adverti.se Related Products you get automated dynamic related products.</description>
11
  <notes>v1.1.1 - This version has removed some common product code into the community package 1.2.0&#xD;
12
  &#xD;
 
 
13
  </notes>
14
  <authors><author><name>Michael</name><user>Oxley</user><email>mike@adverti.se</email></author></authors>
15
- <date>2012-10-07</date>
16
- <time>13:21:55</time>
17
- <contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Advertise_RelatedProducts.xml" hash="7d880814a0e0f3db2d70cf18a819df36"/></dir></dir><dir name="code"><dir name="community"><dir name="Advertise"><dir name="RelatedProducts"><dir name="Block"><dir name="Adminhtml"><file name="RelatedProducts.php" hash="bf83e04772f63d840d5240109b7f0ddb"/></dir><file name="Index.php" hash="1a29b9a0cefc7ee40f0c1f4f0d1737a4"/><file name="Related.php" hash="9741ce76d47ebf68935538800f325e7a"/></dir><dir name="Helper"><file name="Data.php" hash="b94a3f896b1dc7ea574bf287e852257a"/></dir><dir name="Model"><file name="Config.php" hash="1c21e575b9a1cff46da1c300a8f967e9"/><dir name="Resource"><file name="Setup.php" hash="27ecf3f264e8617c8d204ffdbd85eaee"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="RelatedProductsController.php" hash="b0f198b978db71f4d33e68830684b46f"/></dir><file name="IndexController.php" hash="b7e7f7cbdf6c7f37aa8f543897be592a"/><file name="RelatedProductsController.php" hash="987796c54d8a94f206862cbcd959b8e7"/></dir><dir name="data"><dir name="relatedproducts_setup"><file name="data-install-1.0.1.php" hash="9c7b575ef4e16e61a6491ae6b3c9f64f"/><file name="data-upgrade-1.0.0-1.0.1.php" hash="ff4c3d76476d9fbabdc5e02b9f3413b1"/></dir></dir><dir name="etc"><file name="config.xml" hash="9ac0c607fc9e0924afa2c01d8bd7d9db"/><file name="system.xml" hash="dfe73d77d21aa76c4eb0d02e95b65c5e"/></dir><dir name="sql"><dir name="relatedproducts_setup"><file name="install-1.0.1.php" hash="8c2149f87b02b37efc2a755705f24a61"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="advertiserelatedproducts.xml" hash="f9ff40283aab0531320ae896e70983d5"/></dir></dir></dir></dir></dir></dir><dir name="."><file name="README-Advertise-Related-Products.txt" hash="1d756ded96e8e8800589148ae6b9c519"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>AdvertiseCommunity</name><channel>community</channel><min>1.2.0</min><max>1.2.9</max></package></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AdvertiseRelatedProducts</name>
4
+ <version>1.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
10
  <description>With Adverti.se Related Products you get automated dynamic related products.</description>
11
  <notes>v1.1.1 - This version has removed some common product code into the community package 1.2.0&#xD;
12
  &#xD;
13
+ v.1.1.2 - Improved performance when no remote results available&#xD;
14
+ &#xD;
15
  </notes>
16
  <authors><author><name>Michael</name><user>Oxley</user><email>mike@adverti.se</email></author></authors>
17
+ <date>2012-11-02</date>
18
+ <time>13:23:53</time>
19
+ <contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Advertise_RelatedProducts.xml" hash="7d880814a0e0f3db2d70cf18a819df36"/></dir></dir><dir name="code"><dir name="community"><dir name="Advertise"><dir name="RelatedProducts"><dir name="Block"><dir name="Adminhtml"><file name="RelatedProducts.php" hash="bf83e04772f63d840d5240109b7f0ddb"/></dir><file name="Index.php" hash="1a29b9a0cefc7ee40f0c1f4f0d1737a4"/><file name="Related.php" hash="e29913838ab2b907c45acee517ff690e"/></dir><dir name="Helper"><file name="Data.php" hash="b94a3f896b1dc7ea574bf287e852257a"/></dir><dir name="Model"><file name="Config.php" hash="1c21e575b9a1cff46da1c300a8f967e9"/><dir name="Resource"><file name="Setup.php" hash="27ecf3f264e8617c8d204ffdbd85eaee"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="RelatedProductsController.php" hash="b0f198b978db71f4d33e68830684b46f"/></dir><file name="IndexController.php" hash="b7e7f7cbdf6c7f37aa8f543897be592a"/><file name="RelatedProductsController.php" hash="987796c54d8a94f206862cbcd959b8e7"/></dir><dir name="data"><dir name="relatedproducts_setup"><file name="data-install-1.0.1.php" hash="9c7b575ef4e16e61a6491ae6b3c9f64f"/><file name="data-upgrade-1.0.0-1.0.1.php" hash="ff4c3d76476d9fbabdc5e02b9f3413b1"/></dir></dir><dir name="etc"><file name="config.xml" hash="9ac0c607fc9e0924afa2c01d8bd7d9db"/><file name="system.xml" hash="dfe73d77d21aa76c4eb0d02e95b65c5e"/></dir><dir name="sql"><dir name="relatedproducts_setup"><file name="install-1.0.1.php" hash="8c2149f87b02b37efc2a755705f24a61"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="advertiserelatedproducts.xml" hash="f9ff40283aab0531320ae896e70983d5"/></dir></dir></dir></dir></dir></dir><dir name="."><file name="README-Advertise-Related-Products.txt" hash="1d756ded96e8e8800589148ae6b9c519"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>AdvertiseCommunity</name><channel>community</channel><min>1.2.0</min><max>1.2.9</max></package></required></dependencies>
22
  </package>