Product image change on attribute selection

May 17, 2011

we can change product main image on selection of attribute. below are steps.

step1.
-open template/catalog/product/view/type/options/configurable.phtml
-add
var mainProductImgSrc = document.getElementById(“image”).src;//added
on bottom of page after spConfig
step2.
-open template/catalog/produict/view.phtml
- add this after
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);

//added

var assocIMG =

<?php
if ($_product->getTypeId() == “configurable”) {
echo “{“;
$associated_products = $_product->loadByAttribute(‘sku’, $_product->getSku())->getTypeInstance()->getUsedProducts();
foreach ($associated_products as $assoc)
$dados[] = $assoc->getId().”:’”.($assoc->image == “no_selection” || $assoc->image == “” ? $this->helper(‘catalog/image’)->init($_product, ‘image’, $_product->image)->resize(365,400) : $this->helper(‘catalog/image’)->init($assoc, ‘image’, $assoc->image)->resize(365,400)).”‘”;
} else {
$dados[] = “””;
}
echo implode(‘,’, $dados );
if ($_product->getTypeId() == “configurable”) {
echo “}”;
}
?>
//added

step3.
- open js/varien/product.js
-add
//added
settings = $$(‘.super-attribute-select’);
imgSrc = mainProductImgSrc;
settings.each(function(element)
{
attributeId = element.attributeId;
if(element.options[element.selectedIndex].config)
imgSrc = assocIMG[element.options[element.selectedIndex].config.products];
$(‘image’).src = imgSrc;
} );
//added end
Before
}.bind(this));
},
formatPrice: function(price) {
return formatCurrency(price, this.priceFormat);
}
around line : 715

=== By this way when attribute will change then its image also change.


Attribute Display in alphabetical order

March 28, 2011

This module displayes attrribute in fron side on separate link in alphabets order.

Want this , tell here…

 


Attribute Meta

March 28, 2011

Attribute meta for all the category.

You have to first create attribute set

crate category with name as like attribute set.

create products on that sets and assign that category.

in front side display that category with that attr  set.

by this way you can use this module via category?atributename=optionvalue

This module is very useful for Meta for various attributes.

Want this , reply here…

 


full text search- spped up searching

March 26, 2011

add fulltext search to speed up the searching in php

ALTER TABLE  $tablename ADD FULLTEXT(body, title);

$query = “SELECT * FROM $tablename WHERE MATCH(title, body) AGAINST (‘PHP’)  “;

This is uefull in very large data.

 

Only supperted by MyIsAM type.


Use EVAL() for php code replace within string

March 25, 2011

Use EVAL () for replacing php var from given string.

For email template : instead of str_replace…

We  can use this for email template , cms pages for php varibale …

This speeds up the execution.

 


Get multiple records with limit clouse

March 25, 2011

SELECT SQL_CALC_FOUND_ROWS * FROM <tablename> limit 0,10;
SELECT FOUND_ROWS();

$row = mysql_fetch_row(mysql_query(“SELECT FOUND_ROWS()”));
$total = $row[0];

We can get totat records by using above query.

This is for very large records.

This speeds up the query and page execution.


How to create a new page in the zencart?

February 5, 2009

For creating a page in zencart we use this instructions:

1. From admin side goto ezpages and create new page with link .

2. create a page  named this

\includes\templates\template_default\templates\tpl_mypage_default.php

in this page copy the content from other page in same directory.

3.  write define(‘FILENAME_DEFINE_MYPAGE’, ‘define_mypage’); in the
\includes\filenames.php

4. create a page in this directory

\includes\languages\english\mypage.php

5. create a page in this directory
\includes\languages\english\html_includes\define_mypage.php

6. create a folder and page in this directory

\includes\modules\pages\mypage\header.php

Please copy the content from particular page in same directory.

7. go to define editor section from Tools menu in admin side. then select that page define_mypage and here you can insert description for that page.


Overriding layout for 1.5 series

October 2, 2008

There are html folder in particular template folder

Customise the Component Output for joomla 1.5 series

To override a component layout (for example the default layout in the article view), copy:

/components/com_content/views/article/tmpl/default.php

to:

/templates/rhuk_milkyway/html/com_content/article/default.php

Customise the Module Output

To override a module layout (for example the Latest News module ), copy:

/components/mod_latest_news/default.php

to:

/templates/rhuk_milkyway/html/mod_latest_news/default.php

Add New Module Styles

To add new module styles (chrome), add them to the following file:

/templates/rhuk_milkyway/html/modules.php

Customise the Pagination Links

To customise the way the items-per-page selector and pagination links display, edit the following file:

/templates/rhuk_milkyway/html/pagination.php


first Rails Aplication

September 9, 2008

Ror First application on rails 2.0
1. rails –database mysql hello
or rails -d mysql hello
2. create manually database on mysql
or rake db:create:all
3. ruby script/generate controller say hello

4. ruby script/server
5. type on http://localhost:3000/say/hello

for cearting table
script/generate scaffold Post title:string body:text
rake db:migrate

Steps
- rails -d mysql test
-cd test
—-manuially set the dtabase usernamr and pwd in database.yml file
-rake db:create:all
-ruby script/server (starting the server)
-ruby script/generate scaffold Movie title:string (for table cration)
-rake db:migrate

