jquery - Trying to show the total price of a grouped product in view page simultaneously on selection of qty in Magento -
i'm try display total price of grouped product on selection of quantities, simultaneously updates price in total shown in picture. issue i'm facing is, i'm able see updated total price. price value not appropriate. , considering 1 item price i.e; price remains same , and calculating total price. please me, how can this. in advance:)
and code below;
<table class="data-table grouped-items-table" id="super-product-table"> <col /> <col /> <col width="1" /> <thead> <tr> <th><?php echo $this->__('product name') ?></th> <?php if ($this->getcanshowproductprice($_product)): ?> <th class="a-right"><?php echo $this->__('price') ?></th> <?php endif; ?> <?php if ($_product->issaleable()): ?> <th class="a-center"><?php echo $this->__('qty') ?></th> <?php endif; ?> </tr> </thead> <tbody> <?php if ($_hasassociatedproducts): ?> <?php foreach ($_associatedproducts $_item): ?> <?php $_finalpriceincltax = $this->helper('tax')->getprice($_item, $_item->getfinalprice(), true) ?> <tr> <td><?php echo $this->escapehtml($_item->getname()) ?></td> <?php if ($this->getcanshowproductprice($_product)): ?> <td class="a-right"> <?php if ($this->getcanshowproductprice($_item)): ?> <?php echo $this->getpricehtml($_item, true) ?> <?php echo $this->gettierpricehtml($_item) ?> <?php endif; ?> </td> <?php endif; ?> <?php if ($_product->issaleable()): ?> <td class="a-center"> <?php if ($_item->issaleable()) : ?> <input type="text" name="super_group[<?php echo $_item->getid() ?>]" maxlength="12" value="<?php echo $_item->getqty()*1 ?>" title="<?php echo $this->__('qty') ?>" class="txt" /> <input type="hidden" name="myprice" maxlength="12" id="myprice" value="<?php echo $_item->getprice() ?>" title="<?php echo $this->__('') ?>" class="myprice" /> <?php else: ?> <p class="availability out-of-stock"><span><?php echo $this->__('out of stock') ?></span></p> <?php endif; ?> </td> <?php endif; ?> <tr><div class="myprice" style="display:none;"><?php echo $_item->getprice() ?></div></tr> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="<?php if ($_product->issaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('no options of product available.') ?></td> </tr> <?php endif; ?> <tr id="summation"> <td> </td> <td align="right"><strong style=""> total price: </strong></td> <td align="center"><strong><span id="sum">0</span></strong></td> </tr> </tbody>
$(document).ready(function(){ $(".txt").each(function() { $(this).keyup(function(){ var price = $('.myprice').html(); calculatesum(price); }); }); }); function calculatesum(price) { var sum = 0; $(".txt").each(function() { if(!isnan(this.value) && this.value.length!=0) { sum = sum + price * parsefloat(this.value); } }); $("#sum").html(sum.tofixed(2)); }
i think problem (if understand correctly, not 100% sure).
$(this).keyup(function(){ var price = $('.myprice').html(); calculatesum(price); });
you have code. i'm assuming myprice class on txt element? need :
$(this).find('.myprice').html();
what doing, find price classes. hope helps
Comments
Post a Comment