cancel
Showing results for 
Search instead for 
Did you mean: 

Set an external link in cart button

Set an external link in cart button

Hi fellas! Smiley Very Happy

 

I'm using RWD theme with 1.9.1.1 version. 

 

I would like to solve a doubt. I wanna to set an external link into "add to cart" button as the image below. 

 

External Link

 

Actually i would like that when some client click on "add to cart" button, open another website. 

 

At first, i created an attribute called "Link_ex" and then i tried to call this attribute within the code:

 

<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>

 

The code above, is located in the file "list.phtml" (app / design / frontend / rwd / default / template / catalog / product / list.phtml) but unfortunately i'm not getting. 

 

Could a friend help me? Thanks for any help!

 

Best Wishes Smiley Happy

6 REPLIES

Re: Set an external link in cart button

Goto your List.phtml file path and replace code inside: onclick="setLocation(' ')

 

Replace your code:

 

<?php echo $this->getAddToCartUrl($_product) ?>

 

and keep this code instead:

 

<?php echo $_helper->productAttribute($_product, $_product->getLinkEx(), 'link_ex') ?>

 

NOTE: Catalog>> Manage Product. Select your product and make sure you use http:// for Link_ex attribute.

 

E.g: https://www.google.co.in (Good)

www.google.co.in (Bad)


Hope this helps!

Query solved? Accept as Solution.Thanks
Eric Baily

Re: Set an external link in cart button

 I think it need more info.

 

Admin order processing happens only when you add a product into a cart and then check-out.

 

If an external link added then adding to cart happens outside the magento and create order when the "outside" process gets over?

 

If its just going to be a link then why use magento and spend amount of VPS or dedicated servers?

 

May be I am wrong but just curious..Smiley Happy

Re: Set an external link in cart button

Hi AddWeb. Thanks for the help Smiley Happy

 

Well, i tried to do as you said but didn't work Smiley Sad and because of this i created a css block to try to solve this and even so didn't work. I'm gonna to try other ways for this. Anuway, thanks for the help Smiley Very Happy

Re: Set an external link in cart button

Hi sathyashrayan. Thanks for your post. Actually some products that i sell are from other stores and that's why i needed to set a button to open store website. Do you have any tip for this? Thanks for the help dude!

Re: Set an external link in cart button

You need addweb solution's answer and also you need to make your attribute available in product list collection,

in admin->catalog->attribute, find your attribute, edit it and change 'used in product list' yes

Re: Set an external link in cart button

Let me explain you in detail. This solution would work definately for you Michel.

 

1.  Go to your magento eCommerce admin panel and follow the path: Catalog >> Attributes >> Manage Attributes.

2. Add one attribute, you would land to Attribute Information page.

3. In Properties tab, Under Frontend Properties section there would be "Used in Product Listing" field select it as Yes. Save the configuration.

4. Go to Catalog >>Attributes >> Manage Attributes Sets, Select created attribute which you need to show under the attribute section on front end.

 

For E.g: Select "Default" Set Name. Drag attribute (Attribute which you have created) which would be shown under "Unassigned Attributes" section to "Groups" section under General folder.

 

5. Further, Goto Catalog >> Manage Products. Edit any one of your products and view the general section and you can find your created attribute here. Now, add your URL (E.g: https://www.google.co.in) into created attribute's field. Save configuration.

 

Now, open your phtml file which would be placed at:  app\design\frontend\mypackage\mytheme\template\catalog\product\list.phtml and edit your code.

 

Your Code:

 

<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>  

 

Replace the below code into Grid Mode Code: [ Around Line no: 153 ]

 

<button type = "button" title = "<? php echo $ this -?> __ ('Buy Now)>"? class = "button btn-cart" onclick = "setLocation ('<?php echo $_helper->productAttribute($_product, $_product->getLinkEx(), 'link_ex') ?>') "> <span> <span> <? php echo $ this -> __ ('? Buy Now ')> </ span> </ span> </ button> 

 

Let me explain you the added code:

 

<?php echo $_helper->productAttribute($_product, $_product->getLinkEx(), 'link_ex') ?>

 

This code will get value of your created attribute. 

getLinkEx() : This is your created attribute code (So make sure you enter that particulat attribute code which you have created)

 

Hope this would help you now!

Query solved? Accept as Solution.Thanks
Eric Baily