Friday, 23 November 2012

Using php to display visitor / user information such as their IP address

$ip = $_SERVER['REMOTE_ADDR'];
$hostaddress = gethostbyaddr($ip);
$browser = $_SERVER['HTTP_USER_AGENT'];
$referred = $_SERVER['HTTP_REFERER']; // a quirky spelling mistake that stuck in php

print "Display IP address:
\n";
print "$ip

\n";
print "More detailed host address:
\n";
print "$hostaddress

\n";
print "Display browser info:
\n";
print "$browser

\n";
print "Where you came from (if you clicked on a link to get here:
\n";
if ($referred == "") {
print "Page was directly requested";
}
else {
print "$referred";
}

Most Important Tables in magento are: eav_attribute and eav_entity_type

PRODUCT

                Main Table: catalog_product_entity

                                catalog_product_entity_datetime

 catalog_product_entity_decimal

 catalog_product_entity_gallery

                catalog_product_entity_int

 catalog_product_entity_media_gallery

 catalog_product_entity_media_gallery_value

catalog_product_entity_text

                catalog_product_entity_tier_price

 catalog_product_entity_varchar


CATEGORY

                Main Table: catalog_category_entity

                                catalog_category_entity_datetime

 catalog_category_entity_decimal

 catalog_category_entity_int

 catalog_category_entity_text

 catalog_category_entity_varchar

catalog_category_product



PARTY

                Main Table: customer_entity   and customer_address_entity

                                customer_entity_datetime

 customer_entity_decimal

 customer_entity_int

 customer_entity_text

 customer_entity_varchar

 customer_group

 customer_address_entity_datetime

 customer_address_entity_decimal

 customer_address_entity_int

 customer_address_entity_text

 customer_address_entity_varchar


ORDER

Main Table: sales_flat_order

 sales_flat_order_address

 sales_flat_order_grid

 sales_flat_order_item

 sales_flat_order_payment

 sales_flat_order_status_history

Wednesday, 21 November 2012

my paypal details

my paypal details :

Login : mayank.patel@live.in

Seller Account : mayank_1354093144_biz@live.in / mayank_seller
Buyer Account : mayank_1354092969_per@live.in / mayank_buyer

Clean Magento database

TRUNCATE TABLE `dataflow_batch_export`;
TRUNCATE TABLE `dataflow_batch_import`;
TRUNCATE TABLE `log_customer`;
TRUNCATE TABLE `log_quote`;
TRUNCATE TABLE `log_summary`;
TRUNCATE TABLE `log_summary_type`;
TRUNCATE TABLE `log_url`;
TRUNCATE TABLE `log_url_info`;
TRUNCATE TABLE `log_visitor`;
TRUNCATE TABLE `log_visitor_info`;
TRUNCATE TABLE `log_visitor_online`;
TRUNCATE TABLE `report_viewed_product_index`;
TRUNCATE TABLE `report_compared_product_index`;
TRUNCATE TABLE `report_event`;

magento: insert query for a custom table

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

$sql = 'INSERT INTO tableName (`field1`, `field2`) VALUES (?, ?)';
$bind = array('value1', 'value2');
$connection->query($sql, $bind);
$connection->commit();

Show subcategory in a category page

If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/*theme_name*/template/catalog/category/view.phtml

<?php
$_category  = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper     = Mage::helper('catalog/category');
?>

<ul>
<?foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
<?php
$cur_category = Mage::getModel('catalog/category')->load($cat->getId());
$_img = $cur_category->getImageUrl();
?>
<li>
<a href="<?php echo $helper->getCategoryUrl($cat);?>">
<img src="<?php echo $_img?>" title="$cat->getName()"/>
<cite><?php echo $cat->getName();?></cite>
</a>
</li>
<?php endif?>
<?php endforeach;?>
</ul>

how do i change the price filter attributes price range with text

You can configure step of price ranges via admin panel. Log in into admin panel and go to System->Configuration->Catalog->Catalog->Layered Navigation. There select "Manual" in dropdown Price Navigation Step Calculation and enter prefered value into next input field.

Magento – Show Quantity Box in Products List

Find the following line on list.phtml file

 

<?php if($_product->isSaleable()): ?>
<button onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?<')">>span>
<?php echo $this->__('Add to Cart') ?></span></button>


 

Replace with:

 

