2

I need to change the frontend price of a product when two custom options dropdowns are selected. I have found some code in this question, but where do I put the files? change price

UPDATE1:

added below codeto the options file and nothing happens when I adjust the quantity ?

$('#qty').keyup(function(){
alert('test');
});

UPDATE2

jQuery.noConflict();
 $('#qty').keyup(function(){
    alert('test');
    });

but now report 'Function expected'

UPDATE 3 I have the test code working now, Thanks. The real code doesnt work as expected, I want to update the price on the product page. This should equal the value of the dropdown multiplied x 4. Currently the code updates the price by adding 50 to it.

jQuery('#select_3').removeAttr('onchange').change(function(){
price=50;
optionsPrice.chagePrice('opConfig',price);
optionsPrice.reload();
8
  • You can put the javascript in template/catalog/product/view/options.phtml
    – eetzen
    Commented Jul 29, 2015 at 9:36
  • doesnt appear to work, see updated answer pls. Commented Jul 29, 2015 at 9:58
  • Beware for this is clearly jQuery, you should not use "$" which is reserved to prototype. Consider api.jquery.com/jquery.noconflict Commented Jul 29, 2015 at 10:00
  • Do you have any error/warning in javascript console? Commented Jul 29, 2015 at 10:01
  • yes error occured so changed code, now a new error 'Function expected' Commented Jul 29, 2015 at 10:24

1 Answer 1

1

About your code, I sppose you meant

jQuery('#select_3').removeAttr('onchange').change(function(){
    var price=50; //add var declaration
    optionsPrice.changePrice('opConfig',price);
    optionsPrice.reload();
}); //close the change binding

But where does optionsPrice come from? Pay a closer attention to the answers, I won't explain them here: your topic would be marked as 'duplicate' and you should ask for explanations on the original topic.

7
  • as i have under 50 reputation I cant add comment to orginal answer so grateful for support. optionsPrice came from the previous answer, I thought it was a class ?? I've now prefixed var infront of price=50 but still get summation of 50+price. Commented Jul 29, 2015 at 14:28
  • magento.stackexchange.com/a/60531/7773 -> if you want to update the price, that should not be in javascript (clientside) but in php (serverside) Commented Jul 29, 2015 at 14:35
  • Dont I need to do client side in addition to server side to give the user an immediate result? Commented Jul 29, 2015 at 15:05
  • Then you might consider ajax call, something like this question stackoverflow.com/q/15579192/2375207 Commented Jul 29, 2015 at 15:11
  • There it is, custom option price in the cart stackoverflow.com/a/23099871/2375207 Commented Jul 29, 2015 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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