Add Products From Amazon To Your Magento Shop

2012-10-14 Bertas Magento

I wanted to add product links from Amazon to my Magento shop and earn up to 10% from Amazon Affiliate program. I have searched for complete solution, but was unable to find. There is some of them, but no one was exactly as I wanted. So I have spent couple days and made one. There is some pictures how it looks.

If you want something similar, please read this article.

This manual is for magento ver. 1.6.1.0

Create new attribute amazon_link:

Go to Catalog->Attributes->Manage Attributes and click “Add New Attribute”

Attribute Code: amazon_link
Catalog Input Type for Store: change to Text Area
Values Required: change to Yes
Used in Product Listing: change to Yes

All over values leave as they are.

Click on “Manage Label/Options” and put “Amazon link” bellow Admin.

Click “Save Attribute”

Add New Attribute Set:

Catalog->Attributes->Manage Attribute Sets

Click “Add New Set”

Write “Amazon books” or other name there and click “Save Attribute Set”.

In “Edit Attribute Set” windows (which should appear after you click “Save Attribute Set”) add new Group by clicking “Add New” in Group part.

Enter “Amazon” as group name and drop “amazon_link” from Unassigned Attributes to “Amazon” group. Click “Save Attribute Set”.

 

Create new design for Amazon goods

Create amazon directory in app/design/frontend/default folder.

mkdir app/design/fronend/default/amazon

 

Create directory structure in amazon dir

mkdir -p app/design/frontend/default/amazon/template/catalog/product

 

copy list.phtml from your theme to app/design/frontend/default/amazon/template/catalog/product

cp app/design/frontend/default/modern/template/catalog/product/list.phtml app/design/frontend/default/amazon/template/catalog/product

 

open app/design/frontend/default/amazon/template/catalog/product/list.phtml and delete lines from 56 to 64. Lines should like these

    <?php if($_product->getRatingSummary()): ?>
                   <?php echo $this->getReviewsSummaryHtml($_product) ?>
                   <?php endif; ?>
                   <?php echo $this->getPriceHtml($_product, true) ?>
                   <?php if($_product->isSaleable()): ?>
                       <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>
                   <?php else: ?>
                       <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                   <?php endif; ?>

Also delete lines 69-76 which looks like these:

<ul class="add-to-links">
                       <?php if ($this->helper('wishlist')->isAllow()) : ?>
                           <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                       <?php endif; ?>
                       <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                           <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                       <?php endif; ?>
                   </ul>

 

Delete lines 100-115:

<?php echo $this->getPriceHtml($_product, true) ?>
               <div class="actions">
                   <?php if($_product->isSaleable()): ?>
                       <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>
                   <?php else: ?>
                       <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                   <?php endif; ?>
                   <ul class="add-to-links">
                       <?php if ($this->helper('wishlist')->isAllow()) : ?>
                           <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                       <?php endif; ?>
                       <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                           <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                       <?php endif; ?>
                   </ul>
               </div>

 

Copy view.phtml in the same way as list.phtml

cp app/design/frontend/default/modern/template/catalog/product/view.phtml app/design/frontend/default/amazon/template/catalog/product/

 

Open app/design/frontend/default/amazon/template/catalog/product/view.phtml with text editor and delete lines 57-73. Lines contains this text:

<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
           <?php echo $this->getChildHtml('alert_urls') ?>
 
<?php echo $this->getChildHtml('product_type_data') ?>
 
<?php echo $this->getTierPriceHtml() ?>
           <?php echo $this->getChildHtml('extrahint') ?>
 
           <?php if (!$this->hasOptions()):?>
               <div class="add-to-box">
                   <?php if($_product->isSaleable()): ?>
                       <?php echo $this->getChildHtml('addtocart') ?>
                       <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                           <span class="or"><?php echo $this->__('OR') ?></span>
                       <?php endif; ?>
                   <?php endif; ?>
                   <?php echo $this->getChildHtml('addto') ?>
               </div>
           <?php endif; ?>

 

Save image below to your computer and upload it to media folder.

Create folder structure app/code/local/Mage/Catalog/Block/Product/View

mkdir -p app/code/local/Mage/Catalog/Block/Product/View

 

Create there file Amazonlink.php and put this code in it:

<?php
 
class Mage_Catalog_Block_Product_View_Amazonlink extends Mage_Core_Block_Template
{
 
