Home

Saturday, December 24, 2016

How to set character limit for Product Name, Description, Short Description in Magento ?

<?php
$productName = $_helper->productAttribute($_product, $_product->getName(), 'name');
echo Mage::helper('core/string')->truncate($productName, $length = 50, $etc = '...', $remainder = '', $breakWords = true);
?>

Wednesday, September 28, 2016

How to get all configurable products in magento ?

$collection = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id','configurable');

foreach ($collection as $product)
{
     echo $product->getName();
}

Saturday, August 20, 2016

How to get Diamond Inventory from RapNet using API ?

<?php
$data = '{"request": {"header": {"username": "xxxxxxx","password": "xxxx"},
"body": {
"shapes": [],
"size_to": "",
"size_from": "",
"color_from": "",
"color_to": "",
"clarity_from": "",
"clarity_to": "",
"cut_from": "",
"cut_to": "",
"polish_from": "",
"polish_to": "",
"symmetry_from": "",
"symmetry_to": "",
"labs": [],
"price_total_from": "",
"price_total_to": "",
"page_number": "1",
"page_size": "20",
"sort_by": "price",
"sort_direction": "ASC"
}}}';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

curl_setopt($curl, CURLOPT_URL, 'http://technet.rapaport.com/HTTP/JSON/RetailFeed/GetDiamonds.aspx');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
$data = json_decode($result,true);
$diamonds_returned = $data['response']['body']['search_results']['diamonds_returned'];
$total_diamonds_found =  $data['response']['body']['search_results']['total_diamonds_found'];
echo "<pre>";
print_r($data);
curl_close($curl);
?>

How to Change the price before adding to cart in magento with custom option selection price?

Put below code in app\code\community\YBizz\PriceChange\Model\Observer.php
<?php
class DRC_PriceChange_Model_Observer  {

    public function change_price(Varient_Event_Observer $observer) 
    {   
        $item = $observer->getQuoteItem();
        if ($item->getParentItem()) {$item = $item->getParentItem();}
        $price = $item->getProduct()->getFinalPrice();
        $new_price = 20 + $price;

        $item->setCustomPrice($new_price);
        $item->setOriginalCustomPrice($new_price);
        $item->getProduct()->setIsSuperMode(true);      
    }
}
?>

Wednesday, August 3, 2016

How to get value of Attribute Option in magento ?

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

function getAttributeOptionValue($arg_attribute, $arg_value)
{
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table');  
$attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
$attribute = $attribute_model->load($attribute_code);
$attribute_table = $attribute_options_model->setAttribute($attribute);
$options = $attribute_options_model->getAllOptions(false);  
foreach($options as $option)
{
if ($option['label'] == $arg_value)
{
return $option['value'];
}
}  
return false;
}
echo $optionValue = getAttributeOptionValue("diamond_symmetry", "Very Good");
?>

How to add new value in attribute magento ?

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

$optionValue = addAttributeValue("diamond_symmetry", "Excellent");

function addAttributeValue($arg_attribute, $arg_value)
    {
        $attribute_model        = Mage::getModel('eav/entity_attribute');

        $attribute_code         = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
        $attribute              = $attribute_model->load($attribute_code);

        if(!attributeValueExists($arg_attribute, $arg_value))
        {
            $value['option'] = array($arg_value,$arg_value);
            $result = array('value' => $value);
            $attribute->setData('option',$result);
            $attribute->save();
        }

$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;
        $attribute_table        = $attribute_options_model->setAttribute($attribute);
        $options                = $attribute_options_model->getAllOptions(false);

        foreach($options as $option)
        {
            if ($option['label'] == $arg_value)
            {
                return $option['value'];
            }
        }
       return false;
    }

function attributeValueExists($arg_attribute, $arg_value)
    {
        $attribute_model        = Mage::getModel('eav/entity_attribute');
        $attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;

        $attribute_code         = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
        $attribute              = $attribute_model->load($attribute_code);

        $attribute_table        = $attribute_options_model->setAttribute($attribute);
        $options                = $attribute_options_model->getAllOptions(false);

        foreach($options as $option)
        {
            if ($option['label'] == $arg_value)
            {
                return $option['value'];
            }
        }

        return false;
    }
