ColorSwicherModule - Version 1.0.0

Version Notes

Show dynamic associated product images while selecting configurable option(color-switcher)

Download this release

Release Info

Developer Magento Core Team
Extension ColorSwicherModule
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Neev/ColorSwicher/etc/config.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Neev_ColorSwicher>
5
+ <version>0.1.0</version>
6
+ </Neev_ColorSwicher>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <colorswicher>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Neev_ColorSwicher</module>
14
+ <frontName>colorswicher</frontName>
15
+ </args>
16
+ </colorswicher>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <colorswicher>
21
+ <file>colorswicher.xml</file>
22
+ </colorswicher>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+
27
+ </config>
app/design/frontend/base/default/layout/colorswicher.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <PRODUCT_TYPE_configurable translate="label" module="catalog">
4
+ <reference name="head">
5
+ <block type="page/html" name="top.Js" as="topJs" template="colorswicher/page/html/jshead.phtml"/>
6
+ <action method="addJs"><script>varien/config.js</script></action>
7
+ </reference>
8
+ <reference name="product.info">
9
+ <action method="setTemplate">
10
+ <template>colorswicher/product/view.phtml</template>
11
+ </action>
12
+ </reference>
13
+ <reference name="product.info.media">
14
+ <action method="setTemplate">
15
+ <template>colorswicher/product/media.phtml</template>
16
+ </action>
17
+ </reference>
18
+ </PRODUCT_TYPE_configurable>
19
+
20
+ </layout>
app/design/frontend/base/default/template/colorswicher/page/html/jshead.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_product = Mage::registry('current_product');
3
+ ?>
4
+ <script type="text/javascript">
5
+ //<![CDATA[
6
+ var assocIMG = // Added - Removed { here, causes issues with other scripts when not working with a configurable product.
7
+ <?php
8
+ if ($_product->getTypeId() == "configurable") {
9
+ echo "{";
10
+ $associated_products = $_product->loadByAttribute('sku', $_product->getSku())->getTypeInstance()->getUsedProducts();
11
+ foreach ($associated_products as $assoc)
12
+ $dados[] = $assoc->getId().":'".($assoc->image == "no_selection" || $assoc->image == "" ? $this->helper('catalog/image')->init($_product, 'image', $_product->image)->resize(375,460) : $this->helper('catalog/image')->init($assoc, 'image', $assoc->image)->resize(375,460))."'";
13
+ } else {
14
+ $dados[] = "''";
15
+ }
16
+ echo implode(',', $dados );
17
+ if ($_product->getTypeId() == "configurable") {
18
+ echo "}";
19
+ }
20
+ ?> ;
21
+ //]]
22
+ </script>
app/design/frontend/base/default/template/colorswicher/product/media.phtml ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product media data template
29
+ *
30
+ * @see Mage_Catalog_Block_Product_View_Media
31
+ */
32
+ ?>
33
+ <?php
34
+ $_product = $this->getProduct();
35
+ $_helper = $this->helper('catalog/output');
36
+ ?>
37
+ <?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
38
+ <p class="product-image product-image-zoom">
39
+ <?php
40
+ $_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
41
+ echo $_helper->productAttribute($_product, $_img, 'image');
42
+ ?>
43
+ </p>
44
+ <p class="zoom-notice" id="track_hint"><?php echo $this->__('Double click on above image to view full picture') ?></p>
45
+ <div class="zoom">
46
+ <img id="zoom_out" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_out.gif') ?>" alt="<?php echo $this->__('Zoom Out') ?>" title="<?php echo $this->__('Zoom Out') ?>" class="btn-zoom-out" />
47
+ <div id="track">
48
+ <div id="handle"></div>
49
+ </div>
50
+ <img id="zoom_in" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_in.gif') ?>" alt="<?php echo $this->__('Zoom In') ?>" title="<?php echo $this->__('Zoom In') ?>" class="btn-zoom-in" />
51
+ </div>
52
+ <script type="text/javascript">
53
+ //<![CDATA[
54
+ Event.observe(window, 'load', function() {
55
+ product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
56
+ });
57
+ //]]>
58
+ </script>
59
+ <?php else: ?>
60
+ <p class="product-image">
61
+ <?php
62
+ $_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(265).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
63
+ echo $_helper->productAttribute($_product, $_img, 'image');
64
+ ?>
65
+ </p>
66
+ <?php endif; ?>
67
+ <?php if (count($this->getGalleryImages()) > 0): ?>
68
+ <div class="more-views">
69
+ <h2><?php echo $this->__('More Views') ?></h2>
70
+ <ul>
71
+ <?php foreach ($this->getGalleryImages() as $_image): ?>
72
+ <li>
73
+ <a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
74
+ </li>
75
+ <?php
76
+ endforeach; ?>
77
+ </ul>
78
+ </div>
79
+ <?php endif; ?>
app/design/frontend/base/default/template/colorswicher/product/view.phtml ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_modern
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product view template
29
+ *
30
+ * @see Mage_Catalog_Block_Product_View
31
+ * @see Mage_Review_Block_Product_View
32
+ */
33
+ ?>
34
+ <?php
35
+ $_helper = $this->helper('catalog/output');
36
+ $_product = $this->getProduct();
37
+ ?>
38
+ <script type="text/javascript">
39
+ var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
40
+ </script>
41
+ <div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
42
+ <div class="product-view">
43
+ <div class="product-essential">
44
+ <form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
45
+ <div class="no-display">
46
+ <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
47
+ <input type="hidden" name="related_product" id="related-products-field" value="" />
48
+ </div>
49
+
50
+ <div class="product-shop">
51
+ <div class="product-name">
52
+ <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
53
+ </div>
54
+
55
+ <?php if ($this->canEmailToFriend()): ?>
56
+ <p class="email-friend"><a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><?php echo $this->__('Email to a Friend') ?></a></p>
57
+ <?php endif; ?>
58
+
59
+ <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
60
+ <?php echo $this->getChildHtml('alert_urls') ?>
61
+ <?php echo $this->getChildHtml('product_type_data') ?>
62
+ <?php echo $this->getTierPriceHtml() ?>
63
+
64
+ <?php if (!$this->hasOptions()):?>
65
+ <div class="add-to-box">
66
+ <?php if($_product->isSaleable()): ?>
67
+ <?php echo $this->getChildHtml('addtocart') ?>
68
+ <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
69
+ <span class="or"><?php echo $this->__('OR') ?></span>
70
+ <?php endif; ?>
71
+ <?php endif; ?>
72
+ <?php echo $this->getChildHtml('addto') ?>
73
+ </div>
74
+ <?php else:?>
75
+ <?php echo $this->getChildHtml('addto') ?>
76
+ <?php endif; ?>
77
+
78
+ <?php if ($_product->getShortDescription()):?>
79
+ <div class="short-description">
80
+ <h2><?php echo $this->__('Quick Overview') ?></h2>
81
+ <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
82
+ </div>
83
+ <?php endif;?>
84
+
85
+ <?php echo $this->getChildHtml('other');?>
86
+
87
+ <?php if ($_product->isSaleable() && $this->hasOptions()):?>
88
+ <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
89
+ <?php endif;?>
90
+
91
+ </div>
92
+
93
+ <div class="product-img-box">
94
+ <?php echo $this->getChildHtml('media') ?>
95
+ </div>
96
+
97
+ <div class="clearer"></div>
98
+ <?php if ($_product->isSaleable() && $this->hasOptions()):?>
99
+ <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
100
+ <?php endif;?>
101
+ </form>
102
+ <script type="text/javascript">
103
+ //<![CDATA[
104
+ var productAddToCartForm = new VarienForm('product_addtocart_form');
105
+ productAddToCartForm.submit = function(){
106
+ if (this.validator.validate()) {
107
+ this.form.submit();
108
+ }
109
+ }.bind(productAddToCartForm);
110
+ //]]>
111
+ </script>
112
+ </div>
113
+
114
+ <div class="product-collateral">
115
+ <?php echo $this->getChildHtml('info_tabs') ?>
116
+ <?php echo $this->getChildHtml('product_additional_data') ?>
117
+ </div>
118
+ </div>
app/etc/modules/Neev_ColorSwicher.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Neev_ColorSwicher>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Neev_ColorSwicher>
8
+ </modules>
9
+ </config>
js/varien/config.js ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ if(typeof Product=='undefined') {
2
+ var Product = {};
3
+ }
4
+ if(typeof selectedAssocProducts=='undefined') {
5
+ var selectedAssocProducts = {};
6
+ }
7
+ /**************************** CONFIGURABLE PRODUCT **************************/
8
+ Product.Config = Class.create();
9
+ Product.Config.prototype = {
10
+ initialize: function(config){
11
+ this.config = config;
12
+ this.taxConfig = this.config.taxConfig;
13
+ this.settings = $$('.super-attribute-select');
14
+ this.state = new Hash();
15
+ this.priceTemplate = new Template(this.config.template);
16
+ this.prices = config.prices;
17
+ this.settings.each(function(element){
18
+ Event.observe(element, 'change', this.configure.bind(this))
19
+ }.bind(this));
20
+
21
+ // fill state
22
+ this.settings.each(function(element){
23
+ var attributeId = element.id.replace(/[a-z]*/, '');
24
+ if(attributeId && this.config.attributes[attributeId]) {
25
+ element.config = this.config.attributes[attributeId];
26
+ element.attributeId = attributeId;
27
+ this.state[attributeId] = false;
28
+ }
29
+ }.bind(this))
30
+
31
+ // Init settings dropdown
32
+ var childSettings = [];
33
+ for(var i=this.settings.length-1;i>=0;i--){
34
+ var prevSetting = this.settings[i-1] ? this.settings[i-1] : false;
35
+ var nextSetting = this.settings[i+1] ? this.settings[i+1] : false;
36
+ if(i==0){
37
+ this.fillSelect(this.settings[i])
38
+ }
39
+ else {
40
+ this.settings[i].disabled=true;
41
+ }
42
+ $(this.settings[i]).childSettings = childSettings.clone();
43
+ $(this.settings[i]).prevSetting = prevSetting;
44
+ $(this.settings[i]).nextSetting = nextSetting;
45
+ childSettings.push(this.settings[i]);
46
+ }
47
+
48
+ // try retireve options from url
49
+ var separatorIndex = window.location.href.indexOf('#');
50
+ if (separatorIndex!=-1) {
51
+ var paramsStr = window.location.href.substr(separatorIndex+1);
52
+ this.values = paramsStr.toQueryParams();
53
+ this.settings.each(function(element){
54
+ var attributeId = element.attributeId;
55
+ element.value = this.values[attributeId];
56
+ this.configureElement(element);
57
+ }.bind(this));
58
+ }
59
+ },
60
+
61
+ configure: function(event){
62
+ var element = Event.element(event);
63
+ this.configureElement(element);
64
+ },
65
+
66
+ configureElement : function(element) {
67
+ this.reloadOptionLabels(element);
68
+ if(element.value){
69
+ this.state[element.config.id] = element.value;
70
+ if(element.nextSetting){
71
+ element.nextSetting.disabled = false;
72
+ this.fillSelect(element.nextSetting);
73
+ this.resetChildren(element.nextSetting);
74
+ }
75
+ }
76
+ else {
77
+ this.resetChildren(element);
78
+ }
79
+ this.reloadPrice();
80
+ // Calculator.updatePrice();
81
+ /***** Load Associated Image : This should come after this.resetChildren is called *****/
82
+
83
+ // If an option doesnt have a value attribute, it'll take its innerHTML as its value - hence the reason for || element.value.substr(0,6) == 'choose'
84
+ if (!element.value || element.value.substr(0,6) == 'choose') return; // Selected "choose option"
85
+ var attributeId = element.id.replace(/[a-z]*/, '');
86
+ for (var a in this.config.attributes)
87
+ {
88
+ for (i = 0; i < this.config.attributes[a].options.length; i++)
89
+ {
90
+ if (this.config.attributes[a].options[i].id != element.value) continue;
91
+ selectedAssocProducts[a] = this.config.attributes[attributeId].options[i].products;
92
+
93
+ }
94
+ }
95
+
96
+ var productNo = selectedAssocProductsImg(selectedAssocProducts) || selectedAssocProducts[attributeId][0];
97
+ var changeImg = document.getElementById("image");
98
+ var associatedProductImg= assocIMG[productNo] ;
99
+ changeImg.src=associatedProductImg;
100
+ },
101
+
102
+ reloadOptionLabels: function(element){
103
+ var selectedPrice;
104
+ if(element.options[element.selectedIndex].config){
105
+ selectedPrice = parseFloat(element.options[element.selectedIndex].config.price)
106
+ }
107
+ else{
108
+ selectedPrice = 0;
109
+ }
110
+ for(var i=0;i<element.options.length;i++){
111
+ if(element.options[i].config){
112
+ element.options[i].text = this.getOptionLabel(element.options[i].config, element.options[i].config.price-selectedPrice);
113
+ }
114
+ }
115
+ },
116
+
117
+ resetChildren : function(element){
118
+ if(element.childSettings) {
119
+ for(var i=0;i<element.childSettings.length;i++){
120
+ element.childSettings[i].selectedIndex = 0;
121
+ element.childSettings[i].disabled = true;
122
+ if(element.config){
123
+ this.state[element.config.id] = false;
124
+ }
125
+ }
126
+ }
127
+ },
128
+
129
+ fillSelect: function(element){
130
+ var attributeId = element.id.replace(/[a-z]*/, '');
131
+ var options = this.getAttributeOptions(attributeId);
132
+ this.clearSelect(element);
133
+ element.options[0] = new Option(this.config.chooseText, '');
134
+
135
+ var prevConfig = false;
136
+ if(element.prevSetting){
137
+ prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
138
+ }
139
+
140
+ if(options) {
141
+ var index = 1;
142
+ for(var i=0;i<options.length;i++){
143
+ var allowedProducts = [];
144
+ if(prevConfig) {
145
+ for(var j=0;j<options[i].products.length;j++){
146
+ if(prevConfig.config.allowedProducts
147
+ && prevConfig.config.allowedProducts.indexOf(options[i].products[j])>-1){
148
+ allowedProducts.push(options[i].products[j]);
149
+ }
150
+ }
151
+ } else {
152
+ allowedProducts = options[i].products.clone();
153
+ }
154
+
155
+ if(allowedProducts.size()>0){
156
+ options[i].allowedProducts = allowedProducts;
157
+ element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
158
+ element.options[index].config = options[i];
159
+ index++;
160
+ }
161
+ }
162
+ }
163
+ },
164
+
165
+ getOptionLabel: function(option, price){
166
+ var price = parseFloat(price);
167
+ if (this.taxConfig.includeTax) {
168
+ var tax = price / (100 + this.taxConfig.defaultTax) * this.taxConfig.defaultTax;
169
+ var excl = price - tax;
170
+ var incl = excl*(1+(this.taxConfig.currentTax/100));
171
+ } else {
172
+ var tax = price * (this.taxConfig.currentTax / 100);
173
+ var excl = price;
174
+ var incl = excl + tax;
175
+ }
176
+
177
+ if (this.taxConfig.showIncludeTax || this.taxConfig.showBothPrices) {
178
+ price = incl;
179
+ } else {
180
+ price = excl;
181
+ }
182
+
183
+ var str = option.label;
184
+ if(price){
185
+ if (this.taxConfig.showBothPrices) {
186
+ str+= ' ' + this.formatPrice(excl, true) + ' (' + this.formatPrice(price, true) + ' ' + this.taxConfig.inclTaxTitle + ')';
187
+ } else {
188
+ str+= ' ' + this.formatPrice(price, true);
189
+ }
190
+ }
191
+ return str;
192
+ },
193
+
194
+ formatPrice: function(price, showSign){
195
+ var str = '';
196
+ price = parseFloat(price);
197
+ if(showSign){
198
+ if(price<0){
199
+ str+= '-';
200
+ price = -price;
201
+ }
202
+ else{
203
+ str+= '+';
204
+ }
205
+ }
206
+
207
+ var roundedPrice = (Math.round(price*100)/100).toString();
208
+
209
+ if (this.prices && this.prices[roundedPrice]) {
210
+ str+= this.prices[roundedPrice];
211
+ }
212
+ else {
213
+ str+= this.priceTemplate.evaluate({price:price.toFixed(2)});
214
+ }
215
+ return str;
216
+ },
217
+
218
+ clearSelect: function(element){
219
+ for(var i=element.options.length-1;i>=0;i--){
220
+ element.remove(i);
221
+ }
222
+ },
223
+
224
+ getAttributeOptions: function(attributeId){
225
+ if(this.config.attributes[attributeId]){
226
+ return this.config.attributes[attributeId].options;
227
+ }
228
+ },
229
+
230
+ reloadPrice: function(){
231
+ var price = 0;
232
+ for(var i=this.settings.length-1;i>=0;i--){
233
+ var selected = this.settings[i].options[this.settings[i].selectedIndex];
234
+ if(selected.config){
235
+ price += parseFloat(selected.config.price);
236
+ }
237
+ }
238
+
239
+ optionsPrice.changePrice('config', price);
240
+ optionsPrice.reload();
241
+
242
+ return price;
243
+
244
+ if($('product-price-'+this.config.productId)){
245
+ $('product-price-'+this.config.productId).innerHTML = price;
246
+ }
247
+ this.reloadOldPrice();
248
+ },
249
+
250
+ reloadOldPrice: function(){
251
+ if ($('old-price-'+this.config.productId)) {
252
+
253
+ var price = parseFloat(this.config.oldPrice);
254
+ for(var i=this.settings.length-1;i>=0;i--){
255
+ var selected = this.settings[i].options[this.settings[i].selectedIndex];
256
+ if(selected.config){
257
+ price+= parseFloat(selected.config.price);
258
+ }
259
+ }
260
+ if (price < 0)
261
+ price = 0;
262
+ price = this.formatPrice(price);
263
+
264
+ if($('old-price-'+this.config.productId)){
265
+ $('old-price-'+this.config.productId).innerHTML = price;
266
+ }
267
+
268
+ }
269
+ }
270
+ }
271
+ function selectedAssocProductsImg(selectedAssocProduct) // passing associated image array here
272
+ {
273
+ if (selectedAssocProduct == null) return false;
274
+
275
+ var newselectedAssocProduct = new Array();
276
+ if (selectedAssocProduct.length == undefined) // push all data in new array if more than one images
277
+ {
278
+ for (var i in selectedAssocProduct)
279
+ newselectedAssocProduct.push(selectedAssocProduct[i]);
280
+ }
281
+ else
282
+ newselectedAssocProduct = selectedAssocProduct;
283
+
284
+ if (newselectedAssocProduct.length == 1) return false; // return false if array legth 1
285
+ var finalImgArray = new Array();
286
+ function eachAttribute(newselectedAssocProduct, iIndex, jIndex, JnextIndex)
287
+ {
288
+ if (iIndex == null) iIndex = 0;
289
+ if (jIndex == null) jIndex = 0;
290
+ if (JnextIndex == null) JnextIndex = newselectedAssocProduct[iIndex].length;
291
+ if (iIndex == newselectedAssocProduct.length - 1) return;
292
+ for (var i = jIndex; i < JnextIndex; i++)
293
+ {
294
+ if (finalImgArray.indexOf(newselectedAssocProduct[iIndex][i]) != -1) continue;
295
+ for (var j = 0; j < newselectedAssocProduct[iIndex + 1].length; j++)
296
+ {
297
+ if (newselectedAssocProduct[iIndex][i] != newselectedAssocProduct[iIndex+1][j]) continue;
298
+ eachAttribute(newselectedAssocProduct, iIndex + 1, j, j + 1);
299
+ if (iIndex + 1 == newselectedAssocProduct.length - 1) { finalImgArray.push(newselectedAssocProduct[iIndex][i]); break; }
300
+ }
301
+ }
302
+ }
303
+
304
+ eachAttribute(newselectedAssocProduct);
305
+ return finalImgArray;
306
+ }
307
+
package.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ColorSwicherModule</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Show dynamic associated product images while selecting configurable option(color-switcher)</summary>
10
+ <description>This is one of the magento most client required feature.
11
+ We can do it by many ways.After wasting my couple of days I found out one of easier and optimized way.
12
+ No need to add any extra attribute label or color or take care about images its work like charm.Code is fully dynamic.
13
+ It displays the image of that associated product is selected by us from drop down.</description>
14
+ <notes>Show dynamic associated product images while selecting configurable option(color-switcher)</notes>
15
+ <authors><author><name>saurab_chandra</name><user>auto-converted</user><email>magentoaccount@neevtech.com</email></author></authors>
16
+ <date>2013-01-11</date>
17
+ <time>13:29:40</time>
18
+ <contents><target name="mage"><dir name="app"><dir name="code"><dir name="local"><dir name="Neev"><dir name="ColorSwicher"><dir name="etc"><file name="config.xml" hash="23648bdc250b618e709eb6961afda68d"/></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="colorswicher.xml" hash="0dfc93397c585e9de3a916e49905b8ae"/></dir><dir name="template"><dir name="colorswicher"><dir name="page"><dir name="html"><file name="jshead.phtml" hash="6fbacdcffb88bbf42c8c309cdfc1b455"/></dir></dir><dir name="product"><file name="media.phtml" hash="0cc009bd2cbe1836519a8c9cd6cd8644"/><file name="view.phtml" hash="de48af8f436d0a6e4966bb869932f117"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Neev_ColorSwicher.xml" hash="e759ba8f15a4a0d0355732c6a6266692"/></dir></dir></dir><dir name="js"><dir name="varien"><file name="config.js" hash="1906edde63f02bcc8071b191456353ca"/></dir></dir></target></contents>
19
+ <compatible/>
20
+ <dependencies/>
21
+ </package>