HTML/JavaScript

Tuesday, July 29, 2014

Import large .sql file into MySQL

C:\> mysql -hlocalhost -uroot -proot

mysql> SHOW VARIABLES LIKE 'wait_timeout';

If this is very low (e.g. 30 seconds) then increase it (e.g. 5 minutes):

mysql> SET SESSION wait_timeout = 300;
mysql> SET SESSION interactive_timeout = 300;

Then execute your SQL file (issue a USE `db` if necessary):
mysql> use TUTORIALS;

mysql> \. database.sql

Friday, July 25, 2014

“The service is unavailable.” Magento admin links

Issue was with some kind of Zend cache! I simply went to magento/lib/Zend/Cache/Backend/File.php and changed the

'cache_dir' => null,

to

'cache_dir' => 'tmp/',

Before doing it, I created folder named tmp under root of my website given IUSR writing permission.

Tuesday, July 8, 2014

Upgrading Magento Via SSH

Once you've accessed your site via SSH, change in to the directory where Magento is installed and run the following commands to upgrade Magento (you should make a backup of your files and database before proceeding):

chmod +x mage
./mage mage-setup .
./mage config-set preferred_state stable
./mage sync
./mage install http://connect20.magentocommerce.com/community Mage_All_Latest --force
php shell/indexer.php reindexall
rm -rf downloader/.cache/ var/cache/


For Magento 1.4.x and earlier, please use the following commands:
chmod +x pear
./pear upgrade-all
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/* var/cache/

If you receive an error, that means the PEAR registry has not been initialized. You need to run the following commands:

chmod 550 pear
./pear mage-setup .
./pear install magento-core/Mage_All_Latest
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/* var/cache/

Friday, May 23, 2014

Associate simple products with configurable products programmatically in Magento

This was an interesting one the other day – we had the simple products created, and we had the configurable products created, but since they’d been created separately, they weren’t associated with each other. Could we come up with a script to do just that? Turns out…yes!

The starting point is a CSV file with two columns – on the left the SKU of the simple product, and on the right the SKU of the configurable product with which it is to be associated. Don’t worry about putting in a header row – really not necessary.

That CSV then gets uploaded to the web root of the site called “skus.csv” (or whatever you want, really). The script which does the magic is nice and simple and looks like this (I’ll run through the salient points further down) :

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$file_handle = fopen("skus.csv", "r");
while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);
    $simpleSku = $line_of_text[0];
    $configurableSku = $line_of_text[1];
    $simpleProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$simpleSku);
    $configurableProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$configurableSku);
    $simpleId = $simpleProduct->getId();
    $ids = $configurableProduct->getTypeInstance()->getUsedProductIds();
    $newids = array();
    foreach ( $ids as $id ) {
        $newids[$id] = 1;
    }
    $newids[$simpleId] = 1;
    echo "Updating configurable product " . $configurableSku;
    echo "<br>";
    Mage::getResourceModel('catalog/product_type_configurable')
->saveProducts($configurableProduct, array_keys($newids));
}
fclose($file_handle);
?>

The first three lines are self-evident enough if you’ve done any programming in Magento. The following lines are where the fun begins :

$file_handle = fopen("skus.csv", "r");
while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);

Let’s open the skus.csv file (or whatever you’ve called it) and then loop through its lines.

    $simpleSku = $line_of_text[0];
    $configurableSku = $line_of_text[1];
    $simpleProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$simpleSku);
    $configurableProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$configurableSku);

Let’s transfer the simple product SKU from the CSV into a variable, and likewise the configurable product SKU. Then let’s use that SKU to load both products into $simpleProduct and $configurableProduct respectively.

    $simpleId = $simpleProduct->getId();

For the simple product, all we need to get is its ID, so let’s squirrel that away in $simpleId.

For the configurable product, it’s a little more tricky. We need to ensure that we add the simple product to its associated products, not replace any existing ones. Since we’re going to be adding an array of simple products (even if that array only has one product in it) the way we do this is to get the existing simple products which are associated with the configurable product, and put them in an array, then add in the new simple product to that array.

    $ids = $configurableProduct->getTypeInstance()->getUsedProductIds();
    $newids = array();
    foreach ( $ids as $id ) {
        $newids[$id] = 1;
    }
    $newids[$simpleId] = 1;

So here we do just that. We load any existing associated products into $ids, then loop through that and transfer them into the $newids array, then add the $simpleId to the end of the $newids array.

Finally let’s have a little output so we know what’s going on :

    echo "Updating configurable product " . $configurableSku;
    echo "<br>";

And then do the actual key part – save the configurable product with the products in the $newids array as its associated simple products.

    Mage::getResourceModel('catalog/product_type_configurable')
->saveProducts($configurableProduct, array_keys($newids));

And that’s pretty much all there is to it. It should run relatively quickly, but if in doubt then run it from the command line to avoid any timeouts. You can download the complete file below, and do shout if you’ve got any questions or suggestions for improvements.

Monday, April 14, 2014

Send Email programmatically using magento

<?php
include "app/Mage.php";
Mage::app();
error_reporting(E_ALL);
ini_set("display_errors", 1);

// The Id you just marked from the transactional email template id
$templateId = 1;

// Define the sender, here we query Magento default email (in the configuration)
// For customer support email, use : 'trans_email/ident_support/...'
$sender = Array('name' => Mage::getStoreConfig('trans_email/ident_general/name'),
                'email' => Mage::getStoreConfig('trans_email/ident_general/email'));

// Set you store
// This information may be taken from the current logged in user
$store = Mage::app()->getStore();

// In this array, you set the variables you use in your template
$vars = Array('my_var' => $my_var,
              'another_var' => 12);

// You don't care about this...       
$translate  = Mage::getSingleton('core/translate');

// Send your email
Mage::getModel('core/email_template')->sendTransactional($templateId,
                                                         $sender,
                                                         'abc@abc.com',
                                                         'Recipient Name',
                                                         $vars,
                                                         $store->getId());

// You don't care as well       
$translate->setTranslateInline(true);
?>

Tuesday, April 8, 2014

Magento – Group by collection in magento


You can try this:

$collection->getSelect()->distinct(true);
But this will retrieve distinct values based on id. If you want to retrieve videos using distinct video values, you should group by “value”.

$collection->getSelect()->group(‘value’);
If you want to debug the query executed :

$collection->getSelect()->__toString();

Hope this helps :)

Magento – Add Export to csv button in form


This code is add button export to csv in form same as  grid page.

public function getElementHtml()
{

$buttonBlock = $this->getForm()->getParent()->getLayout()->createBlock(‘adminhtml/widget_button’);

$params = array(
‘website’ => $buttonBlock->getRequest()->getParam(‘website’)
);

$data = array(
‘label’     => Mage::helper(‘adminhtml’)->__(‘Download sample CSV’),
‘onclick’   => ‘setLocation(\”.Mage::helper(‘adminhtml’)->getUrl(“*/*/exportCsv”, $params) . ‘conditionName/\’ +\’/tablerates.csv\’ )’,
‘class’     => ”,
);
$html = $buttonBlock->setData($data)->toHtml();
return $html;
}

