Tải bản đầy đủ (.pdf) (45 trang)

inchoo's magento posts

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.86 MB, 45 trang )

September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 1
Inchoo's Magento Posts
You're reading the 200th blog post edition of Inchoo's
Magento e-book. It collects all of our blog posts on
Magento. We want to thank everyone for staying with
us so far and hope we will live to see 1000th blog post
anniversary. :)
Inchoo is an ecommerce design and development
company specialized in building Magento online stores.
Boost the speed of your Magento
One of the drawbacks of Magento is currently its speed if
default configuration is used. There are certain ways of making
it run faster. The best one is to enable GZip compression by
changing .htaccess file a little. You just need to uncomment
part of the code. In my case, the speed increase was exactly
235%.
Add custom structural block / reference
in Magento | Inchoo
If you already performed some Magento research, you will
know that it is built on a fully modular model that gives
great scalability and flexibility for your store. While creating
a theme, you are provided with many content blocks that you
can place in structural blocks. If you are not sure what they
are, please read Designer’s Guide to Magento first. Magento
provides few structural blocks by default and many content
blocks. This article tells what needs to be in place to create new
structural block.
What are structural blocks?
They are the parent blocks of content blocks and serve to
position its content blocks within a store page context. Take


a look at the image below. These structural blocks exist in the
forms of the header area, left column area, right column…etc.
which serve to create the visual structure for a store page. Our
goal is to create a new structural block called “newreference”.
Step 1: Name the structural block
Open the file layout/page.xml in your active theme folder.
Inside you will find lines like:
<block type="core/text_list" name="left" as="left"/>
<block type="core/text_list" name="content" as="content"/>
<block type="core/text_list" name="right" as="right"/>
Let’s mimic this and add a new line somewhere inside the same
block tag.
<block type="core/text_list" name="newreference" as="newreference"/>
Good. Now we told Magento that new structural block exists
with the name “newreference”. Magento still doesn’t know
what to do with it.
Step 2: Tell Magento where to place it
We now need to point Magento where it should output this
new structural block. Let’s go to template/page folder in our
active theme folder. You will notice different layouts there.
Let’s assume we want the new structural block to appear only
on pages that use 2-column layout with right sidebar. In that
case we should open 2columns-right.phtml file.
www.besthosting4magento.com
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 2
Let’s assume we wish the “newreference” block to be placed
below 2 columns, but above the footer. In this case, our
updated file could look like this:
<! start middle >

<div class="middle-container">
<div class="middle col-2-right-layout">< ?php getChildHtml('breadcrumbs') ?>
<! start center >
<div id="main" class="col-main"><! start global messages >
< ?php getChildHtml('global_messages') ?>
<! end global messages >
<! start content >
< ?php getChildHtml('content') ?>
<! end content ></div>
<! end center >
<! start right >
<div class="col-right side-col">< ?php getChildHtml('right') ?></div>
<! end right ></div>
<div>< ?php getChildHtml('newreference') ?></div>
</div>
<! end middle >
Step 3: Populating structural block
We have the block properly placed, but unfortunately nothing
is new on the frontsite. Let’s populate the new block with
something. We will put new products block there as an
example. Go to appropriate layout XML file and add this block
to appropriate place.
<reference name="newreference">
<block type="catalog/product_new" name="home.product.new" template="catalog/product/new.phtml" />
</reference>
That’s it. I hope it will help someone
There are 15 comments
How to delete orders in Magento? |
Inchoo
You got a Magento project to develop, you created a Magento

theme, you placed initial products and categories and you
also placed some test orders to see if Shipping and Payment
methods work as expected. Everything seems to be cool and
the client wishes to launch the site. You launch it. When you
enter the administration for the first time after the launch, you
will see all your test orders there. You know those should be
deleted. But how?
If you try to delete orders in the backend, you will find out
that you can only set the status to “cancelled” and the order is
still there. Unfortunately, Magento doesn’t enable us to delete
those via administration, so you will not see any “Delete order”
button. This can be quite frustrating both to developers and
the merchants. People coming from an SAP world find the
inability to delete to have some merit but there should be a
status that removes the sales count from the reports i.e. sales,
inventory, etc.
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;

TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;

ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;

ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 3
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
After you have it executed, the test orders will not be in the
database any more. Keep in mind that this will delete ALL
orders, in the database. So, you should execute this queries
immediately after launch.
connect2MAGE | WordPress plugin for
easy Magento database connection
Hi everyone. I wrote this little plugin while working on one
of our projects. If you know your way around WordPress
then you know what $wpdb variable stands for. Imagine the
following scenario. You have WordPress installation on one
database, Magento on another. You know your way around
SQL. You can always make new object based on WPDB class
inside your template files giving it database access parameters,
or you can use this plugin and use $MAGEDB the same way
you use $wpdb.
Below is a little example of using $MAGEDB to connect to

Magento database and retrieve some products by reading id’s
from custom field of some post inside your WordPress.
Place this code inside one of your templates, like single.php.
< ?php
global $MAGEDB;
$MAGEDB->show_errors(true);
/** BASIC SETUP */
//$storeUrl = 'http://server/shop/index.php/';
$storeUrl = get_option('connect2MAGE_StoreUrl');
//$urlExt = '.html';
$urlExt = get_option('connect2MAGE_UrlExt');
/** END OF BASIC SETUP */
$entityIds = get_post_custom_values(get_option('connect2MAGE_CustomFieldName'));
$result = array();
if(!empty($entityIds))
{
$entityIds = $entityIds[0];
$sql = "SELECT `e`.*, `_table_price`.`value` AS `price`, IFNULL(_table_visibility.value, _table_visibility_default.value) AS `visibility`, IFNULL(_table_status.value, _table_status_default.value) AS `status`, `_table_url_key`.`value` AS `url_key`, IFNULL(_table_name.value, _table_name_default.value) AS `name` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_entity_decimal` AS `_table_price` ON (_table_price.entity_id = e.entity_id) AND (_table_price.attribute_id='99') AND (_table_price.store_id=0) INNER JOIN `catalog_product_entity_int` AS `_table_visibility_default` ON (_table_visibility_default.entity_id = e.entity_id) AND (_table_visibility_default.attribute_id='526') AND _table_visibility_default.store_id=0 LEFT JOIN `catalog_product_entity_int` AS `_table_visibility` ON (_table_visibility.entity_id = e.entity_id) AND (_table_visibility.attribute_id='526') AND (_table_visibility.store_id='1') INNER JOIN `catalog_product_entity_int` AS `_table_status_default` ON (_table_status_default.entity_id = e.entity_id) AND (_table_status_default.attribute_id='273') AND _table_status_default.store_id=0 LEFT JOIN `catalog_product_entity_int` AS `_table_status` ON (_table_status.entity_id = e.entity_id) AND (_table_status.attribute_id='273') AND (_table_status.store_id='1') INNER JOIN `catalog_product_entity_varchar` AS `_table_url_key` ON (_table_url_key.entity_id = e.entity_id) AND (_table_url_key.attribute_id='481') AND (_table_url_key.store_id=0) INNER JOIN `catalog_product_entity_varchar` AS `_table_name_default` ON (_table_name_default.entity_id = e.entity_id) AND (_table_name_default.attribute_id='96') AND _table_name_default.store_id=0 LEFT JOIN `catalog_product_entity_varchar` AS `_table_name` ON (_table_name.entity_id = e.entity_id) AND (_table_name.attribute_id='96') AND (_table_name.store_id='1') WHERE (e.entity_id in (".$entityIds.")) AND (_table_price.value >= 0 and _table_price.value < = 999999999999) AND (IFNULL(_table_visibility.value, _table_visibility_default.value) in (2, 4)) AND (IFNULL(_table_status.value, _table_status_default.value) in (1)) AND (_table_url_key.value not in ('P1FHN3G0LRWGMYZ3')) AND (IFNULL(_table_name.value, _table_name_default.value) not in ('P1FHN3G0LRWGMYZ3'))";
$result = $MAGEDB->get_results($sql);
var_dump($result);
}
else
{
echo '<p class="relatedProductInfo">No related products available </p>';
}
?>
< ?php if (!empty($result)): ?>
<table id="relatedProductsList">
< ?php foreach ($result as $item): ?>
<tr class="productInfo">

<td><a href="<?php echo $storeUrl ?>/< ?php echo $item->url_key ?>< ?php echo $urlExt ?>">< ?php echo $item->name ?></a></td>
<td>< ?php _e('Starting at') ?> $ < ?php echo floatval($item->price) ?></td>
</tr>
< ?php endforeach; ?>
</table>
< ?php endif; ?>
Hope some of you find this useful. Especially those who refuse
to use Web Services for connecting different systems.
Download connect2MAGE WordPress plugin.
There are 6 comments
Custom checkout cart - How to send
email after successful checkout in
Magento | Inchoo
Recently I have been working on a custom checkout page for
one of our clients in Sweden. I had some trouble figuring out
how to send default Magento order email with all of the order
info. After an hour or so of studying Magento core code, here
is the solution on how to send email after successful order has
been made.
Not sure how useful this alone will be for you, so I’ll throw a
little advice along the way. When trying to figure how to reuse
Magento code, separate some time to study the Model classes
with more detail. Then “tapping into” and reusing some of
them should be far more easier.
Latest News RSS box in Magento using
Zend_Feed_Rss | Inchoo
You would like to have a eCommerce power of Magento, but
also have a blog to empower your business? In this case,
you probably know that Magento doesn’t have some article
manager in the box. Many clients seek for supplementary