?>

Thursday, June 11, 2015

jQuery Window Width Determined Initially and When Resized

jQuery(window).ready(function() {
    var wi = jQuery(window).width(); 
    jQuery("p.testp").text('Initial screen width is currently: ' + wi + 'px.');

    jQuery(window).resize(function() {
        var wi = jQuery(window).width();

        if (wi <= 480){
            jQuery("p.testp").text('Screen width is less than or equal to 480px. Width is currently: ' + wi + 'px.');           
            }
        else if (wi <= 767){
            jQuery("p.testp").text('Screen width is between 481px and 767px. Width is currently: ' + wi + 'px.');           
            }
        else if (wi <= 980){
            jQuery("p.testp").text('Screen width is between 768px and 980px. Width is currently: ' + wi + 'px.');           
            }
        else if (wi <= 1200){
            jQuery("p.testp").text('Screen width is between 981px and 1199px. Width is currently: ' + wi + 'px.');           
            }
        else {
            jQuery("p.testp").text('Screen width is greater than 1200px. Width is currently: ' + wi + 'px.');
//        jQuery().addClass();
            }
    });           
});

<p class="testp"></p>

Reference By :  http://www.surfingsuccess.com/jquery/window-width.html#.VXk5YPnPxNM

Friday, January 23, 2015

How to add product in woocommerce using programmatically with wpml