Enjoy.. :D

Monday, April 7, 2014

Magento admin form fields

In this tutorial, i will show you all different magento admin form fields we can use in admin forms.

Magento has many different type of field available by default, so lets take a look the syntax of using each of these fields.

if you wan to to validate fields check my magento validation post.

You can add form fileds in form.php in class like YOURPACKAGE_YOURMODULE_Block_Adminhtml_Form_Edit_Tab_Form inside the _prepareForm() function. All the different type of form fields available in magento are located in folder lib\Varien\Data\Form\Element
Text
01    $fieldset->addField('title', 'text', array(
02              'label'     => Mage::helper('core')->__('This is Text Field'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "alert('on click');",
07              'onchange' => "alert('on change');",
08              'style'   => "border:10px",
09              'value'  => 'hello !!',
10              'disabled' => false,
11              'readonly' => true,
12              'after_element_html' => '<small>Comments</small>',
13              'tabindex' => 1
14            ));


Time
01    $fieldset->addField('time', 'time', array(
02              'label'     => Mage::helper('core')->__('This is Time Field'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "",
07              'onchange' => "",
08              'value'  => '12,04,15',
09              'disabled' => false,
10              'readonly' => false,
11              'after_element_html' => '<small>Comments</small>',
12              'tabindex' => 1
13            ));


Textarea
01    $fieldset->addField('textarea', 'textarea', array(
02              'label'     => Mage::helper('core')->__('This is TextArea Field'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "",
07              'onchange' => "",
08              'value'  => '<b><b/>',
09              'disabled' => false,
10              'readonly' => false,
11              'after_element_html' => '<small>Comments</small>',
12              'tabindex' => 1
13            ));


Submit Button
1    $fieldset->addField('submit', 'submit', array(
2              'label'     => Mage::helper('core')->__('Submit button'),
3              'required'  => true,
4              'value'  => 'Submit',
5              'after_element_html' => '<small>Comments</small>',
6              'tabindex' => 1
7            ));


Dropdown / Selectbox
01    $fieldset->addField('select', 'select', array(
02              'label'     => Mage::helper('core')->__('Select'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "",
07              'onchange' => "",
08              'value'  => '1',
09              'values' => array('-1'=>'Please Select..','1' => 'Option1','2' => 'Option2', '3' => 'Option3'),
10              'disabled' => false,
11              'readonly' => false,
12              'after_element_html' => '<small>Comments</small>',
13              'tabindex' => 1
14            ));



here is another way to add Dropdown or select box
01    $fieldset->addField('select2', 'select', array(
02              'label'     => Mage::helper('core')->__('Select Type2'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "",
07              'onchange' => "",
08              'value'  => '4',
09              'values' => array(
10                                    '-1'=>'Please Select..',
11                                    '1' => array(
12                                                    'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
13                                                    'label' => 'Size'  
14                                               ),
15                                    '2' => array(
16                                                    'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
17                                                    'label' => 'Color' 
18                                               ),                                       
19   
20                               ),
21              'disabled' => false,
22              'readonly' => false,
23              'after_element_html' => '<small>Comments</small>',
24              'tabindex' => 1
25            ));


Radio Button
01    $fieldset->addField('radio', 'radio', array(
02              'label'     => Mage::helper('core')->__('Radio'),
03              'name'      => 'title',
04              'onclick' => "",
05              'onchange' => "",
06              'value'  => '1',
07              'disabled' => false,
08              'readonly' => false,
09              'after_element_html' => '<small>Comments</small>',
10              'tabindex' => 1
11            ));



here is another way to add  radio button
01    $fieldset->addField('radio2', 'radios', array(
02              'label'     => Mage::helper('core')->__('Radios'),
03              'name'      => 'title',
04              'onclick' => "",
05              'onchange' => "",
06              'value'  => '2',
07              'values' => array(
08                                array('value'=>'1','label'=>'Radio1'),
09                                array('value'=>'2','label'=>'Radio2'),
10                                array('value'=>'3','label'=>'Radio3'),
11                           ),
12              'disabled' => false,
13              'readonly' => false,
14              'after_element_html' => '<small>Comments</small>',
15              'tabindex' => 1
16            ));


Password Field
01    $fieldset->addField('password', 'password', array(
02              'label'     => Mage::helper('core')->__('Password'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "",
07              'onchange' => "",
08              'style'   => "",
09              'value'  => 'hello !!',
10              'disabled' => false,
11              'readonly' => false,
12              'after_element_html' => '<small>Comments</small>',
13              'tabindex' => 1
14            ));



another way to add password field
01    $fieldset->addField('obscure', 'obscure', array(
02              'label'     => Mage::helper('core')->__('Obscure'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'obscure',
06              'onclick' => "",
07              'onchange' => "",
08              'style'   => "",
09              'value'  => '123456789',
10              'after_element_html' => '<small>Comments</small>',
11              'tabindex' => 1
12            ));


Note
1    $fieldset->addField('note', 'note', array(
2              'text'     => Mage::helper('core')->__('Text Text'),
3            ));


Multiselect
01    $fieldset->addField('multiselect2', 'multiselect', array(
02              'label'     => Mage::helper('core')->__('Select Type2'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "return false;",
07              'onchange' => "return false;",
08              'value'  => '4',
09              'values' => array(
10                                    '-1'=> array( 'label' => 'Please Select..', 'value' => '-1'),
11                                    '1' => array(
12                                                    'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
13                                                    'label' => 'Size'  
14                                               ),
15                                    '2' => array(
16                                                    'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
17                                                    'label' => 'Color' 
18                                               ),                                       
19   
20                               ),
21              'disabled' => false,
22              'readonly' => false,
23              'after_element_html' => '<small>Comments</small>',
24              'tabindex' => 1
25            ));


Multiline
01    $fieldset->addField('multiline', 'multiline', array(
02              'label'     => Mage::helper('core')->__('Multi Line'),
03              'class'     => 'required-entry',
04              'required'  => true,
05              'name'      => 'title',
06              'onclick' => "",
07              'onchange' => "",
08              'style'   => "border:10px",
09              'value'  => 'hello !!',
10              'disabled' => false,
11              'readonly' => true,
12              'after_element_html' => '<small>Comments</small>',
13              'tabindex' => 1
14            ));


Link
1    $fieldset->addField('link', 'link', array(
2              'label'     => Mage::helper('fore')->__('Link'),
3              'style'   => "",
4              'href' => 'raisereview.com',
5              'value'  => 'RaiseReview by R Vadgama',
6              'after_element_html' => ''
7            ));


Label
1    $fieldset->addField('label', 'label', array(
2              'value'     => Mage::helper('core')->__('Label Text'),
3            ));


Image Upload
1    $fieldset->addField('image', 'image', array(
2              'value'     => 'http://raisereview.com/logo.png',
3            ));


File Upload
1    $fieldset->addField('file', 'file', array(
2              'label'     => Mage::helper('core')->__('Upload'),
3              'value'  => 'Uplaod',
4              'disabled' => false,
5              'readonly' => true,
6              'after_element_html' => '<small>Comments</small>',
7              'tabindex' => 1
8            ));


Date
1    $fieldset->addField('date', 'date', array(
2              'label'     => Mage::helper('core')->__('Date'),
3              'after_element_html' => '<small>Comments</small>',
4              'tabindex' => 1,
5              'image' => $this->getSkinUrl('images/grid-cal.gif'),
6              'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
7            ));


Checkbox
01    $fieldset->addField('checkbox', 'checkbox', array(
02              'label'     => Mage::helper('core')->__('Checkbox'),
03              'name'      => 'Checkbox',
04              'checked' => false,
05              'onclick' => "",
06              'onchange' => "",
07              'value'  => '1',
08              'disabled' => false,
09              'after_element_html' => '<small>Comments</small>',
10              'tabindex' => 1
11            ));



another way to add checkbox
01    $fieldset->addField('checkboxes', 'checkboxes', array(
02              'label'     => Mage::helper('core')->__('Checkboxs'),
03              'name'      => 'Checkbox',
04              'values' => array(
05                                array('value'=>'1','label'=>'Checkbox1'),
06                                array('value'=>'2','label'=>'Checkbox2'),
07                                array('value'=>'3','label'=>'Checkbox3'),
08                           ),
09              'onclick' => "",
10              'onchange' => "",
11              'value'  => '1',
12              'disabled' => false,
13              'after_element_html' => '<small>Comments</small>',
14              'tabindex' => 1
15            ));

Wednesday, March 26, 2014

Replace field by My sql Query

UPDATE your_table
SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/news/')
WHERE your_field LIKE '%articles/updates/%'

Monday, March 24, 2014

How to redirect after login to a particular page which depend upon the page from which login is clicked in magento?

By deafult, when customer/user log in Magento, he/she is redirected to its account page.

But if you’d like to redirect the customer back to the product/page he was visiting before.

Login to Magento Admin.

Go to System -> Configuration -> Customer Configuration -> Login Options.

From the drop-down select "no" and save configuration.

Refresh the cache and try to login.

Hope! you will enjoy.

Get all disabled products programmatically in Magento

Get all disabled products from Magento using product collection:

<?php
set_time_limit(0);
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors",'On');

require_once 'app/Mage.php';
umask(0);
Mage::app('default');

$products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
  ->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::
STATUS_DISABLED);

$products->load();
foreach($products as $product) {
    echo $product->getData('sku')."<br />";
    //var_dump($product->getStatus());
}
?>

Get all disabled products from Magento using Database SQL query:

<?php
set_time_limit(0);
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors",'On');

require_once 'app/Mage.php';
umask(0);
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$conn = Mage::getSingleton('core/resource')->getConnection('core_write');

$catSQL = "SELECT *
FROM `itshot_catalog_product_entity_int`
WHERE `attribute_id` =84  // status=84 (see status id from attributes)
AND `value` =2  // disabled value=2
//AND `entity_id` >30970"; // if you want to show result from range
$categories = $conn->fetchAll($catSQL);
foreach ($categories as $product)
{
    $id = trim($product["entity_id"]);
}
?>

Magento filter collection codes

A collection is a Model type containing other Models, it is basically used in Magento to handle product lists (ie. from a category or a bundle option), but not only. Please use following collection filter code in magento:

How to use multiple database tables in single custom module in Magento

Creating a module which interact with a database table is quite simple. Most of the developers use magento module creator to create such module. But what if you want a module with multiple database tables. Following is the example of module with two database tables.

Step 1. Create setup file of your custom module with following queries.

CREATE TABLE `test` (
`test_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 25 ) NOT NULL
) ENGINE = MYISAM

CREATE TABLE `test2` (
`test2_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 25 ) NOT NULL
) ENGINE = MYISAM

Step 2. Create pool file to register your module under app/etc/modules/Mypackage_Mymodule.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mypackage_Mymodule>
            <active>true</active>
            <codePool>local</codePool>
        </Mypackage_Mymodule>
    </modules>
</config>

Step 3. Your module configuration file should looks like following

app/code/local/ Mypackage/Mymodule/etc/config.xml
   

<?xml version="1.0"?>
<config>
    <modules>
        <Mypackage_Mymodule>
            <version>0.1.0</version>
        </Mypackage_Mymodule>
    </modules>
    <global>
        <models>
            <Mymodule>
                <class>Mypackage_Mymodule_Model</class>
                <resourceModel>mymodule_mysql4</resourceModel>
            </mymodule>
           
            <!-- model vs db table relation -->
            <mymodule_mysql4>
                <class>Mypackage_Mymodule_Model_Mysql4</class>
                <!-- db table with name test -->
                <entities>
                    <test>
                        <table>test</table>
                    </test>
             <test2>
                        <table>test2</table>
                    </test2>

                </entities>
            </mymodule_mysql4>
        </models>
        <resources>
            <mymodule_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mymodule_write>
            <mymodule_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mymodule_read>
        </resources>
    </global>
</config>

Step 4. Now create models Test.php and Test2.php. Here we configure these model with the handler of table test and test2.

/app/code/local/Mypackage/Mymodule/Model/Test.php

<?php

class Mypackage_ Mymodule_Model_Test extends Mage_Core_Model_Abstract
{
   
    public function _construct()
    {
        parent::_construct();
        $this->_init('mymodule/test');
    }
}

/app/code/local/Mypackage/Mymodule/Model/Test2.php

<?php

class Mypackage_Mymodule_Model_Test2 extends Mage_Core_Model_Abstract
{
   
   public function _construct()
    {
        parent::_construct();
        $this->_init('mymodule/test2');
    }
}

Step 5. Now create the resource models for model test and test2. In these files we also set the primary key of both the tables test and test2.

/app/code/local/Mypackage/Mmodule/Model/Mysql4/Test.php

<?php

class Mypackage_Mymodule_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {   
        $this->_init('mymodule/test', 'test_id');
    }
}

/app/code/local/Mypackage/Mmodule/Model/Mysql4/Test2.php.

<?php

class Mypackage_Mymodule_Model_Mysql4_Test2 extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {   
        $this->_init('mymodule/test2', 'test2_id');
    }
}

Step 6. Create a collection classes so that we can retrieve data from table test and test2.

/local/Mypackage/Mymodule/Model/Mysql4/Test/Collection.php

<?php

class Mypackage_Mymodule_Model_Mysql4_Test_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('mymodule/test');
    }
}

/local/Mypackage/Mymodule/Model/Mysql4/Test2/Collection.php

<?php

class Mypackage_Mymodule_Model_Mysql4_Test2_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('mymodule/test2');
    }
}

So, now you have a custom module with two tables. Your module can interact with these tables with their models and respective collections as follows :


$testModel = Mage::getModel('mymodule/test')
    ->setName("abcd")
    ->save();

$test2Model = Mage::getModel('mymodule/test2')
    ->setName("abcd")
    ->save();

Hope this will help you.

How to select the images as base image thumbnail image in bulk?

UPDATE catalog_product_entity_media_gallery AS mg,
       catalog_product_entity_media_gallery_value AS mgv,
       catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (85,86,87)
AND mgv.position = 1;


where 85,86 and 87 attribute id for base image, thumbnail and small image.

Error - There was a problem with reindexing process (Product flat data) indexes

If re-indexing the Product flat data index gives an unknown re-indexing error or "Some problem with re-indexing process" error message or the re-indexing of Product flat data index is never completed, then it is most likely due to references to products that have been deleted or no longer exist.

You could try truncating those catalog_product_flat_* tables. Backup your database and then via MySQL console, phpMyAdmin or other MySQL client run the following:

truncate table ´catalog_product_flat_1´;
truncate table ´catalog_product_flat_2´;
truncate table ´catalog_product_flat_3´;



Do this for all catalog_product_flat_* tables. Then re-index the Product flat data index to rebuild / repopulate those tables.