Jump to content

How to change product price via function in product page and cart and when update quantity in cart


Recommended Posts

I have this code in priceCalculation method i Product.php:

 

$attributes['width'] = $_GET['width'];
        $attributes['height'] = $_GET['height'];

        $price = ppbs::get_price($id_product, $attributes, $use_tax);

        $price = Tools::ps_round($price, $decimals);

        if ($price < 0) {
            $price = 0;
        }


        self::$_prices[$cache_id] = $price;

        return self::$_prices[$cache_id];

And i prices.tpl:

function delay(callback, ms) {
        var timer = 0;
        return function() {
            var context = this, args = arguments;
            clearTimeout(timer);
            timer = setTimeout(function () {
                callback.apply(context, args);
            }, ms || 0);
        };
    }
    var width = 1;
    var height = 1;
    $(document).ready(function() {
        $("#height").on("input", delay(function (e) {
            height = $('#height').val();
          },500)),
            $("#width").on("input", delay(function (e) {
                width = $('#width').val();
                console.log(height);
                $.ajax({
                    url: 'index.php?controller=product&token=' + prestashop.token + '&id_product=' + {$product.id_product} + '&width=' + width + '&height=' + height,
                    data: { height: height, width: width, ajax: 1,
                        action: 'refresh' },
                    type: 'POST',
                    success: function(result) {
                            if (typeof result ==='object') {
                                if (typeof result.product_details !== 'undefined') {
                                    // if you keep the same classes and ids as in theme product.tpl then you can simply

                                    $(".product-prices").replaceWith(result.product_prices);
                                }

                            }}
            },500)}))

The price was reloaded in product page when i change width and height, but in cart price is not changed.

 

Please help me

Thanks for all support replies

Edited by manioart (see edit history)
Link to comment
Share on other sites

  • manioart changed the title to How to change product price via function in product page and cart and when update quantity in cart

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...