Friday 24 June 2011

Fixing Magento Catalog Price Rules Issue

To solve this issue, edit Cron.php (in the root installation directory).

try {
Mage::getConfig()->init()->loadEventObservers(’crontab’);
Mage::app()->addEventArea(’crontab’);
Mage::dispatchEvent(’default’);
$observ = Mage::getModel(’catalogrule/observer’);
$observ->dailyCatalogUpdate("0 1 * * *");

Moving Magento From One Host To Another

1. take buckup of your database
2. take backup of your files.
3. create new database on your new host
4. save your database and password of your database
5. open local.xml in magento folder on path app\etc change infomation of  previous database with new.

         <connection>
                    <host><![CDATA[localhost]]></host>
                    <username><![CDATA[username]]></username>
                    <password><![CDATA[password]]></password>
                    <dbname><![CDATA[databasename]]></dbname>
                    <active>1</active>
                </connection>
6. upload all your files to you new host.
7. go to you new host database open table `core_config_data` change the value of your old host name with new host name

example:

Before Changing Host

               config_id     scope  scope_id    path                           value
    Edit     Delete     2     default     0     web/unsecure/base_url     http://localhost/oldhost/
    Edit     Delete     3     default     0     web/secure/base_url     http://localhost/oldhost/

After Changing Host

               config_id     scope  scope_id    path                           value
    Edit     Delete     2     default     0     web/unsecure/base_url     http://localhost/newhost/
    Edit     Delete     3     default     0     web/secure/base_url     http://localhost/newhost/

Thursday 23 June 2011

Running Custom SQL Query in Magento.

As i explained previously that magento works on EAV model so, when ever custom sql query has been executed, It must be checked that the result must be combination of one to more tables.
<?php
// fetch read database connection that is used in Mage_Core module
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$read->query("SE...");
$row = $value->fetch();

print_r($row); // As Array

// For Write

// fetch write database connection that is used in Mage_Core module
$write = Mage::getSingleton('core/resource')->getConnection('core_write');

// now $write is an instance of Zend_Db_Adapter_Abstract
$write->query("insert into tablename values ('magento','cool','work')");

?>

Wednesday 22 June 2011

Display All Product Attribute in Mageto Shopping Cart

Open the location given below
note: path can differ according to templete

app\design\frontend\base\default\template\checkout\cart\item\default.phtml


use the Code below in default.phtml.

<?php
     $product = Mage::getModel('catalog/product')->load($this->getProduct()->getId());
    $attributes = $product->getAttributes();
   
    foreach ($attributes as $attribute) {
        if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined()) {
            $value = $attribute->getFrontend()->getValue($product);
            if (strlen($value) && $product->hasData($attribute->getAttributeCode())) {
                $data[$attribute->getAttributeCode()] = array(
                    'label' => $attribute->getFrontend()->getLabel(),
                    'value' => $value //$product->getData($attribute->getAttributeCode())
                );
?>
    <span style="font-weight:bold;"><?php echo $data[$attribute->getAttributeCode()]['label']; ?></span>: <span><?php echo $data[$attribute->getAttributeCode()]['value']; ?></span>
<?php
            }
        }
    }
?>

Magento Methods getModel(), getData()

getModel()

The getModel() function is used to create an instance of a Model class.
For example: $Product = Mage::getModel(’catalog/product’);
this tells magento to create instance of  Mage_Catalog_Model_Product class
Some useful methods include getName, getPrice, getTypeId, getStatus which we can execute like
<?php echo ‘Name: ‘. $Product->getName();?>
<?php echo ‘Price: ‘ . $Product->getPrice();?>
getData()



This function is used to get relevant data from the object instance. Let’s say you want to retrieve the SKU value. You can use some other method for that like getSku() method that needs to be executed on object of Product type or you can:

Example:
$min_sale_qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getData('min_sale_qty');

Change Color of “Availability :In stock” Product Page In Magento

There are different type of view type available in magneto for every type of products in my case i am using default type you can get all view type file at one location path given below.

Note: path and file may vary according to product type

app/design/frontend/base/default/template/catalog/product/view/type/default.phtml

Find the line below:
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>

and change class with inline css as given below

<p style="color:#00ff00"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>

