• Store
  • Blog
  • Forum
  • Contact

  • FAQ
  • Register
  • Login
  • Homepage ‹ aheadWorks Magento Extensions ‹ AJAX Cart Pro ‹ General questions
  • Print view
Magento Advisor

Issue with customized list.phtml

You are welcome to discuss here everything including installation and configuration of AJAX Cart Pro.
Post a reply
6 posts • Page 1 of 1

Issue with customized list.phtml

Postby bytezmoi » Tue Nov 09, 2010 10:51 pm

I have added code to list.phtml to put a quantity box on category pages, so the buyer does not have to visit the product page itself. AJAX Cart Pro works great without the tweak. But with the tweak, the first Add to Cart on a category page goes into the cart in the left column via AJAX, without a problem. But if I add a second item to the cart, it goes to the checkout page, index.php/checkout/cart/
If I add another item to the cart from a product page instead of a category page, ACP works fine again.
So what am I doing wrong? Here is the tweak:

<!--<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>-->

<!-- HACK TO ADD QUANTITY BOX TO CATEGORY PAGE -->

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
<fieldset class="add-to-cart-box">
<legend><?php echo $this->__('Add item to Cart') ?></legend>
<?php if(!$_product->isGrouped()): ?>
<span class="qty-box"><label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input name="qty" type="text" class="input-text qty” id="qty" maxlength="6" size="6" value="<?php echo $this->getMinimalQty($_product)== null?1:$this->getMinimalQty($_product) ?>"/></span>
<?php endif; ?>
<button class="form-button" onclick="setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)"><span><?php echo $this->__('Add to Cart') ?></span></button>
</fieldset>
</form>
<script type="text/javascript">

//<![CDATA[

var productAddToCartForm = new VarienForm('product_addtocart_form');

productAddToCartForm.submit = function(){

if (this.validator.validate()) {

this.form.submit();

}

}.bind(productAddToCartForm);

//]]>

</script>
bytezmoi
 
Posts: 1
Joined: Tue Nov 09, 2010 10:33 pm
Top

Re: Issue with customized list.phtml

Postby Stasia » Wed Nov 10, 2010 9:10 am

I hope that somebody from our forum members can make it work right. But if you need some help from aheadWorks in this question, it is better to address your customization request to our custom development team - http://ecommerce.aheadworks.com/contacts ;)
User avatar
Stasia
 
Posts: 1005
Joined: Fri Dec 18, 2009 8:40 am
Top

Re: Issue with customized list.phtml

Postby imwy2cool » Wed Nov 10, 2010 5:24 pm

I'll see if I can dig up the code. I made this happen.
imwy2cool
 
Posts: 32
Joined: Fri Apr 23, 2010 2:37 pm
Top

Re: Issue with customized list.phtml

Postby imwy2cool » Wed Nov 10, 2010 5:33 pm

bytezmoi wrote:I have added code to list.phtml to put a quantity box on category pages, so the buyer does not have to visit the product page itself. AJAX Cart Pro works great without the tweak. But with the tweak, the first Add to Cart on a category page goes into the cart in the left column via AJAX, without a problem. But if I add a second item to the cart, it goes to the checkout page, index.php/checkout/cart/
If I add another item to the cart from a product page instead of a category page, ACP works fine again.
So what am I doing wrong? Here is the tweak:

<!--<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>-->

<!-- HACK TO ADD QUANTITY BOX TO CATEGORY PAGE -->

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
<fieldset class="add-to-cart-box">
<legend><?php echo $this->__('Add item to Cart') ?></legend>
<?php if(!$_product->isGrouped()): ?>
<span class="qty-box"><label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input name="qty" type="text" class="input-text qty” id="qty" maxlength="6" size="6" value="<?php echo $this->getMinimalQty($_product)== null?1:$this->getMinimalQty($_product) ?>"/></span>
<?php endif; ?>
<button class="form-button" onclick="setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)"><span><?php echo $this->__('Add to Cart') ?></span></button>
</fieldset>
</form>
<script type="text/javascript">

//<![CDATA[

var productAddToCartForm = new VarienForm('product_addtocart_form');

productAddToCartForm.submit = function(){

if (this.validator.validate()) {

this.form.submit();

}

}.bind(productAddToCartForm);

//]]>

</script>



Code: Select all
<?php if($_product->isSaleable()): ?>

            <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="button" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</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="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span> 
                <?php else: ?>
                <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
                <?php endif; ?>



It's been quite a while since I did this so I don't remember all of the ins and outs . . . hopefully it will help. Let me see if I can find my notes on it though . . .

Okay here are my original notes:


Open up this file:
/public_html/app/design/frontend/default/default (or your template name) /template/catalog/product/list.phtml

Code: Select all
<!-- Find this block of code: -->
<?php if($_product->isSaleable()): ?>
<button type="button" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>

<!-- And replace it with this block of code: -->
<?php if($_product->isSaleable()): ?>
<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="button" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</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="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span> 
<?php else: ?>



I am a version behind the latest update though so I don't know if the code will still work with the latest version. I haven't had a chance to update because I need to test the changes and make sure they work without error in the new version. You might also have different classes, etc for your buttons as this was based on a modified default theme.
imwy2cool
 
Posts: 32
Joined: Fri Apr 23, 2010 2:37 pm
Top

Re: Issue with customized list.phtml

Postby peterq » Sun Dec 12, 2010 10:21 am

works perfectly!!! Thank you
peterq
 
Posts: 7
Joined: Fri Jul 16, 2010 2:37 pm
Top

Re: Issue with customized list.phtml

Postby Nbordeau » Wed Aug 10, 2011 4:37 am

Hey,

I am so in debt to you my sir. Thanks so much for the fix!

Best Regards,
Nick
Nbordeau
 
Posts: 3
Joined: Wed Aug 10, 2011 4:35 am
Top

Post a reply
6 posts • Page 1 of 1

Return to General questions

Who is online

Users browsing this forum: No registered users and 1 guest

  • Board index
  • The team • Delete all board cookies • All times are UTC

Magento Enterprise extensions | Buy Magento template

© 2013 aheadWorks Magento Extensions
Your world of Magento extensions and themes!