solution like Wordpress to accomplish this goal. Ok, so you
created a blog on same or different domain and you would
like those articles to appear somewhere in Magento (probably
sidebar). This article will explain how to do it.
Let’s create a file called latest_news.phtml
in app/design/frontend/default/[your_theme]/template/
callouts/latest_news.phtml
Now we will create a PHP block that will display the list
of articles from RSS feed. We will use Inchoo RSS for
demonstration purposes. In your scenario, replace it with your
own valid RSS URL.
< ?php $channel = new Zend_Feed_Rss(' ?>
<div class="block block-latest-news">
<div class="block-title">
<h2>< ?php echo $this->__('Latest News') ?></h2>
</div>
<div class="block-content">
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 4
<ol id="graybox-latest-news">
< ?php foreach ($channel as $item): ?>
<li><a href="<?php echo $item->link; ?>">< ?php echo $item->title; ?></a></li>
< ?php endforeach; ?>
</ol>
</div>
</div>
Step 2
Now, we should decide where to place it. I assume you already
know how Magento blocks and references work. Let’s assume
you would like to place it in right column by default for whole

catalog. In this case open your app/design/frontend/default/
[your_theme]/layout/catalog.xml file and under “default” tag
update “right” reference with something similar.
That’s it. You should be able to see the list of articles from RSS
feed with the URLs. Hope this will help someone.
Advanced search in Magento and how to
use it in your own way
It’s been a while since my last post. I’ve been working on
Magento quite actively last two months. I noticed this negative
trend in my blogging; more I know about Magento, the less
I write about it. Some things just look so easy now, and they
start to feel like something I should not write about. Anyhow….
time to share some wisdom with community
Our current client uses somewhat specific (don’t they all) store
set. When I say specific, i don’t imply anything bad about it.
One of the stand up features at this clients site is the advanced
search functionality. One of the coolest features of the built in
advanced search is the possibility to search based on attributes
assigned to a product.
To do the search by attributes, your attributes must have that
option turned on when created (or later, when editing an
attribute). In our case we had a client that wanted something
like
ain/catalogsearch/partnumber
or
ain/catalogsearch/brand
instead of the default one
ain/catalogsearch/advanced
with all of the searchable fields on form.
Some of you might say why not use the default and call it a day.

Well, default one does not get very user friendly when large
number of custom added searchable attributes are added in
Magento admin interface. Then the frontend search form gets
cluttered and users are easily to get confused.
So in our example we would like to use the advanced search
and all of it’s behaviour and logic but to use it on somewhat
special link and to hide unnecessary fields. Therefore, our
custom pages he would have only one input field on form and
the submit button. How do we set this up? Well, all of the logic
and functionality is already there.
What we need is to:
• use the ain/catalogsearch/
partnumber as a link
• show only custom_partnumber field on the search form
First, we have to see where does the /advanced come from.
Lets open our template folder at
app\design\frontend\default\default\template
\catalogsearch\
there you will see the /advanced folder. Make a copy of that
entire folder, in the same location, and name it to something
like /custom.
Now your /custom folder should have 2 files: form.phtml and
result.phtml.
Next in line is the /layout folder in our template. You need
to open catalogsearch.xml file. Go to line 64. Do you see the
<catalogsearch_advanced_index> tag there. Make the copy of
it (including all of the content it hold with the closing tag also).
Put the copy of that entire small chunk of code right below.
Now rename all of the occurrences of “advanced” to “custom”
there like on code below:

<catalogsearch_custom_index>
<!– Mage_Catalogsearch –>
<reference name=”root”>
<action
method=”setTemplate”><template>page/2columns-
right.phtml</template></action>
</reference>
<reference name=”head”>
<action method=”addItem”><type>js_css</
type><name>calendar/calendar-win2k-1.css</
name><params/><!–<if/
><condition>can_load_calendar_js</condition>–></
action>
<action method=”addItem”><type>js</
type><name>calendar/calendar.js</name><!–<params/
><if/><condition>can_load_calendar_js</condition>–
></action>
<action method=”addItem”><type>js</
type><name>calendar/lang/calendar-en.js</name><!–
<params/><if/><condition>can_load_calendar_js</
condition>–></action>
<action method=”addItem”><type>js</
type><name>calendar/calendar-setup.js</name><!–
<params/><if/><condition>can_load_calendar_js</
condition>–></action>
</reference>
<reference name=”content”>
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 5
<block type=”catalogsearch/custom_form”

name=”catalogsearch_custom_form”
template=”catalogsearch/custom/form.phtml”/>
</reference>
</catalogsearch_custom_index>
Do the same for <catalogsearch_advanced_result> tag.
Now go to the app\code\core\Mage\CatalogSearch\Block
folder. And make a copy of /Advanced folder naming
it /Custom. Open /Custom/Form.php and replace
class name Mage_CatalogSearch_Block_Advanced_Form
with Mage_CatalogSearch_Block_Custom_Form, then
open /Custom/Result.php and replace class
name Mage_CatalogSearch_Block_Advanced_Result with
Mage_CatalogSearch_Block_Custom_Result.
Inside Form.php there is getModel() function. DO NOT
replace the Mage::getSingleton(’catalogsearch/advanced’);
with Mage::getSingleton(’catalogsearch/custom’);. The point
is to use the default advanced search logic here. Same goes for
getSearchModel() function inside Result.php file.
Next in line, controllers. We need to make
the copy of AdvancedController.php and name it
CustomController.php, then open it and replace the
class name Mage_CatalogSearch_AdvancedController with
Mage_CatalogSearch_CustomController.
Inside this CustomController.php there is a function
called resultAction(). You need to replace the ( …
Mage::getSingleton(’catalogsearch/advanced’) … ) string
‘catalogsearch/advanced’ with ‘catalogsearch/custom’. This is
the one telling the browser what page to open.
Now if you open your url link in browser with /index.php/
catalogsearch/custom instead of /index.php/catalogsearch/

advanced you will see the same form there.
And for the final task… As we said at the start, the point of all
this is to 1) get more custom link in url and 2) display only one
custom searchable attribute field in form. Therefore, for the
last step we need to go to the template\catalogsearch\custom
folder and open form.phtml file.
Inside that file, there is one foreach loop that goes like
<?php foreach ($this->getSearchableAttributes() as
$_attribute): ?>
All we need to do now is to place one if() condition
right below it. If your custom attribute name (code) is
“my_custom_attribute” then your if() condition might look
something like
<?php foreach ($this->getSearchableAttributes() as
$_attribute): ?>
<?php if($_code == ‘my_custom_attribute’): ?>

<?php endif; ?>
<?php endforeach; ?>
And you are done. Now you have somewhat more custom url,
and only one custom field displayed on that url.
This might not be the best method of reusing already written
code, however I hope it’s any eye opener to somewhat more
elegant aproach.
Enyoj.
There are 14 comments
Related products
There are three types of product relations in Magento:
Up-sells, Related Products, and Cross-sell Products. When
viewing a product, Upsells for this product are items that your

customers would ideally buy instead of the product they’re
viewing. They might be better quality, produce a higher profit
margin, be more popular, etc. These appear on the product
info page. Related products appear in the product info page
as well, in the right column. Related products are meant to
be purchased in addition to the item the customer is viewing.
Finally, Cross-sell items appear in the shopping cart. When
a customer navigates to the shopping cart (this can happen
automatically after adding a product, or not), the cross-sells
block displays a selection of items marked as cross-sells to the
items already in the cart. They’re a bit like impulse buys – like
magazines and candy at the cash registers in grocery stores.
Upsells
This is the example of the Up-sell. Ideally, the visitor is
supposed to analyze those products as they should be relevant
to the one that is just loaded.
There are 2 comments
File upload in Magento
Now, Magento already have frontend and admin part of file
upload option implemented in themes. Since backend part is
still missing, understand that this still doesn’t work, however,
if you’re interested how it looks, read on
We are coding module of similar functionality for one of our
clients as we speak, but we have our fingers crossed to see this
option in next Magento version!
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 6
Inchoo TV – Magento channel
Making use of Magento getSingleton
method

In one of my previous articles I showed you how to use
getModel and getData methods in Magento. Although we
should not put those to methods at the same level, since I’d say
the getModel is a bit more higher. Higher in sense, you first
use the geModel to create the instance of object then you use
getData to retrieve the data from that instance. I have said it
before, and I’m saying it again; Magento is a great peace of
full OOP power of PHP. It’s architecture is something not yet
widely seen in CMS solutions.
One of the architectural goodies of Magento is it’s Singleton
design pattern. In short, Singleton design pattern ensures a
class has only one instance. Therefore one should provide a
global point of access to that single instance of a class.
So why would you want to limit yourself to only one instance?
Let’s say you have an application that utilizes database
connection. Why would you create multiple instance of the
same database connection object? What if you had references
to an object in multiple places in your application? Wouldn’t
you like to avoid the overhead of creating a new instance of
that object for each reference? Then there is the case where
you might want to pass the object’s state from one reference
to another rather than always starting from an initial state.
Inside the Mage.php file of Magento system there is a
getSingleton method (function if you prefer). Since it’s
footprint is rather small, I’ll copy paste the code for you to see
it.
First, notice the word static. In PHP and in other OOP
languages keyword static stands for something like “this can
be called on non objects, directly from class”. Now let me show
you the footprint of the getModel method.

Do you notice the parameters inside the brackets? They are the
same for both of theme. Where am I getting with this? Well,
I already showed you how to figure out the list of all of the
available parameters in one of my previous articles on my site.
So all we need to do at this point is, play with those parameters
using getSingleton() method and observe the results.
Most important thing you need to remember is that using
getSingleton you are calling already instantiated object. So if
you get the empty array as a result, it means the object is
empty. Only the blueprint is there, but nothing is loaded in it.
We had the similar case using getModel(’catalog/product‘)
on some pages. If we done var_dump or print_r we could
saw the return array was empty. Then we had to use the load
method to load some data into our newly instantiated object.
What I’m trying to say, you need to play with it
to get the feeling. Some models will return data rich
objects some will return empty arrays. If we were to do
Mage::getSingleton(’catalog/session) on view.phtml file we
would retrieve an array with some useful data in it. Do
not get confused with me mentioning the view.phmtl file,
it’s just he file i like to use to test the code. Using
Mage::getSingleton(’core/session) would retrieve us some
more data. You get the picture. Test, test, test… What’s great
about the whole thing is that naming in Magento is perfectly
logical so most of the time you will probably find stuff you need
in few minutes or so.
Figuring out Magento object context
One of the problems working under the hood of the Magento
CMS is determining the context of $this. If you are about
to do any advanced stuff with your template, besides layout