<form action="
<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<input name="qty" type="text" id="qty" maxlength="12" value="
<?php echo $this->getMinimalQty($_product) ?>" />
<button" onclick="productAddToCartForm_
<?php echo $_product->getId(); ?>.submit()"><span>
<?php echo $this->__('Add to Cart') ?></span></button>
</form>
<script type="text/javascript">
var productAddToCartForm_
<?php echo $_product->getId(); ?> = new VarienForm('product_addtocart_form_
<?php echo $_product->getId(); ?>');
productAddToCartForm_
<?php echo $_product->getId(); ?>.submit = function(){
if (this.validator.validate()) {
this.form.submit();
}
}.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);
</script>


 

 

Javascript – get Url

window.location.href - get entire url
window.location.protocol - get protocol: "http" / "https"
window.location.host - get hostname, e.g: "www.g31zone.com"
window.location.pathname - get script name, e.g: "example/index.html"

Tuesday, 20 November 2012

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/

Running script out side Magento Folder and Updating Project Database

Place this script 'image.php' out side magento folder and run this with http://yoursite/image.php, this will update all product images if there is no small or thumbnail image.
It will make first image as thumb and small image.

An example to run script out side magento folder.

<?php
require 'app/Mage.php';
Mage::app();

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
if (!$product->hasImage()) continue;
if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
$product->save();
}

Get productID from specific order in Magento



$order = Mage::getModel('sales/order')->load($order_id);

$items = $order->getAllItems();

$itemcount=count($items);

$name=array();

$unitPrice=array();

$sku=array();

$ids=array();

$qty=array();

foreach ($items as $itemId => $item)

{

    $name[] = $item->getName();

    $unitPrice[]=$item->getPrice();

    $sku[]=$item->getSku();

    $ids[]=$item->getProductId();

    $qty[]=$item->getQtyToInvoice();

}


Magento addAttributeToFilter


Get all product collection with the below code:

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');


Add different types of filters  on collection. example shown below

//  Equal To (eq)
$collection->addAttributeToFilter('status', array('eq' => 1));

// Not Equal To (neq)
$collection->addAttributeToFilter('visibility', array('neq' => 1));

// Greater Than (gt)
$collection->addAttributeToFilter('price', array('gt' => 3.99));

// Less Than (lt)
$collection->addAttributeToFilter('price', array('lt' => 3.99));

// Greater Than or Equal To (gteq)
$collection->addAttributeToFilter('price', array('gteq' => 4.99));

// Less Than or Equal To (lteq)
$collection->addAttributeToFilter('price', array('lteq' => 4.99));

// Contains (like) - also uses % wildcards
$collection->addAttributeToFilter('sku', array('like' => 'DVD%'));

// Does Not Contain (nlike) - also uses % wildcards
$collection->addAttributeToFilter('sku', array('nlike' => 'ABC%'));

// In Array (in)
$collection->addAttributeToFilter('id', array('in' => array(1,3,12)));

// Not In Array (nin)
$collection->addAttributeToFilter('id', array('nin' => array(1,2,12)));

// Is NULL (null)
$collection->addAttributeToFilter('description', 'null');

// Is Not NULL (notnull)
$collection->addAttributeToFilter('description', 'notnull');

display product in magento with sql in list.phtml file

Place this following code in your  phtml file where you want to display particular category products this will return array of products and you can use this array to display product of particular category.
$sql = “SELECT product_id  FROM catalog_category_product WHERE category_id=57″;
$data = Mage::getSingleton(‘core/resource’) ->getConnection(‘core_read’)->fetchAll($sql);

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 Image Switcher On MouseOver

Step1. open file on location given below
app/design/frontend/default/default/template/catalog/product/view/media.phtml

 

Step2. Search the code in media.phtml file
<a onclick="popWin('&lt;?php echo $this-&gt;getGalleryUrl($_image) ?&gt;', 'gallery', 'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" href="#"> <!--nested img tag stays the same--></a>

 

Step 3. Replace searched code with code below.
<a title="&lt;?php echo $_product-&gt;getName();?&gt;" onmouseover="$('image').src = this.href; return false;" href="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($this-&gt;getProduct(), 'image', $_image-&gt;getFile()); ?&gt;"> <img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($this-&gt;getProduct(), 'thumbnail', $_image-&gt;getFile())-&gt;resize(56); ?&gt;" alt="&lt;?php echo $this-&gt;htmlEscape($_image-&gt;getLabel()) ?&gt;" width="56" height="56" /></a>

