Author Topic: Price Updater  (Read 13895 times)

Macchiato

  • Beginner
  • *
  • Posts: 43
Price Updater
« on: September 21, 2011, 12:57:56 pm »
The Price Updater will automatically add the product price and all attribute prices together and display the total amount. The Price Updater was tested in Joomla 1.5.23 with VirtueMart 1.1.9, I have used the Ja Larix template, but the Price Updater should work in any other version and template, cause it's an standalone script and it's not version dependent.

Follow the steps to implement the Price Updater:


--- STEP 1 ---
Make sure you have the decimal symbol set to period/dot (.) and the thousands separator set to comma (,)
You can change these by going to the backend of Joomla, then select Components --> VirtueMart --> Store --> Edit Store. Below "Currency Display Style" change the decimal symbol to period/dot (.) and the thousands separator to comma (,)


--- STEP 2 ---
Open: /components/com_virtuemart/themes/default/templates/common/price.tpl.php

and replace:
Code: [Select]
<?php
if( !empty( $price_info["product_price_id"] )) { ?>

<span class="productPrice">
<?php echo $CURRENCY_DISPLAY->getFullValue($base_price?>
<?php echo $text_including_tax ?>
</span>
<?php
}
echo 
$price_table;
?>


with:
Code: [Select]
<?php
if( !empty( $price_info["product_price_id"] )) { ?>

<span class="productPrice">
      <p id="priceUpdater-Price"><?php echo $CURRENCY_DISPLAY->getFullValue($base_price?><?php echo $text_including_tax ?></p>
</span>

<?php } echo $price_table?>


--- STEP 3 ---
Open: /components/com_virtuemart/themes/"your template name"/templates/product_details/flypage.tpl.php

and replace:
Code: [Select]
<tr>
  <td colspan="3"><?php echo $product_type ?></td>
</tr>

with:
Code: [Select]
<tr>
  <td colspan="3"><?php echo $product_type ?></td>
</tr>
<tr>
  <td></td>
  <td align="right" style="border:solid 1px #cccccc;border-right:none;">
        <p>Product Price:</p>
        <p>Attributes Price:</p>
        <p style="font-weight:bold;font-size:110%;background-color:#efefef;">Total:</p>
  </td>
  <td align="left" style="border:solid 1px #cccccc;border-left:none;">
        <p id="priceUpdater-duplicatePrice">$0.00</p>
        <p id="priceUpdater-attributesPrice">$0.00</p>
        <p id="priceUpdater-totalPrice" style="font-weight:bold;font-size:110%;background-color:#efefef;">$0.00</p>
  </td>
</tr>

If you do not use Ja Larix, insert the following code anywhere you like in flypage.tpl.php:
Code: [Select]
<tr>
  <td></td>
  <td align="right" style="border:solid 1px #cccccc;border-right:none;">
        <p>Product Price:</p>
        <p>Attributes Price:</p>
        <p style="font-weight:bold;font-size:110%;background-color:#efefef;">Total:</p>
  </td>
  <td align="left" style="border:solid 1px #cccccc;border-left:none;">
        <p id="priceUpdater-duplicatePrice">$0.00</p>
        <p id="priceUpdater-attributesPrice">$0.00</p>
        <p id="priceUpdater-totalPrice" style="font-weight:bold;font-size:110%;background-color:#efefef;">$0.00</p>
  </td>
</tr>


--- STEP 4 ---
Open: /components/com_virtuemart/themes/"your template name"/templates/product_details/includes/addtocart_form.tpl.php

to make this step more easier, replace the whole page with this code:
Code: [Select]
<?php if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); ?>

<div class="vmCartContainer">
   
<?php
mm_showMyFileName
(__FILE__);
// This function lists all product children ( = Items)
// or, when not children are defined, the product_id
// SO LEAVE THIS IN HERE!
list($html,$children) = $ps_product_attribute->list_attribute( ( $product_parent_id )  ? $product_parent_id $product_id );

if (
$children != "multi") { 

    if( 
CHECK_STOCK == '1' && ( $product_in_stock ) ) {
     
$notify true;
    } else {
    
$notify false;
    }

?>


    <!-- Add to Cart Form -->
    <form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="<?php echo uniqid('addtocart_'?>" class="addtocart_form" <?php if( $this->get_cfg'useAjaxCartActions') && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>

      <!-- Add to Cart and Attribute List Items -->
      <fieldset id="priceUpdater">
     
        <?php 
        
if ($children == "drop") { 
            echo 
$ps_product_attribute->show_quantity_box($product_id,$product_id);
        } 
        if (
$children == "radio") {
            echo 
$ps_product_attribute->show_radio_quantity_box();
        }
        
$button_lbl $VM_LANG->_('PHPSHOP_CART_ADD_TO');
        
$button_cls 'addtocart_button';
if( CHECK_STOCK == '1' && ( $product_in_stock 1) ) {
            
$button_lbl $VM_LANG->_('VM_CART_NOTIFY');
            
$button_cls 'notify_button';
        }
        
?>
   
        <input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
   
        <!-- Attribute List Items -->
        <?php
        
}
        echo 
$html;
        
        if (
USE_AS_CATALOGUE != '1' && $product_price != "" && !stristr$product_price$VM_LANG->_('PHPSHOP_PRODUCT_CALL') )) {
        
?>

        <?php if ($children != "multi") { ?>
        <!-- End Attribute List Items -->
   
      </fieldset><!-- End Add to Cart and Attribute List Items -->
 
     
      <?php  ?>   
      <input type="hidden" name="flypage" value="shop.<?php echo $flypage ?>" />
      <input type="hidden" name="page" value="shop.cart" />
      <input type="hidden" name="manufacturer_id" value="<?php echo $manufacturer_id ?>" />
      <input type="hidden" name="category_id" value="<?php echo $category_id ?>" />
      <input type="hidden" name="func" value="cartAdd" />
      <input type="hidden" name="option" value="<?php echo $option ?>" />
      <input type="hidden" name="Itemid" value="<?php echo $Itemid ?>" />
      <input type="hidden" name="set_price[]" value="" />
      <input type="hidden" name="adjust_price[]" value="" />
      <input type="hidden" name="master_product[]" value="" />
     
      <?php } if ($children != "multi") { ?>

</form><!-- End Add to Cart Form -->


<?php 

    if(
$children == "radio") { ?>

   
    <script language="JavaScript" type="text/javascript">//<![CDATA[
    function alterQuantity(myForm) {
        for (i=0;i<myForm.selItem.length;i++){
            setQuantity = myForm.elements['quantity'];
            selected = myForm.elements['selItem'];
            j = selected[i].id.substr(7);
            k= document.getElementById('quantity' + j);
            if (selected[i].checked==true){
                k.value = myForm.quantity_adjust.value; }
            else {
                k.value  = 0;
            }
        }
    }
//]]>   
</script>
<?php ?>

</div>


For those of you who use a custom code: you only have to add <fieldset id="priceUpdater"> to the page (don't forget to close </fieldset>) Please look at the code above to see where you can place it.


--- STEP 5 ---
For the final step, you copy the following Javascript code and place it in a external Javascript document, let's call the document "price-updater.js".
Place "price-updater.js" in your template's script directory (/templates/"your template name"/scripts)

Code: [Select]
/*------------------------------------------------------------------------
## Price Updater v1 by Macchiato
-------------------------------------------------------------------------*/

function getAmountAndPutInElement(id) {
  var checkForThisID = document.getElementById(id);
  var getAmountSelects = checkForThisID.getElementsByTagName("select"),
  L = getAmountSelects.length,
  i;
 
  for (i = 0; i < L; i++) {
  getAmountSelects[i].onchange = calcTotal;
  }
 
  function calcTotal() {
  var totalEl = document.getElementById("priceUpdater-attributesPrice"),
  totalVal = 0,
  getAmountSelects = checkForThisID.getElementsByTagName("select");
 
  for (var x=0, y=getAmountSelects.length; x<y; x++) {
  var index = getAmountSelects[x].selectedIndex;
  if (index) {
  var value = getAmountSelects[x].options[index].text;
  value = value.substring(value.search(/[(]\+[$]/)+3, value.length-1);
  value = value.replace(/,/g, '');
  totalVal += Number(value);
  }
  }
  totalEl.innerHTML = addCommasandsign(totalVal.toFixed(2));
  addAmountsAndPutInElement("priceUpdater-Price");
  }
}
getAmountAndPutInElement("priceUpdater");


function getTextAndPutInElement(id) {
    var source = document.getElementById(id);
    var target = document.getElementById("priceUpdater-duplicatePrice");
    target.innerHTML = source.innerHTML;
}
getTextAndPutInElement("priceUpdater-Price");


function addCommasandsign(nStr) {
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
  x1 = x1.replace(rgx, '$1' + ',' + '$2');
  }
  return '$' + x1 + x2;
}


function addAmountsAndPutInElement(id) {
  var firstval=document.getElementById(id).innerHTML;
  var secval=document.getElementById('priceUpdater-attributesPrice').innerHTML;
  firstval=firstval.replace('$','');
  firstval=firstval.replace(',','');
  secval=secval.replace('$','');
  secval=secval.replace(',','');
  var totalOne=parseFloat(firstval) + parseFloat(secval);
  var totalTwo=addCommasandsign(totalOne.toFixed(2));
  document.getElementById('priceUpdater-totalPrice').innerHTML=totalTwo;
}
addAmountsAndPutInElement("priceUpdater-Price");


Now place the following line at the bottom of /components/com_virtuemart/themes/"your template name"/templates/product_details/flypage.tpl.php :

<script type="text/javascript" src="templates/"your template name"/scripts/price-updater.js"></script>


That's it :)


P.S. Please post if it works for you, and what Joomla/VirtueMart version and template you are using.
Currently using Joomla 1.5.23 and VirtueMart 1.1.9

"Take a seat and have a coffee." -- Macchiato

tutnet

  • Beginner
  • *
  • Posts: 23
Re: Price Updater
« Reply #1 on: September 28, 2011, 08:27:10 am »
Hi,

I have this working in J1.5.23 with VM 1.1.6 - great mod!

There is however one glitch - it only works with $ as the currency.

I have tried swapping in &euro; and € into price-updater.js without any luck.

Any ideas how to make this work with Euros?

Thans

strdesign

  • Beginner
  • *
  • Posts: 23
Re: Price Updater
« Reply #2 on: September 30, 2011, 15:57:06 pm »
Hi Macchiato;  do you have a demo for your Price Updater add-on?
thanks,
Lewis

Macchiato

  • Beginner
  • *
  • Posts: 43
Re: Price Updater
« Reply #3 on: October 14, 2011, 22:44:27 pm »
Hi,

I have this working in J1.5.23 with VM 1.1.6 - great mod!

There is however one glitch - it only works with $ as the currency.

I have tried swapping in &euro; and € into price-updater.js without any luck.

Any ideas how to make this work with Euros?

Thans

Hi Tutnet,

Have you also changed the $ sign to € in flypage.tpl.php?
I haven't tried this with the euro sign yet, but I'm pretty sure you only have to change all the $ signs in the above php and javascript files.
You also need to change the $ sign to € in the VirtueMart configuration and you need to use a dot (0.00) instead of a comma (0,00) for the price format.

Hope this helps and thanks for trying my mod :)
Currently using Joomla 1.5.23 and VirtueMart 1.1.9

"Take a seat and have a coffee." -- Macchiato

Macchiato

  • Beginner
  • *
  • Posts: 43
Re: Price Updater
« Reply #4 on: October 14, 2011, 22:48:58 pm »
Hi Macchiato;  do you have a demo for your Price Updater add-on?
thanks,
Lewis

No not yet, will try to make one in the (near) future... if I have more free time ;)
Currently using Joomla 1.5.23 and VirtueMart 1.1.9

"Take a seat and have a coffee." -- Macchiato

cristi

  • Beginner
  • *
  • Posts: 17
    • Custom Window Treatments
Re: Price Updater
« Reply #5 on: October 15, 2011, 01:13:36 am »
has anyone use this with custom attribute hack? dose it work with it?

tutnet

  • Beginner
  • *
  • Posts: 23
Re: Price Updater
« Reply #6 on: October 15, 2011, 14:39:58 pm »

Hi Tutnet,

Have you also changed the $ sign to € in flypage.tpl.php?
I haven't tried this with the euro sign yet, but I'm pretty sure you only have to change all the $ signs in the above php and javascript files.
You also need to change the $ sign to € in the VirtueMart configuration and you need to use a dot (0.00) instead of a comma (0,00) for the price format.

Hope this helps and thanks for trying my mod :)

Hi Macchiato,

I had to change the code for the Euro to "u20AC"  which is the unicode that corresponds to €.  So the price-updater.js  file now looks like this:
Code: [Select]
/*------------------------------------------------------------------------
## Price Updater v1 by Macchiato
-------------------------------------------------------------------------*/

function getAmountAndPutInElement(id) {
  var checkForThisID = document.getElementById(id);
  var getAmountSelects = checkForThisID.getElementsByTagName("select"),
  L = getAmountSelects.length,
  i;
 
  for (i = 0; i < L; i++) {
  getAmountSelects[i].onchange = calcTotal;
  }
 
  function calcTotal() {
  var totalEl = document.getElementById("priceUpdater-attributesPrice"),
  totalVal = 0,
  getAmountSelects = checkForThisID.getElementsByTagName("select");
 
  for (var x=0, y=getAmountSelects.length; x<y; x++) {
  var index = getAmountSelects[x].selectedIndex;
  if (index) {
  var value = getAmountSelects[x].options[index].text;
  value = value.substring(value.search(/[(]\+[\u20AC]/)+3, value.length-1);
  value = value.replace(/,/g, '');
  totalVal += Number(value);
  }
  }
  totalEl.innerHTML = addCommasandsign(totalVal.toFixed(2));
  addAmountsAndPutInElement("priceUpdater-Price");
  }
}
getAmountAndPutInElement("priceUpdater");


function getTextAndPutInElement(id) {
    var source = document.getElementById(id);
    var target = document.getElementById("priceUpdater-duplicatePrice");
    target.innerHTML = source.innerHTML;
}
getTextAndPutInElement("priceUpdater-Price");


function addCommasandsign(nStr) {
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
  x1 = x1.replace(rgx, '\u20AC1' + ',' + '\u20AC2');
  }
  return '\u20AC' + x1 + x2;
}


function addAmountsAndPutInElement(id) {
  var firstval=document.getElementById(id).innerHTML;
  var secval=document.getElementById('priceUpdater-attributesPrice').innerHTML;
  firstval=firstval.replace('\u20AC','');
  firstval=firstval.replace(',','');
  secval=secval.replace('\u20AC','');
  secval=secval.replace(',','');
  var totalOne=parseFloat(firstval) + parseFloat(secval);
  var totalTwo=addCommasandsign(totalOne.toFixed(2));
  document.getElementById('priceUpdater-totalPrice').innerHTML=totalTwo;
}
addAmountsAndPutInElement("priceUpdater-Price");


Great hack!!!
Tutnet

useris

  • Jr. Member
  • **
  • Posts: 224
Re: Price Updater
« Reply #7 on: November 10, 2011, 20:23:50 pm »
Hi Macchiato ,

Thank you for creating this mod but it does not work for me. When I select attibute property, attribute price and total becomes like this:
Code: [Select]
Attributes Price:

Total:
 $136 16

$NaN

 
Where could be a problem?

amthucgiaitri

  • Beginner
  • *
  • Posts: 4
Re: Price Updater
« Reply #8 on: November 24, 2011, 05:30:56 am »
Hi Macchiato,

I followed your intructions but nothing happen. In the source code, it load the javascript file too. Could you figure out what i miss.

Thanks a lot, man

themiffs

  • Beginner
  • *
  • Posts: 4
Re: Price Updater
« Reply #9 on: November 29, 2011, 10:35:31 am »
I also couldn't get it to work, i re did the entire hack as per the steps 3 times but nothing showed up on any page i was using J.15 and virtuemart 1.1.9

I would love to get it working it sounds like a great hack

Thanks

CHUI

  • Beginner
  • *
  • Posts: 1
Re: Price Updater
« Reply #10 on: February 02, 2012, 00:36:20 am »
This Price Updater is brilliant for me and worked really great! Thank you for this free modification, Macchiato!
I made some little changes in this code but one question is seemed to be hard to implement for me. I'm talking about possibility to hide the extra cost (+$ 900.00), what is mentioned in parentheses becomes not important anymore. This looks ugly now for me and annoying for customer who clicked the dropdown box and see this strange information while Price Updater already calculated a new price including his choice. I tried to implement this in many ways, but failed. I think that this opportunity is the last thing that should be done for Price Updater to become fully implemented needful solution. Hope someone will help! Thanks!

Macchiato

  • Beginner
  • *
  • Posts: 43
Re: Price Updater
« Reply #11 on: April 03, 2012, 11:43:29 am »
Hi Macchiato,

I had to change the code for the Euro to "u20AC"  which is the unicode that corresponds to €.


That's even better, good job! :)
Currently using Joomla 1.5.23 and VirtueMart 1.1.9

"Take a seat and have a coffee." -- Macchiato

Macchiato

  • Beginner
  • *
  • Posts: 43
Re: Price Updater
« Reply #12 on: April 03, 2012, 11:57:28 am »
This Price Updater is brilliant for me and worked really great! Thank you for this free modification, Macchiato!
I made some little changes in this code but one question is seemed to be hard to implement for me. I'm talking about possibility to hide the extra cost (+$ 900.00), what is mentioned in parentheses becomes not important anymore. This looks ugly now for me and annoying for customer who clicked the dropdown box and see this strange information while Price Updater already calculated a new price including his choice. I tried to implement this in many ways, but failed. I think that this opportunity is the last thing that should be done for Price Updater to become fully implemented needful solution. Hope someone will help! Thanks!

Sorry for the late reply. This is possible, but I cannot show you how to do this right now, I'm swamped with work, and this will not change for a while :(
Currently using Joomla 1.5.23 and VirtueMart 1.1.9

"Take a seat and have a coffee." -- Macchiato

Flexes

  • Beginner
  • *
  • Posts: 4
    • mdma
Re: Price Updater
« Reply #13 on: April 08, 2012, 22:10:52 pm »
Hi Macchiato,

I had to change the code for the Euro to "u20AC"  which is the unicode that corresponds to €.

thanks
mdma evil!
I teach English

hermit69

  • Beginner
  • *
  • Posts: 1
Re: Price Updater
« Reply #14 on: July 27, 2012, 23:13:30 pm »
Thank You it is a brilliant script!
I've only one issue - it works with curency format: Symb00, but I need to get it work with format: 00Symb. Is it possibile? Any idea where sholuld I search, what should I modify to get it work?
Best regards Chris