Thursday, January 30, 2014

The question is i have the table suppose, location_master and the table have colom like ‘postcode’, ‘latitude’, ‘longitude’, ‘county’, ‘region’, ‘town’  and thats all , and i have get or generate the all data about the table in suppose .sql or .csv file format, the fact is when i have the data size above 1 GB then how should i import the large data from that csv or sql file to our mysql database table.

generally all use the import facility which the phpmyadmin provide to us. but thats not full proof that to import all the data from file there can be it stop from the half way and also it takes so much time.
the best way to import the data is to fire the import query like below,
We have to use ‘LOAD DATA INFILE’ query to import the file data,

1) Suppose I have to create one dummy table in my database, like the following,
CREATE TABLE location_master LIKE your_table;
the above query is used to create one dummy table name ‘location_master’ in my db.
2) open your phpmyadmin in your wamp
3) select your database in which you have create table,
4) select your new created dummy table
5) then click on query tab from menubar,
6) write the following query in the textarea of ‘SQL query on database’,
“load data local infile ‘/temp/file.csv’ into table location_master
fields terminated by ‘,’
enclosed by ‘”‘
lines terminated by ‘\n’
(‘postcode’, ‘latitude’, ‘longitude’, ‘county’, ‘region’, ‘town’)”;
note: please remeber the csv file should contain the same colom which your table have.
7) The above technic is simple and also take very less time to import data.

Wednesday, January 22, 2014

Replace the it with the original index.php
as the change affected this.
It changed the original line  Mage::run(’default’);
so replace 

Mage::run(’’); 
with 
Mage::run(’default’);

How to change browser caching on your site

It is done by adding some code to a file called .htaccess on your web host/server.

The code below should be added to the top of your .htaccess file.

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

Save the .htaccess file and then refresh your webpage.

Tuesday, January 21, 2014

Cron in Magento is fairly easy to configure. A few lines in config.xml, a method and it’s done. But what happens if you want to spice it up a bit and create a schedule-configurable cron? Fortunately for us, Magento has that already included in the system and it’s pretty easy to implement.
Cron itself is more or less straightforward. As seen in the code below, it is defined in a config.xml file with two main parts: schedule and a method to be ran. A sample below shows a cron job named “my_cron” that runs “doSomething” method inside the observer file every five minutes. If you’re not familiar with the cron schedule format, there’s a bunch of the articles and cron generators on the internet.
<config>
    <crontab>
        <jobs>
            <my_cron>
                <schedule>
                    <cron_expr>*/5 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>mymodule/observer::doSomething</model>
                </run>
            </my_cron>
        </jobs>
    </crontab>
</config>

The thing about this is that the schedule cannot be configured…yet. Inside the Mage_Cron_Model_Observer class, which generates cron jobs, there’s a “generate” method that also checks for the values inside core_config_data table in the same way as it does for config.xml files. Having that in mind, we could save the path to the cron schedule and set any (valid) value we want. So let’s get to work!

Admin configuration

As we want to have schedule-configurable cron we have to have an admin configuration for that. As you can make it whatever and however you want, I’m not going to do the miracles here but I’ll use what Magento already offers to us.
Inside the system.xml will be time (hour, minute and second) and frequency selectors (daily, weekly and monthly) that already come packed within Magento. All the coding that has to be done is to create our own backend model that will format and save the values to path we want. In this case  it’s will be in the mymodule/adminhtml_system_config_backend_mymodel_cron.
<config>
    <sections>
        <catalog>
            <groups>
                <configurable_cron translate="label">
                    <label>Cron Schedule</label>
                    <sort_order>100</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>0</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                        <time translate="label">
                            <label>Start Time</label>
                            <frontend_type>time</frontend_type>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </time>
                        <frequency translate="label">
                            <label>Frequency</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_cron_frequency</source_model>
                            <backend_model>mymodule/adminhtml_system_config_backend_mymodel_cron</backend_model>
                            <sort_order>20</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </frequency>
                    </fields>
                </configurable_cron>
            </groups>
        </catalog>
    </sections>
</config>

Backend model