Import/Export Magento Category Extension

Import/Export Magento Category Extension

Magento GooglePlusOne Extension

Magento GooglePlusOne Extension

Magento ajax add to cart extension

Magento ajax add to cart extension

Tuesday, 6 November 2012

Magento create order programatically

Magento create order programatically

Magento export order csv script

Magento export order csv script

php script to change order status

php script to change order status

Magento script to clear cache

clearcache magento script

Sending email from local system in magneto OR Sending email from magento in local system

1) make sure you did setting in php.ini

i'e

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.yourdomine.com
; http://php.net/smtp-port
smtp_port = 25

and in magento go to admin

System->Configuration->System->Mail Sending Setting->host

replace host from localhost to mail.yourdomine.com

Magento redirect url

Mage::app()->getResponse()->setRedirect(Mage::getUrl("checkout/cart/"));

Magento - How to get all Product details in magento Programmatically?

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

function empty_pk($data){
if($data!=''){return $data;}
else {return "&nbsp;";}
}
$collection = Mage::getModel('catalog/product')->getCollection();

echo '<table border="1"> ';
echo '<tr>';
echo "<th>sku<th />";
echo "<th>name<th />";
echo "<th>qty<th />";
echo "<th>is_in_stock<th />";
echo "<th>price<th />";
echo '</tr>';

foreach ($collection as $product_all) {
//echo '<pre>';print_r($product);echo '</pre>';

$sku = $product_all['sku'];
// retrieve product id using sku
$product_id = Mage::getModel('catalog/product')->getIdBySku($sku);
// call product model and create product object
$product    = Mage::getModel('catalog/product');
// Load product using product id
$product ->load($product_id);

$pk_sku = empty_pk($product['sku']);
$pk_name = empty_pk($product['name']);

$stockData = $product->getStockData();

$pk_qty = empty_pk($stockData['qty']);
$pk_in_stock = empty_pk($stockData['is_in_stock']);
$pk_price = empty_pk($product['price']);

echo '<tr>';
echo "<td>".$pk_sku."<td />";
echo "<td>".$pk_name."<td />";
echo "<td>".$pk_qty."<td />";
echo "<td>".$pk_in_stock."<td />";
echo "<td>".$pk_price."<td />";

echo '</tr>';

}
echo '</table>';
?>

Magento - How to get all Magento Database hosting details?

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$resource = Mage::getConfig()->getNode('global/resources')->asArray();

echo '<pre>';

print_r($resource);
echo '</pre>';
$db_host = $resource['default_setup']['connection']['host'];
$db_user = $resource['default_setup']['connection']['username'];
$db_pass = $resource['default_setup']['connection']['password'];
$db_name = $resource['default_setup']['connection']['dbname'];

echo '<br />host : '.$db_host;
echo '<br />username : '.$db_user;
echo '<br />password : '.$db_pass;
echo '<br />dbname : '.$db_name;
?>

Magento - How to get all order details into table format?

<?php
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
//->addFieldToFilter('hpc_order_id', array('neq' => '',))
//->addFieldToFilter('hpc_order_from', array('eq' => 'ebay',)));

//->addFieldToFilter('status', 'complete')->load(); //pending,complete

//$collection->addAttributeToSort('created_at', 'desc');

$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));

/*
echo '<pre>';
print_r($collection);
echo '</pre>';
*/
echo "<br />supplement order start";
echo '<table border="1" style="1px solid #cccccc">';
echo '<tr>';
echo '<th>Order Id</th>';
echo '<th>Order Created at</th>';
echo '<th>Order Updated at</th>';
echo '<th>Order State</th>';
echo '<th>Order Status</th>';
echo '<th>HPC Order ID</th>';
echo '<th>HPC Order from</th>';
echo '</tr>';