function woocommerce_add_products_dynamicaly()
 {
        //empty cart
        global $woocommerce;
        $woocommerce->cart->empty_cart();
        // Remove default cart message
        $woocommerce->clear_messages();
       
        //price
        $invoiceprice = 1;
       
        //Generate title
        $timestampedtitle = rand()." Date: ".date("d/m/Y")." Amount: £".$invoiceprice;
       
        //Generate message
        $message = date_timestamp_get(date_create())." Date: ".date('m/d/Y h:i:s a', time())." Invoice amount: £".$invoiceprice;

        $post = array(
        'post_author' => '2',
        'post_status' => "publish",
        'post_title' => $timestampedtitle,
        'post_content' => $message,
        'post_parent' => '',
        'post_type' => "product",
        //'post_status' => 'private',
        );

Monday, October 6, 2014

Change and Update WordPress URLS in Database When Site is Moved to new Host

 
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

Tuesday, September 16, 2014

Anyone know how to install pdftk for CentOS?

Reference from http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment
 
# yum install rpm-build
sudo yum install rpm-build
sudo yum install redhat-rpm-config
sudo yum install make
yum install gcc
 
Reference from https://www.pdflabs.com/docs/install-pdftk-on-redhat-or-centos/
 
sudo yum install gcc gcc-java libgcj libgcj-devel gcc-c++ 
wget https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-2.02-src.zip 
unzip pdftk-2.02-src.zip 
cd pdftk-2.02-dist/pdftk 
make -f Makefile.Redhat 
sudo make -f Makefile.Redhat install
Upon completion, you will find pdftk in /usr/local/bin.


Reference from http://pkgs.org/centos-6/repoforge-x86_64/pdftk-1.44-1.el6.rf.x86_64.rpm.html

wget apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/pdftk-1.44-1.el6.rf.x86_64.rpm
rpm -Uvh pdftk-1.44-1.el6.rf.x86_64.rpm OR rpm -Uvh *rpm
yum install pdftk 




How to get PDF boxes information using PHP

If you want to extract Total no of pages,Creator,Creation Date,Producer,Tagged,Page size,MediaBox,CropBox,BleedBox,TrimBox,ArtBox,File size,PDF version etc then you can used below code.

---------------------------------------------------------------------------------------------------------------------
$file_name = "files/client_bussinesscard_front.pdf";
echo "<b>All Details : </b>";
$command_pagesize8 = "pdfinfo -box  $file_name";
shell_exec($command_pagesize8); //run the command
echo "<br><br><hr>";

echo "<b>Total Pages : </b>";
$command_pagesize1 = "pdfinfo -box  $file_name | grep Pages";
shell_exec($command_pagesize1); //run the command
echo "<br><br><hr>";

echo "<b>Page size : </b>";
$command_pagesize2 = "pdfinfo -box  $file_name | grep 'Page size'";
shell_exec($command_pagesize2); //run the command
echo "<br><br><hr>";

$command_pagesize3 = "pdfinfo -box  $file_name | grep 'MediaBox'";
mm($command_pagesize3,"<b>MediaBox Details (wight x height):</b><br>");

$command_pagesize4 = "pdfinfo -box  $file_name | grep 'CropBox'";
mm($command_pagesize4,"<b>CropBox Details (wight x height):</b><br>");

$command_pagesize5 = "pdfinfo -box  $file_name | grep 'BleedBox'";
mm($command_pagesize5,"<b>BleedBox Details (wight x height):</b><br>");

$command_pagesize6 = "pdfinfo -box  $file_name | grep 'TrimBox'";
mm($command_pagesize6,"<b>TrimBox Details (wight x height):</b><br>");

$command_pagesize7 = "pdfinfo -box  $file_name | grep 'ArtBox'";
mm($command_pagesize7,"<b>ArtBox Details (wight x height):</b><br>");

function mm($command,$title)
{
    echo $title;   
    $array = explode(" ",shell_exec($command));   
    foreach($array as $val)
    {
      if($val!="")
      {
          $final_array[].=$val;
      }
    }   
    ?>
    <table width="50%" border="1">
        <tr><th>Points</th><th>MM</th></tr>
        <tr>
            <td align="center"><?php echo $final_array[3] . " x " .$final_array[4]; ?></td>
            <td align="center"><?php echo round(($final_array[3]*0.35277777778),2) . " x " .round(($final_array[4]*0.35277777778),2);?><br>
            <?php echo round(($final_array[3]*0.35277777778)) . " x " .round(($final_array[4]*0.35277777778));?></td>
           </tr>
    </table>
    <?php   
}

Tuesday, June 17, 2014

Getting visitors country from their IP using PHP

<?php
function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
     // $ip="5.2.79.255";//Netherland
     // $ip="81.247.97.77";//Belgium
    }
    return $ip;
}

$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".getRealIpAddr());
echo $xml->geoplugin_countryName ;

echo "<pre>" ;
foreach ($xml as $key => $value)
{
    echo $key , "= " , $value ,  " \n" ;
}
?>

Friday, May 30, 2014

Currency Converter In PHP

/*British Pound GBP
Euro EUR
US Dollar USD
Japanese Yen JPY
Chinese Yuan CNY
Australian Dollar AUD
Swiss Franc CHF
Canadian Dollar CAD
Thai Baht THB
Indian Rupee INR
Indonesian Rupiah IDR
Hong Kong Dollar HKD*/


    $from_Currency = "USD";
    $to_Currency = "EUR";
    $amount = 1;

    $amount = urlencode($amount);
    $from_Currency = urlencode($from_Currency);
    $to_Currency = urlencode($to_Currency);
    $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
    $get = explode("<span class=bld>",$get);
    $get = explode("</span>",$get[1]); 
    $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
   
    $formatter = new NumberFormatter('en_EN',  NumberFormatter::CURRENCY);
    echo "=>  ".$formatter->formatCurrency($converted_amount, 'EUR') . PHP_EOL;

Sunday, April 27, 2014

Magento: Delete All Products Using PhpMyAdmin

SET FOREIGN_KEY_CHECKS = 0;
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_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_category_product_index`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE `cataloginventory_stock`;
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,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');
TRUNCATE TABLE `catalog_product_entity`;
SET FOREIGN_KEY_CHECKS = 1;
rathoddhirendra.blogspot.com-Google pagerank and Worth