Magento Forum

   
How do I add a custom URL for each ‘Add to Cart’ button? 
 
EskimoNinja
Jr. Member
 
Total Posts:  5
Joined:  2009-01-20
 

Is it possible to replace the current link from the ‘Add to Cart’ button for a product with a unique custom link for each product? I basically want to completely remove the Add to Cart button and add a custom link instead. Ideally, this link should be able to be entered in the Admin for each individual product.

I’ve tried looking through some code, and tried a few things which didn’t work. The code for the actual link generated for the Add to Cart button is below.

<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>

Thanks very much for any help at all.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

you can create a new attribute for products, maybe calld add_to_cart. While creating a product you can set the value f.e. “Add this totaly freakin product to our amazing shopping cart smile”.

Now you can set an individual label for the button doing this:

<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $_product->getAddToCart();) ?></span></button>

hope that helps

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
EskimoNinja
Jr. Member
 
Total Posts:  5
Joined:  2009-01-20
 

Thanks for the reply zentrale.

I did exactly as you said, added a new attribute, named it ‘add_to_cart’, and added some data to it for each product. However, the method $_product->getAddToCart() doesn’t seem to return any data. I added in this check below, which displays the error:

<?php if ($_product->getAddToCart() == null) : ?>
    No value returned
!
<?php endif; ?>

Do I need to add the getAddToCart() method somewhere myself?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

hi,

in which .phtml did you put it? can you post some code?

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

than check catalog/etc/config.xml, theres a listing of product attributes for collections:

<product>
            <
collection>
                <
attributes>
                    <
name />
                    <
url_key />
                    <
price />
                    <
special_price />
                    <
special_from_date />
                    <
special_to_date />
                    <
description />
                    <
short_description />
                    <
image />
                    <
thumbnail />
                    <
small_image />
                    <
image_label />
                    <
thumbnail_label />
                    <
small_image_label />
                    <
tax_class_id />
                    <
status />
                </
attributes>
            </
collection>
        </
product>

extend this with <add_to_cart /> for testing.

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
EskimoNinja
Jr. Member
 
Total Posts:  5
Joined:  2009-01-20
 

I’ve added this line to list.phtml, in app\design\frontend\default\default\template\catalog\product\

<a href="<?php echo $_product->getAddToCart(); ?>">Link here!</a>

 
Magento Community Magento Community
Magento Community
Magento Community
 
EskimoNinja
Jr. Member
 
Total Posts:  5
Joined:  2009-01-20
 

After updating the XML file (making sure it had the right file format, UTF 8) this worked perfectly. Zentrale - thanks very much for your help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anjan Barik
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2010-03-19
Kolkata
 

If these are not working then You must try

Mage::getUrl(’checkout/cart/add’, array(’product’=>$row[’product_id’],’qty’=>1)

For example visit http://xhtmlandcsshelp.blogspot.com/2010/07/get-add-to-cart-button-url-in-magento.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
xmivite
Guru
 
Total Posts:  355
Joined:  2009-10-16
 

m4m call for price mod - will work perfect for this..

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top