How to show top selling products on home page in Megento

May 17, 2010

<?php
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);

$storeId = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel(‘reports/product_collection’)
->addAttributeToSelect(‘*’)
->addOrderedQty()
->addAttributeToFilter(‘visibility’, $visibility)
->setOrder(‘ordered_qty’, ‘desc’);
?>
<?php foreach ($_productCollection as $_product): ?>
<!– show as you want name, image, etc –>
<a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->htmlEscape($_product->getName()) ?>”><?php echo $this->htmlEscape($_product->getName()) ?></a><br />
<?php endforeach ?>


Setup Magento on IIS

May 17, 2010

Step 1: Create a new folder called magento under C:\Inetpub\wwwroot, then copy and put all the files into that folder.

Step 2: Right-click on the newly created magento folder and click on Properties. Then, click on the Security tab. Give full permission to this folder. See below.

Step 3: Please prepare the database now using the .sql file. If you need to change any database configuration settings, please open the C:\Inetpub\wwwroot\magento\app\etc\local.xml file for editing.

Step 4: Using any database editor, please open the database table core_config_data and change two path values

path = web/secure/base_url

value = http://nazmul.asthait.com/magento/

and

path = web/secure/base_url

value = http://nazmul.asthait.com/magento/

In both cases, the value http://nazmul.asthait.com/magento/ should be changed.

Note: You should delete all the files and folders under C:\Inetpub\wwwroot\ magento \var\cache in order to prevent unwanted cache problems.  See below.

Step 5: This is the most important step for running a Magento project under IIS.

Please download ISAPI_Rewrite3_0073_Lite.msi from http://www.helicontech.com/download-isapi_rewrite3.htm

See below.

Install this software.

IIS will be automatically restarted after installation.

Verify if the installation was successful by opening up the IIS Manager. Right-click on Web Sites and select Properties. You should now have a new tab if installation was successful. See the screenshot below for reference.

ISAPI Rewrite filter has been successfully installed, but we are not done yet. Your httpd.conf file should be empty, so we need to put some rewrite rules in it. The following lines are taken from the .htaccess file in the root of your Magento installation (that is, the website’s root folder), and put into the httpd.conf file.

So click on Edit, and then you have got a chance to add the following code.

RewriteEngine on

RewriteBase /magento/

RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]

See the screenshot below for reference.

Now press Apply (top-left corner of the editor).

You’re done configuring the ISAPI Rewrite filter and can now run the Magento project.


How to add FCKeditor in Symfony

March 10, 2010

1. Download sfWidgetFormTextareaFCKEditor.class.php.docx and save the code inside the doc as sfWidgetFormTextareaFCKEditor.class.php put this file to {Your Project Name}/lib folder.
2. Download FCKEditor (from fckeditor.net) and unpack it to {Your Project Name}/web/js/fckeditor
3. In the “configure()” method of your form class, configure the fields where you want to use FCKEditor:

$this->widgetSchema[‘address’] = new sfWidgetFormTextareaFCKEditor(
array(
‘width’ => 750,
‘height’ => 350,
‘tool’ => ‘Default’, // name of a configured toolbar
‘config’=> ‘fckeditor/fckconfig.js’ // points to web/js/myfckconfig.js
));

4. You can customize the configuration for FCKEditor, found in {Your Project Name}/web/js/ fckeditor/fckconfig.js


JoomlaPack 2.2.1 : Failed Smart algorithm on JoomlapackCUBE

July 13, 2009

I was in a big problem that joomlaPack works well in Local but when it’s uploaded in godaddy hosting server, it’s not working anymore. It shows the following message in the log file:

Failed Smart algorithm on JoomlapackCUBEDomainDBBackup
CUBE :: Error occured in domain ‘PackDB
Could not open \home\content\b\e\u\beulaho\html\tmp/1eaffe96 for append, in DB dump.

I searched in google and found lots of solutions but none of them is working for me.

Then edited the following file
/administrator/components/com_joomlapack/classes/core/utility
/tempfiles.php

So, I just replaced all the DS by ‘//’ in the whole file.

Example, Replace
return $configuration->getTemporaryDirectory().DS.$fileName;
To
return $configuration->getTemporaryDirectory().‘\\’.$fileName;

That’s all. Special thanks to Riz for giving me Idea.


Moving pointer by mouse click on a image using javascript

October 21, 2008

This is a very simple javascript code for moving a pointer (small box) on an image according to mouse click.

Pls click to download


Import .CSV file and convert it to HTML table view

October 21, 2008

By using the following PHP code you can import CSV / Excel CSV and you can create it by yourself or export from any table using phpMyAdmin and finally convert this data to array for viewing HTML table or you can use this data array as input for programming purpose.

Here is the code

<?php
/**
*
* Import .CSV file and convert it to HTML table view
*
* @author Md. Nazmul Basher (nazmul_basher@yahoo.com)
* @Web https://nazmulb.wordpress.com
* @Mobile +8801712994064
*/
?>
<form action=”<?php echo $_SERVER[‘PHP_SELF’];?>” method=”post” enctype=”multipart/form-data” name=”import”>
<label for=”input_import_file”>Location of the CSV file:</label>
<input name=”import_csvfile” id=”import_csvfile” type=”file”>
<input name=”csvsubmit” id=”csvsubmit” value=”Go” type=”submit”>
</form>
<?php
if($_FILES[‘import_csvfile’][‘tmp_name’]){
echo ‘<table width=”100%” border=”1″ cellspacing=”5″ cellpadding=”0″ bordercolor=”#CCCCCC” style=”border-collapse:collapse;”>’;
$handle = fopen($_FILES[‘import_csvfile’][‘tmp_name’], “r”);
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$num = count($data);
echo “<tr>”;
for ($c=0; $c < $num; $c++) {
echo “<td>&nbsp;”.$data[$c].”</td>”.”\n”;
}
echo “</tr>”;
}
fclose($handle);
echo “</table>”;
}
?>

And here is an example .csv file for import:

Pls click to download

After download just unzip the file to get .csv file inside it.

Thanks


Running PHP code from Database

August 12, 2008

First of all create a Database and run/import the following SQL:

CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`contents` text collate latin1_general_ci NOT NULL,
PRIMARY KEY  (`id`)
);

INSERT INTO `test` (`id`, `contents`) VALUES
(1, ‘for($i=1;$i<=10;$i++){echo $i.”<br />”;}’);


And then run the following code:

<?php
/**
*
* Running PHP code from Database
*
* @author      Md. Nazmul Basher (nazmul_basher@yahoo.com)
* @Web         https://nazmulb.wordpress.com
* @Mobile        +8801712994064
*/

class runPHP
{
var $server;
var    $username;
var $password;
var $db;
var $link;

function __construct($server, $username, $password, $db)
{
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->db = $db;
$this->connect();
}

function connect()
{
$this->link = mysql_connect($this->server, $this->username, $this->password);
mysql_select_db($this->db, $this->link);
}

function runPHPfromDB()
{
$query=”select * from test”;
$result = mysql_query($query);
$data = mysql_fetch_array($result);
eval($data[‘contents’]); // Evaluate a string as PHP code
}

function __destruct() {
}

} // End Class

$res = new runPHP(‘localhost’,’root’,”,’test’);
$res->runPHPfromDB();
?>