Archive

Archive for the ‘technical notes’ Category

Magento Notes — Add Address Field to Customer Export

October 2nd, 2009

Recently came across something weird when a client asked how come when they are in the admin interface: Customers -> Manage Customers, and then they click on “Export to CSV” the Address field isn’t export.  I don’t understand the logic of why the address is omitted.

Funny thing is that the fix to include the Address field isn’t straightforward and NOBODY ran into this problem, as there were no postings on Magento forum nor google search…I was surprised.  Anyways, what happens when users click on “Export to CSV” is essentially what you see in the grid below it is what gets exported, so the fix is to include the Address field in grid.  The file to modify is a core file, so you would have to update this when you do a Magento upgrade. Here’s the path to the file:

app/code/core/Mage/Adminhtml/Block/Customer/grid.php

Near line 45 you will find the below block of code, you will add the line that is in bold:

protected function _prepareCollection()
{
$collection = Mage::getResourceModel(’customer/customer_collection’)
->addNameToSelect()
->addAttributeToSelect(’email’)
->addAttributeToSelect(’created_at’)
->addAttributeToSelect(’group_id’)
->joinAttribute(’billing_street’, ‘customer_address/street’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_postcode’, ‘customer_address/postcode’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_city’, ‘customer_address/city’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_telephone’, ‘customer_address/telephone’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_region’, ‘customer_address/region’, ‘default_billing’, null, ‘left’)
->joinAttribute(’billing_country_id’, ‘customer_address/country_id’, ‘default_billing’, null, ‘left’);

$this->setCollection($collection);

return parent::_prepareCollection();
}

Then near line 103 add a the code below in bold:

$this->addColumn(’Telephone’, array(
‘header’    => Mage::helper(’customer’)->__(’Telephone’),
‘width’     => ‘100′,
‘index’     => ‘billing_telephone’
));
$this->addColumn(’billing_address’, array(
‘header’    => Mage::helper(’customer’)->__(’Address’),
‘width’     => ‘150′,
‘index’     => ‘billing_street’
));

Now you should see Address field displayed in the grid and when export is clicked it would export the field accordingly.

magento, technical notes

Magento Notes — Adding Company Name, Address, Phone in Registration Form

August 26th, 2009

This is a simple yet practical fix that, for some reason, Magento never got around to enabling upto Magento Version 1.3.2.3.

Basically by default the Magento registration form only requires you to enter First Name, Last Name, Email and VAT/Tax Number, but that in a real world scenario is not practical and not enough for business owners to follow up on.  Base on looking into the code here: app/design/frontend/default/blue/template/customer/form/register.phtml, we know Magento has every intention of adding additional fields, just they haven’t been enabled.

By following the fix here, you can reveal the additional fields. Essentially you just have to comment out a IF-Then statement to reveal the proper form fields. Below is the result:

blog posting, magento, technical notes , , , ,

Strategically inserting Google ads into Wordpress blog

May 21st, 2009

Have been working hard to promote blog.52my.info, but have realized that there isn’t an easy way to add google ads more naturally in between posts.  Some research landed me on Problogger.net (an excellent blog that teaches/motivates people how to make money blogging — I am a believer in Darren).

To more naturally add google ads, what you simply need to do is modify your “Main Index Template” usually the index.php file.  In there you should find a while loop that looks something like:

if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;

just change it to something like this:

// Set Counter to 1, First Post
$counter = 1;
if (have_posts()) :
   while (have_posts()) :
      $counter = $counter + 1;
      the_post();
      the_content();
      if(2 == $counter)
      {
         echo 'Adsense code';
      }
   endwhile;
endif;

the things to look for and add are in bold.  The “2″ indicates that google ads will be inserted in every 2 posts. This information was obtained here

blog posting, technical notes, wordpress , ,

Magento Notes — Default sorting is not logical

May 19th, 2009

Now that I have my e-commerce site, tickon.com, running for a while (3-months), I am back at it adding more products to link to my affiliate partners (this is a new experiment on this web site).

As I started to add new products, I noticed that newest items are added to the last page of the category that it was assigned to…not a very smart implementatio in my opinon. Did some googling and found a fix here:

http://www.magentocommerce.com/boards/viewthread/1176/

Essentially what needs to be done is to fix the file: app/code/core/Mage/Catalog/Block/Product/List/toolbar.php

near line 47, I changed the original code to the following:

$this->_availableOrder = array(
‘entity_id’ => $this->__(’Newest’),
‘name’      => $this->__(’Name’),
‘price’     => $this->__(’Price’)
);

The first item listed will be the default sort filter, the default was “best value”…which didn’t make a lot of sense to me.

Second item to fix up is in the same file, but you go to line 108 (approx.) and modify the highlighted part as below:

public function getCurrentDirection()
{
if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) {
$dir = strtolower($dir);
if (in_array($dir, array(’asc’, ‘desc’))) {
return $dir;
}
}
return ‘desc‘;

default is asc, but you need to change it to descending so that it sorts from newest id first.

blog posting, e-commerce, magento, technical notes , ,

Magento Notes — How to reference custom product attributes

April 6th, 2009

One thing that I find very useful as I start to seriously customize the product details page for my B2B client is the ability to create custom attributes.  But it took me forever to figure out how to call them from the view.phtml which is the file you are most likely gonna be modifying as well as list.phtml, both located in: app\design\frontend\default\blue\template\catalog\product

If you have created a custom attribute of type dropdown list or other multi-select list, you will reference the attribute using:

<?php echo $_product->getAttributeText(’attribute_code‘) ?>

where the attribute_code is what you have setup in the admin interface when creating this custom attribute. For textboxes and text area data types, you will call these a little differently using:

<?php echo $_product->getAttributeName() ?>

where getAttributeName is a variable of “get” + “attribute_code” where if you have underscores (_) or dashes (-), they are removed, and each word’s first character is capitalized.  So for example, if you have an attribue code called: shirt_size, your call would be:

<?php echo $_product->getShirtSize() ?>

Note that it is case-sensitive.

The link here has additional information on this topic.

magento, technical notes ,

Magento Notes — Magento for B-2-B Web site

March 27th, 2009

<button class=”button” onclick=”setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><?php echo $this->__(’Add to Cart’) ?></span></button>

I have recently been approached to work on a couple catalog-driven web sites for wholesalers and manufacturers, and what I have been presenting to them is simply a customized Magento installation in which 1) the pricing gets stripped out and/or
2) the pricing and the “add to cart” button gets stripped

Some of them also require that site operators approve customers before they can attempt to login; there’s a plugin for this here.

Below is a how-to on how to hide the “add-to-cart” button to non-logged in users.  Users would need to login in order to have a functional shopping cart:

Step 1 - To hide price: open the template file that shows prices: /app/design/frontend/default/[theme]/template/catalog/product/price.phtml and go to line line 30 (below: <?php $_id = $_product->getId() ?>) and add:

<?php if(Mage::getSingleton(’customer/session’)->isLoggedIn()): ?>

and at the very end, add:

<?php endif; /* if ($this->isCustomerLoggedIn()): */ ?>

Step 2 - go to /app/design/frontend/default/default/template/catalog/product/view/addtocart.phtml and add:

<?php if(Mage::getSingleton(’customer/session’)->isLoggedIn()): ?>

after: <?php $_product = $this->getProduct() ?>

and then add:

<?php endif; ?>

before <fieldset class=”add-to-cart-box”>

Step 3 - Remove add to cart buttons from /app/design/frontend/default/default/template/catalog/product/list.phtml

add the same if and endif statement around the following line of code:

<button class=”button” onclick=”setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><?php echo $this->__(’Add to Cart’) ?></span></button>

so that it looks like:

<?php if(Mage::getSingleton(’customer/session’)->isLoggedIn()): ?>
<button class=”button” onclick=”setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><?php echo $this->__(’Add to Cart’) ?></span></button>
<?php endif; ?>

read through the code and you will see 2 instances of the above (one for grid and one for list view)

Step 4 - Do the same as step 3 to file: /app/design/frontend/default/[theme]/template/catalog/product/compare/list.phtml

