user1573532 user1573532 - 5 months ago 18
PHP Question

Magento shopping Cart - Dynamic pricing

Basically I am web designer. I am a newbie to magento CMS. I am involved in a new magento ecommerce project.

I want to make a dynamic pricing in my products page.

In my site I am selling curtain cloth so i want dynamic billing to be like


user can give width and height of a particular product
I have a fixed price for sq.ft. I need to multiply width and height provided by the user to get a square feet value.


For example please refer this link.

Reference site Url: http://www.woodyattcurtains.com/net-curtains-voiles-c2/net-curtains-c3/ellie-white-net-curtains-p3

I want my product page exactly like this. I had searched many extensions in magento for easily achieving this result. But was unlucky.
Is there any free extensions in magento to achieve this? Or else, please guide me to develop this result through any sort of coding.

Answer

Just add this piece of code in your

app/design/frontend/default/[template_NAME]/template/catalog/product/view.phtml file I had add two new fields for width & height Just like this

<label for="height"><?php echo "Height" ?></label>
            <input type="text" name="height" id="height" maxlength="30" value="1" title="<?php echo 'Height' ?>" class="input-text" />
            <label for="width"><?php echo "Width" ?></label>
            <input type="text" name="width" id="width" maxlength="30" value="1" title="<?php echo 'Width' ?>" class="input-text" />

Also add these php code

<?php  $br_special_price = $_product->getSpecialPrice(); 
    $br_old_price = $_product->getPrice(); 
    $an_id = $_product->getId(); 

$special_priceID="product-price-".$an_id;

$old_priceID="old-price-".$an_id;
?>

Also this script at the end of the file

<script type="text/javascript">
var mq= 0;
function respondToChange(event) {
mq= Math.ceil($('width').getValue() * $('height').getValue() * <?php echo $br_special_price;?> );
document.getElementById('<?php echo $special_priceID; ?>').innerHTML = '&#163; &nbsp;'+mq;
 mq1= Math.ceil($('width').getValue() * $('height').getValue() * <?php echo $br_old_price;?>);
 document.getElementById('<?php echo $old_priceID; ?>').innerHTML = '&#163; &nbsp;'+mq1;
}
$('width').observe('change', respondToChange);
$('height').observe('change', respondToChange); 
</script>

There is a problem in this code. you can able to get prices reflected in all product pages. But you can't pass these updated special price to cart. Older values will be reflected in cart. Hope anyone update this code.