Floating Price for Product Configurator

If you are using a vertical configurator that scrolls, this mod will have the price and quantity float up/down as you scroll up/down so the end user can always see the price as they customize the product’s configuration. This was tested for New Vision Blue skin. Sample





Step 1: Create a javascript file with the code below called windowFloat.js and put it in /store/classes/scripts



var floatingMenuId = 'floatdiv';
var floatingMenu =
{
targetX: 630,
targetY: 300,

hasInner: typeof(window.innerWidth) == 'number',
hasElement: document.documentElement
&& document.documentElement.clientWidth,

menu:
document.getElementById
? document.getElementById(floatingMenuId)
: document.all
? document.all[floatingMenuId]
: document.layers[floatingMenuId]
};

floatingMenu.move = function ()
{
if (document.layers)
{
floatingMenu.menu.left = floatingMenu.nextX;
floatingMenu.menu.top = floatingMenu.nextY;
}
else
{
floatingMenu.menu.style.left = floatingMenu.nextX + 'px';
floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
}
}

floatingMenu.computeShifts = function ()
{
var de = document.documentElement;

floatingMenu.shiftX =
floatingMenu.hasInner
? pageXOffset
: floatingMenu.hasElement
? de.scrollLeft
: document.body.scrollLeft;
if (floatingMenu.targetX < 0)
{
if (floatingMenu.hasElement && floatingMenu.hasInner)
{
// Handle Opera 8 problems
floatingMenu.shiftX +=
de.clientWidth > window.innerWidth
? window.innerWidth
: de.clientWidth
}
else
{
floatingMenu.shiftX +=
floatingMenu.hasElement
? de.clientWidth
: floatingMenu.hasInner
? window.innerWidth
: document.body.clientWidth;
}
}

floatingMenu.shiftY =
floatingMenu.hasInner
? pageYOffset
: floatingMenu.hasElement
? de.scrollTop
: document.body.scrollTop;
if (floatingMenu.targetY < 0)
{
if (floatingMenu.hasElement && floatingMenu.hasInner)
{
// Handle Opera 8 problems
floatingMenu.shiftY +=
de.clientHeight > window.innerHeight
? window.innerHeight
: de.clientHeight
}
else
{
floatingMenu.shiftY +=
floatingMenu.hasElement
? document.documentElement.clientHeight
: floatingMenu.hasInner
? window.innerHeight
: document.body.clientHeight;
}
}
}

floatingMenu.doFloat = function()
{
var stepX, stepY;

floatingMenu.computeShifts();

stepX = (floatingMenu.shiftX +
floatingMenu.targetX - floatingMenu.nextX) * .07;
if (Math.abs(stepX) < .5)
{
stepX = floatingMenu.shiftX +
floatingMenu.targetX - floatingMenu.nextX;
}

stepY = (floatingMenu.shiftY +
floatingMenu.targetY - floatingMenu.nextY) * .07;
if (Math.abs(stepY) < .5)
{
stepY = floatingMenu.shiftY +
floatingMenu.targetY - floatingMenu.nextY;
}

if (Math.abs(stepX) > 0 ||
Math.abs(stepY) > 0)
{
floatingMenu.nextX += stepX;
floatingMenu.nextY += stepY;
floatingMenu.move();
}

setTimeout('floatingMenu.doFloat()', 20);
};

// addEvent designed by Aaron Moore
floatingMenu.addEvent = function(element, listener, handler)
{
if(typeof element[listener] != 'function' ||
typeof element[listener + '_num'] == 'undefined')
{
element[listener + '_num'] = 0;
if (typeof element[listener] == 'function')
{
element[listener + 0] = element[listener];
element[listener + '_num']++;
}
element[listener] = function(e)
{
var r = true;
e = (e) ? e : window.event;
for(var i = element[listener + '_num'] -1; i >= 0; i--)
{
if(element[listener + i](e) == false)
r = false;
}
return r;
}
}

//if handler is not already stored, assign it
for(var i = 0; i < element[listener + '_num']; i++)
if(element[listener + i] == handler)
return;
element[listener + element[listener + '_num']] = handler;
element[listener + '_num']++;
};

floatingMenu.init = function()
{
floatingMenu.initSecondary();
floatingMenu.doFloat();
};

// Some browsers init scrollbars only after
// full document load.
floatingMenu.initSecondary = function()
{
floatingMenu.computeShifts();
floatingMenu.nextX = floatingMenu.shiftX +
floatingMenu.targetX;
floatingMenu.nextY = floatingMenu.shiftY +
floatingMenu.targetY;
floatingMenu.move();
}

if (document.layers)
floatingMenu.addEvent(window, 'onload', floatingMenu.init);
else
{
floatingMenu.init();
floatingMenu.addEvent(window, 'onload',
floatingMenu.initSecondary);
}




Step 2: Then in the /store/skins//customer/product_pages/products_details.tpl



Replace





with

```php {if $product.product_type == ‘C’ && $product.price != 0}



{else}

{/if} ```


Step 3: Then right above:
```php


```

Add
```php {if $product.product_type == 'C' && $product.price != 0}


{/if}
```

Looks good, Thanks whiplash13.

Looks good but I hate such things :slight_smile:

I actually agree with you but it’s even more annoying to have to keep scrolling up to see the adjusted price when you have a long list of options to a product.

Great mod, exactly what i need except for one thing.



Let me explain:

When i apply this mod the review stars, price and product options appear in the floating box making it a bit on the large side.



Is there any way of changing the code so that just he price and nothing else appears in the floating box?



It would also be great to leave the price in its original place also.



If one of you great coders can help me with this it would be greatly appreciated.



Thanks,

Aleks

I am looking into this as it has to do with the update of a span called original_price_`$product.product_id’. This is also refereced in compatabilities.js under addons/product_cofigurator but haven’t figured out how to get it to work. You would need to create a new span with a new name and reference the new_price variable as it is for original_price in compatabilities.js but haven’t had any luck getting it to work. Anyone have any ideas? Code I believe that drives the update of the price is below:



In product_details.tpl

{if $product.list_price > $product.price && !($settings.Addons.product_configurator == 'Y' && $product.product_type == 'C')}{$lang.our_price}{else}{$lang.price}{/if}: {include file="common_templates/price.tpl" value=$product.price span_id="original_price_`$product.product_id`" class="price"}



in compatabilities.js

new_price = parseFloat(fn_format_price(new_price, decplaces));
var alt_price = parseFloat(fn_format_price(new_price / currencies.secondary.coefficient, decplaces));

var tx_price = new_price;
var alt_tx_price = alt_price;
// Original currency
if (document.getElementById('original_price_' + id)) {
document.getElementById('original_price_' + id).innerHTML = fn_format_num(new_price, 2, true);
}

hi,



why not a drop down for each line of options? you could get at least 10 and still have the price showing.



i am trying to figure out how to do this for cs cart 2.0, but

am drowning instead.



beginprinting.com



mickeymouse1000