As I finished this, I found a more detailed wiki post on Magento: http://www.magentocommerce.com/wiki/price_on_application, it’s actually quite a bit more extensive and details on how to add attributes for variations to showing price.

blog posting, e-commerce, magento, technical notes , ,

Uploading mysql database via SSH

March 20th, 2009

I have always uploaded my Magento database via PHPMyAdmin (I know I know, it’s for novices)…but an incident yesterday with SimpleHelix (my current Magento hosting provider) forced me to learn how to import database and use SSH.  The whole incident started two days ago when I tried troubleshooting a new Magento installation, as the installation went through fine, but I kept getting error messages when I tried to view the front-end and when I tried logging into the backend; neither worked.  Tried googling on the web site for the error message (can’t remember what it was), but found no relevant errors…somewhat surprised, so I figure maybe it’s not a Magento issue. Read more…

blog posting, evaluation, technical notes , , , ,

Magento Notes — Show thumbnail image without pop-up window

March 19th, 2009

Finding ways to improve on the usability of tickon.com, I have made a small improvement.  I thought it was quite annoying to always have to wait for a new window to open to view the alternate images, so did some googling and found the perfect fix on Magento forum (link to exact post).  This fix simply allows you to click on the thumbnail alternate images and have it be shown in the large image box above.  Without going through the discussion thread…here’s the quick fix:

Locate media.phtml in app/design/frontend/default/themename/template/catalog/product/view, and near line# 59, you should see:

<a href=”#” onclick=”popWin(’<?php echo $this->getGalleryUrl($_image) ?>’, ‘gallery’, ‘width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes’); return false;”><img src=”<?php echo $this->helper(’catalog/image’)->init($this->getProduct(), ‘thumbnail’, $_image->getFile())->resize(120); ?>” alt=”<?php echo $this->htmlEscape($_image->getLabel()) ?>” title=”<?php echo $this->htmlEscape($_image->getLabel()) ?>” /></a>

change the part in red to the following:

<a href=”<?php echo $this->helper(’catalog/image’)->init($this->getProduct(), ‘image’, $_image->getFile()); ?>” title=”<?php echo $_product->getName();?>” onclick=”$(’image’).src = this.href; return false;”>

You should be able to modify it a bit more if you want the image to update on mouseover.

blog posting, e-commerce, magento, technical notes , ,

Wordpress Notes — Going live from local development environment

March 17th, 2009

As I launch more wordpress web sites, I am realizing that there are inherent issues with how Wordpress saves the posts…it always uses absolute path for URL links.  This creates problem for me as in my scenario, all of my local development have a url path of http://localhost:8080/sitename, so when I moved the blog to production and assign it a valid domain name like http://blog.52my.info, all the existing post links and image links would still be referring to the local computer for images and posts! This is TRICKY, as you won’t noticed this problem, because more than likely YOU ARE browsing the site that you have uploaded using the same computer where the dev blog was hosted, and you would see all images load up properly b/c they are stored on your local computer.  But when you go to another computer, you will see all the missing posts and images, etc.

The fix for this is to run several SQL scripts in which it would do a find and replace for all data in the mysql tables and rename them to the proper domain name url. I found this information from this great post here. But the long and short of it is run the following scrips:

1. update the wp_options table:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

2. Update wp_posts

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

3. Update post contents in which there are links within post content to the blog itself:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

blog posting, technical notes, wordpress , ,

Magento Notes — Fix for adding contact form in CMS pages

March 16th, 2009

This is a follow-up post on a fix that I had suggested about adding a contact us form through the CMS admin tool here.  What I found out was that the form post back left out the action parameter…when you do a view source.  So essentially the form gets filled out but doesn’t get sent to the site owner.

I found this out on my own tickon.com web site’s submit a product page.  Below is the fix for this:

Go into: app/design/frontend/default/blue/template/contacts and modify the form.phtml.  On (or around) line# 32, replace:

<form action=”<?php echo $this->getFormAction(); ?>” id=”contactForm” method=”post”>

with

<form action=”<?php echo Mage::getUrl(); ?>contacts/index/post/” id=”contactForm” method=”post”>

and you should be ready to go.

e-commerce, magento, technical notes , ,