changes, you need to get familiar with Magento’s objects
(classes).
Let’s have a look at the /app/design/frontend/default/
default/template/catalog/product/view.phtml file. If you
open this file and execute var_dump($this) your browser will
return empty page after a short period of delay. By page I mean
on the product view page; the one you see when you click on
Magetno product. Experienced users will open PHP error log
and notice the error message caused by var_dump(). Error
message:
PHP Fatal error: Allowed memory size of 134217728 bytes
exhausted (tried to allocate 121374721 bytes)
I like using print_r() and var_dump(), mostly because so far
I had no positive experience using fancy debug or any other
debugger with systems like Magento.
Why is PHP throwing errors then? If you google out the
error PHP has thrown at you, you’ll see that PHP 5.2
has memory limit. Follow the link />manual/en/ini.core.php#ini.memory-limit to see how and
what exactly.
Google search gave me some useful results trying to solve my
problems. I found Krumo at />It’s a PHP debugging tool, replacement for print_r() and
var_dump(). After setting up Krumo and running it on
Magento it gave me exactly what I wanted. It gave me the
object type of the dumped file; in this case it gave me object
type of $this.
If you’re using an IDE studio with code completion support
like NuSphere PhpED, ZendStudio or NetBeans and you
decide to do something like $this-> you won’t get any methods
listed. I haven’t yet seen the IDE that can perform this kind of
smart logic and figure out the context of $this by it self.

What you can do is use the information obtained
by krumo::dump($this). Performing krumo::dump($this)
on /app/design/frontend/default/default/template/catalog/
product/view.phtml file will return object type,
Mage_Catalog_Block_Product_View.
Now if you do
Mage_Catalog_Block_Product_View::
your IDE supporting code completion will give you
a drop down of all the available methods, let’s say
canEmailToFriend();
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 7
Mage_Catalog_Block_Product_View::canEmailToFriend();
Now all you need to do is to replace
Mage_Catalog_Block_Product_View with $this like
$this->canEmailToFriend();
And you’re done. All of this may look like “why do I need this”.
What you need it a smart IDE, one that can figure out the
context of $this by it self and call the methods accordingly. No
IDE currently does that, if I’m not missing on something. For
now I see no better solution to retrieve the object context of
$this across all those Magento files.
If you need some help setting up Krumo with Magento
you can read my other, somewhat detailed article on
activecodeline.com.
Hope this was useful for you.
There are 2 comments
Get product review info (independent) of
review page
Here at Inchoo, we are working on a private project, that

should see daylight any time soon. One of the requirements
we had is to show product review info on pages independent
of product review page. Let’s say you wish to show review info
on home page for some of the products. After few weeks with
working with Magento, one learns how to use the model stuff
directly from view files. Although this might not be the “right”
way, it’s most definitely the fastest way (and I doubt most of
your clients would prefer any other , especially if it’s some
minor modification).
Simple random banner rotator in
Magento using static blocks
This is my first post here and I’ll write about my first challenge
regarding Magento since I came to work at Inchoo.
Please note that you are not restricted only to images, you
could use text, video or whatever you want here, but I’ll focus
on images with links as title says.
In order to show this block, you should be familiar with
Magento layouts.
Since that is out of scope for this article, I’ll show you how to
put it below the content on cms pages.
Changing default category sort order in
Magento
Category toolbar has many options. By default is shows how
many items are in the category, you can choose how many
products you wish to be displayed per page, you can change
the listing type (List or Grid) and you may choose Sort Order.
This “Sort Order” can be confusing. The default “Sort Order”
is “Best Value”. What does it mean? How is the Best value
determined? Can we change the default sort order?
What is “Best Value” filed?

When you go to Category page in Magento administration, you
will see “Category Products” tab. From there, you will see the
list of products that are associated to this category. The last
column in “Position”. That is how “Best Value” is determined.
So, best value is not something that is dynamically calculated.
You can tailor it to your likings.
How to change default Sort Order
The file you need to look at is: /app/code/core/Mage/Catalog/
Block/Product/List/Toolbar.php Since we’ll modify it, make a
copy to /app/code/local/Mage/Catalog/Block/Product/List/
Toolbar.php
One there, you will notice this code at the beginning of the file:
$this->_availableOrder = array(
'position' => $this->__('Best Value'),
'name' => $this->__('Name'),
'price' => $this->__('Price')
);
Default order takes the first value available. So, all you have to
do is to either:
• reorder it if you want to have a selection in the Toolbar or
• set only one value of choice if you will remove the
selection from the toolbar
I hope this will help somebody.
There are 4 comments
Couple of days ago we launched a new Magento project:
Pebblehill Designs. This site utilizes Magento features and
turns it into a very powerful online catalog. You won’t notice
the Shopping Cart or checkout process yet. Even without
those, this site shows exactly what Pebblehill has to offer: the
most popular styles of custom upholstered furniture.

You can customize the furniture collection to express your
own unique style made with the highest quality materials and
craftsmanship available.
Pebble Hill Designs’ parsons chairs are “American made” with
pride in Georgia. The quality speaks for itself. Your products
are pre-assembled and ready for use when you receive them.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 8
The love and the passion for beautiful home interiors
translates into a high-quality product with a sophisticated
style manufactured in the USA. Pebblehill Designs has
assembled some of the most popular styles of custom
upholstered furniture to offer to our customers. All styles are
available in every fabric shown or you can provide your own
fabric. You can customize the furniture collection to express
your own unique style made with the highest quality materials
and craftsmanship available.
TeraFlex PLUS, another Magento +
Wordpress duo
After we launched TeraFlex Suspensions website few months
ago, we created a new similar website for Teraflex PLUS.
Although the name is similar, this is not the same company.
The primary goal of this site is to help Jeep owners to upgrade
their pets with parts and accessories for any type of adventure.
The secondary goal is to create a Jeep enthusiast community
in Utah, USA and surroundings. The site is powered by
Wordpress and Magento combination.
Magento is a superb Shopping Cart, but it lacks some of the
CMS features. Wordpress is a superb CMS, but it fails to
provide the needs for the eCommerce goals. The combination

of these can create a very powerful website. We present you
TeraFlex PLUS : Jeep Adventure Outfitters
/>Magento part of the site can be viewed if you click at Shop by
Vehicle or Shop by Brand tabs from the main menu, but you
will notice that some blocks seamlessly integrate between two
solutions.
We developed this site as the Surgeworks team. The design
was created by one of out top designers, Rafael Torales. We
hope you enjoy it and feel free to post your comments.
There are 6 comments
The Best Shopping Cart :: Trend analysis
of osCommerce, Magento, ZenCart and
CRE Loaded | Inchoo
If you try to ask this question on some forum or newsgroup,
you will surely get many replies. Everyone will present you
his favorite. My first developed online store was created with
standard osCommerce platform. After three or four projects,
I started to work with CRE Loaded and used it frequently for
years. Although it was also an osCommerce fork, it had many
advantages. I switched to Magento™ early this year and this
is my final choice.
Google™ Trends is a great tool to check some platforms
popularity by comparing it to the competition. For my short
analysis, I compared:
As you can see, osCommerce still remains the most popular
eCommerce platform. However, you can notice that this
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 9
popularity is fading. ZenCart is stable for the past two years.
And my previous favorite, CRE Loaded (much better solution

than ZenCart in my opinion), is very low. Its popularity is also
fading even after their team put great effort into a new website
and identity.
Now, take a look at blue line. My prediction is that sometime
in Q1 2009, Magento will become most popular eCommerce
platform. It will surely kick osCommerce off the throne where
that fat duck was sitting for many years. It was about time.
First of all, let me inform you that this article is for those of
you who are just starting with Magento. If you are a Magento
expert, you will probably know this. Consider it just a reminder
for those who use Magento for first time. There are three
common mistakes that most people do when they try to use
Magento for first time, so read this article and you won’t be
one of them.:)
• More experienced PHP developers will first read
Magento Designers Guide before they try to style
Magento, but others won’t and that’s the mistake
number two. Since Magento has great theme fallback
system there is really no need to touch default theme.
Although easiest way to make new theme for new
Magento is top copy the whole theme to a new folder,
don’t do that. Copy only the files you will need: from /
design/frontend/default/default/ directory to /design/
frontend/default/YOUR_NEW_THEME directory. Do
the same thing with /skin/frontend/default/default/
Congratulations, you have your own theme just like
that. All that left is to apply new theme (System-
>Configuration->Design) and you are ready to do with
your theme files whatever you want.
• Third mistake is modifying Magento core files. What files

are core ones? All what is in app/code/core folder. If you
have a need to modify some of those ones, you just need
to duplicate that file in the same directory path to app/
code/local. For example, if you need to modify the file
app/code/core/Mage/Checkout/Block/Success.php
copy it to
app/code/local/Mage/Checkout/Block/Success.php
and leave the core file intact. This way your Magento will
be more bullet-proof to future updates.
Custom CMS page layout in Magento |
Inchoo
Last week I had a request to add new custom layout
for few cms pages in one Magento shop. It’s really
useful for different static pages of your shop. First create
extension with only config file in it: app/code/local/Inchoo/
AdditionalCmsPageLayouts/etc/config.xml
Add your page/custom-static-page-1.phtml template file (or
copy some default one for start) and you’re done There is
also tutorial about this on Magento Wiki. However i don’t like
approach of duplicating and overriding Mage files from /local,
if it can be avoided, so i decided to write this small and useful
example of adding or overriding default Magento settings
through separated config files. And yes, Magento values can
be overridden this way. Default layouts config can be found
in app/code/core/Mage/Cms/etc/config.xml along with used
xml code structure, so check it out. Thank you for listening!
Drupal to Magento integration, simple
link tweak with multilingual site
I see my coworker and friend Željko Prša made a nice little post
on Adding a new language in Magento so I figure I’ll jump with