Tuesday 21 June 2011

Magento Single Page Checkout Extension

EasyCheckout is an extension which will convert your checkout page as you see in image you can download it from a link:

https://rapidshare.com/files/341090454/EasyCheckout.zip

Installation steps are given in install.txt file inside zip.

Contact this blog if you have any query...

Display Featured Product Radomly on Magento HomePage


Create new file homepage.phtml and copy content from list.phtml to homepage.phtml, log in to your magento admin go to cms pages click home page
paste step1 to contect area. click save.

strp 1.

{{block type="catalog/product_list"  category_id="93" template="catalog/product/homepage.phtml"}}


now open  hopepage.phtml use the code below to randomly display 4 product at once

step 2.
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
    if ($_productCollection->count()):
    $_productCollection = $_productCollection->getItems();
    shuffle($_productCollection);
    $i = 0;
             foreach ($_productCollection as $_product):
        if ($i < 4):
                             // Product Data With CSS
        endif;
    $i++;
     endforeach;
    endif;

?>

Monday 20 June 2011

Get All Products Reviews On CMS Page In Magento

Create on phtml file in catalog/product/review.phtml, Place the code below in review.phtml
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product)
{
        //var_dump($product);
$storeId    = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($product->getData('entity_id'));
}

Now create CMS Page in mageto backend and call it as shown below in content section of your CMS page

{{block type="core/template" name="review"  template="catalog/product/review.phtml"}}
and you are done just check it http://yoursite/review.html

Speedup Your Magento Site

its possible to make your magento site fast by following steps below

1. first  we need to update .htaccess file on root. this code below activate Gzip compression.

## http://developer.yahoo.com/performance/rules.html#gzip
    
    # Insert filter
    SetOutputFilter DEFLATE
    
    # Netscape 4.x has some problems_
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch bMSIE !no-gzip !gzip-only-text/html
    # Don’t compress images
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    
    # Make sure proxies don’t deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
    
    # enable resulting html compression
    php_flag zlib.output_compression on

2. secoundly we need to save all products and category as 'FLAT RESOURCE'

    a. go to system->configration->catalog->frontend
    b. Use Flat Catalog Category, Use Flat Catalog Product you will see these 2 option at the end, Select Both to Yes.
    c. reindex all data from Index Management.

Display Magento Available Quantity in DropDown on list.phtml

 <select name="qty">
  <?php $i = 1 ?>
  <?php do { ?>
    <option value="<?php echo $i?>">
      <?php echo $i?>
      <?php $i++ ?>
    </option>
    <?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?>
</select>

Or try this


Set min_sale_qty of a product in backend, go to product inventory tab and find 'Minimum Qty Allowed in Shopping Cart' put desarable quantity there, we have to do this because we have to give equal interval between quantity in dropdow.

note: path can differ according to templete

app\design\frontend\base\default\template\checkout\cart\item\default.phtml

found quantity text box in that file and replace it with code below.

<?php $min_sale_qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getData('min_sale_qty');
    $total_qyt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getQty();
     ?>
    <select name="cart[<?php echo $_item->getId() ?>][qty]">
    <?php for($i = $min_sale_qty; $i <= $total_qyt; $i = $i + $min_sale_qty)
      {
      ?>
    <option value="<?php echo $i?>">
      <?php echo $i?>
    </option>
   <?php }?>
   </select>

Sunday 19 June 2011

Magento Flat Table Option Of Saving Products

Magento stores product data in EAV model i.e. entity attribute value model, This make the magento site slow as in EAV model single table is divided in parts which makes data fetching slow, now in magento 'Magento ver. 1.5.0.1' we have option to save product as Flat resource.

Magento Advance Layer Navigation

Magento Extension to convert magento layerd navigation to ajax layer navigation, download it from the link below, this is free version.
Features:
              1. multiple select filter with ajax layer navigation
              2. SEO link .
              3. Back end Configuration
              4. three option to display price
Installation:
              1. copy app and skin folder and paste it to you magento folder it will ask to overwrite all file select ok, it will not replace your existing file but it will create requried files for AdvLay extension.
              2. remove all cache from var folder.
and you are done with it.

https://rapidshare.com/files/817619639/AdvLay.rar