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...