Jump to content

On the fly PRICE Calculator (need to assign 3 variables)


Recommended Posts

Hello.

Coming back to customized product page for On the fly calculation of Length and Width.

1. There is a basic price of the item (in my case I consider it as price per 1 linear meter)

So I regestered a new function in init.php

$smarty->register_function('on_the_fly', array('Tools', 'displayPriceSmarty'));



I added new function in js/tools.js (not in themes/../js/ tools.js!) as follows:

function on_the_fly(formObj){
   var length = new Number(formObj.frameLength.value);
   var width = new Number(formObj.frameWidth.value);
   var basePrice = ((2 * length) + (2 * width))/100;
   var price = basePrice * MainPrice;
   formObj.total.value = price.toFixed(2); ;
}




Afterwords I made some changes in product.tpl as follows:

1. Adding new variable, so we can get BASE prive of the item

var MainPrice = '{$product->getPrice(true, $smarty.const.NULL)}'; 



2. Adding extra price (which is supposed to be Price for linear meter). In my case only has to work with certain categories! Changing class and id names seems to be important, so the attributes do not add on for this price.

<!--Linear meter price only for Marcos a medida-->
{if $category->id==8 || id==9 || id==10 || id==11 || id==12 || id==13 || id==14 || id==15 || id==16 || id==17}

  {l s='Metro lineal - '}
{if !$priceDisplay || $priceDisplay == 2}
{convertPrice price=$product->getPrice(true, $smarty.const.NULL)} 
{if $tax_enabled}{l s='tax incl.'}{/if}
{/if}  {/if}



3. Adding extra fields for Lengh and Width and Subtotal Price in the buy_block form

              <!-- on the fly calculator --> 
          {if $category->id==8 || id==9 || id==10 || id==11 || id==12 || id==13 || id==14 || id==15 || id==16 || id==17} 



{l s='Altura (cm):'}
       <input type="text" name="frameLength"><span class="medida_example">(Ej: 80.27)


{l s='Anchura (cm):'}
       <input type="text" name="frameWidth"><span class="medida_example">(Ej: 110.12)


{l s='Subtotal'}
       <input id="total" name="total" disabled="disabled" value=""/>


       {/if}
>



4. Moved Price with VAT after Attributes, so in my case it should work as TOTAL PRICE

<!-- final price -->   
  {l s='Precio total:'}
{if !$priceDisplay || $priceDisplay == 2}
{convertPrice price=$product->getPrice(true, $smarty.const.NULL)}
{if $tax_enabled}{l s='tax incl.'}{/if}
{/if} 



So now comes questions. Till now I get the result in

 <input id="total" name="total" disabled="disabled" value=""/> 



Till now it works correct. See the attachement print screen.

But now I need to use this result.

So, what is the best way to assign this result, frameWidth and frameLength as variable, so it can be used for further calculations? Because all attributes have to be added on the top of "Result price"

Is it Product.php (classes) which is responsable for formula calculations?

I need some help to continue.

29020_OWiUTvhbRKIGv02IyYm2_t

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...
  • 2 months later...
  • 2 months later...
  • 2 months later...
  • 2 months later...
  • 7 months later...

Hello it looks like you very understand this. I need simple thing - to display only base price on product-list.tpl, now it calculated like this: base price + attribute price impact, wich is bad...

 

Can you help me please? I can send some money to your Paypal if it will works, but I am student, so I cant afford to much :) It would be very kind from you to help me...

 

Thanks

Link to comment
Share on other sites

  • 10 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...