foreach ($collection as $col) {
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';

echo "<br />supplement order ends";

Magento - Steps to moving magento from one server to other

Step 1:

clear the /var/cache and /var/session directory which is allow more space to you
then add your magento folder into zip/rar file and extract them on the target server.

Step 2:

once you finished with the copying then you should set the correct permissions for
magento files and folders
as
/var and contents should have permissions “777″
/media and contents should have permissions “777″
/app/etc and contents should have permissions “777″

Step 3:

Now important part is that set the new database connection settings in the
file /app/etc/local.xml
as


<resources>
<db>
<table_prefix><![CDATA[db_prefix]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[db_host]]></host>
<username><![CDATA[db_user]]></username>
<password><![CDATA[db_password]]></password>
<dbname><![CDATA[db_name]]></dbname>
<initstatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdotype><![CDATA[]]></pdoType>
<active>1</active>
</connection>
</default_setup>
</resources>

You need to replace db_prefix db_host db_user db_password etc.. with your values.

Step 4:

Now goto your Database admin panel like phpmyadmin and run the query below


UPDATE core_config_data SET VALUE="http://newhostsite.com/"
WHERE path="web/unsecure/base_url";
UPDATE core_config_data SET VALUE="http://newhostsite.com/"
WHERE path="web/unsecure/base_url";

Where “newhostsite.com” is a new server domain name.

Magento - Store Information

Get store data

Mage::app()->getStore();

Store Id

Mage::app()->getStore()->getStoreId();

Store code

Mage::app()->getStore()->getCode();

Website Id

Mage::app()->getStore()->getWebsiteId();

Store Name

Mage::app()->getStore()->getName();

Is Active

Mage::app()->getStore()->getIsActive();

Store Home Url

Mage::app()->getStore()->getHomeUrl();

Magento - Import Manufacturers

1> Create a file in the root of magento dir: manufacturer_import.php

2> Write the following code there:

 

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$_manufacturers = file('manufacturers.txt');
$_attribute =  Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'manufacturer');
$manufacturers = array('value' => array(), 'order' => array(), 'delete' => array());
$i = 0;
foreach($_manufacturers as $_manufacturer){
$i++;
$manufacturers['value']['option_' . $i] = array($_manufacturer);
}
$_attribute->setOption($manufacturers);
try{
$_attribute->save();
echo 'Manufacturer successfully imported';
}catch(Exception $e){
echo 'Import Error::'.$e->getMessage();
}
?>

 
3> Note i have used manufacturers.txt in the root dir with the values of manufacturers in newline format. For example:



Dell
Toshiba
Sony
Fujitsu



Magento Set, Retrieve and Unset Session Variables

To set a Magento session variable:

$myValue = 'Hello World';
Mage::getSingleton('core/session')->setMyValue($myValue);

To Retrieve:

$myValue = '';
$myValue=Mage::getSingleton('core/session')->getMyValue();

To Unset:

Mage::getSingleton('core/session')->unsMyValue();

Note that ‘MyValue’ can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.

How to add product programmatically in magento 1.7.0 with image and custom field

Magento add product script

Magento script to make is anchor yes to all categories.

isanchoryesIs anchor yes to all categories in magento

Monday, 5 November 2012

Magento important tables

sales_flat_quote -> magento cart master table.
sales_flat_order -> magento order master table.
eav_attribute -> magento attribute master table.
catalog_product_entity -> product master table.
catalog_product_entity_varchar -> product master table values.
catalog_category_entity -> category master table.
catalog_category_entity_varchar -> category master table values.
core_resource -> plugin table.
newsletter_subscriber -> newsletter subscriber master table.
review -> review master table.
review_detail -> review detail table.
customer_entity -> customer main table
wishlist -> wishlist main table.
admin_user -> admin user master table.
cms_block -> cms block master table.
cms_page -> cms page master table.

Saturday, 3 November 2012

Magento: How to delete test orders in magento


  1. Login to Admin Panel and go to Sales-->Orders.

  2. Note down your test order ids, for example: 100000001,100000002,100000003,100000111,100000112,100000199

  3. Now create a php file in magento root directory and name it: deleteOrders.php

  4. Now copy below code and paste it in your file:
    <?php

    require 'app/Mage.php';
    Mage::app('admin')->setUseSessionInUrl(false);                                                                                                                 //replace your own orders numbers here:
    $test_order_ids=array(
    '100000001',
    '100000002',
    '100000003',
    '100000109',
    '100000112',
    '100000134'
    );
    foreach($test_order_ids as $id){
    try{
    Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
    echo "order #".$id." is removed".PHP_EOL;
    }catch(Exception $e){
    echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
    }
    }
    echo "complete."

     ?>



  5. Now go to your browsers address bar and run file from here like:
    [Your_Magento_Base_URL] /deleteOrders.php

  6. At the end, delete deleteOrders.php.

    That's All.. Cheers :)