a little Drupal to Magento integration trick concerning link
issues and multilingual sites. Here is a piece of code you can
use in your Drupal templates to do the proper switching from
Drupal site to Magento while keeping the selected language of
site. Note, this tweak assumes you have the desired language
setup on both Drupal and Magento side.
This part goes to some of your Drupal theme file

global $language ;
$lname = ($language->language == null) ? 'en' : $language->language; /* like "en", "de" */
$storeView = null;
if($lname == 'de') { $storeView = '?___store=german&amp;amp;amp;amp;___from_store=english'; }
??>
</p><p style="text-align: left;"><a id="main_menu_shop" href="<?php echo 'http://'.$_SERVER['HTTP_HOST'].base_path() ?>shop/index.php/someProductLink.html< ?php echo $storeView ?>">Shop</a>

Note the $storeView variable; GET ___store holds the value
of code name of the view you assigned in Magento, while GET
___from_store variable is used as helper to Magento inner
workings. You can basically omit the other one. Your links to
Shop from Drupal to Magento should now activate the proper
language, the same one you have active on Drupal side.
There are 1 comments
Adding a new language in Magento
As anything in Magento adding a new language is something
that requires a certain procedure which we will explain right
now and for future reference.
• 3. Now go to: Configuration -> Current Configuration
Scope (Select your language from the dropdown) and on
the right side under “Locale options” choose the desired
language.

That’s it, now when you go to the frontend of the site, you’ll
notice a dropdown menu allowing the language switching.
Access denied in Magento admin
Some of you may encountered this problem. You install new
Magento extension through downloader, try to access its
configuration settings and Magento throws “Access denied”
page at you. Although you’re administrator of the system.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 10
So what happened here? Magento just doesn’t have stored
privileges for this new extension.
First just try to logout and login again. If that doesn’t work,
you need to reset admin privileges.
Navigate to System->Permissions->Roles and click
Administrators role.
Check your Role Resources settings just in case, Resource
Access dropdown should be already set to All for
administrators.
Without changing anything just click “Save Role” button, so
that Magento re-saves all permissions.
You should be able to access your new extension now without
problems.
There are 5 comments
If you worked with osCommerce, Zen Cart, CRE Loaded or any
similar eCommerce platform before, you might find Magento
database structure quite confusing when you see it for the first
time. I advise you not to rush too much figuring out what
is what by glancing through database. Try to spend first few
hours getting familiar with some background. For purposes
of flexibility, the Magento database heavily utilizes an Entity-

Attribute-Value (EAV) data model. As is often the case, the
cost of flexibility is complexity. Is there something in Magento
that is simple from developers point of view?
Data manipulation in Magento is often more knowledge
demanding than that typical use of traditional relational
tables. Therefore, an understanding of EAV principles and
how they have been modeled into Magento it is HIGHLY
recommended before making changes to the Magento
data or the Magento schema (Wikipedia: Entity-attribute-
value_model). Varien has simplified the identification of EAV
related tables with consistent naming conventions. Core EAV
tables are prefixed with “EAV_”. Diagrams in this post contain
a section labeled “EAV” which displays Magento’s core EAV
tables and thier relationships to non-EAV tables.
Database diagrams and documents found in this post are
intended to mirror the database schema as defined by Varien.
Table relationships depicted in the diagrams represent only
those relationships explicitly defined as Foreign Keys in the
Magento database. Additional informal/undiagrammed table
relationships may also exist, so when modifying the schema
or directly manipulating data it is important to identify and
evaluate possible changes to these tables as well (and the
tables they relate to, and the tables they relate to…).
The author of Database Diagram is Gordon Goodwin, IT
Consultant. You can see his info in the PDF.
There are 12 comments
Magento + .Net Framework, simple order
preview app
For those of you who are into kinky stuff I made a simple,
more of a proof of concept, application that sits in Widnows

taskbar and shows the order info in balloon popup. Took me
little more than half of hour to get this working. Almost forgot
how great C# is
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 11
Magento has this great feature, rss feed for orders. You
can access it via link http://myshopsite/rss/order/new. It
requires authentication, so you need to provide Magento user
and pass to access this link. Idea I wanted to play around
was how to get this info in my windows app. It’s really, really
simple. Below is the screenshot of this little app for you to see
what I’m talking about.
And here is the application it self simpleorderpreview and full
source code (Visual Studio 2008 Express C#, entire solution
project) acmnewproducts.
When you un-archive files from simpleorderpreview there is
only one thing you need to do prior to running .exe file. You
need to open ACMNewProducts.exe.config and set username,
password and url of your own Magento shop. That’s it. Now
you can run the app.
One click on Magento icon inside the taskbar executes
show order process, while double cliking the icon closes the
application.
I will not go into the details in this post on how this works.
Basicaly it’s simple XML parser. Most important part is the
HTTP authentification, which you can see in code source code.
Hope you find this usefull, something to play with.
There are 4 comments
Associate simple product with custom
options in grouped product in Magento |

Inchoo
Does the title sound complicated? Grouped Products display
several products on one page. For example – if you’re selling
chef’s knives and you have the same knife in four sizes, you can
make a grouped product to display all four sizes. Customers
can select the size(s) they want and add to cart from this page.
Another example would be a themed bedroom set – you can
create a grouped product and sell the sheets, comforter, and
pillow cases all from the same page.
Technically, we create a simple products and after that a
grouped products. When we edit the grouped product, we will
associate simple products to it.It works very fine, but some of
you might have issue if a simple product has custom options.
If that’s the case, and if costum options are set as required
(default way), the simple product will not be associative to the
grouped product. Let’s see what needs to be changed in that
case.
On Magento site, there is a nice tutorial how to create a
grouped product. Please read it first to become familiar with
the process. If you don’t have to assign simple products with
custom options to a grouped product, that tutorial will be
enough.
Manually create Google Sitemap in
Magento | Inchoo
Most of you probably know this, but let’s define what the
sitemaps are. Sitemaps are a simple way for site creators to
give search engines the information about pages on their site
that are available for public. Basically, those are just 1 or more
XML files that lists URLs for a site along with additional meta
informatio about each URL (like last update, how often it

changes, its importance relevant to other pages). With this in
mind, search engines can be more clever while crawling the
site. Click here see how sitemap of this site looks like.
You will hear the term Google Sitemap a lot, but XML Schema
for the Sitemap protocol is not related only to Google at all. It
can be used in many places, but the most important ones are
Google Webmaster Tools and Yahoo! Site Explorer.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 12
How do we create Google Sitemap in Magento?
1. Sitemap File Configuration
First we need to create sitemap file in Magento. This is
basically pointer to tell Magento where to create sitemap file
and how to name it. Log in to Magento Administration and go
to:
Catalog -> Google Sitemap
Check to see if the sitemap file is already present. Lets
assume we wish to create sitemap in the URL: http://
www.yourstore.com/sitemap/sitemap.xml
To do it successfully,
1. FTP to the server
2. create sitemap folder
3. chmod the folder to 777
On some servers, previous steps will not be required, but it is
better to create the file first so that Magento can edit it.
Let’s go to Magento administration now and click on “Add
Sitemap” button. Just insert the default values.
After this step, we just told Magento where to create sitemap
file. It is not yet created.
2. Configure Sitemap

Sitemap can be configured from the interface System ->
Configuration -> Catalog->Google Sitemap. If you are not sure
what does it all mean, check XML Tag definitions section from
“Sitemaps XML format” document.
3. Create Sitemap Manually
Looks like Magento folks were thinking that sitemap should
only be created by a cron job. Yes, it can be done that way
also. Be sure to read Wiki article How to Set Up a Cron Job
to get familiar with it. If you are looking for manual creation,
quit your search for “Create Sitemap” button. You will not find
it. But there is a workaround. You can enter manual URL to
execute sitemap creation:
/>generate/sitemap_id/[ID of Sitemap from step 1]
Of course, replace the content with square brackets with actual
Sitemap ID.
There are 9 comments
Observer pitfalls of building serious
modules in Magento
Unlike good old WordPress that “every kid in the block” knows
how to create a plugin for, Magento is a whole new system. It
requires extensive knowledge of OOP, ORM’s, MVC, and few
other stuff. This is why not “every kid in the block” can write a
module for Magento, and this is why I love it. However, unlike
WordPress, Drupal and other community driven systems out
there who keep in mind backward compatibility things with
Magento things are a bit different.
One of the things that caught my eye and made me
wonder about the consequences is the Observer and override
functionality that probably most of the serious custom made
Magento modules will utilize. Utilizing Observers enables you

to observe and execute some action inside the “customer work
flow” or even some admin stuff. Such functionality is heavily
known is systems like WordPress and it’s called “hooks”.
Besides hooking, another useful an very powerful feature
which is actually related more to the OOP concept itself is the
overriding. Personally i find the combination of observers and
overrides to be the coolest and most powerful stuff in Magento
module development.
So where is the issue? As of time of this writing, the
latest Magento version is 1.3.1. Let’s look at the previous
“major” release prior to that one, version 1.2.1.2. Here is
a prepareForCart method signature from app/code/core/
Mage/Catalog/Model/Product/Type/Abstract.php (line 239,
Magento version 1.2.1.2):
Notice the difference? Although this might not look like
“that big of a deal” suppose you had implemented override
functionality like
In the above code, we override the prepareForCart method to
to some custom stuff for us. This peace of code would work
perfectly fine in version 1.2.1.2, but when client decides to
upgrade the shop to 1.3.1 or newer he would get the error like
To me, stuff like this is a serious downside towards building
advanced modules. Changing core files and core functionality
can have serious impact on custom made modules each
Magento upgrade. Therefore, one should keep an eye open
on what modules he will throw into the shop. Personally I
consider online stores very serious and have strong feelings
about each store owner having somewhat of dedicated
developer that will be in charge even for stuff like adding new
modules.

