.

.

Set up cron in blue host

Step 1 login into cpanel
Step 2 go to cron job


Step3) In command you can change path like this

PHP

Command to run a PHP5 cron job:
php /home/username/public_html/cron.php
Optional flags are sometimes required for a PHP cron job:
php -q /home/username/public_html/cron.php
Command to use a specific php.ini file:
php -c /home/username/public_html/php.ini /home/username/public_html/myscript.php
Command to GET a remote file:
/usr/bin/GET http://www.example.com/file.php

Perl

Command to run a CGI cron job:
perl /home/username/public_html/cgi-bin/file.pl

SSH

Command to run a shell script cron job:
/bin/sh /home/username/public_html/file.sh






How to assign default category to all products by query in magento

How to assign default category to all products by query in magento

Step1 ) Create a php file like assigntoDeafultCat.php

Step2) Paste this code in this file

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

// $productIds is an array of the products you want to modify.
// Create it however you want, I did it like this...
$productsIds = Mage::getModel('catalog/product')->getCollection()
    ->getAllIds();

//print_r($productsIds); die;

// Array of category_ids to add.
$newCategories = array(2);

foreach($productsIds as $id) { 


    $product = Mage::getModel('catalog/product')->load($id);
    $product->setCategoryIds(
        array_merge($product->getCategoryIds(), $newCategories)
    );

    $product->save();
}
echo "done";
?>

Step 3)save this file in root &  Run this file on browser like http://localhost/mage_venus/assigntoDeafultCat.php

Step After show done , check your products

Create block in phtml & call different block according to country

Step 1)Create two static blocks 

Step 2 )create main phtml block & call it  like home_slider.phtml & save in template/cms/home_slider.phtml




<?php
function get_client_ip_server() {
    $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP'])
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if($_SERVER['HTTP_X_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if($_SERVER['HTTP_X_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if($_SERVER['HTTP_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if($_SERVER['HTTP_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
 
    return $ipaddress;
}

 $ip_addr=get_client_ip_server();

//echo $ip_addr= '103.36.125.146';
?>
<?php
$url = "http://www.geoplugin.net/json.gp?ip='".$ip_addr."'";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
  echo curl_error($ch);
  echo "\n<br />";
  $contents = '';
} else {
  curl_close($ch);
}

if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}

$contents;

$result=json_decode($contents);
//print_r($result);
?>   

<?php
//echo $result->geoplugin_countryCode;
if( $result->geoplugin_countryCode == "IN" ) {
//do something here, like load a specific static block...
echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-carousel-india')->toHtml();
}
else
{
echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-carousel-international')->toHtml();
}

echo $ip = $_SERVER["HTTP_CLIENT_IP"];

?>

Step3) Now this phtml block home_slider.html call it where you want to use, I am using in layout local.xml

<block type="core/template" name="slider" template="cms/home_slider.phtml" before="content"></block>
how to call block according to client geo location

how to call block according to client geo location

<?php
function get_client_ip_server() {
    $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP'])
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if($_SERVER['HTTP_X_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if($_SERVER['HTTP_X_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if($_SERVER['HTTP_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if($_SERVER['HTTP_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';

    return $ipaddress;
}

 $ip_addr=get_client_ip_server();

//echo $ip_addr= '103.36.125.146';
?>
<?php
$url = "http://www.geoplugin.net/json.gp?ip='".$ip_addr."'";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
  echo curl_error($ch);
  echo "\n<br />";
  $contents = '';
} else {
  curl_close($ch);
}

if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}

$contents;

$result=json_decode($contents);
//print_r($result);
?>  

<?php
//echo $result->geoplugin_countryCode;
if( $result->geoplugin_countryCode == "IN" ) {
//do something here, like load a specific static block...
echo $this->getLayout()->createBlock('cms/block')->setBlockId('indiareturnpolicy')->toHtml();
}
else
{
echo $this->getLayout()->createBlock('cms/block')->setBlockId('international-return-policy')->toHtml();
}

echo $ip = $_SERVER["HTTP_CLIENT_IP"];
?>
file_get_contents works on Local but not on server

file_get_contents works on Local but not on server

Use curl for solve this issue
<?php
$url = "http://www.testing.com/";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
  echo curl_error($ch);
  echo "\n<br />";
  $contents = '';
} else {
  curl_close($ch);
}

if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}

echo $contents;
?>    

How to change category filter position in magento layer navigation

How to change category filter position in magento layer navigation

Open Attributes which is using in layered navigation and there is field/textbox to add position values Under Front End properties.
Put position as per your requirement.
Then reindex also.
If want to set Category filter position, then follow these steps:
Copy file: app\code\core\Mage\Catalog\Block\Layer\View.php Paste file: app\code\local\Mage\Catalog\Block\Layer\View.php
Then Update code of app\code\local\Mage\Catalog\Block\Layer\View.php file.
Replace getFilters() function code with below code:
public function getFilters()
{
    $filters = array();
    $catFilters = array(); // Created New array
    if ($categoryFilter = $this->_getCategoryFilter()) {
        $catFilters[] = $categoryFilter; // Assign category to new array
    }

    $filterableAttributes = $this->_getFilterableAttributes();
    foreach ($filterableAttributes as $attribute) {
        $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
    }

    /* Pushed category filter array to position 1, 
if want to change position then update value in this function. */
    array_splice( $filters, 1, 0, $catFilters ); 
    return $filters;
}

How To Show Most Viewed Product In Magento

How To Show Most Viewed Product In Magento


Step 1: Create a file app/code/local/Mage/Catalog/Block/Product/Mostviewed.php and add the following lines of code in it

class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract{
    public function __construct(){
        parent::__construct();
        $storeId    = Mage::app()->getStore()->getId();
        $products = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToSelect('*')
            ->addAttributeToSelect(array('name', 'price', 'small_image'))
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            ->addViewsCount();
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
 
        $products->setPageSize(5)->setCurPage(1);
        $this->setProductCollection($products);
    }
}

Step 2: Create a fileapp/design/frontend/default/YourTheme/template/catalog/product/mostviewed.phtml and add the following lines of code in it

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class=" most_viewed">
<div class="mv_title"><?php echo $this->__('These Products Are Popular Right Now!') ?></div>
<?php $_collectionSize = 5;//count($_products->getItems()); echo $_collectionSize; ?>
<ul class="products-grid" id="products-grid-table">
<?php $i=1; foreach ($_products->getItems() as $_product): ?>
    <li id="td_<?php echo $i;?>" <?php if($i%5==0 or $i==$_collectionSize){echo 'class="last"';} ?> >
        <div id="cont_<?php echo $i;?>">        
            <a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
            </a>
            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
            <div class="a-center">                        
                <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
       <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <?php if($_product->isSaleable()): ?>
                    <button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
                    <div class="clear"></div>
                <?php else: ?>
                    <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span></p>
                    <div class="clear"></div>
                <?php endif; ?>
                <ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                    <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                    <li class="last"><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
                </ul>
            </div>
        </div>
    </li>
<?php $i++; endforeach; $kol = $_collectionSize; ?>
</ul>
</div>
<?php endif; ?>

Step 3: Now, we have the code in place which will fetch the most viewed products on call. Still, we need to add a block to show most viewed products in a desired location

{{block type="catalog/product_mostviewed" template="catalog/product/mostviewed.phtml"}}