bbPress 2.0 (plugin) – Adding User Role to Replies

In bbPress 2.0, the recent plugin version, that comes packed with the twentyten bbPress theme, I noticed that a role was not being displayed within the topic reply template.

I ended up adapting the core design from twentyten to WooThemes Canvas and felt the forum role was an essential aspect that was missing.

I came up with a quick solution but perhaps you can contribute a more dynamic solution for removing the bbp_ prefix that is included when simply displaying a bbPress Role.

Here is what I came up with:

roles ) && is_array( $user->roles ) ) {
foreach ( $user->roles as $role )
if ( $role == bbp_moderator ) {
echo 'Moderator';
} elseif ( $role == bbp_participant ) {
echo 'Participant';
} else {
echo $role;
}
}

?>

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 http://www.domain.com/image-name.jpg 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);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)) {
unlink($fullpath);
}
$fp = fopen($fullpath,’x’);
fwrite($fp, $rawdata);
fclose($fp);
}
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:

General:
Currency Setup – Scheduled Import Settings
* Contacts – Email Options

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

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

Sales:
* 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

Advanced:
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 Authorize.net in test mode.

American Express

Card Number 370000000000002
Expiration 05/2011
Vcode 1111

Useful WordPress Template Updates

A continual collection of WordPress template and code changes that I find useful when designing and developing WordPress blogs.

Body Class Reference

Especially when developing a number of custom elements on specific pages of your site you will want to be able to call that specific page or body class using the following update to the header.php file

Replace

<body>

With

<body <?php body_class( $class ); ?>>

Styling Your WordPress Page List

In customizing WordPress navigation bards I have found it increasingly important to continue to add addition html into such WordPress functions as a simple page list. As as example I sought to add a <span> before and after each link in a standard page list.

I have come across two solid solutions. One being a custom page list:

<ul>
  <?php $list = wp_list_pages('echo=0&title_li=');
  $list = str_replace('<a ','<span><a ',$list);
  $list = str_replace('</a> ','</a></span>',$list);
  echo $list; ?>
</ul>

However the second solution is a simple update to the wordpress page list that is already commonly used throughout wordpress template files:

<ul>
<?php wp_list_pages('title_li=&depth=1&link_before=<span>&link_after=</span>'); ?>
</ul>

You may want to also include the additional sort order function when adding the page list to your blog's setup:

<ul>
<?php wp_list_pages('sort_column=menu_order&title_li=&depth=1&link_before=<span>&link_after=</span>'); ?>
</ul>

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”/>
</block>

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>
<block type=”core/template” name=”contactForm” template=”contacts/form.phtml”/>
</reference>

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>catalog.compare.sidebar</name></action>
<action method=”unsetChild”><name>right.reports.product.viewed</name></action>
<action method=”unsetChild”><name>right.permanent.callout</name></action>
</reference>