Just consider the financial loss for a store owner of any more
serious web shop if he decides to download the and install
module himself just to realize that for incompatibility reasons
this new module made his shop fully nonfunctional.
How to transfer large Magento database
from live to development server and
other way round
I have been involved in Magento development for almost a
year now. God knows I had (and still have) my moments of
pain with it . If you are in professional, everyday, PHP
development that focuses mainly on Magento then your life
probably isn’t all flowers and bees. Magento is extremely rich
eCommerce platform, but its main downside IMHO is its size
and code complexity. If you download Magento via SVN, you
will sound find out it has around 11 600 and more files. This
is no small figure. Transferring that much of files over the
FTP can be a real night mare. Luckily we have SSH and tar
command to handle this really neat.
But what about database. Today I worked on database with
more than 20 000 products in store and with extremely
large number of categories. What seemed like easy database
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 13
transfer from live site to local developer machine to do a test
and fix on few issues tunerd out to be an issue for itself.
Without further delay, here is my favorite tool to handle all
database related work from now on: Navicat.
Among my favorite features is the Data transfer. Directly
moving one database to another among different MySQL
servers works like a charm. I find yourself strangled among

often database recommended action I suggests you test the
trial version of this tool.
Here are some screenshots of Navicat Data transfer in Action.
There are 4 comments
Affiliates for all – Magento integration
Recently one of our clients needed and info on Affiliate module
for Magento. When it comes to Magento, word “module” is
loosely related. Sure, every module needs config files in order
to report it’s “connection” to Magento core. Modules like this,
Affiliates for all, are modules I consider loosely related to core.
They are in one or another way connected to Magento but they
are self standing, independent, applications.
Installation of Affiliate module is a trivial task. It mostly
comes down to extracting downloaded archive file to a web
accessible directory (to your server, hosting) and configuring
the config.inc file. (For security reasons, try renaming
the config.inc to config.inc.php, plus changing the /lib/
bootstrap.php on line 23 to include config.inc.php). After
importing affiliates.sql into the database our installation is
done.
To configure Magento part, one needs to copy required files
form /carts directory of Affiliate module and then (turn off
Cache) go to System > Configuration and set the required
options. After that you can go back to your Affiliate For
All application, upload some banners and set their url links
to point to your Magento shop. When you test banner the
links (click on one of them to get you to Magento store,
then Magento store url should have a little GET variable
in url like ?ref=someNum). Now when you do the entire
checkout process, order info gets recorded to Affiliate For All

application.
If you wish to play with Affiliate For All without installing it,
you can check out the demo (just use “Admin” both for user
and password).
There are 2 comments
New Magento theme tutorial | Inchoo
There are many new Magento stores that are published
each day. If you are with Magento for a longer time, you
will also notice that many of those look similar to default
or modern Magento theme. Creating an totally unique and
custom one can be a difficult process, easpecially taking into
consideration number of different interfaces we have. This is
why many Magento developers choose to use the CSS from
one of mendioned Magento themes that come with default
installation and style those up. This is not a bad choice at all
as it speeds up the process and those default themes are very
good. But, for those of you who wish to make an extra effort,
we suggest that you to take a look at Magento Blank Theme for
a head start.
Before you get to this point, be sure to read Magento
Designer’s Guide, where the Magento design terminology is
explained in this PDF document.
Blank Theme is a sample skeleton theme for Magento designer
and a perfect way to start a new one. Let’s be honest, we will
rarely want to develop a totally new layout. We wish the header
on the top, footer on the bottom. We wish to have 1, 2 or 3
columns, we wish to have boxes. Blank Theme does just that:
provides a layout, but without any heavy styling. This makes
it excellent base ground for a new Magento project. It doesn’t
come with default installation, so you will have to use Magento

Connect to get it.
/>theme
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 14
Magento community member Ross gave a good review
comment:
This is a great theme to use for wire-framing or as a base
for developing a custom theme! It looks like a lot of work has
gone in to slimming down the HTML and CSS, which makes
it much easier to work with compared to the default theme.
I particularly appreciate the well structured and commented
CSS. The only things I would want different at this stage is
for the ‘callouts’ to be taken out (and removal of associated
media images), and for this theme to be included in the main
Magento download (I would even like it to be the ‘default’). 5
stars from me!
Take a sneak peak of how does product info page looks line
with no styling, but in finished layout. I’m sure that the CSS
wizards will find this invaluable.
There are 11 comments
Magento product view page analysis |
Inchoo
One of the most edited file in Magento is the template file
View.phtml file. Reason for this is that a lot of clients would
like to rearrange it differently on their online stores. Here is
the analysis of that file and the list of all the methods it uses.
One thing to keep in mind, this document shows you the
View.phtml block file and shows you it’s inherited methods.
All of the Magento block files have the similar inheritance
principle. Therefore to find out the available methods all you

need to do is open up the extended (inherited) classes.
If you are using some smart IDE solution like NetBeans 6.5
with PHP code completion support, you can simply do the
Mage_Catalog_Block_Product_View-> and press the Ctrl +
Space to get the dropdown list of all the available methods.
If that’s not the case, then you will how to do the things the
manual way.
Create a Color Switcher in Magento
Magento comes packed with a lot of options. But no matter
how many options you put into some product you can never
cover all of them. One of such options (for now) is a color
switcher in Magento. To be more precise, an image switcher
based on color selection.
Recently I’ve made a screencast on my site on this subject,
with somewhat different title. The idea is to have a dropdown
box from which you choose a color and based on the color
selection product image changes. All of this is to be based on
some simple javascript (in my case, jQuery).
Before we continue, you might want to see color switcher in
action. We used this solution on our Kapitol Reef project.
First you need to upload some images to your product and
give them some meaningful names like Red, Blue, Green
depending on your product color. When I say give them
name, I mean on label values. Same goes for creating custom
attribute. You create a dropdown selection box and create the
same amount of dropdown options as you have images, giving
them the same name Red, Green, Blue… and so on. Here are
some images for you to see what I’m talking about:
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 15

After this is done we go to the code part. There are three things
you need to do here.
Upload the jQuery and save it into the /js/jquery/jquery.js.
One important note on jQuery; for some reason I had to use
jQuery 1.2.3 to get this example working. Latest version 1.2.6
(as of time of this writing) did not work. You can see the exact
error it gave me on my screencast.
Now you need to modify /template/page/html/head.phtml
file to include the jQuery script (or any other if you can code
the same logic into it) and write down few lines of JS to
do the switching (you can download my version of file here
head.phtml)
And finaly, you need to modify the /template/catalog/
product/view/media.phtml file to grab all of the product
images and dump them into some div. Here is my sample
(media.phtml) so just copy paste the code.
And some additional screenshots for you to see final result
After some additional styling you can get some impressive
results for this. Hope you find it useful.
You can see complete screencast at:
/>MagentoProductColorChooser.swf
There are 28 comments
Magento’s Onepage Checkout in a
nutshell
For the last two days I’ve been working on a custom checkout
page for one of our clients. Basicaly a page can be shown
in Magento using simple Core_Template type. Basically all
code is set inside the .phtml file so it can be shown on every
possible page or block, meaning it’s object independent, no
inheritance. Something you can call from with your layout files

like
To complete my work, I had two mayor requirements. One
was to manage my way around programmable adding a simple
products to cart, plus their quantity and other was to do
checkout with items in cart. Checkout was to be made with
predefined payment method as well as shipping method. After
reviewing a lot of Magento’s code involved in checkout process
and process of adding products to cart and so on I’ve put
together what I see as the most short example one can use to
do a checkout with such predefined conditions.
If you have such special requirements for your site below is the
code that you can place on whatever file you wish and include
it yout tempalte as block type core/template.
Where ubmitCustomCheckout is the name of the submit
button or submit input field. To extract addresses you can use
something like
Magento official documentation
download
We were among a few of the studios to receive the early release
of the Magento documentation before it’s official release date.
We broke the embargo ’cause we just didn’t have the heart
to keep it to our selves, we all now how painful it is to work
without it.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 16
Designer's Guide to Magento PDF
download | Inchoo
After many developed CRE Loaded’s online stores and
watching Magento development progress for quite some time,
I decided it was time to use Magento with my next client. My

starting point for development was official Designer’s guide.
I’m the type of guy who likes to have documents nice&clean,
so I tried to print it but print was a mess. That’s when I decided
to create PDF of the official documentation for easy print. This
is probably the best starting tutorial for creating a fresh new
Magento template.
I plan to write a short related tutorials in the days of 1st
Magento development project, so I invite you to subscribe to
RSS if you wish to be posted.
Custom admin theme in Magento
As mentioned on Magento forums the easiest way to achieve
this is with overriding adminhtml config with your local
custom one and activate it as module.
This is just a small example of different approach with Admin
Theme config option in admin panel, to show you how things
can be done in different ways in Magento.
Follow directory structure, copy files to their place and you will
notice new “Admin Theme” option in System->Configuration-
>General->Design (Default Config scope). Your theme goes
in app/design/adminhtml/default/yourthemename folder. It
doesn’t need to be whole theme of course, just the files you’re
changing.
Disabling wishlist functionality
If like many of the Magento store owners you find that some of
the built-in features are not useful to you or to your customers
you can always disable them via the admin interface buy
disabling their respective modules.
Wishlist is not one of them.
To remove all of the traces of the wishlist functionality you
need to do the following:

1. Go to the Admin interface (select the appropriate scope)
and under System -> Configuration -> Customers -> Whishlist
select “No” under the “Enabled” in the General options.
This will remove all of the whishlist links in the magento blocks
as well as the whishlist itself.
2. Just to make things perfect you should
check the (yourskinname)/template/catalog/product/view/
addto.phtml and remove the “pipe” character from that file so
that it doesn’t disturb the looks of your site
3. Finally, since you do not need Whishlist anymore it is wise to
disable it’s respective module output thru the admin interface
(Go to: System -> Configuration ->Advanced->Advanced and
set disable “Mage_Whishlist” )
That’s it. Your whish is Magento’s command.
There are 4 comments
Magento Installation with SVN or Wget
Unix command | Inchoo
Those of you who know what SVN is, feel free to skip this
article. Those of you who are not familiar with SVN, this is
a must-read. If you use standard FTP to upload all Magento
files, you may find this process very time consuming. Magento
1.1.8 has over 6.700 files in over 2.200 folders. FTPing can
sometimes take few hours on some servers. Let’s look at
alternatives.
Both alternatives require SSH access to the server. I’m aware
that some low quality webhosting providers do not provide
you with SSH info immediately. If you don’t have SSH info,
ask webhosting support. If they don’t give it to you, change
webhosting provider. Make it a rule, you’ll make your life
much easier.

Get yourself familiar with basic UNIX commands first.
Alternative 1: SVN
In the Downloads tab on Magento website, you will notice SVN
page link:
/>You can see how short this page is. You have 2 commands
you can run at SVN. You can chack latest work in progress or
you can checkout latest stable version. If you are starting to
develop a real project, you will probably want a stable version.
Let’s look at the original command:
svn checkout />source/branches/1.1
This is probably not the exact command you wish to run on
the server. It will place the files in trunk folder. I will assume
two things:
1. You will want the clean code
2. You will want to specify the folder where you wish
Magento to be installed
If those are correct assumptions, you will want to run a
command similar to this one:
svn export force http://
svn.magentocommerce.com/source/branches/1.1
shop
• svn – This is the command
• export - The difference with checkout is that with an
export, you get a clean copy of the code, and none of
the subversion metadata, so it can’t be used to svn up or
make further changes.
• –force – you will overwrite all of the folders and files if
they exist
• />branches/1.1 - this is SVN URL. Leave it
intact.

September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 17
• shop - the name of the folder you wish to place the files
into. You may set the folders name to your likings.
Read more about SVN at Wikipedia SVN Page and Subversion
official site.
Alternative 2: Installing via wget
I will not be very descriptive here. This alternative is very well
explained on Magento website in Wiki section:
/>installing_magento_via_shell_ssh
Both scenarios will only place files. You still need to run web
based installer afterward. But, that is another story.
There are 6 comments
Custom Transactional Emails
Since transactional emails are very important for the process
of online shopping you need to have them set up just the you
want them and the default templates just don’t cut it. You
need your own logo, email data and custom verbiage to be
consistent with the image of your company.
Here how it’s done :
1. Creating custom transactional e-mails via Admin
a) In the admin panel of your magento installation go to:
System->Transactional Emails
You’ll be presented with a list of default emails. You’ll need
to create a custom email so the only way to avoid writing our
custom templates from scratch is to use the existing code of
the template.
Hint: If you want to see the template before copying, first click
on the “Preview” button on the right.
b) To create the new template click on the “Add new template”

above the “Transactional Emails” list. This is the part where
Magento helps you with the option to load a deafult template
for you to customize. Nice feature indeed.
Once you have loaded the deafult template give it a unique
name under the “Template name” input field by adding a
prefix of your own but leaving the deafult name as well.
Example: ” mysite :: New account “.
That way you can easily spot them in the long list of default
and custom emails.
Afterwards you can easily customize the verbiage and styling
within the “Template subject” and “Template content”.
The “Template content” is the body of the message that the
user will recieve upon transaction so be sure to change the E-
mail, name of the company etc. You’ll need to upload the logo
of your company in the images folder of the skin you’re using.
Once you are done with editing, save the changes and repeat
the process for the rest of the email templates.
2. Assigning the templates to different stores and storeviews
Assigning is the easiest part. Just go to the System
> Configuration > Sales > Sales Emails and select the
corresponding template minding the configuration scope.
After you’re done with setting your new templates save the
configuration by clicking on the “Save config”.
That’s it. Wise thing to do now would be to check how the
emails look when received so make a test purchase to verify
everything is the way it should be.
There are 3 comments
Bestseller products in Magento
Bestseller or best selling product is one of the features people
tend to ask for when it comes to Magento™.

There are multiple ways to implement this feature.
In this example, I’m not using controller or model directories
at all; I’m going to show you how to implement this feature
using only one file: the View.
Basically, what you need to do is to create the directory inside
your template directory and place the bestseller.phtml file in
it. In my example, I’m using the custom-created directory /
inchoo. All of the screenshots provided here are based on that
directory structure.
Adding this feature to your store is a matter of two simple
steps:
• copy bestseller-phtml file to your directory
• display the block on home page
To add a block to a home page, you simply log into the
Magento, CMS > Manage Pages > Home. Then add the
following to the content area:
{{block type=”core/template” template=”inchoo/
bestseller.phtml”}}
Notice the type attribute. I used core/template which means
you can place this code anywhere in your site and it will work.
Code does not inherit any collection objects from controllers
since it has none. All that is necessary for the bestseller.phtml
to work is defined in that single file.
One more thing: If you study the code in bestseller.phtml file
you will see, at the very top of the file, the part that says: $this-
>show_total.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 18
If I were to write
{{block type=”core/template” show_total=”12″

template=”inchoo/bestseller.phtml”}}
in my home page, then $this would be assigned property
show_total with a value of 12.
Therefore, the provided bestseller.phtml file provides the
option of setting the number of products you wish to see listed.
Here is the bestseller.phtml packed in bestseller.zip.
Hope you find this useful.
There are 20 comments
Magento 1.2. is out with downloadable
products | Inchoo
Just at the dawn of 2008, Varien launched a new version
of Magento: 1.2. Upgrading previous Magento versions was
sometimes not an easy task since Varien used to change
standard function names which caused themes to break. We
backup the site, made a copy, took a deep breath, expected the
worse, and… Nothing The upgrade went smoothly. Wow,
that felt good.
We were joking at the company today.
Zeljko: You know what’s easy in Magento?
Branko: There is nothing easy in Magento!
Zeljko is an front end interface developer, while Branko is
a programmer. Although creating Magento theme is a clear
process if you follow designer’s guide, programming is much
more complex. Before this version, Magento upgrades used to
cause troubles. Hope this is over.
There is always a good practice NOT to update platform to
latest version immediately. Even in this case this proved to
be valid. Two days after version 1.2. came version 1.2.0.1. that
fixed some flaws. Keep this in mind when you wish to upgrade
to newest version of the platform immediately after it appears.

New version sorts some issues from Magento 1.1.x versions
and brings some highly requested features such as:
• Support for Downloadable Products. (to see this new
product type in action visit the Magento Demo Store. We
added an example of an MP3 product and an eBook )
• Added Layered Navigation to site search result page,
with control on the attribute level to include or exclude
attributes used on the search results page.
• Improved site search to utilize MySQL fulltext search
• Added support for fixed-taxes on product level for such
taxes as “State Environmental Fee” in the USA and
“WEEE/DEEE” in the EU.
• Upgraded Zend Framework to the latest stable version
1.7.2
• Added a Layered Navigation Cache for improved
performance of large catalogs (currently in beta and is
NOT recommended for production use).
If you need to upgrade existing Magento version through the
Magento Connect Manager to 1.2.0.1, follow this steps:
• Do NOT use your live or production site. We suggest
making a copy of your site and upgrading that copy first.
• Backup your index.php and .htaccess files (if modified)
• Log into your Magento Connect Manager.
• Select the ‘Setting’ tab.
• Change the Preferred State to ‘Stable’, and save settings.
• For the Mage_All_Latest package select upgrade.
• Click on the ‘Commit Changes’ button. The upgrade
should start.
• After upgrade is complete click on the ‘Refresh’ button.
• Copy your original index.php and .htaccess files back (if

needed)
• Log into your admin and rebuild search index
• You should now have Magento 1.2.0 installed.
Happy Magentizing
There are 1 comments
Listing out products on sale in Magento |
Inchoo
One of my recent articles was on the subject of sorting “On
Sale” product in Magento. The following is a cleaner and more
advanced look at how—with few tricks and smart moves—you
can reuse existing Magento code and modify it to suit your
needs.
Product can be “on sale” in two ways:
1. when an item has a special price assigned to it on the
individual level, or
2. when a special promotion “covers” the item
It is important to remember that you don’t have to set up the
special price on each product to get it to be on sale; you can
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 19
simply create a promotion rule and say something like “Set all
the products in Category X to be on sale.”
I provided few screenshots at the bottom of this article to
provide a closer look at what I’m talking about. I will not go
into too much details here since this is a bit more advanced
HOW TO, but here is the process in a nutshell:
First, create a copy of /catalog/product/list.phtml file
and name it onsale_list.phtml. Here is my version of
onsale_list.phtml file.
Second, “activate” this new file. There are few ways you can do

this. Let’s say you wish to assign this onsale_list.phtml on one
of our categories, named “On Sale,” for instance.
We then go to Categories > Manage Categories > On Sale…
select Custom design and under Custom layout update, place
the following:
product_list_toolbar
If you now go to your category On Sale, it should only show
products you have assigned to category “On sale” that have a
special price set to them.
If you now wish to apply Promotion rules to entire “On sale”
category, then you simply assign a rule to one item, and all
the items assigned to the same “On sale” category (covered by
promotion rules) will be automatically listed in the grid.
Basically, the magic is in one simple IF statement
< ?php if(($_product->special_price !== null) or ($_product-
>_rule_price !== null)): ?>
for each block that lists products.
Check out the screenshots, they explain a lot.
Hope you find a way to try this out. Feel free to provide some
feedback or additional suggestions.
There are 3 comments
Magento
After many weeks of work, our 1st Magento project hit
the Web: TeraFlex Suspensions. As the purpose of the site
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 20
in not primarily selling, but also branding and community
development, we decided to use Wordpress and Magento
combination to accomplish the client’s goals.
The Magento portion is visible at />products/. We created an original and custom theme from