    protected $_amazonlink;
    protected $_product = null;
 
    function getProduct()
    {
       if (!$this->_product) {
           $this->_product = Mage::registry('product');
       }
       return $this->_product;
    }
 
    public function getAmazonLink()
    {
       $this->_amazonlink = "";
 
       $product = $this->getProduct();
       $attributes = $product->getAttributes();
 
       foreach ($attributes as $attribute) {
           if ($attribute->getAttributeCode() == 'amazon_link') {
               $this->_amazonlink .= $attribute->getFrontend()->getValue($product);
           }
       }
 
       return $this->_amazonlink;
    }
 
}
 
?>

 

Create directory app/design/frontend/default/amazon/layout:

mkdir -p app/design/frontend/default/amazon/layout

 

Copy app/design/frontend/default/modern/layout/catalog.xml to this dir:

cp app/design/frontend/default/modern/layout/catalog.xml app/desigb/frontend/default/amazon/layout.xml

 

Insert this line in this file (after line 205):

<block type="catalog/product_view_amazonlink" name="product.info.amazonlink" as="amazonlink" template="catalog/product/view/amazonlink.phtml"/>

Add

<?php echo $this->getChildHtml('amazonlink') ?>

to app/design/frontend/default/amazon/template/catalog/product/view.phtml before

<?php if ($_product->getShortDescription()):?>

Create directory app/design/frontend/default/amazon/template/catalog/product/view:

mkdir app/design/frontend/default/amazon/template/catalog/product/view

Create amazonlink.phtml file in this directory and put this code in it:

<?php
    echo $this->getAmazonLink();
?>

Copy Abstract.php from app/code/core/Mage/Catalog/Block/Product to app/code/local/Mage/Catalog/Block/Product:

cp app/code/core/Mage/Catalog/Block/Product/Abstract.php app/code/local/Mage/Catalog/Block/Product

Add the function below to app/code/local/Mage/Catalog/Block/Product/Abstract.php

public function getAmazonLink($product)
    {
       $_amazonlink = "";
       $attributes = $product->getAttributes();
 
       foreach ($attributes as $attribute) {
           if ($attribute->getAttributeCode() == 'amazon_link') {
               $_amazonlink .= $attribute->getFrontend()->getValue($product);
           }
       }
 
       return $_amazonlink;
}

Open app/design/frontend/default/amazon/template/catalog/product/list.phtml and add this line

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

before

<div class="desc std">

and after

<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>

 

Add New Subcategory for Amazon products

Go to Catalog->Mange Categories
Click on “Default Category” and press “Add Subcategory”

Put “Amazon Books” in Name field.
Is Active change to Yes

 

Click on “Custom Design”
Apply to Products: change to Yes
Custom Design: change to created design, if you follow this manual, the select amazon.

Click “Save Category”

Add products from Amazon to your store.

Go to Catalog->Manage Products
Click “Add Product”

Attribute Set: change to “Amazon books”

Click “Continue”

Select product from amazon. Connect to https://affiliate-program.amazon.co.uk. Click on “Links and Banners”->Product Links

Search for product you want to add to your store. Click “Get Link” near product you want to add.
Click right mouse button on product image and select “Save Image As..” (Mozilla) and save it to your computer. Click “Text only” in amazon control panel.
Copy Product name (CTRL+C) and put in Name field in magento store.

Write description, short description, SKU, Weight (i always put zero).
Change Status to Enabled.
Visibility change to Catalog (i do not include products in search, because i do not know how to modify search results listing to show “Buy from Amazon” button).

 

Click “Prices”

Put price. I always put 0 there, because we do not show price in listing and product view.
Tax Class change to None

Click “Images”

Click “Browse Files…”. Select saved image and click “Open”. Click “Upload Files”
Select Base Image, Small Image and Thumbnail near selected image.


Click “Amazon”

Copy “HTML Code For This Product Link” from Amazon panel and paste it to amazon_link field.
Also copy “Product Previews Script” from Amazon panel and paste it to the same amazon_link after Product link.
Change Product Name in amazon_link to

<img src=”http://your.magentoshop.com/media/buyfromamazon.gif”>

 

Delete part in red and put part in blue.

Click “Inventory”. Near “Manage Stock” uncheck “Use Config Settings” and then change value to “No”.

Click “Categories”, select “Amazon Books” and click “Save”


Leave a Reply

Powered by WordPress. Designed by elogi.