Importing Images From External URL into Magento

There are occasions where you might not have access to downloading the images from your current setup into the Magento or it is simply easier to reference the current file path on an external URL. The following snipet will add the ability for you to grab images from an external URL when importing products through a data feed. Rather then setting up the image column within the data feed with /image-name.jpg you can now use the full URL path as an example.

Download the following file – app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php and search for the following section of code:

foreach ($imageData as $file => $fields) {
try {
$product->addImageToMediaGallery(Mage::getBaseDir(‘media’) . DS . ‘import’ . $html_filename, $fields);
catch (Exception $e) {}

Comment out the previous section of code or replace tit with the following:

foreach ($imageData as $file => $fields) {
$path_parts = pathinfo($file);
$html_filename = DS . $path_parts[‘basename’];
$fullpath = Mage::getBaseDir(‘media’) . DS . ‘import’ . $html_filename;
try {
$ch = curl_init ($file);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_close ($ch);
if(file_exists($fullpath)) {
$fp = fopen($fullpath,’x’);
fwrite($fp, $rawdata);
catch (Exception $e) {}
try {
$product->addImageToMediaGallery(Mage::getBaseDir(‘media’) . DS . ‘import’ . $html_filename, $fields);
catch (Exception $e) {}

Upload the updated Product.php file to into your local setup to prevent overwriting during upgrades – app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php

Selecting Custom Magento Transactional Emails

For reference, these are the places the transactional e-mails can be adjusted:

Currency Setup – Scheduled Import Settings
* Contacts – Email Options

Catalog – Product Alerts
Google Sitemap – Generation Settings
* Email to a Friend – Email templates

* Newsletter – Subscription Options
* Customer Configuration – Create New Account Options
* Wishlist – Share options

* Sales Emails – Order
* Sales Emails – Order Comments
* Sales Emails – Invoice
* Sales Emails – Invoice Comments
* Sales Emails – Shipment
* Sales Emails – Shipment Comments
* Sales Emails – Credit Memo
* Sales Emails – Credit Memo Comments
Checkout – Payment Failed Emails

Admin – Admin User Emails
System – Log Cleaning

(* Per storeview/language)

Test Credit Card Numbers

Credit card numbers that can be used to test Magneto’s connection with in test mode.

American Express

Card Number 370000000000002
Expiration 05/2011
Vcode 1111

Customize the Content Layout on Magento Category Pages

Add content above and below Magento product listings using the Category Description available in 1.4, then updating where the static block displays on the category page when customizing the Display Settings to include both a static block and products.

The main focus of being able to customize the content in Magento category pages was to add the ability for me to be able to have an introductory paragraph of content, but also add additional content after the product listing. Thus I was able to add a foundation of custom content to main category pages without pushing the products further and further down the page. [Read more…]

Add Pagination In Product Listings

I have noticed on a number of Magento websites that I have been designing, don’t include the pagination or pager links within the category listings. To remedy this oversight, simply update catalog.xml to include call to pager.phtml file wiht the following code:

<block type=”page/html_pager” name=”product_list_toolbar_pager”/>

You will want to locate the reference to the Product List Toolbar and updated to match the following:

<block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”>
<block type=”page/html_pager” name=”product_list_toolbar_pager”/>

Just place the pager reference inside the Product List Toolbar and you are set. Rememeber to refresh your cache before trying to view the live changes.

Insert a Custom Block into Magento Template File

As apposed to creating / adding a block to one of your Magento theme files, working directly in one of the template or .phtml files is a better way to call a static block.

In continuing to develop and learn Magento I have made a number of discoveries that help clarify how to work within the setup of Magento. In most cases when looking to customize a given page, I was directed to making updates to the Layout .xml files.

However if I was looking to simply add a static block to a specific section of a template file, creating a static block to the appropriate .xml file would simply add the static block above or below a given area.

The following code for example, would add the contact_intro above my contact form, but in the setup of that page, I wanted the contact_intro to integrate into a specific section of the fonrm.phtml template. This was not possible by updating the contacts.xml file as follows:

<reference name=”content”>
<block type=”cms/block” name=”contact_intro”>
<action method=”setBlockId”><block_id>contact_intro</block_id></action>
<block type=”core/template” name=”contactForm” template=”contacts/form.phtml”/>

Instead I needed to update the form.phtml file directly. Where I could place the contact_intro directly into the setup of the contacts page html:

<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘contact_intro’)->toHtml() ?>

Now I do not have two seperate blocks, when trying to add a block to the layout file. I have placed the static block exactly where I want it to be called within the contacts page.

I hope this helps clear things up as it has for me when trying to accomplish certain Magento layout updates.

Remove Sidebar Callouts in Magento Layout

Here are a coupe of quick references for removing sidebar callouts in either a template/layout .xml file or custom page Layout per page. I used the following to remove some unwanted blocks from the homepage sidebar by updating the XML Layout for the homepage under the Design tab, such as the cart which is unnecessary on a website homepage.

<reference name=”right”>
<action method=”unsetChild”><name>cart_sidebar</name></action>
<action method=”unsetChild”><name></name></action>
<action method=”unsetChild”><name>right.reports.product.viewed</name></action>
<action method=”unsetChild”><name>right.permanent.callout</name></action>

Magento Upgrade Error

Fatal error:  Call to a member function toHtml() on a non-object in /public_html/app/code/core/Mage/Core/Model/Layout.php on line 529

The line in page.xml that seems to cause the problem is

<block type=”core/profiler” output=”toHtml”/>

Magento now uses an updated call:

<block type=”core/profiler” output=”toHtml” name=”core_profiler”/>

This should be one of the initial changes that can get your site live and updated when upgrading to Magento

Custom SEF Sidebar Navigation For Magento

I wanted to share a quick snippet of code that I created for adding a custom navigation section to your Magento left column area. I currently created this navigation area for a client to replace the layered navigation. The layered navigation has a lot of great features and organization but probably better severs as a multi -select drop down. Also in the previous versions of Magento the layered navigation was not search engine friendly.

This is not currently the case but I still find that there is not enough control over the category / subcategory display within the layered navigation. This custom navigation block could be used above some of the other build in features such as price, manufacturer etc. that is simple to accomplish with the layered navigation.

Also of note, I have found including other SEO centralized developers, that the layered navigation simply refreshs that page, so should you have content on the main category page, the layered navigation link creates confusion becuase the page content continues to display. [Read more…]

Make ‘Ship to This Address’ Default Option During Magento Checkout

As you may uncover there are a number of obvious changes that need to be made to the Magento core code. The default shipping option being one of them, this may in fact be yet another change that you would want to record and check during any upgrades as the code change is made to the core code of Magento.

Navigate to – app/code/core/Mage/Checkout/Block/Onepage/Billing.php

To update the default shipping option to ‘Ship to this Adress’ simply edit the core magento file located on your server:


public function isUseBillingAddressForShipping()
if (($this->getQuote()->getIsVirtual()) || !$this->getQuote()->getShippingAddress()->getSameAsBilling())
return false;
return true;


public function isUseBillingAddressForShipping()
if (($this->getQuote()->getIsVirtual()) || (!$this->getQuote()->getShippingAddress()->getSameAsBilling()))
return true;
} else {
return false;