I am trying to create a page that updates the quantity off all items that are in the shopping cart to a minimum value. I am using an adaptation off the cart page for this. Below is the code I am using:
<?php
$x= $this->getQty();
$minValue = 8;
if ($x>= $minValue) {
echo 'Proceed with number: '.$x;
}
else {
$x= 8;
echo 'Minimum number is: '.$x;
}
?>
<input type="text" pattern="\d*" name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $x?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12"/>
<button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update'); ?>" class="button btn-update"><span><span><?php echo $this->__('Update'); ?></span></span>
</button>
This code is working as expected. Unfortunately users will need to hit the update button for the update to have effect. When the user just continues to the checkout the original value is transfered to this page.
Any idea on how to update the value in the input box without the user having to click a link?
Note: I know the best way off having a similar function is to have a minimum quantity placed in your shopping cart in the first place (which is in Magento's basic settings). Unfortunately in this case I need an update on the cart page.
Update. This adaptation (Please do not change core files) off the cart page seems to do the trick. It retrieves the number off items and updates the cart. Next to this I removed all links directly to the checkout page so people are forced to visit the cart page first.
AS anybody can see who has any experience in coding can see. I am not a programmer. So any recommendations to make this code better are greatly appreciated.
template/checkout/cart.phtml
<?php echo $this->getMessagesBlock()->toHtml() ?>
<div class="aantal">Number of people:
<input type="text" id="mhpeople" size="6" value="" class="input-text qty" maxlength="12" />
<button onclick="myEventCalc()">Calculate</button>
<br /><span class="min-aantal">(minimum amount is 8)</span>
</div>
<script>
function myEventCalc() {
var y = document.getElementById("mhpeople").value;
var x = document.getElementsByClassName("qty");
var i;
for (i = 0; i < x.length; i++) {
x[i].value = y ;
}
$('cart-form').submit();
}
Adaptation off template/checkout/cart/item/default.phtml
<script language="javascript">
var mhy = document.getElementById("mhcart").value;
var mhx = document.getElementById("mhpeople");
mhx.value = mhy ;
var mhz = document.getElementsByClassName("qty");
if (<?php echo $y?> < 8) {
$('cart-form').submit();
}
var y = document.getElementById("mhpeople").value;
if (y != <?php echo $z?>) {
myEventCalc()
}