R
R
Rinat Haisman2018-11-08 16:19:06
opencart
Rinat Haisman, 2018-11-08 16:19:06

OpenCart: how to increase the quantity of a product by a multiple of the minimum in the product card?

Actually, subject. Wholesale store, sold only in boxes, with a clear number of items in each box.
For OpenCart, there is the Simple module, which does an excellent job, but only with a check-out (purchase confirmation: +/- number of products is also possible on this page).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rinat Haisman, 2018-11-09
@Rinat_Haisman

The issue was resolved by the code:
HTML:

<button class="counter counter-minus material-design-horizontal39" href='#'></button>
<input type="text" data-minimum="<?php echo $minimum; ?>" name="quantity" size="3" value="<?php echo $minimum; ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>"/>
<button class="counter counter-plus material-design-add186" href='#'></button>

jQuery:
;(function ($) {
    $(document).on('click', '.counter-minus, .counter-plus', function(e) {
        e.preventDefault();
    
        var input = $(this).parent().find('input[name*="quantity"]'),
        value = 1;
    
        var minimum = $(input).data('minimum');
    
        if ($(this).hasClass('counter-minus') && input.val() > minimum) {
            value = parseInt(input.val()) - minimum;
        } else if ($(this).hasClass('counter-plus')) {
            value = parseInt(input.val()) + minimum;
        }
        input.val(value);
    });
})(jQuery);

(When copying, be careful not to capture extra BOM characters)

Z
zoozag, 2018-11-08
@zoozag

In simplecheckout.js, see the increaseProductQuantity and decreaseProductQuantity functions.
As far as I can see, it adds / subtracts a multiple of the minimum amount.

A
Alexmaax, 2019-12-20
@Alexmaax

Change
input type="text"
to
input type="number" in the code
and add
min="<?php echo $minimum; ?>" step="<?php echo $minimum; ?>"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question