Friday, 6 April 2012

magento display attribute in dropdown

Create a attribute
and then
edit app/code/core/Mage/Catalog/Block/Navigation.php

public function getAllManu()
{
$product = Mage::getModel(‘catalog/product’);
$attributes = Mage::getResourceModel(‘eav/entity_attribute_collection’)
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter(‘attribute_code’, ‘manufacturer’); //can be changed to any attribute
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
return $manufacturers;
}
and then
edit app/design/frontend/default/default/template/catalog/navigation/top.phtml

  1. <select id=“select-manufacturer” onchange=“window.location.href=this.value”>
  2. <option value=“#” selected=“selected”>–Select Manufacturer–</option>
  3.     <?php foreach ($this->getAllManu() as $manufacturer): ?>
  4.         <option value=“/catalogsearch/advanced/result/?manufacturer[]=<?php echo $manufacturer['value'] ?>”><?php echo $manufacturer['label'] ?></option>
  5.     <?php endforeach; ?>
  6.     </select>

captcha (alpha numeric) in php

<?php
$RandomStr = md5(microtime());// md5 to generate the random string
$ResultStr = substr($RandomStr,0,8);
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, $RandomStr, $text_color);
imagejpeg($im,$ResultStr.'.jpg');
imagedestroy($im);
//echo '’.$randval.”;
?>

ebooks of drupal 6 and drupal 7

magento free ebook download

Thursday, 1 March 2012

add google translate with selected language, google translate api with selected language

function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: ‘en’,
includedLanguages: ‘ja’,
defaultLanguage: ‘ja’,
multilanguagePage: true
}, ‘google_translate_element’);
}

set google translater default language, google translate default language

We can set google translate default language
by working with cookies
for this first use google translate to translate your web page
then see what cookies he has created
(for this right click on your web page then page info
then security then view cookies and click on googtrans you see what is the translation he is using and what is the path and what is the domain or host name )
and put this all data in setcookies function
example
setcookie(“googtrans”, “/en/ja”, time()+3600, “/”, “www.example.com”);
//setcookie(“googtrans”, “en/ja”);
setcookie(“googtrans”, “/en/en”, time()+3600, “/”, “.example.com”);

call a function regularly , call a function after a particular time period, call function continue


function getdata(){
var langu = jQuery(“.goog-te-combo”).html(‘<option value=”">Select Lanugage</option><option value=”en”>English</option><option value=”ja”>Japanese</option>’);
jQuery(“.goog-te-gadget”).css({“margin-top”:”0px”});
intervaltime();
}
</script>



<script>
function intervaltime(){
window.setInterval(function(){
getdata();
}, 5000);
}
$(function() {
setTimeout(getdata, 3000);
});
</script>