1

When I'm clicking the "update cart"-button on the configure cart item page, the quantity of the item is added instead of update. For example: if I've got 2 apples in my cart and enter as new quantity 3, then the cart is update to 5 apples instead of 3.

This is the code of my updatecart.phtml:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Update Cart'); ?>
<?php if ($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if (!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>
  • The code written above is to add the product to the cart and not update. Basically what it will do is it will add the product entered in the qty box and will add to previously added product – Dexter Oct 9 '14 at 12:06
  • Yes, I know. But would be the right code for updating? – Ella Oct 25 '14 at 8:31
1

First, you want to make sure the block type for this template is checkout/cart, that way all the given methods are available. Then the following should be able to produce what you want it to do:

<form action="<?=Mage::getUrl('checkout/cart/updatePost'); ?>">
  <?php foreach($this->getItems() as $_item): ?>
<?php if ($_product->isSaleable()): ?>

  <div class="add-to-cart">

      <?php if ( ! $_item->getProduct()->isGrouped()): ?>

      <label for="qty"><?php echo $this->__('Qty:') ?></label>
      <input type="text" name="cart[<?=$_item->getId()][qty]" maxlength="12" value="<?php echo $_item->getQty(); ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
      <?php endif; ?>

      <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" name="update_cart_action" value="update_qty">
      <span><span><?=$this->__('Update Cart');?></span></span>
      </button>
      <?php echo $this->getChildHtml('', true, true) ?>
  </div>

<?php endif; // isSaleable() ?>
  <?php endforeach; // $this->getItems()
</form>

What happens here is that the correct form is being used, you'll be looping through the cart items and have an update field for each one. There's work to be done for you, right now there's no label or anything to show what product goes with the qty field you may be updating. But this should work.

Be aware, this is untested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.