Reputation: 613
I'm trying to get my Upsell products, which I use instead of related products on the view.phtml, to work with a Quantity field in front of the Add to cart button. I'am also using AheadWorks Ajax AddToCart Pro 2.5 extension.
Right now, I'am adding the products without quantity fields with this snippet:
<form action="<?php echo $this->getAddToCartUrl($_link) ?>" method="post" id="view_addtocart_form_<?php echo $_link->getId(); ?>"><button onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')" class="greenbutton" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button></form>
This works great, but I cannot change the quantity due to the lacking quantity field. Then I try to use this from my list.phtml which works fine, in the category view:
<script type="text/javascript">
function setQty(id, url) {
var qty = document.getElementById('qty_' + id).value;
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="greenbutton-small" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Læg i kurv</span></span></button>';
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_product->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
Now, the funny thing is, this does not work if I try to use it in upsell.phtml, but I cannot figure out why? This works perfect with Ajax Cart Pro from AW in the Category view's.
Upvotes: 4
Views: 5141
Reputation: 6097
In upsell.phtml
the product object is called $_link
per the following code:
<?php if($_link=$this->getIterableItem()): ?>
If you're trying to include your code in your upsell.phtml
then you'll have to change $_product
to $_link
like this:
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_link->getId(); ?>" id="qty_<?php echo $_link->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_link->getId(); ?>, '<?php echo $this->getAddToCartUrl($_link) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_link->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
It should go after the following line:
<?php if($_link=$this->getIterableItem()): ?>
Upvotes: 4