3

I have displayed Magento products on my site's homepage. Some products have some custom options of checkbox type. I have displayed those custom options under the product image. But I do not have any idea how to change particular product price after checking or unchecking that custom option checkbox.

enter image description here

Here is the code which I have used to display custom options:

$options = Mage::getModel('catalog/product_option')->getProductOptionCollection($emq_product);

//for showing custom options
foreach($options as $o) {
    //echo $o->getTitle();
    $emq_type = $o->getType();
    if ($emq_type=="checkbox") {
        foreach($o->getValues() as $v) {
            echo $v->getTitle();
            echo "<input  id='".$emq_prod_id."' type='checkbox' class='emq_chk' price='". number_format($v->getPrice())."'/>";
        }                           
    }
}
1

You need to give a price to the option, get a look at the screenshot enter image description here

  • I have already assigned a price to each custom option. but it is working on Product view page only not on this home page. – ved Oct 8 '15 at 6:25
1

custom option code will be

$options = Mage::getModel('catalog/product_option')->getProductOptionCollection($emq_product);

//for showing custom options
foreach ($options as $o) {
    //echo $o->getTitle();
    $emq_type = $o->getType();
    if ($emq_type=="checkbox") {
        foreach ($o->getValues() as $v) {
            echo $v->getTitle();
            echo "<input  id='".$emq_prod_id."' type='checkbox' class='emq_chk' onClick='changeprice(this,". number_format($v->getPrice()).",". $emq_product->getId()).",". $emq_product->getFinalPrice()).")' price='". number_format($v->getPrice())."'/>";
        }
    }
}

add this after the for loop

<script>
changeprice (check,price,product,final) {
    if(jQuery(check).is(":checked")) {
        //add var declaration
        var tot=parseFloat(price)+parseFloat(final);
        jQuery("#changeprice"+product).text( tot );;
    }
}
</script>
  • Uncaught ReferenceError: optionsPrice is not defined – ved Oct 8 '15 at 7:02
  • can you paste you html too? – Qaisar Satti Oct 8 '15 at 7:04
  • I have added the code. But I think it is not getting the js file.. DO you have any idea which js it needs for optionsPrice? – ved Oct 8 '15 at 7:08
  • how you showing the price. i am talking about that. – Qaisar Satti Oct 8 '15 at 7:09
  • Sorry but I am not getting you. I have added 'price' attribute in checkbox. Is that correct? – ved Oct 8 '15 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.