I found an old Mod to do this in a rather nice way, but the Author did not update it anymore, so, I added a little to it. This Mod does not require anything else, it needs no Admin Settings, it just counts one up or down.
Source:
http://www.opencart.com/index.php?route ... load_id=31
Page to modify:
catalog/view/theme/default/template/product
/product.tpl
---
OC v1.5.6.1 Original Script, about Line 221:
---
FIND:
---
Code: Select all
<div class="cart">
<div><?php echo $text_qty; ?>
<input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
---
REPLACE WITH:
---
Code: Select all
<div class="cart">
<script>
$(document).ready( function() {
var elm = $('#htop');
function spin( vl ) {
elm.val( parseInt( elm.val(), 10 ) + vl );
}
$('#increase').click( function() { spin( 1 ); } );
$('#decrease').click( function() { if (elm.val () > 0 ){spin( -1 ); } });
});
</script>
<input type="button" id="decrease" value="-" /> <input type="text" name="quantity" id="htop" size="1" value="<?php echo $minimum; ?>" readonly/>
<input type="button" id="increase" value="+" /> <input type="hidden" name="product_id" size="1" value="<?php echo $product_id; ?>" />
---
Then, on the already modified Product Page, around Line 382
---
FIND:
---
Code: Select all
$('#button-cart').bind('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
---
REPLACE WITH:
---
Code: Select all
$('#button-cart').bind('click', function() {
var available_quantity = <?php echo $available_quantity; ?>;
var minimum_quantity = <?php echo $minimum; ?>;
$('.quantity_error').remove();
if(parseInt($('input[name="quantity"]').val()) > available_quantity || parseInt($('input[name="quantity"]').val()) < minimum_quantity) {
$('input[name="quantity"]').closest('.cart').append('<span class="quantity_error" style="color:red;font-size:13px;display:block;">Artikel ist in dieser Anzahl nicht lieferbar.</span>');
return false;
}
$.ajax({
url: 'index.php?route=checkout/cart/add',
and
LEAVE, whatever follows the >
>url: 'index.php?route=checkout/cart/add',<< Line
, in it's Place!
Change this >>
Artikel ist in dieser Anzahl nicht lieferbar.<< to any language required, or you could create/use a Variable in order to make it multilanguage compatible.
The Font/Color -Type can be set in this part: >>
color:red;font-size:13px;<<
see here how it works:
http://www.ipc.li/shop/index.php?route= ... duct_id=40
If one likes to allow Customers to manually change the Quantity-Value, remove the >>
readonly<< word where it is placed in one of the input Routines above.
if the Script has not been damaged by pasting it here, the Mod should work as it is taken directly from my File.
Info for All using lots of
VQMOD's in the Product-Display Section:
The
<div class="cart"> Line is beeing used as ANCHOR for many different VQMOD's available. So, make sure that no VQMOD will collide when installing this 'hardcoded' Modification. Specifically, VQMOD's calling for 'Action' by placing anything '
AFTER' the
<div class="cart"> Line, can endanger functions as well as placement order.
That's it, hopefully, took me a while to remember and include everything here. Good Luck!
Ernie
PS. Remember, back up the file first in case you screw up!