scratch since we did not want it to look like the default one or to
have a feel similar to the default one. It was not an easy task as
the learning curve for Magento template system is quite steep
compared to other solutions. However, it is worth the time.
We added featured products to products page, the lightbox to
products info page, and numerous styles that made this store
quite unique.
Wordpress
All the menu elements outside Products tab are run by
Wordpress. We have stuff like:
All of these elements turn Wordpress into a feature-rich CMS
suitable for larger projects.
How do you like the new site? Feel free to post a comment.
There are 4 comments
Place Contact form in CMS Page in
Magento | Inchoo
As you know, Magento has a built-in contact form that can
be used for general contacts. That form isn’t part of any CMS
page, you cannot edit some introduction text, you cannot
add phone numbers administration, and you cannot see the
breadcrumbs. If you wish to edit text in that default contact
form, you will need to update front-end files. Luckily, there is
an alternative.
If you are a developer, editing your contact form HTML is an
easy task. You only need to open file:
app/design/frontend/default/[yourtheme]/template/
contacts/form.phtml and you will find your way around.
However, there are cases when you would like to give your
client an option to edit some intro text, edit his phone
numbers, edit text behind the form, etc. You are probably

guessing that it would be nice to be able to embed contact form
in some CMS page. No problem.
I know that this is not some breakthrough article, but I will
certanly create contact CMS page on all of my future Magento
projects.
Custom price filter in Magento
Quite a few people have asked me for a price filter functionality
that comes with Magento. Mostly, the questions are same:
How does one put the price filter anywhere on the page? How
does one set it’s on price ranges in that filter? What defines
default price ranges. Is it possible to set price filter for all my
products instead of just single category? Lot of questions. The
answer might be simpler then you might think.
There are two ways to approach this problem. Head trough
wall or stop and think approach.Default Magento price filter
works with algoritam which functions on the following logic
1. Find the lowest and highest price in the range of filtered
products.
2. Find what power of 10 these are in.
3. If there’s 2 or less ranges available we go one power
down.
So one approach would to be to somehow override default
price filter logic by rewriting it and embedding some new logic
of yours. I call this one head trough wall. I’m not implying
that this is wrong approach, on the contrary this is the generic
solution. However it does require some more time to come up
with.
Second solution is by far more easier. It involves using simple
HTML (could use it in your static blocks).
If one wishes to use the price range filter to filter trough entire

product collection he can simply create a subcategory under
the Default root category and add all of the products to it. Then
we write some static html code with urls made to fire up the
price filter.
Let’s look at the default Magento sample data. It gies you the
following category layout
Root Catalog (6)
• Furniture (6)
• Living Room (4)
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 21
• Bed Room (4)
Notice the url link above… It wont work if you put it like http://
somesite.domain/furniture/living-room/?price=1%2C199
It wont work like that because by default you do not have price
filter functionality covering second subcategory level. What
this means is that following link wont work
ain/furniture/living-room/?
price=1%2C199
Since the first subcategory level is Furniture, and second are
Living Room and Bed Room, by default the following url will
work with or withoutindex.php.
• url: ain/furniture/?
price=1%2C199
• url: ain/index.php/furniture/?
price=1%2C199
You could therefore create simple HTML like
<select onchange=”setLocation(this.value)”>
<option value=”ain/all/?
price=1%2C10000″> <!– Here you place your own ranges –

>
0,00 € – 10 000,00 €
</option>
<option value=”ain/all/?
price=2%2C10000″> <!– Here you place your own ranges –
>
10 000,00 € – 20 000,00 €
</option>
<option value=”ain/all/?
price=3%2C10000″> <!– Here you place your own ranges –
>
20 000,00 € – 30 000,00 €
</option>
</select>
And put it into some of the static block. Notice the links in
above HTML code. The /all part of the url is the url key of the
All category in which we added all of our products.
Last, but not least is understanding of the “price=…”
parametar.
1%2C10000 – where 1 stands for first range of 10000 (last
number)
or
2%2C10000 – where 2 stands for second ranfge of 10000,
(first would be 0-10000).
So if we were to write something like
3%2C10 it would be the price range from 20-30, where 3
stands for third range of tens (number 10). Firs is from 0-10,
second 10-20, third 20-30.
Most of this is quite selfexplanaory so, for those who need
this kind of functionality across some special pages, hope you

integrate it withouth any problems.
There are 4 comments
Magentique - Magento Showcase
Launched | Inchoo
We launched one internal project today: magentique.com. For
the last few months we were working almost exlusively on
Magento projects. As many of you, we were also wondering
what sites are developed with it. There are very little galleries
that give the list of Magento powered stores and that’s how
this idea was created. We present you Magentique and hope
you like it.
Curiosity about this project is that we used Magento to develop
it. You’ll not see a shopping cart or Add to Cart buttons, but
Magento was the tool we used. Take a look at the gallery,
comment the sites you like. Subscribe to RSS. Share it with
you friends. Also, we would welcome your submissions of new
stores you own, you created or just the ones you like.
Hi,
I like your work with Magento, and i see that y’re not
affraid of experimenting. My question is relative to http://
www.raspberrykids.com. I like the layout, especially folder tab
with ‘Description’, ‘Tags’ etc. I didnt find such a feature in
Magento. Can you explain it on Inchoo web (in some article),
of course, only when it isnt company secret ) Thankx. Have
a nice day.
Online stores on magentique.com are not only our works.
Magentique is the gallery that lists all Magento sites and not
only our portfolio.
Regarding blog topics, we try to write about the things we work
on. However, we can not cover all Magento possibilities. Hope

you agree.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 22
Can an online store have only one product? Sure it can and
we give you the one that just launched. Kapitol Reef was
founded to develop, perfect, manufacture and market a new
breed of snorkels based upon pressure-balanced breathing in
the aquatic environment. The entire focus for this company
is to deliver best-of-class products, starting with the snorkel.
Kapitol Reef is in the market for many years and this week
they published a new site. Similar to our work on Teraflex
project, we used Wordpress and Magento platforms for the
development.
The request was to have an extensive online store solution
with multiple customers groups. Those groups should have
different product prices and different payment options.
Magento seemed like a great solution for such a request,
although the initial concern was if it might be an overkill
considering the fact we only have one product to start with?
When the development started to roll out, the concern was no
more. This will work superbly. We give you the new Magento
store that uses a combination of Wordpress and Magento.
Magento portion of the site is visible from the Online Store tab.
You may also notice a styled color switcher feature we
developed for this project. As this product comes in various
colors, we decided to spice up the product info page and style
the color choosing to replace the default select box.
There are 7 comments
Form Validation in Magento | Inchoo
One of the coolest things in Magento is a form validation, and

the way how it’s done. Magento uses Prototype library (which,
personlay, I’m not a big fan of) to manage form validation. All
you need to do when writing custom form is to assign a valid
class names to your input fields. Here is an example of how
your custom form might look in order to get use of automatic
form validation.
<form name="<em><strong>my-custom-form</strong>" id="my-custom-form" action="" method="post">
<label for="firstname">< ?php echo $this->__('First name') ?> <span class="required">*</span></label><br />
<input id="firstname" name="firstname" class="<em/><strong>input-text required-entry</strong>" />
<label for="lastname">< ?php echo $this->__('Last name') ?> <span class="required">*</span></label><br />
<input id="lastname" name="lastname" class="<em/><strong>input-text required-entry</strong>" />
<label for="useremail">< ?php echo $this->__('Email') ?> <span class="required">*</span></label><br />
<input type="text" name="useremail" id="useremail" class="<em/><strong>input-text required-entry validate-email</strong>" />
<input type="submit" name="submit" value="<?php echo $this-/>__('Submit') ?>" />
</form>< ?php /* END OF my-custom-form */?>
<script type="text/javascript">
//< ![CDATA[
var customForm = new VarienForm('<em><strong>my-custom-form</strong>');
//]]>
</script>
You will notice all of the input fields have one common
class name, required-entry. I’m not gonna go over all of the
available class names here. To find available class names, try
going to One page checkout page, where you have checkout
form, then simply view source and look for class names next
to input, radio select and other fields.
Most important thing besides assigning class names is that
little piece of JavaScript below the form. Remember to pass
form id into the new VarienForm object.
Basically thats it. Constructing the form this way, automaticaly

makes your form reuse already existing validation code, the
one that the rest of the shop is using.
There are 5 comments
CSRF Attack Prevention
If you login to your Magento admin today, you are welcomed
with message box that says:
CSRF Attack Prevention Read details !
Yesterday Magento team acknowledged CSRF vulnerability
and provided solution in a form of tutorial to change admin
path (frontName) of your Magento shop.
I find this approach strange and funny at the same time. Is
hiding vulnerability new way of fixing it? Especially since
some users of French Magento forums found similar problem
in downloader (Magento connect manager). I can confirm this
couse i tested it myself. The most funny part was that Magento
cached my get request so i couldn’t get rid of my test alert box
Few fast tips for Magento admins:
1. Follow official Magento news, forums, updates.
2. Don’t click suspicious links. These kind of attacks are
usually done through malformed links that admin clicks
through mail, comment, or any other source.
3. Clear “saved passwords” from browsers. Since most
web browsers offer to remember passwords, and then
autocomplete them, these kind of attack could easily stole your
password.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 23
There are 4 comments
Magento Connect
One of the first things that really confused me when i

