News:

Support the VirtueMart project and become a member

Main Menu

Price for surface new feature

Started by Il_maca, February 21, 2012, 22:12:45 PM

Previous topic - Next topic

Il_maca

Hi, i don't know if this issue is already proposed... is possible add an option for the price per surface? e.g. 3€ at swuare meters...and add a control for the surface or 2 spin for height and width...it's very important feature. It is relatively simple to implement...

2maz

#1
Hi developers, same need here. You all know the converted custom attributes extended who include a price calculation per surface. (width field X lenght field= new calculated price for the surface). The code is allready and many users are waiting for this basic function. So why don't you integrate it in this new release. This hack works only with 1.1 versions of Virtuemart.
http://forum.virtuemart.net/index.php?topic=93745.0
http://forum.virtuemart.net/index.php?topic=39666.0
Unfortunatly I'm not a PHP programmer but maybe some of you will find the next link useful for intergration in version 2.0:
http://forum.virtuemart.net/index.php?topic=97737.msg322148#msg322148
Thanks.

Studio 42

HI,
It's a good idea, and we want to do something so.
But want do it better. Using Product price or variante price with %-+
eg +10%,-5,+0.40 ...
and ops using the variant or product price ...

Il_maca

Hello, I apologize if I could not answer quickly! The hack linked is in theory very effective, but it works fine only with the default template! So, i made a custom hack very simple:
1. first, add a new custom attributes, called e.g. Meters
2. modify the "addtocart_custom_attribute.tpl.php" adding a new if statement that control the name of the field (this is setted in the page of product, in admin). If the statement is true (if the name of the field is Meters) make 2 fields with unique id (height and width) and a hidden field with the unique id of meters.
3. Adding javascript function to controls the fields and write in the meters field a value to show in the cart.
this is an example of code, in  "addtocart_custom_attribute.tpl.php"

foreach($attributes as $attribute){
    foreach( $attribute as $attr => $val ) {
        // Using this we make all the variables available in the template
        // translated example: $this->set( 'product_name', $product_name );
        $this->set( $attr, $val );
    }
if (strtolower($attribute['title'])=="dimensione"){
echo "<br><fieldset style='width:150px;'><legend style='text-align:left'>Dimensione: </legend>";
?>
<!--Altezza-->
<div style="position:relative;clear:both;left:12px;">
<div class="vmAttribChildDetail" style="text-align:left; margin: 3px;"><label for="Altezza_field">Altezza: </label></div>
<div class="vmAttribChildDetail" style="text-align:left; margin:3px;">
cm
<input type="text" class="inputboxquantity" size="4" id="Altezza_field" name="<?php echo "Altezza".$attribute['product_id'?>" value="<?php echo $min*100?>" onkeyup="lesschar('Altezza_field')" maxlength="4"/>
</div>
<input type="hidden" name="custom_attribute_fields[]" value="<?php echo "Altezza".$attribute['product_id'?>" />
<input type="hidden" name="custom_attribute_fields_check[<?php echo "Altezza".$attribute['product_id'?>]" value="<?php echo md5($mosConfig_secret"Altezza".$attribute['product_id'] ) ?>" />
</div>

<!--Larghezza-->
<div style="position:relative;clear:both;left:12px;">
<div class="vmAttribChildDetail" style="text-align:left; margin: 3px;"><label for="Larghezza_field">Larghezza: </label></div>


<div class="vmAttribChildDetail" style="text-align:left; margin:3px;">
cm
<input type="text" class="inputboxquantity" size="4" id="Larghezza_field" name="<?php "Larghezza".$attribute['product_id'?>" value="<?php echo $min*100?>" onkeyup="lesschar('Larghezza_field')" maxlength="4"/>
</div>
<input type="hidden" name="custom_attribute_fields[]" value="<?php echo "Larghezza".$attribute['product_id'?>" />
<input type="hidden" name="custom_attribute_fields_check[<?php echo "Larghezza".$attribute['product_id'?>]" value="<?php echo md5($mosConfig_secret"Larghezza".$attribute['product_id'] ) ?>" />
</div>


<input type="hidden" class="inputboxattrib" id="<?php echo $attribute['titlevar'?>_field" size="30" name="<?php echo $attribute['titlevar'].$attribute['product_id'?>" />
</fieldset>
<br>
<!--Quantità-->
<div style="position:relative;clear:both;left:12px;">
<div class="vmAttribChildDetail" style="text-align:left; margin: 3px;"><label for="Quantità_field">Quantità: </label></div>
<div class="vmAttribChildDetail" style="text-align:left; margin:3px;">
<input type="text" class="inputboxquantity" size="4" id="Quantità_field" name="<?php echo "Quantità".$attribute['product_id'?>" value="1" onkeyup="lesschar('Quantità_field')" maxlength="4"/>
</div>
<input type="hidden" name="custom_attribute_fields[]" value="<?php echo "Quantità".$attribute['product_id'?>" />
<input type="hidden" name="custom_attribute_fields_check[<?php echo "Quantità".$attribute['product_id'?>]" value="<?php echo md5($mosConfig_secret"Quantità".$attribute['product_id'] ) ?>" />
</div>
<script type='text/javascript'>
window.onload=function(){
var misure = "Quantità: " + document.getElementById('Quantità_field').value +" - Altezza: " + document.getElementById('Altezza_field').value +" cm - Larghezza: " + document.getElementById('Larghezza_field').value +" cm";
Document.getElementById('<?php echo $attribute['titlevar'?>_field').value = misure;
}

function lesschar(id){
var val = document.getElementById(id);
var valv = val.value;
valv = valv.replace(/[^0-9]/gi, "");
if (isNaN(valv) || !valv) valv = 1;
else if (valv > 0) valv = parseInt(valv,10);
val.value = valv;
var qnt = document.getElementById('Quantità_field');
var height = document.getElementById('Altezza_field');
var width = document.getElementById('Larghezza_field');
var tot = document.getElementById('quantity<?php echo $attribute['product_id'?>');

tot.value = (parseInt(qnt.value, 10) * parseInt(height.value, 10) * parseInt(width.value, 10)) / 10000;

var misure = "Quantità: " + parseInt(qnt.value, 10) +" - Altezza: " + parseInt(height.value, 10) +" cm - Larghezza: " + parseInt(width.value, 10) +" cm";
Document.getElementById('<?php echo $attribute['titlevar'?>_field').value = misure;
}
</script>
}else ...

Il_maca

This is a very easy feature to implement, but is very powerful. With the same idea, I resolved the problem of multi sizes of product, in the same order... this is feature to implement in virtuemart! I apologize for my bad english and I hope to be helpful