Magento Forum

   
Page 1 of 2
Change “Add to Cart” button to “Buy It Now”
 
platinumtackle
Member
 
Total Posts:  40
Joined:  2008-09-30
 

So I have created a new theme which contains the following folders and files.
template/catalog/product/view.phtml
template/catalog/product/view/buyitnow.html

I have added a global attribute called buyitnowurl and can access it from the view.phtml.

Here are the two sections of code.

view.phtml

<?php if (!$this->hasOptions()):?>
                <?php 
echo $this->getChildHtml('tierprices'?>
                
<div class="add-to-holder">
                    
<?php if($_product->isSaleable()): ?>
                        
<a href="<?php echo $_product->getData('buyitnowurl') ?>"><button class="form-button"><span><?php echo $this->__('Buy It Now'?></span></button></a>
                        
<?php echo $this->getChildHtml('buyitnow'?>
                        <?php 
if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                            
<span class="add-or"><?php echo $this->__('OR'?></span>
                        
<?php endif; ?>
                    <?php 
endif; ?>
                    <?php 
echo $this->getChildHtml('addto'?>
                
</div>
            
<?php else:?>
                <?php 
echo $this->getChildHtml('addto'?>
            <?php 
endif; ?>

view/buyitnow.phtml

<?php $_product $this->getProduct() ?>

<?php 
if($_product->isSaleable()): ?>
    
<fieldset class="add-to-cart-box">
        <
legend><?php echo $this->__('Buy It Now Button'?></legend>        
        <
a href="<?php echo $_product->getData('buyitnowurl') ?>"><button class="form-button"><span><?php echo $this->__('Buy It Now'?></span></button></a>
    </
fieldset>
<?php endif; ?>

I have two questions.

1.  if I call $this->getChildHtml(’buyitnow’) nothing happens, but if I post the a href in the view.phtml like it is now the button displays.  What am I doing wrong?

2.  I removed the javascript for adding the item to the cart, but if I click the button it still adds the item, what other things do I need to remove to keep it from adding to the cart when I go to the new url?

Any help would be appreciated greatly.

 
Magento Community Magento Community
Magento Community
Magento Community
 
theallgreenstore
Member
 
Total Posts:  33
Joined:  2009-01-08
 

Were you ever able to figure this one out?  I need to do the same thing.

 
Magento Community Magento Community
Magento Community
Magento Community
 
platinumtackle
Member
 
Total Posts:  40
Joined:  2008-09-30
 

Magento is a extremely structure tuned product.  To solve this problem you will notice that the template/catalog/product directory contains the view.phtml file and view folder.  If you look in view folder you will see addtocart.phtml file which houses the actual add to cart button definition.  You add a new file called buyitnow.phtml which creates the button.  Then you go to catalog.xml and search for addtocart.phtml.  You will see how to define a child element and add your buyitnow child element.  The magento will know what you are talking about when you want the childhtml with the name.

The answer to second question is that view.phtml contains an action that always get executed.  You should add an attribute that specifies if buy it now should be used insead of add to cart.  Then add php around the action html definition only if it is to be used.  Hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
theallgreenstore
Member
 
Total Posts:  33
Joined:  2009-01-08
 

I’m brand new to Magento, but I think I get it.  I can now see the button and have defined the buyitnowurl attribute, but the button doesn’t go anywhere, it can’t find the url.  Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
theallgreenstore
Member
 
Total Posts:  33
Joined:  2009-01-08
 

Nevermind, I got it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
graphicagenda
Jr. Member
 
Total Posts:  8
Joined:  2008-08-21
 

Can you post your solution so others may see??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Delbert
Jr. Member
 
Total Posts:  1
Joined:  2009-04-02
 

Make sure you have caching on Layouts and Blocks HTML output switched off. Otherwise the steps described above will not work. 3 hours of hair pulling to discover this!

 
Magento Community Magento Community
Magento Community
Magento Community
 
tinnud
Member
 
Total Posts:  37
Joined:  2008-12-10
UK
 

I changed the text from ‘Add to Cart’ to ‘Buy Now’ by doing this:

Log into Admin then go to System>Configuration>Developer

Select ‘Translate Inline’ and change ‘Enabled for Frontend’ to yes.

Save configuration and go to your home page. Refresh it and you’ll notice some lines all over your site. Hover your mouse over the ‘Add to Cart’ button and a little book will appear. Select it and in the appropriate field change ‘Add to Cart’ to whatever it is you’d like to change it to. Click save and then go back to your Admin.

Change ‘Enabled for Frontend’ to no and save configuration. Then refresh your cache, refresh your home page and the changes should have taken place.

You can use this method for most of the magento text and I’ve found it incredibly useful grin

Hope this helps!

Kevin - http://www.tinnud.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
silversand999
Jr. Member
 
Total Posts:  11
Joined:  2008-07-04
 

@tinnud: “Translate Inline” does work for many text-related changes, but keep in mind it’s a hack/workaround, not an actual code solution. Nothing wrong with using it, but it tends to break in a spectacular manner when you change Magento versions.

@platinumtackle:

I’m using Version 1.3.1 + Yoast Blank_SEO Theme, so “Your Mileage May Vary”. Try this though:

In folder app/design/frontend/default/{your_theme}/template/catalog/product/list.phtml, find this code:

<?php if($_product->isSaleable()): ?>
    
<button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
      <
span><?php echo $this->__('[b]Add to Cart[/b]'?></span>
    </
button>
  
<?php else: ?>
      
<class="availability">
        <
span class="out-of-stock"><?php echo $this->__('[b]Out of stock[/b]'?></span>
    </
p>
  
<?php endif; ?>

(do a search for button class="button” )

As you can see, here you can change the actual text printed in the button.

(As a bonus, you get the element class names so you can open up the CSS in skin\frontend\default\{your_theme}\ and have fun.)

Note that despite the filename (list.phtml), this file contains definitions for BOTH the LIST view and the GRID view - and the division is not really obvious.
If you want the same text on the button in both modes, you’ll have to modify the relevant lines in both code sections.

I’m not sure if it’s Varien or Yoast who decided to split them using the exclamation point in the getMode line, but it’s hard to spot.

Everything from <?php if($this->getMode()!='grid'): ?> to <?php else: ?> is for the LIST view.
(Note the exclamation point - non-programmers may not catch that the ! means “not”, as in “Mode: NOT Grid”.)

After the <?php else: ?> line, the GRID mode definitions begin.

--------------

P.S. Advice to anyone posting questions and/or solutions: PLEASE PLEASE PLEASE specify what version you’re using, and provide the full path to the file.
Things are very different in some areas of Magento between versions.

 
Magento Community Magento Community
Magento Community
Magento Community
 
back2007
Member
 
Total Posts:  59
Joined:  2009-03-30
 

You also can change translation in the app\locale\en_US\Mage_Catalog.csv file.  Just replace
“Add to Cart","Add to Cart” line with “Add to Cart","Buy it Now” and clear your store cache

 
Magento Community Magento Community
Magento Community
Magento Community
 
dpereda
Jr. Member
 
Total Posts:  5
Joined:  2008-11-12
 

OK, after searching and searching this is the closest it seems anyone has come to releasing how to link a product to a 3rd party site.

So in the Product View I have it working.
But in the List and Grid views you click on the Buy It Now button and it take you to the shopping cart. 

I think this is related to comment about changing the catalog.xml file, but I don’t understand what needs to be done.

Thanks for getting me this far.

 
Magento Community Magento Community
Magento Community
Magento Community
 
platinumtackle
Member
 
Total Posts:  40
Joined:  2008-09-30
 

You need to look in list.phtml under catalog/product. There is a form action that I disable if the product is not for sale.  I have added several attributes that are specific to my store that help me determine what buttons to display and what action should occur.  You can see examples at http://www.platinumtackle.com.  I can not post any code as it is specific for my needs.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dpereda
Jr. Member
 
Total Posts:  5
Joined:  2008-11-12
 

Platinum,

That is a great site you have there.  I really appreciate your help as well as others.  I think I have it all fixed and working now.
I don’t need all the features you have.

I will be releasing my basic template for an affiliate site using magneto on my blog http://danpereda.com/2009/08/using-magento-commerce-as-an-affiliate-site/.  I still have some more testing and clean up to do before I release it tho.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dpereda
Jr. Member
 
Total Posts:  5
Joined:  2008-11-12
 

Grrrrrrrrrrrrr!!!!!!!!

OK, It works fine in Firefox, but now testing it in IE8 and it will not link to the 3rd party site.

Any Ideas?

in catalog/product/view.phtm I have the following and it doesn’t work

<a href="<?php echo $_product->getData('buyitnowurl') ?>" target="_blank">
<
button class="form-button">
<
span>
CLICK HERE
</span>
</
button>
</
a>

But if I change it to this

<a href="<?php echo $_product->getData('buyitnowurl') ?>" target="_blank">

CLICK HERE

</a>
The link does work, obviously I don’t have the nice pretty click box.

 
Magento Community Magento Community
Magento Community
Magento Community
 
irideflatland
Member
 
Avatar
Total Posts:  41
Joined:  2009-10-20
 

Has anyone gotten any farther with this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
irideflatland
Member
 
Avatar
Total Posts:  41
Joined:  2009-10-20
 

Ok so in app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml I changed a couple things. First of all, I changed the button text here, which was easy to do. Then I edited line 35 to this:

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="location.href='<?php echo $_product->getData('buyitnowurl') ?>'"><span><span><?php echo $buttonTitle ?></span></span></button>

I made a global attribute buyitnowurl and put the external URL in there.

It kind of works. I have configurable products. The simple products associated with the configurable products are just color variations. I want the user to be able to select a color, and when they click the button, they should be taken to the affiliate page for that specific color. But it will only go to the buyitnowurl of the configurable product.

Any solutions to that?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2