The frontend types in the admin configuration don’t save the inputs in the way the cron generator can read them. Because of that we have to have a backend model that fill format those inputs the way we want.
From the sample code above on how the regular cron job is set in the config.xml, the same paths should be used in the core_config_data table that we’re going to deal with. From the code above, the path to our schedule would be “crontab/jobs/my_cron/schedule/cron_expr”. The code below formats the inputs and saves the value to the table.
class Inchoo_MyModule_Model_Adminhtml_System_Config_Backend_MyModel_Cron extends Mage_Core_Model_Config_Data
{
    const CRON_STRING_PATH = ‘crontab/jobs/my_cron/schedule/cron_expr';
    protected function _afterSave()
    {
        $time = $this->getData('groups/configurable_cron/fields/time/value');
        $frequencyDaily = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_DAILY;
        $frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
        $frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
        $cronDayOfWeek = date('N');
        $cronExprArray = array(
            intval($time[1]),                                   # Minute
            intval($time[0]),                                   # Hour
            (frequency == $frequencyMonthly) ? '1' : '*',       # Day of the Month
            '*',                                                # Month of the Year
            (frequency == $frequencyWeekly) ? '1' : '*',        # Day of the Week
        );
        $cronExprString = join(' ', $cronExprArray);
        try {
            Mage::getModel('core/config_data')
                ->load(self::CRON_STRING_PATH, 'path')
                ->setValue($cronExprString)
                ->setPath(self::CRON_STRING_PATH)
                ->save();
        }
        catch (Exception $e) {
            throw new Exception(Mage::helper('cron')->__('Unable to save the cron expression.'));
        }
    }
}
Cron generator goes through the cron jobs and takes only the ones with the schedule defined. To have the schedule read from the config table, the schedule node has to be removed from the config.xml and only have the model defined, as shown below.
<config>
    <crontab>
        <jobs>
            <my_cron>
                <run>
                    <model>mymodule/observer::doSomething</model>
                </run>
            </my_cron>
        </jobs>
    </crontab>
</config>

What happens in the background? Cron generator runs through the config.xml files and config table, looks for the cron schedules and populates the cron schedule table. At this point models are irrelevant. All the cron jobs that have no schedule defined will be skipped. Another method, Cron dispatch, reads the cron jobs from the cron schedule table, collects the methods from both config.xml files and the config table and runs them.

Observer

In the observer will be the method that will be ran by the cron. What code comes here is up to you.

class Inchoo_MyModule_Model_Observer
{
    public function doSomething()
    {
    // do something
    }
}

This is just one example of using cron schedules. There’s plenty of room for modifications and improvements depending on your needs after you get the point how this works.
You can add featured products in HOMEPAGE as following.

1. ADD A NEW ATTRIBUTE

Go to Catalog > Manage Attributes and add a new attribute. Enter featured_product as Attribute Code. Change Catalog Input Type to Yes/No. In the left column click on Manage Label / Options and enter something like Featured Product as label. Click the Save button.

Now that we have a new product attribute to mark the featured products, we only need to add it to an attribute set so it actually appears as an option when we edit a product. Go toCatalog / Manage Attribute Sets and edit the attribute sets that you are using for your store. If there is only the default one, edit the default one. The right column is a list of unassigned attributes – drag featured_product into the middle column and place it where it makes sense. Now save the attribute list.

When you edit a product now, you will find a new attribute Featured Product. Edit a couple of products and set it to Yes.



2. CREATE THE TEMPLATE FOR FEATURED PRODUCTS

Your templates directory should be something like

"app > design > frontend > default > yourtheme > template"

yourtheme is the name of your Magento theme. Create a new directory custom inside the template folder. Inside this directory create a new file featured.phtml and copy the following code:



<div id="home-featured">
<div class="page-title featured-title">
        <h3><?php echo $this->__('Featured products') ?></h3>
    </div>

<?php
// some helpers
$_helper = $this->helper('catalog/output');
$storeId = Mage::app()->getStore()->getId();
$catalog = $this->getLayout()->createBlock('catalog/product_list')->setStoreId($storeId);

// get all products that are marked as featured
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('featured_product');
$collection->addFieldToFilter(array(
array('attribute' => 'featured_product', 'eq' => true),
));

// if no products are currently featured, display some text
if (!$collection->count()) :
?>

<p class="note-msg"><?php echo $this->__('There are no featured products at the moment.') ?></p>

<?php else : ?>

<div class="category-products">

<?php
$_collectionSize = $collection->count();
$_columnCount = 4;
$i = 0;

foreach ($collection as $_product) :
$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($_product->getId());

?>

    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid">
    <?php endif ?>
        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
            <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
            <?php if($_product->getRatingSummary()): ?>
            <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
            <?php endif; ?>
            <?php echo $this->getPriceHtml($_product, true) ?>
            <div class="actions">
                <?php if($_product->isSaleable()): ?>
                    <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $catalog->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                <?php else: ?>
                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?>
                <ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$catalog->getAddToCompareUrl($_product)): ?>
                        <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
                </ul>
            </div>
        </li>
    <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
    </ul>
    <?php endif ?>

<?php endforeach ?>

        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>

</div>

<?php endif ?>

</div>


3. ADD A NEW BLOCK TO THE HOMEPAGE

Now that we have a template for featured products, we need to add this new block to the homepage. Go to CMS > Pages and edit the Homepage. In the left menu go to Design andenter the following into Layout Update XML:


<reference name="content">
<block type="core/template" name="home-featured" template="custom/featured.phtml"/>
</reference>