Dynamic price update on drop down event

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 yıl önce
i was wondering if it is possible to let the price of an item update dynamically depending on selected attributes (i know, this is working) AND the selected amount (discounts) when using a drop down for number of items.

so if my customer selects 10000 pieces and it's like 0,20€ cheaper apiece if you choose more than 9000 that this discount difference is factored into the displayed unit price.
8 yıl önce
AAlexx wrote:
i was wondering if it is possible to let the price of an item update dynamically depending on selected attributes (i know, this is working) AND the selected amount (discounts) when using a drop down for number of items.

so if my customer selects 10000 pieces and it's like 0,20€ cheaper apiece if you choose more than 9000 that this discount difference is factored into the displayed unit price.


Hi,

If I understood you correctly, you want to make the dynamic price update work both with allowed quantities and tier pricing.

It will be nice to have this feature out of the box !

I have created "imperfect" JS solution which works fine - it just do not show the price incl./excl. TAX text.

Just add this code to your product page.

<script type="text/javascript">
    (function ($) {
        var priceElement = $('.product-price span');

        var updateTierPriceOnAllowedQuantityChanged = function () {
            var selectedQuantity = parseInt($('.add-to-cart .qty-dropdown').val()) || 0;
            var newPrice = '';
            
            $('.prices-table .item-quantity').each(function () {
                var that = $(this);
                var thatIndex = that.index();

                if (selectedQuantity >= parseInt(that.text())) {
                    newPrice = $('.prices-table .item-price').eq(thatIndex-1).text();
                }
            });

            if (newPrice !== '') {
                priceElement.text(newPrice);
            } else {
                priceElement.text(priceElement.attr('data-originalPrice'));
            }
        };

        $(document).ready(function () {
            priceElement.attr('data-originalPrice', priceElement.text().trim());

            updateTierPriceOnAllowedQuantityChanged();

            $('.add-to-cart .qty-dropdown').on('change', updateTierPriceOnAllowedQuantityChanged);
        });
    })(jQuery);
</script>


Regards, Deni !
8 yıl önce
hi again.

thx for the script... it mostly works but when using it in conjuncture with price reducing radio box attribute the price ranges will be completely overridden again. i've tried to add

$('.option-list').on('click', updateTierPriceOnAllowedQuantityChanged);


to the bottom of the script. sadly i can WATCH the price switch from the correct value to the new an overridden value when clicking on the radio box. there's some other script somewhere later down the line that overwrites the prices when using those radio box attributes that change the base price as well.
8 yıl önce
anyone? pretty please?
8 yıl önce
are there any plans to incorporate that into nopcommerce any time soon? i don't think that's too far fetched. i've tried to make different changes but i'm not familiar enough with the scripts and intricacies to really make it work.

it seems that the price calculation needs to be done somewhere in the the code and not after the fact via java script? not sure if that is possible but the interaction between default price changes due to attributes and tiers are currently outplaying each other. somehow the base price needs to be modified before the serialization in the respective script in _ProductAttributes.cshtml happens:

 //render scripts
        //almost the same implementation is used in the \Views\Product\_RentalInfo.cshtml file
        <script type="text/javascript">
            function @(attributeChangeHandlerFuncName)() {
                $.ajax({
                    cache: false,
                    url: '@Html.Raw(Url.Action("ProductDetails_AttributeChange", "ShoppingCart", new {productId = productId, validateAttributeConditions = attributesHaveConditions}))',
                    data: $('#product-details-form').serialize(),
                    type: 'post',
                    success: function(data) {
                        if (data.price) {
                            $('.price-value-@productId').text(data.price);
                        }
7 yıl önce
Has there been any decision to include this feature in a future version?
6 yıl önce
Does anyone know where the code sample above needs to be placed? What file exactly?
2 yıl önce
Nop-Templates.com wrote:
i was wondering if it is possible to let the price of an item update dynamically depending on selected attributes (i know, this is working) AND the selected amount (discounts) when using a drop down for number of items.

so if my customer selects 10000 pieces and it's like 0,20€ cheaper apiece if you choose more than 9000 that this discount difference is factored into the displayed unit price.

Hi,

If I understood you correctly, you want to make the dynamic price update work both with allowed quantities and tier pricing.

It will be nice to have this feature out of the box !

I have created "imperfect" JS solution which works fine - it just do not show the price incl./excl. TAX text.

Just add this code to your product page.

<script type="text/javascript">
    (function ($) {
        var priceElement = $('.product-price span');

        var updateTierPriceOnAllowedQuantityChanged = function () {
            var selectedQuantity = parseInt($('.add-to-cart .qty-dropdown').val()) || 0;
            var newPrice = '';
            
            $('.prices-table .item-quantity').each(function () {
                var that = $(this);
                var thatIndex = that.index();

                if (selectedQuantity >= parseInt(that.text())) {
                    newPrice = $('.prices-table .item-price').eq(thatIndex-1).text();
                }
            });

            if (newPrice !== '') {
                priceElement.text(newPrice);
            } else {
                priceElement.text(priceElement.attr('data-originalPrice'));
            }
        };

        $(document).ready(function () {
            priceElement.attr('data-originalPrice', priceElement.text().trim());

            updateTierPriceOnAllowedQuantityChanged();

            $('.add-to-cart .qty-dropdown').on('change', updateTierPriceOnAllowedQuantityChanged);
        });
    })(jQuery);
</script>


Regards, Deni !


I tried it on Nop 4.40.4, but it does not work.
Should the script be placed at this file - \Nop.Web\Views\Product\ProductTemplate.Simple ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.