==for mongrel server
service mongrel_cluster restart
script/server –help
service nginx start

for including file
rendre:partial “path”;
render(:partial => ‘/controls/footer’)

for mongrel server steps

==start
1. copy mongrel_cluster.yml into config
changes that
2. insert some code in etc/ngix/*.conf
in that
upstream hello.rajesh {
server 127.0.0.1:8005;
}
and
server {
listen       81;
server_name  hello.rajesh;

root /sites/hello/public;

#charset koi8-r;

access_log  /var/log/nginx/hello.access.log  main;

location ~ ^/$ {
if (-f /index.html){
rewrite (.*) /index.html last;
}
proxy_pass  http://hello.rajesh;
}

location / {
if (!-f $request_filename.html) {
proxy_pass  http://hello.rajesh;
}
rewrite (.*) $1.html last;
}

location ~ .html {
root /sites/hello/public;
}

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
root /sites/hello/public;
}

location / {
proxy_pass  http://hello.rajesh;
proxy_redirect     off;
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

}

3. ln -s /sites/hello/config/mongrel_cluster.yml /etc/mongrel_cluster/hello.yml
4. chown -R mongrel:mongrel /sites/hello
==end
for creating only model and table
ruby script/generate model images_imagecategories image_id:integer imagecategories_id:integer
ruby script/generate model imagecategories_images images_id:integer imagecategories_id:integer


Ajax Uploading image, How to get image width and height for uploaded image, how to make validation for image width and height, how to call php function in javascript?

September 9, 2008

For that use following code for uplaoding image, there are 3 files to make this clear.

1.index.php

<!–
/* This scipt uses webtoolkit.js for Frame and aJAx style upload */
–>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-US” lang=”en-US”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Iframe Ajax for Upload</title>
<script type=”text/javascript” src=”webtoolkit.js”></script>
<script type=”text/javascript”>
function startCallback() {
// make something useful before submit (onStart)
return true;
}
function completeCallback(response) {
// make something useful after (onComplete)
var src_path =response;
//alert(response);
var img_obj  =document.getElementById(‘img_div’);
var newimg=document.createElement(‘img’);
img_obj.appendChild(newimg);
newimg.src = src_path;
newimg.onload=function()
{ // get an image width and hieght
new_w = img_obj.getElementsByTagName(‘img’)[0].width;
new_h =img_obj.getElementsByTagName(‘img’)[0].height;

if(new_w>100) //make neccessary validation depends on width adn hight
{
var ret = “<?php posting1(‘”+response+”‘);?>”;
alert(ret);
}
//remove the image from disp location here
img_obj.removeChild(newimg);
}
}
</script>
</head>
<body>

<form action=”my_upload.php” method=”post” onsubmit=”return AIM.submit(this, {‘onStart’ : startCallback, ‘onComplete’ : completeCallback})” enctype=”multipart/form-data”>
<div><label>Name:</label> <input type=”text” name=”form[name]” /></div>
<div><label>File:</label> <input type=”file” name=”form[file]” /></div>
<div><input type=”submit” value=”SUBMIT” /></div>
</form>
<hr/>
<div id=”img_div”></div>
</body>
</html>
<?php
function posting1($ret)
{
echo “code for update database and remove image for the same”.$ret;
}

?>


2.my_upload.php

<!–
/* In this page we can make upload logic by using php code */
–>
<?php
$fname =  $_FILES['form']['name']['file'];
$uploaded_path = “”.$fname;        ///var/www/html/demo/test/my_upload/
$ftname =  $_FILES['form']['tmp_name']['file'];

if(move_uploaded_file($ftname,$uploaded_path))
$ret = $uploaded_path;
else $ret =  $uploaded_path;
//$ret =”http://localhost:100/demo/test/”.$fname;
$disp_path =$fname;
echo $disp_path;
?>


3.webtoolkit.js
/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
**/

AIM = {

frame : function(c) {

var n = ‘f’ + Math.floor(Math.random() * 99999);
var d = document.createElement(‘DIV’);
d.innerHTML = ‘<iframe style=”display:none” src=”about:blank” id=”‘+n+’” name=”‘+n+’” onload=”AIM.loaded(\”+n+’\')”></iframe>’;
document.body.appendChild(d);

var i = document.getElementById(n);
if (c && typeof(c.onComplete) == ‘function’) {
i.onComplete = c.onComplete;
}

return n;
},

form : function(f, name) {
f.setAttribute(‘target’, name);
},

submit : function(f, c) {
AIM.form(f, AIM.frame(c));
if (c && typeof(c.onStart) == ‘function’) {
return c.onStart();
} else {
return true;
}
},

loaded : function(id) {
var i = document.getElementById(id);
if (i.contentDocument) {
var d = i.contentDocument;
} else if (i.contentWindow) {
var d = i.contentWindow.document;
} else {
var d = window.frames[id].document;
}
if (d.location.href == “about:blank”) {
return;
}

if (typeof(i.onComplete) == ‘function’) {
i.onComplete(d.body.innerHTML);
}
}

}


Follow

Get every new post delivered to your Inbox.