How to change the Magento Admin Panel Title?

If you want to change default title of Magento Admin, there is an easy solution:
Just open the main.xml file, which is located in app/design/adminhtml/default/default/layout folder.

Find line like below:

<action method="setTitle" translate="title"><title>Magento Admin</title></action>

 and replace the words Magento Admin with the words you like to be in default title.

Hide Attributes which have no value in Magento

Open attribute.phtml, which is located in app/design/frontend/[your package]/[your theme]/template/catalog/product/view folder, and find code like this:

 

<?php foreach ($_additional as $_data): ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>


Now replace this by:



<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != ")) { ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>

Magento: How to view Magento version

Create file versionTest.php parallel to index.php in root folder.
Now copy and paste following code in versionTest.php:
<?php
include_once(‘App/Mage.php’);
Mage::app();
echo Mage::getVersion();
?>

Magento - Reset the admin password

UPDATE admin_user SET password=CONCAT(MD5('admin123')) WHERE username='admin';

Script for to remove the cache - Magento

 <?php require_once ("app/Mage.php"); umask(0); Mage::run(); Mage::app()->getCache()->clean(); exit("done"); ?> 



can call that file with :http://yourdomainname/cache-clear.php


Magento Add Free Shipping promotions to the sidebar my cart block

app/design/frontend/base/default/template/checkout/cart/sidebar.phtml

 

 

replace the following code :

 

 
        <!--The section we want is around line 48-->
<p>
<?php if ($this->canApplyMsrp()): ?>
<span><?php echo $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?></span>
<?php else: ?>
<span><?php echo $this->__('Cart Subtotal:') ?></span> <?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
<?php if ($_subtotalInclTax = $this->getSubtotalInclTax()): ?>
<br />(<?php echo Mage::helper('checkout')->formatPrice($_subtotalInclTax) ?> <?php echo Mage::helper('tax')->getIncExcText(true) ?>)
<?php endif; ?>
<?php endif; ?>
</p>
</div>
<?php endif ?>
<!--Here is our conditional statement, if more that $60 in cart, then $free_delivery is less than zero, and first message gets displayed -->
<?php $free_delivery=60-$this->getSubtotal();?>
<?php if ($free_delivery<0): ?>
<br /><p><b>Free UPS Ground delivery with this order!</b></p>
<!--Here is the second part, if less that $60 in cart, then $free_delivery message displays a teaser to add more stuff to cart-->
<?php else: ?>
<br /><p>Free UPS Ground delivery when spending $60 or more!
<!--Here is where the amount they need to spend is displayed-->
<br><b>Spend another <?php echo Mage::helper('checkout')->formatPrice($free_delivery) ?> to get free delivery with this order!</b></p>
<?php endif ?>
<?php if($_cartQty && $this->isPossibleOnepageCheckout()): ?>

Thursday, 1 November 2012

Customizing Onepage Checkout - Remove login

removelogin_oncheckout

Billing same as Shipping Address / Remove Billing Options

removeshippingsteps

 

bilingshipping

Show subcategory in a category page

If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/*theme_name*/template/catalog/category/view.phtml

<?php
$_category  = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper     = Mage::helper('catalog/category');
?>

<ul>
<?foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
<?php
$cur_category = Mage::getModel('catalog/category')->load($cat->getId());
$_img = $cur_category->getImageUrl();
?>
<li>
<a href="<?php echo $helper->getCategoryUrl($cat);?>">
<img src="<?php echo $_img?>" title="$cat->getName()"/>
<cite><?php echo $cat->getName();?></cite>
</a>
</li>
<?php endif?>
<?php endforeach;?>
</ul>

Delete all product from cart

I have add a function in the app\code\core\Mage\Checkout\controllers\CartController.php
public function deleteallAction()
{
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item)
{
$itemId = $item->getItemId();
$cartHelper->getCart()->removeItem($itemId)->save();
}
$this->_redirectReferer(Mage::getUrl('*/*'));
}


 
if you call this it will delete all item in the cart.


the url should be http://www.yoursite.com/index.php/checkout/cart/deleteall/