Myextensions_Helloworld - Version 1.0

Version Notes

Probably the final version of this extension. :P

Download this release

Release Info

Developer Magento Core Team
Extension Myextensions_Helloworld
Version 1.0
Comparing to
See all releases


Version 1.0

app/code/local/Myextensions/Helloworld/Block/Hi.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Myextensions_Helloworld_Block_Hi extends Mage_Core_Block_Template
3
+ {
4
+ protected function _toHtml()
5
+ {
6
+ return "Hello World";
7
+ }
8
+ }
9
+ ?>
app/code/local/Myextensions/Helloworld/Block/Randomproducts.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Myextensions_Helloworld_Block_Randomproducts extends Mage_Core_Block_Template
3
+ {
4
+ protected function _toHtml()
5
+ {
6
+ $randProdModel = Mage::getModel('Myextensions_Helloworld/Randomproducts');
7
+ $randProducts = $randProdModel->getRandomProducts();
8
+ $html = "<ul>";
9
+ foreach ($randProducts as $product)
10
+ {
11
+ $name = $product->getName();
12
+ $price = number_format($product->getPrice(), 2);
13
+ $imageLink = $this->helper('catalog/image')
14
+ ->init($product, 'thumbnail')->resize(100,100);
15
+ $productLink = $this->helper('catalog/product')->getProductUrl($product);
16
+ $html .= "
17
+ <p>
18
+ <a href='$productLink'><img src='$imageLink' alt='$name'/></a><br/>
19
+ $name <br/>
20
+ $price
21
+ </p>";
22
+ }
23
+ $html .= "<ul>";
24
+ return $html;
25
+ }
26
+ }
27
+ ?>
app/code/local/Myextensions/Helloworld/Model/Randomproducts.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Myextensions_Helloworld_Model_Randomproducts extends Mage_Core_Model_Abstract
3
+ {
4
+ public function getRandomProducts($maxCount = 1)
5
+ {
6
+ $randProducts = array();
7
+ $allProducts = array();
8
+ $productCollection = Mage::getModel('catalog/product')
9
+ ->getCollection()
10
+ ->addAttributeToSelect('*')
11
+ ->getItems();
12
+ foreach ($productCollection as $id => $data)
13
+ {
14
+ $allProducts[] = $data;
15
+ }
16
+ $productIds = array_keys($allProducts);
17
+ $totalProductIds = count($productIds);
18
+ for ($i=0; $i<$maxCount; $i++)
19
+ {
20
+ $randIndex = rand(0,$totalProductIds);
21
+ $randProductId = $productIds[$randIndex];
22
+ $randProducts[] = $allProducts[$randProductId];
23
+ }
24
+ return $randProducts;
25
+ }
26
+ }
27
+ ?>
app/code/local/Myextensions/Helloworld/etc/config.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Myextensions_Helloworld>
6
+ <version>1.0</version>
7
+ </Myextensions_Helloworld>
8
+ </modules>
9
+
10
+ <global>
11
+ <blocks>
12
+ <Myextensions_Helloworld>
13
+ <class>Myextensions_Helloworld_Block</class>
14
+ </Myextensions_Helloworld>
15
+ </blocks>
16
+ <models>
17
+ <Myextensions_Helloworld>
18
+ <class>Myextensions_Helloworld_Model</class>
19
+ </Myextensions_Helloworld>
20
+ </models>
21
+ </global>
22
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Myextensions_Helloworld</name>
4
+ <version>1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/licenses/gpl.html">GPLv3</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The great Hello World extension</summary>
10
+ <description>This extension is able to display the message 'Hello world'. It can also display a random product.</description>
11
+ <notes>Probably the final version of this extension. :P</notes>
12
+ <authors><author><name>Atriya Sen</name><user>auto-converted</user><email>atriya@indusnet.co.in</email></author></authors>
13
+ <date>2010-10-06</date>
14
+ <time>11:51:41</time>
15
+ <contents><target name="magelocal"><dir name="Myextensions"><dir name="Helloworld"><dir name="Block"><file name="Hi.php" hash="e1710d91f27efa7eaed479cd9e18a719"/><file name="Randomproducts.php" hash="b88bbd938390cc9b7f60a25b5a37367f"/></dir><dir name="etc"><file name="config.xml" hash="20fce7ec5bb6532bb80fccf635162d64"/></dir><dir name="Model"><file name="Randomproducts.php" hash="9681f08f9679ab9022b98a39b14d9cbe"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>