start using Magento is Magento connect. I just started
learning things, so i was looking for some plugin examples. I
visited Magento connect page with extensions and looked for
download button, instead i found “Get extension key” one.
If i recall correctly their What is this? explanation wasn’t the
same back then or i was just so terrified of Magento at start
that i didn’t understand anything at that point I knew i
need to paste that key somewhere, in something they called
my Magento connect manager or Magento downloader, but i
didn’t understand where it is.
Visit Magento connect page. There are really some great
extensions there and many of them are free.
Find extension that interest you, click “Get extension key”,
agree with license agreement and get key. Pay attention to
Stability description field (stable, alpha, beta).
If you click Settings tab of your connect manager you will see
“Preferred State” option there. If you’re installing extension
with different “stability” or you get something similar to
you should change this option to appropriate one. You should
of course be careful with alphas and betas and know what
you’re doing.
If you are developer or just interested, ftp to downloader/
pearlib/download after you install extension and you’ll find
packed downloaded extensions there.
After you use the downloader do you need to change the folder
permissions back for security reasons or is it OK just to leave
them at 777?
This really depends on your server configuration, however
it’s always good to restore permissions to defaults if they are
changed to 777, just to be sure.

Magento™ and Google™ Website
Optimizer
I attended a webinar yesterday called “Maximizing Magento
Webinar: Optimizing Conversions with Website Testing.” It
was a nice and informative hour-long webinar with Google and
Magento team speakers that provided us some really useful
information.
First of all, you should know what Google Website Optimizer
is. It’s a powerful tool that allows you to test various page
concepts directly on your visitors and see which of your ideas
works best in practice.
The idea behind Google Website Optimizer is “You should
test that.” If you have an idea you don’t know will work—or
whether it will increase you conversions—Google has created
this tool to help you test it.
Google Website Optimizer is easily integrated in Magento.
You can test various changes on your product pages and see
which ones work best for your visitors. Only product page
integration between Magento and Google Website Optimizer
is made for now, however according to Roy Rubin, we can
expect integration with our shopping cart and checkout pages
soon.
What Google Website Optimizer does is serve different
variations of your site to the visitors so that you can test which
one converts best. You can set up easily “A-B compare” where
you serve half of your visitors one page variation and half
of your visitors another. Then all you have to do is compare
results or set up multiple page variations. The Optimizer gives
you nice, clean reports where you can see how are your page
variations performing. To learn more about conversion rates,

read how to improve your web shop conversion rates.
TIPS:
• Run the tests for at least a week or a sample of 10,000
visitors or more. You can’t know if the page variation is
actually good if your test sample was too small.
• Do the big changes first, then fine-tune later. This
one comes from the Google and their experience with
Website Optimizer. You should first try to make big
differences and see in which direction has the response
you want, then refine the pages for optimal conversions.
If you can’t see the change in first five seconds of viewing
the page variation, the change is too small.
• Beware of HiPPO! This one also comes from Google.
HiPPO stands for Highest Paycheck Person’s Opinion.
When you have powerful tool such as Google Website
Optimizer, you can actually test all the ideas and see
which one makes you the most money. HiPPO will often
want to serve his visitors his idea—despite the fact that he
could earn more by serving them some other variation.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 24
There are 1 comments
Extending Order object and hooking on
event in Magento
One of my previous articles was a Magento Event Hooks.
This one will be a practical example on using the event
hooks. Although the more proper way would be to call them
Observers, bare with me. I’m use to this “hooks”.
Here’s the walk-trough on how to add a new property
(attribute) to an object (Mage_Sales_Model_Order object in

our case).
To add an attribute to object, we need (the dirty way) 2 little
steps
• Go to app/code/core/Mage folder. If you drill down
into most of the folders and go to /Model subfolder
there you will see /Entity subfolder under /Model for
most of the stuff (modules) under /Mage. For our
example we go to app/code/core/Mage/Sales/Model/
Entity/Setup.php file. This Setup.php file holds Objects
fields definitions in database. We need to add new fields
to public function getDefaultEntities(). Once again, this
is the “quick” and “dirty” way of adding new attributes.
The “propper” way would be to create the sql file and
update config file to read the new sql file and… Whatever,
I haven’t got the whole day Here is the code in my
example, that I added to the array in public function
getDefaultEntities().
'inchoo_custom_info' => array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Extra info',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',

'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => false,
'unique' => false,
),
Basically you can copy-paste some existing attribute that
suites you the most and just change the array key name.
• Run this code only once (you can place it inside any file,
like index.php or view.phtml or any other that you will
execute) then uncomment or remove this code.
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$AttrCode = 'inchoo_custom_info';
$settings = array('position' => 1, 'is_required' => 0);
$setup->addAttribute('11', $AttrCode, $settings);
NOTE: In code above, note the line $setup-
>addAttribute(’11′, $AttrCode, $settings). You probabily
wonder where did I pool the number “11″ from?
If you open your database (with any tool), and go
to sales_order table, you will notice entity_type_id
column. Each and every entry in sales_order table
has the same value for entity_type_id column. In my
Magento installation, this value is “11″. Keep in mind
that this does not have to mean yours will also be the
same.
To confirm everything went ok, just Search the database
for the “inchoo_custom_info” (or whatever you used for
attribute name).
Ok, now that we added new attribute (property) to Order

object, we will go on to Observer part. We will create a
hook that will watch for successfull checkout process and
trigger appropriate code execution. In my example I needed
to add some extra info to order upon it’s successfull creation.
Meaning as soon as checkout process is successfully executed,
order is stored in database with some extra info I saved in its
previously created field “inchoo_custom_info”.
Here is my Observer file, I called it Observer.php and
it’s saved under app/code/local/Inchoo/HookSystem/Model/
Observer.php.
< ?php
class Inchoo_HookSystem_Model_Observer
{
/**
* Event Hook: checkout_type_onepage_save_order
* @param $observer Varien_Event_Observer
*/
public function hookToOrderSaveEvent()
{
/**
* NOTE:
* Order has already been saved, now we simply add some stuff to it,
* that will be saved to database. We add the stuff to Order object property
* called "inchoo_custom_info"
*/
$order = new Mage_Sales_Model_Order();
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order->loadByIncrementId($incrementId);
$extraInfo = array(
'shirt_color' => 'Freakin cool blue color',

'developer_is_freak' => true,
'coded_by' => 'Branko Ajzele, Web Application Developer'
);
$extraInfo = serialize($extraInfo);
$order->setData('inchoo_custom_info', $extraInfo);
$order->save();
}
}
Since this is a module, we also need to add some config
files. Here is the content of my app/code/local/Inchoo/
HookSystem/etc/config.xml
< ?xml version="1.0"?>
<config>
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 25
<global>
<models>
<hooksystem>
<class>Inchoo_HookSystem_Model</class>
</hooksystem>
</models>
</global>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<hooksystem_order_success>
<type>singleton</type>
<class>hooksystem/observer</class>
<method>hookToOrderSaveEvent</method>

</hooksystem_order_success>
</observers>
</checkout_onepage_controller_success_action>
</events>
</frontend>
</config>
And one more config file to add to app/etc/modules/
Inchoo_HookSystem.xml.
< ?xml version="1.0"?>
<config>
<modules>
<inchoo_hooksystem>
<active>true</active>
<codepool>local</codepool>
</inchoo_hooksystem>
</modules>
</config>
And for the final step, open the app/design/adminhtml/
default/mytheme/template/sales/order/view/tab/
info.phtml file and add the following to it:
< ?php /** START CUSTOM Coded by Branko Ajzele | */ ?>
< ?php
/**
* NOTE:
* 'inchoo_custom_info' assumes you have added new attribute/property to Sale/Order entity
* Please use serialize and unserialize with 'inchoo_custom_info'
*/
$extraInfo = $_order->getData('inchoo_custom_info');
?>
< ?php if($extraInfo != null or !empty($extraInfo)): ?>

< ?php $extraInfo = unserialize($extraInfo) ?>
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-products">Extra order info</h4>
</div>
</div>
<div style="height: 30px; padding: 10px; border: #ccc 1px solid; margin-bottom: 20px;">
<pre>
< ?php print_r($extraInfo) ?>
</pre>
</div>
<br /><br /><br /><br /><br /><br /><br />
<div class="clear"></div>
< ?php endif; ?>
< ?php /** END CUSTOM Coded by Branko Ajzele | */ ?>
Feel free to remove all my comments. One thing to keep in
mind here, the url path has the “mytheme” pointing to my
custom theme. Usefull if you do not wish to edit default admin
tempate files. Cooworker and friend of mine, Ivan Weiller,
wrote a nice little plugin for switching the admin themes (to
avoid editing the default one). You can download Admintheme
module here.
Important: Our colour highlighting plugin on this site seems to
lower-case some tag names on xml code, so keep that in mind
if you experience some trouble with sample code.
Huh, we are done! Final result is shown on image.
Cheers…
There are 8 comments
Happy 1st birthday Magento
Magento celebrates his 1st birthday today and we wish to

congratulate them for the first successful year. In this year
Magento evolved to fully usable online store application
and reached version 1.1. Over 425,000 downloads makes
it the fastest growing ecommerce platform on the market.
Community presented over 165 extensions via Magento
Connect, but the real number of add ons is much greater.
Inchoo and Surgeworks will keep you posted for about further
development.
Unprintable Content (Video, Flash, etc.)
Internal Server Error
Many of us who started experimenting with this interface and
tried to place various values for Base URL, came to a dead end
where Magento breaks. Usually, we get Internal Server Error
500 with each page load. The problem lies in the fact that we
can no longer open the Magento administration to correct the
error. What needs to be done in such a scenario?
One of our clients wrote me a message today:
I have put www.mydomain.com in a bad spot.
I changed the base URL to {{base_URL}} and
now im getting a 500 server error on both
the front end and the admin panel. I have
looked through the database and cannot find
the right field to change this value back. Can
you point me in the right direction?
The client went to System> Configuration> Web> Unsecure
and placed an invalid value for Base URL field. Beware of this
field. Unfortunately, Magento just updates it without any pre-
warnings, but change of this specific value can cause Magento
to crash.
Usually, we get an error that looks like this:

The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator,
and inform them of
the time the error occurred, and anything you
might have done that may have caused the
error.
More information about this error may be
available in the server error log.

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×