SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
September 8th, 2009
                                                    www.besthosting4magento.com                                       Published by: inchoo




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                 Step 1: Name the structural block
blocks. This article tells what needs to be in place to create new
                                                                           Open the file layout/page.xml in your active theme folder.
structural block.
                                                                           Inside you will find lines like:
What are structural blocks?                                                 <block type="core/text_list" name="left" as="left"/>
They are the parent blocks of content blocks and serve to                   <block type="core/text_list" name="content" as="content"/>
                                                                            <block type="core/text_list" name="right" as="right"/>
position its content blocks within a store page context. Take
a look at the image below. These structural blocks exist in the            Let’s mimic this and add a new line somewhere inside the same
forms of the header area, left column area, right column…etc.              block tag.
which serve to create the visual structure for a store page. Our
goal is to create a new structural block called “newreference”.             <block type="core/text_list" name="newreference" as="newrefe

                                                                           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.

Created using zinepal.com. Go online to create your own zines or read what others have already published.                               1
September 8th, 2009                                                                                                  Published by: inchoo
Let’s assume we wish the “newreference” block to be placed    TRUNCATE `sales_order_entity_datetime`;
below 2 columns, but above the footer. In this case, our      TRUNCATE `sales_order_entity_decimal`;
                                                              TRUNCATE `sales_order_entity_int`;
updated file could look like this:                            TRUNCATE `sales_order_entity_text`;
                                                              TRUNCATE `sales_order_entity_varchar`;
 <!-- start middle -->
                                                              TRUNCATE `sales_order_int`;
 <div class="middle-container">
                                                              TRUNCATE `sales_order_text`;
 <div class="middle col-2-right-layout">< ?php getChildHtml('breadcrumbs') ?>
                                                              TRUNCATE `sales_order_varchar`;
 <!-- start center -->
                                                              TRUNCATE `sales_flat_quote`;
 <div id="main" class="col-main"><!-- start global messages -->
                                                              TRUNCATE `sales_flat_quote_address`;
 < ?php getChildHtml('global_messages') ?>
                                                              TRUNCATE `sales_flat_quote_address_item`;
 <!-- end global messages -->
                                                              TRUNCATE `sales_flat_quote_item`;
 <!-- start content -->
                                                              TRUNCATE `sales_flat_quote_item_option`;
 < ?php getChildHtml('content') ?>
                                                              TRUNCATE `sales_flat_order_item`;
 <!-- end content --></div>
                                                              TRUNCATE `sendfriend_log`;
 <!-- end center -->
                                                              TRUNCATE `tag`;
                                                              TRUNCATE `tag_relation`;
 <!-- start right -->
                                                              TRUNCATE `tag_summary`;
 <div class="col-right side-col">< ?php getChildHtml('right') ?></div>
                                                              TRUNCATE `wishlist`;
 <!-- end right --></div>
                                                              TRUNCATE `log_quote`;
 <div>< ?php getChildHtml('newreference') ?></div>
                                                              TRUNCATE `report_event`;
 </div>
 <!-- end middle -->
                                                              ALTER TABLE `sales_order` AUTO_INCREMENT=1;

Step 3: Populating structural block
                                                              ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
                                                              ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
                                                              ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
We have the block properly placed, but unfortunately nothing
                                                              ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
is new on the frontsite. Let’s populate the new block with    ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
something. We will put new products block there as an         ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
example. Go to appropriate layout XML file and add this block ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
to appropriate place.                                         ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
                                                              ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
 <reference name="newreference">                              ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
 <block type="catalog/product_new" name="home.product.new" ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
                                                               template="catalog/product/new.phtml" />
 </reference>                                                 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
That’s it. I hope it will help someone
                                                              ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
There are 15 comments                                         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;
How to delete orders in Magento? |                            ALTER TABLE `tag` AUTO_INCREMENT=1;
                                                              ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
Inchoo                                                        ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
                                                              ALTER TABLE `wishlist` AUTO_INCREMENT=1;
                                                              ALTER TABLE `log_quote` AUTO_INCREMENT=1;
You got a Magento project to develop, you created a Magento
                                                              ALTER TABLE `report_event` AUTO_INCREMENT=1;
theme, you placed initial products and categories and you
also placed some test orders to see if Shipping and Payment                 -- reset    customers
methods work as expected. Everything seems to be cool and                   TRUNCATE    `customer_address_entity`;
the client wishes to launch the site. You launch it. When you               TRUNCATE    `customer_address_entity_datetime`;
                                                                            TRUNCATE    `customer_address_entity_decimal`;
enter the administration for the first time after the launch, you           TRUNCATE    `customer_address_entity_int`;
will see all your test orders there. You know those should be               TRUNCATE    `customer_address_entity_text`;
deleted. But how?                                                           TRUNCATE    `customer_address_entity_varchar`;
                                                                            TRUNCATE    `customer_entity`;
If you try to delete orders in the backend, you will find out               TRUNCATE    `customer_entity_datetime`;
that you can only set the status to “cancelled” and the order is            TRUNCATE    `customer_entity_decimal`;
still there. Unfortunately, Magento doesn’t enable us to delete             TRUNCATE    `customer_entity_int`;
those via administration, so you will not see any “Delete order”            TRUNCATE    `customer_entity_text`;
                                                                            TRUNCATE    `customer_entity_varchar`;
button. This can be quite frustrating both to developers and
                                                                            TRUNCATE    `log_customer`;
the merchants. People coming from an SAP world find the                     TRUNCATE    `log_visitor`;
inability to delete to have some merit but there should be a                TRUNCATE    `log_visitor_info`;
status that removes the sales count from the reports i.e. sales,
inventory, etc.                                                             ALTER   TABLE   `customer_address_entity` AUTO_INCREMENT=1;
                                                                            ALTER   TABLE   `customer_address_entity_datetime` AUTO_INCREMEN
 SET FOREIGN_KEY_CHECKS=0;                                                  ALTER   TABLE   `customer_address_entity_decimal` AUTO_INCREMENT
                                                                            ALTER   TABLE   `customer_address_entity_int` AUTO_INCREMENT=1;
 TRUNCATE   `sales_order`;                                                  ALTER   TABLE   `customer_address_entity_text` AUTO_INCREMENT=1;
 TRUNCATE   `sales_order_datetime`;                                         ALTER   TABLE   `customer_address_entity_varchar` AUTO_INCREMENT
 TRUNCATE   `sales_order_decimal`;                                          ALTER   TABLE   `customer_entity` AUTO_INCREMENT=1;
 TRUNCATE   `sales_order_entity`;                                           ALTER   TABLE   `customer_entity_datetime` AUTO_INCREMENT=1;

Created using zinepal.com. Go online to create your own zines or read what others have already published.                              2
September 8th, 2009                                                                                                     Published by: inchoo
 ALTER   TABLE   `customer_entity_decimal` AUTO_INCREMENT=1;                ?>
 ALTER   TABLE   `customer_entity_int` AUTO_INCREMENT=1;
 ALTER   TABLE   `customer_entity_text` AUTO_INCREMENT=1;                   < ?php if (!empty($result)): ?>
 ALTER   TABLE   `customer_entity_varchar` AUTO_INCREMENT=1;                <table id="relatedProductsList">
 ALTER   TABLE   `log_customer` AUTO_INCREMENT=1;                           < ?php foreach ($result as $item): ?>
 ALTER   TABLE   `log_visitor` AUTO_INCREMENT=1;                            <tr class="productInfo">
 ALTER   TABLE   `log_visitor_info` AUTO_INCREMENT=1;                       <td><a href="<?php echo $storeUrl ?>/< ?php echo $item->url_
                                                                            <td>< ?php _e('Starting at') ?> $ < ?php echo floatval($item
 -- Reset all ID counters                                                   </tr>
 TRUNCATE `eav_entity_store`;                                               < ?php endforeach; ?>
 ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;                           </table>
                                                                            < ?php endif; ?>
 SET FOREIGN_KEY_CHECKS=1;
                                                                           Hope some of you find this useful. Especially those who refuse
After you have it executed, the test orders will not be in the             to use Web Services for connecting different systems.
database any more. Keep in mind that this will delete ALL
orders, in the database. So, you should execute this queries               Download connect2MAGE WordPress plugin.
immediately after launch.                                                  There are 6 comments

connect2MAGE | WordPress plugin for                                        Custom checkout cart - How to send
easy Magento database connection                                           email after successful checkout in
Hi everyone. I wrote this little plugin while working on one               Magento | Inchoo
of our projects. If you know your way around WordPress
then you know what $wpdb variable stands for. Imagine the                  Recently I have been working on a custom checkout page for
following scenario. You have WordPress installation on one                 one of our clients in Sweden. I had some trouble figuring out
database, Magento on another. You know your way around                     how to send default Magento order email with all of the order
SQL. You can always make new object based on WPDB class                    info. After an hour or so of studying Magento core code, here
inside your template files giving it database access parameters,           is the solution on how to send email after successful order has
or you can use this plugin and use $MAGEDB the same way                    been made.
you use $wpdb.                                                             Not sure how useful this alone will be for you, so I’ll throw a
Below is a little example of using $MAGEDB to connect to                   little advice along the way. When trying to figure how to reuse
Magento database and retrieve some products by reading id’s                Magento code, separate some time to study the Model classes
from custom field of some post inside your WordPress.                      with more detail. Then “tapping into” and reusing some of
                                                                           them should be far more easier.
Place this code inside one of your templates, like single.php.
 < ?php
                                                                           Latest News RSS box in Magento using
 global $MAGEDB;
 $MAGEDB->show_errors(true);
                                                                           Zend_Feed_Rss | Inchoo
                                                                           You would like to have a eCommerce power of Magento, but
 /** BASIC SETUP */
                                                                           also have a blog to empower your business? In this case,
 //$storeUrl = 'http://server/shop/index.php/';                            you probably know that Magento doesn’t have some article
 $storeUrl = get_option('connect2MAGE_StoreUrl');                          manager in the box. Many clients seek for supplementary
                                                                           solution like Wordpress to accomplish this goal. Ok, so you
 //$urlExt = '.html';
                                                                           created a blog on same or different domain and you would
 $urlExt = get_option('connect2MAGE_UrlExt');
                                                                           like those articles to appear somewhere in Magento (probably
 /** END OF BASIC SETUP */                                                 sidebar). This article will explain how to do it.
                                                          Let’s    create    a
 $entityIds = get_post_custom_values(get_option('connect2MAGE_CustomFieldName'));
                                                                                  file   called     latest_news.phtml
                                                          in    app/design/frontend/default/[your_theme]/template/
 $result = array();                                       callouts/latest_news.phtml
                                                          Now we will create a PHP block that will display the list
 if(!empty($entityIds))                                   of articles from RSS feed. We will use Inchoo RSS for
 {
 $entityIds = $entityIds[0];
                                                          demonstration purposes. In your scenario, replace it with your
 $sql = "SELECT `e`.*, `_table_price`.`value` AS `price`, own valid RSS URL.
                                                           IFNULL(_table_visibility.value, _table_visibility_default.va
 $result = $MAGEDB->get_results($sql);
 var_dump($result);                                                         < ?php $channel = new Zend_Feed_Rss('http://feeds.feedburner
 }
                                                          <div class="block block-latest-news">
 else                                                     <div class="block-title">
 {                                                        <h2>< ?php echo $this->__('Latest News') ?></h2>
                                                          </div>
 echo '<p class="relatedProductInfo">No related products available...</p>';
 }                                                        <div class="block-content">

Created using zinepal.com. Go online to create your own zines or read what others have already published.                                 3
September 8th, 2009                                                                                                        Published by: inchoo
 <ol id="graybox-latest-news">                              • use     the    http://somestore.domain/catalogsearch/
 < ?php foreach ($channel as $item): ?>                        partnumber as a link
 <li><a href="<?php echo $item->link; ?>">< ?php echo $item->title; ?></a></li>
 < ?php endforeach; ?>                                      • show only custom_partnumber field on the search form
 </ol>
 </div>                                                  First, we have to see where does the /advanced come from.
 </div>
                                                                           Lets open our template folder at
Step 2                                                                     appdesignfrontenddefaultdefaulttemplate
Now, we should decide where to place it. I assume you already              catalogsearch
know how Magento blocks and references work. Let’s assume
                                                                           there you will see the /advanced folder. Make a copy of that
you would like to place it in right column by default for whole
                                                                           entire folder, in the same location, and name it to something
catalog. In this case open your app/design/frontend/default/
                                                                           like /custom.
[your_theme]/layout/catalog.xml file and under “default” tag
update “right” reference with something similar.                           Now your /custom folder should have 2 files: form.phtml and
                                                                           result.phtml.
That’s it. You should be able to see the list of articles from RSS
feed with the URLs. Hope this will help someone.                           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

Advanced search in Magento and how to
                                                                           <catalogsearch_advanced_index> tag there. Make the copy of
                                                                           it (including all of the content it hold with the closing tag also).
use it in your own way                                                     Put the copy of that entire small chunk of code right below.
                                                                           Now rename all of the occurrences of “advanced” to “custom”
It’s been a while since my last post. I’ve been working on                 there like on code below:
Magento quite actively last two months. I noticed this negative
                                                                           <catalogsearch_custom_index>
trend in my blogging; more I know about Magento, the less
                                                                           <!– Mage_Catalogsearch –>
I write about it. Some things just look so easy now, and they
start to feel like something I should not write about. Anyhow….
                                                                           <reference name=”root”>
time to share some wisdom with community
Our current client uses somewhat specific (don’t they all) store           <action
set. When I say specific, i don’t imply anything bad about it.             method=”setTemplate”><template>page/2columns-
One of the stand up features at this clients site is the advanced          right.phtml</template></action>
search functionality. One of the coolest features of the built in
advanced search is the possibility to search based on attributes           </reference>
assigned to a product.
                                                                           <reference name=”head”>
To do the search by attributes, your attributes must have that
option turned on when created (or later, when editing an
                                                                           <action              method=”addItem”><type>js_css</
attribute). In our case we had a client that wanted something
                                                                           type><name>calendar/calendar-win2k-1.css</
like
                                                                           name><params/><!–<if/
http://somestore.domain/catalogsearch/partnumber                           ><condition>can_load_calendar_js</condition>–></
or                                                                         action>

http://somestore.domain/catalogsearch/brand                                <action                  method=”addItem”><type>js</
instead of the default one                                                 type><name>calendar/calendar.js</name><!–<params/
http://somestore.domain/catalogsearch/advanced                             ><if/><condition>can_load_calendar_js</condition>–
with all of the searchable fields on form.                                 ></action>

Some of you might say why not use the default and call it a day.           <action                 method=”addItem”><type>js</
Well, default one does not get very user friendly when large               type><name>calendar/lang/calendar-en.js</name><!–
number of custom added searchable attributes are added in                  <params/><if/><condition>can_load_calendar_js</
Magento admin interface. Then the frontend search form gets                condition>–></action>
cluttered and users are easily to get confused.
So in our example we would like to use the advanced search                 <action                 method=”addItem”><type>js</
and all of it’s behaviour and logic but to use it on somewhat              type><name>calendar/calendar-setup.js</name><!–
special link and to hide unnecessary fields. Therefore, our                <params/><if/><condition>can_load_calendar_js</
custom pages he would have only one input field on form and                condition>–></action>
the submit button. How do we set this up? Well, all of the logic
and functionality is already there.                                        </reference>
What we need is to:
                                                                           <reference name=”content”>


Created using zinepal.com. Go online to create your own zines or read what others have already published.                                    4
September 8th, 2009                                                                                                      Published by: inchoo
<block                type=”catalogsearch/custom_form”                     This might not be the best method of reusing already written
name=”catalogsearch_custom_form”                                           code, however I hope it’s any eye opener to somewhat more
template=”catalogsearch/custom/form.phtml”/>                               elegant aproach.
                                                                           Enyoj.
</reference>
                                                                           There are 14 comments
</catalogsearch_custom_index>
Do the same for <catalogsearch_advanced_result> tag.                       Related products
Now go to the appcodecoreMageCatalogSearchBlock
                                                                           There are three types of product relations in Magento:
folder. And make a copy of /Advanced folder naming
                                                                           Up-sells, Related Products, and Cross-sell Products. When
it /Custom. Open /Custom/Form.php and replace
                                                                           viewing a product, Upsells for this product are items that your
class name Mage_CatalogSearch_Block_Advanced_Form
                                                                           customers would ideally buy instead of the product they’re
with    Mage_CatalogSearch_Block_Custom_Form,   then
                                                                           viewing. They might be better quality, produce a higher profit
open     /Custom/Result.php    and    replace   class
                                                                           margin, be more popular, etc. These appear on the product
name Mage_CatalogSearch_Block_Advanced_Result with
                                                                           info page. Related products appear in the product info page
Mage_CatalogSearch_Block_Custom_Result.
                                                                           as well, in the right column. Related products are meant to
Inside Form.php there is getModel() function. DO NOT                       be purchased in addition to the item the customer is viewing.
replace the Mage::getSingleton(’catalogsearch/advanced’);                  Finally, Cross-sell items appear in the shopping cart. When
with Mage::getSingleton(’catalogsearch/custom’);. The point                a customer navigates to the shopping cart (this can happen
is to use the default advanced search logic here. Same goes for            automatically after adding a product, or not), the cross-sells
getSearchModel() function inside Result.php file.                          block displays a selection of items marked as cross-sells to the
Next in line, controllers. We need to make                                 items already in the cart. They’re a bit like impulse buys – like
the copy of AdvancedController.php and name it                             magazines and candy at the cash registers in grocery stores.
CustomController.php, then open it and replace the
class name Mage_CatalogSearch_AdvancedController with
                                                                           Upsells
Mage_CatalogSearch_CustomController.                                       This is the example of the Up-sell. Ideally, the visitor is
                                                                           supposed to analyze those products as they should be relevant
Inside this CustomController.php there is a function
                                                                           to the one that is just loaded.
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 templatecatalogsearchcustom
folder and open form.phtml file.
Inside that file, there is one foreach loop that goes like
                                                                           There are 2 comments
<?php foreach ($this->getSearchableAttributes()                  as
$_attribute): ?>                                                           File upload in Magento
All we need to do now is to place one if() condition
                                                                           Now, Magento already have frontend and admin part of file
right below it. If your custom attribute name (code) is
                                                                           upload option implemented in themes. Since backend part is
“my_custom_attribute” then your if() condition might look
                                                                           still missing, understand that this still doesn’t work, however,
something like
                                                                           if you’re interested how it looks, read on ..
<?php    foreach    ($this->getSearchableAttributes()                 as
                                                                           We are coding module of similar functionality for one of our
$_attribute): ?>
                                                                           clients as we speak, but we have our fingers crossed to see this
<?php if($_code == ‘my_custom_attribute’): ?>
                                                                           option in next Magento version!
…
<?php endif; ?>
<?php endforeach; ?>
And you are done. Now you have somewhat more custom url,
and only one custom field displayed on that url.


Created using zinepal.com. Go online to create your own zines or read what others have already published.                                  5
September 8th, 2009                                                                                                      Published by: inchoo

Inchoo TV – Magento channel                                                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

Making use of Magento getSingleton
                                                                           logical so most of the time you will probably find stuff you need
                                                                           in few minutes or so.
method
In one of my previous articles I showed you how to use                     Figuring out Magento object context
getModel and getData methods in Magento. Although we
                                                                           One of the problems working under the hood of the Magento
should not put those to methods at the same level, since I’d say
                                                                           CMS is determining the context of $this. If you are about
the getModel is a bit more higher. Higher in sense, you first
                                                                           to do any advanced stuff with your template, besides layout
use the geModel to create the instance of object then you use
                                                                           changes, you need to get familiar with Magento’s objects
getData to retrieve the data from that instance. I have said it
                                                                           (classes).
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              Let’s have a look at the /app/design/frontend/default/
widely seen in CMS solutions.                                              default/template/catalog/product/view.phtml file. If you
                                                                           open this file and execute var_dump($this) your browser will
One of the architectural goodies of Magento is it’s Singleton
                                                                           return empty page after a short period of delay. By page I mean
design pattern. In short, Singleton design pattern ensures a
                                                                           on the product view page; the one you see when you click on
class has only one instance. Therefore one should provide a
                                                                           Magetno product. Experienced users will open PHP error log
global point of access to that single instance of a class.
                                                                           and notice the error message caused by var_dump(). Error
So why would you want to limit yourself to only one instance?              message:
Let’s say you have an application that utilizes database                   PHP Fatal error: Allowed memory size of 134217728 bytes
connection. Why would you create multiple instance of the                  exhausted (tried to allocate 121374721 bytes)
same database connection object? What if you had references
                                                                           I like using print_r() and var_dump(), mostly because so far
to an object in multiple places in your application? Wouldn’t
                                                                           I had no positive experience using fancy debug or any other
you like to avoid the overhead of creating a new instance of
                                                                           debugger with systems like Magento.
that object for each reference? Then there is the case where
you might want to pass the object’s state from one reference               Why is PHP throwing errors then? If you google out the
to another rather than always starting from an initial state.              error PHP has thrown at you, you’ll see that PHP 5.2
                                                                           has memory limit. Follow the link http://www.php.net/
Inside the Mage.php file of Magento system there is a
                                                                           manual/en/ini.core.php#ini.memory-limit to see how and
getSingleton method (function if you prefer). Since it’s
                                                                           what exactly.
footprint is rather small, I’ll copy paste the code for you to see
it.                                                                        Google search gave me some useful results trying to solve my
                                                                           problems. I found Krumo at http://krumo.sourceforge.net/.
First, notice the word static. In PHP and in other OOP
                                                                           It’s a PHP debugging tool, replacement for print_r() and
languages keyword static stands for something like “this can
                                                                           var_dump(). After setting up Krumo and running it on
be called on non objects, directly from class”. Now let me show
                                                                           Magento it gave me exactly what I wanted. It gave me the
you the footprint of the getModel method.
                                                                           object type of the dumped file; in this case it gave me object
Do you notice the parameters inside the brackets? They are the             type of $this.
same for both of theme. Where am I getting with this? Well,
                                                                           If you’re using an IDE studio with code completion support
I already showed you how to figure out the list of all of the
                                                                           like NuSphere PhpED, ZendStudio or NetBeans and you
available parameters in one of my previous articles on my site.
                                                                           decide to do something like $this-> you won’t get any methods
So all we need to do at this point is, play with those parameters
                                                                           listed. I haven’t yet seen the IDE that can perform this kind of
using getSingleton() method and observe the results.
                                                                           smart logic and figure out the context of $this by it self.
Most important thing you need to remember is that using
                                                                           What you can do is use the information obtained
getSingleton you are calling already instantiated object. So if
                                                                           by krumo::dump($this). Performing krumo::dump($this)
you get the empty array as a result, it means the object is
                                                                           on /app/design/frontend/default/default/template/catalog/
empty. Only the blueprint is there, but nothing is loaded in it.
                                                                           product/view.phtml file will return object type,
We had the similar case using getModel(’catalog/product‘)
                                                                           Mage_Catalog_Block_Product_View.
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                Now if you do
method to load some data into our newly instantiated object.               Mage_Catalog_Block_Product_View::
What I’m trying to say, you need to play with it                           your IDE supporting code completion will give you
to get the feeling. Some models will return data rich                      a drop down of all the available methods, let’s say
objects some will return empty arrays. If we were to do                    canEmailToFriend();
Created using zinepal.com. Go online to create your own zines or read what others have already published.                                  6
September 8th, 2009                                                                                                       Published by: inchoo
Mage_Catalog_Block_Product_View::canEmailToFriend();                       What is “Best Value” filed?
Now  all  you  need  to   do  is   to    replace
                                                                           When you go to Category page in Magento administration, you
Mage_Catalog_Block_Product_View with $this like
                                                                           will see “Category Products” tab. From there, you will see the
$this->canEmailToFriend();                                                 list of products that are associated to this category. The last
And you’re done. All of this may look like “why do I need this”.           column in “Position”. That is how “Best Value” is determined.
What you need it a smart IDE, one that can figure out the                  So, best value is not something that is dynamically calculated.
context of $this by it self and call the methods accordingly. No           You can tailor it to your likings.
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                 How to change default Sort Order
we had is to show product review info on pages independent                 The file you need to look at is: /app/code/core/Mage/Catalog/
of product review page. Let’s say you wish to show review info             Block/Product/List/Toolbar.php Since we’ll modify it, make a
on home page for some of the products. After few weeks with                copy to /app/code/local/Mage/Catalog/Block/Product/List/
working with Magento, one learns how to use the model stuff                Toolbar.php
directly from view files. Although this might not be the “right”
way, it’s most definitely the fastest way (and I doubt most of             One there, you will notice this code at the beginning of the file:
your clients would prefer any other      , especially if it’s some          $this->_availableOrder = array(
minor modification).                                                        'position' => $this->__('Best Value'),
                                                                            'name'      => $this->__('Name'),
                                                                            'price'     => $this->__('Price')
Simple random banner rotator in                                             );

Magento using static blocks                                                Default order takes the first value available. So, all you have to
                                                                           do is to either:
This is my first post here and I’ll write about my first challenge
regarding Magento since I came to work at Inchoo.                              • reorder it if you want to have a selection in the Toolbar or
Please note that you are not restricted only to images, you                    • set only one value of choice if you will remove the
could use text, video or whatever you want here, but I’ll focus                  selection from the toolbar
on images with links as title says.
In order to show this block, you should be familiar with                   I hope this will help somebody.
Magento layouts.
                                                                           There are 4 comments
Since that is out of scope for this article, I’ll show you how to
put it below the content on cms pages.
                                                                           Couple of days ago we launched a new Magento project:

Changing default category sort order in
                                                                           Pebblehill Designs. This site utilizes Magento features and
                                                                           turns it into a very powerful online catalog. You won’t notice
Magento                                                                    the Shopping Cart or checkout process yet. Even without
                                                                           those, this site shows exactly what Pebblehill has to offer: the
Category toolbar has many options. By default is shows how                 most popular styles of custom upholstered furniture.
many items are in the category, you can choose how many
                                                                           You can customize the furniture collection to express your
products you wish to be displayed per page, you can change
                                                                           own unique style made with the highest quality materials and
the listing type (List or Grid) and you may choose Sort Order.
                                                                           craftsmanship available.
This “Sort Order” can be confusing. The default “Sort Order”
is “Best Value”. What does it mean? How is the Best value                  Pebble Hill Designs’ parsons chairs are “American made” with
determined? Can we change the default sort order?                          pride in Georgia. The quality speaks for itself. Your products
                                                                           are pre-assembled and ready for use when you receive them.


Created using zinepal.com. Go online to create your own zines or read what others have already published.                                   7
September 8th, 2009                                                                                                    Published by: inchoo
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.



                                                                           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
TeraFlex PLUS, another Magento +                                           standard osCommerce platform. After three or four projects,
                                                                           I started to work with CRE Loaded and used it frequently for
Wordpress duo                                                              years. Although it was also an osCommerce fork, it had many
After we launched TeraFlex Suspensions website few months                  advantages. I switched to Magento™ early this year and this
ago, we created a new similar website for Teraflex PLUS.                   is my final choice.
Although the name is similar, this is not the same company.                Google™ Trends is a great tool to check some platforms
The primary goal of this site is to help Jeep owners to upgrade            popularity by comparing it to the competition. For my short
their pets with parts and accessories for any type of adventure.           analysis, I compared:
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
http://www.teraflexplus.com/


                                                                           As you can see, osCommerce still remains the most popular
                                                                           eCommerce platform. However, you can notice that this

Created using zinepal.com. Go online to create your own zines or read what others have already published.                                8
September 8th, 2009                                                                                                      Published by: inchoo
popularity is fading. ZenCart is stable for the past two years.            also tutorial about this on Magento Wiki. However i don’t like
And my previous favorite, CRE Loaded (much better solution                 approach of duplicating and overriding Mage files from /local,
than ZenCart in my opinion), is very low. Its popularity is also           if it can be avoided, so i decided to write this small and useful
fading even after their team put great effort into a new website           example of adding or overriding default Magento settings
and identity.                                                              through separated config files. And yes, Magento values can
                                                                           be overridden this way. Default layouts config can be found
Now, take a look at blue line. My prediction is that sometime
                                                                           in app/code/core/Mage/Cms/etc/config.xml along with used
in Q1 2009, Magento will become most popular eCommerce
                                                                           xml code structure, so check it out. Thank you for listening!
platform. It will surely kick osCommerce off the throne where
that fat duck was sitting for many years. It was about time.
                                                                           Drupal to Magento integration, simple
First of all, let me inform you that this article is for those of          link tweak with multilingual site
you who are just starting with Magento. If you are a Magento
expert, you will probably know this. Consider it just a reminder           I see my coworker and friend Željko Prša made a nice little post
for those who use Magento for first time. There are three                  on Adding a new language in Magento so I figure I’ll jump with
common mistakes that most people do when they try to use                   a little Drupal to Magento integration trick concerning link
Magento for first time, so read this article and you won’t be              issues and multilingual sites. Here is a piece of code you can
one of them.:)                                                             use in your Drupal templates to do the proper switching from
                                                                           Drupal site to Magento while keeping the selected language of
   • More experienced PHP developers will first read                       site. Note, this tweak assumes you have the desired language
     Magento Designers Guide before they try to style                      setup on both Drupal and Magento side.
     Magento, but others won’t and that’s the mistake                      This part goes to some of your Drupal theme file
     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                         global $language ;
     Magento is top copy the whole theme to a new folder,                   $lname = ($language->language == null) ? 'en' : $language->l
                                                                            $storeView = null;
     don’t do that. Copy only the files you will need: from /               if($lname == 'de') { $storeView = '?___store=german&amp;amp;
     design/frontend/default/default/ directory to /design/                 ??>
     frontend/default/YOUR_NEW_THEME directory. Do
     the same thing with /skin/frontend/default/default/                    </p><p style="text-align: left;"><a id="main_menu_shop" href
                                                                            ...
     Congratulations, you have your own theme just like
     that. All that left is to apply new theme (System-                    Note the $storeView variable; GET ___store holds the value
     >Configuration->Design) and you are ready to do with                  of code name of the view you assigned in Magento, while GET
     your theme files whatever you want.                                   ___from_store variable is used as helper to Magento inner
                                                                           workings. You can basically omit the other one. Your links to
   • Third mistake is modifying Magento core files. What files
                                                                           Shop from Drupal to Magento should now activate the proper
     are core ones? All what is in app/code/core folder. If you
                                                                           language, the same one you have active on Drupal side.
     have a need to modify some of those ones, you just need
     to duplicate that file in the same directory path to app/             There are 1 comments
     code/local. For example, if you need to modify the file
     app/code/core/Mage/Checkout/Block/Success.php
                                                                           Adding a new language in Magento
      copy it to                                                           As anything in Magento adding a new language is something
                                                                           that requires a certain procedure which we will explain right
      app/code/local/Mage/Checkout/Block/Success.php                       now and for future reference.
      and leave the core file intact. This way your Magento will               • 3. Now go to: Configuration -> Current Configuration
      be more bullet-proof to future updates.                                    Scope (Select your language from the dropdown) and on
                                                                                 the right side under “Locale options” choose the desired
                                                                                 language.
Custom CMS page layout in Magento |
Inchoo
                                                                           That’s it, now when you go to the frontend of the site, you’ll
                                                                           notice a dropdown menu allowing the language switching.
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
                                                                           Access denied in Magento admin
extension with only config file in it: app/code/local/Inchoo/              Some of you may encountered this problem. You install new
AdditionalCmsPageLayouts/etc/config.xml                                    Magento extension through downloader, try to access its
Add your page/custom-static-page-1.phtml template file (or                 configuration settings and Magento throws “Access denied”
                                                                           page at you. Although you’re administrator of the system.
copy some default one for start) and you’re done There is

Created using zinepal.com. Go online to create your own zines or read what others have already published.                                  9
September 8th, 2009                                                                                                     Published by: inchoo

                                                                           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
So what happened here? Magento just doesn’t have stored                    tables. Therefore, an understanding of EAV principles and
privileges for this new extension.                                         how they have been modeled into Magento it is HIGHLY
First just try to logout and login again. If that doesn’t work,            recommended before making changes to the Magento
you need to reset admin privileges.                                        data or the Magento schema (Wikipedia: Entity-attribute-
                                                                           value_model). Varien has simplified the identification of EAV
Navigate to System->Permissions->Roles                    and     click
                                                                           related tables with consistent naming conventions. Core EAV
Administrators role.
                                                                           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.




Check your Role Resources settings just in case, Resource
Access dropdown should be already set to All for                           Database diagrams and documents found in this post are
administrators.                                                            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
Without changing anything just click “Save Role” button, so
                                                                           For those of you who are into kinky stuff I made a simple,
that Magento re-saves all permissions.
                                                                           more of a proof of concept, application that sits in Widnows
You should be able to access your new extension now without                taskbar and shows the order info in balloon popup. Took me
problems.                                                                  little more than half of hour to get this working. Almost forgot
                                                                           how great C# is
Created using zinepal.com. Go online to create your own zines or read what others have already published.                                10
September 8th, 2009                                                                                                       Published by: inchoo
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.




                                                                           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
And here is the application it self simpleorderpreview and full            (default way), the simple product will not be associative to the
source code (Visual Studio 2008 Express C#, entire solution                grouped product. Let’s see what needs to be changed in that
project) acmnewproducts.                                                   case.

When you un-archive files from simpleorderpreview there is                 On Magento site, there is a nice tutorial how to create a
only one thing you need to do prior to running .exe file. You              grouped product. Please read it first to become familiar with
need to open ACMNewProducts.exe.config and set username,                   the process. If you don’t have to assign simple products with
password and url of your own Magento shop. That’s it. Now                  custom options to a grouped product, that tutorial will be
you can run the app.                                                       enough.

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
                                                                           Manually create Google Sitemap in
options in grouped product in Magento |
                                                                           Magento | Inchoo
Inchoo
                                                                           Most of you probably know this, but let’s define what the
Does the title sound complicated? Grouped Products display                 sitemaps are. Sitemaps are a simple way for site creators to
several products on one page. For example – if you’re selling              give search engines the information about pages on their site
chef’s knives and you have the same knife in four sizes, you can           that are available for public. Basically, those are just 1 or more
make a grouped product to display all four sizes. Customers                XML files that lists URLs for a site along with additional meta
can select the size(s) they want and add to cart from this page.           informatio about each URL (like last update, how often it
Another example would be a themed bedroom set – you can                    changes, its importance relevant to other pages). With this in
create a grouped product and sell the sheets, comforter, and               mind, search engines can be more clever while crawling the
pillow cases all from the same page.                                       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.




Created using zinepal.com. Go online to create your own zines or read what others have already published.                                  11
September 8th, 2009                                                                                                     Published by: inchoo

How do we create Google Sitemap in Magento?                                One of the things that caught my eye and made me
                                                                           wonder about the consequences is the Observer and override
1. Sitemap File Configuration                                              functionality that probably most of the serious custom made
                                                                           Magento modules will utilize. Utilizing Observers enables you
First we need to create sitemap file in Magento. This is
                                                                           to observe and execute some action inside the “customer work
basically pointer to tell Magento where to create sitemap file
                                                                           flow” or even some admin stuff. Such functionality is heavily
and how to name it. Log in to Magento Administration and go
                                                                           known is systems like WordPress and it’s called “hooks”.
to:
                                                                           Besides hooking, another useful an very powerful feature
Catalog -> Google Sitemap
                                                                           which is actually related more to the OOP concept itself is the
Check to see if the sitemap file is already present. Lets                  overriding. Personally i find the combination of observers and
assume we wish to create sitemap in the URL: http://                       overrides to be the coolest and most powerful stuff in Magento
www.yourstore.com/sitemap/sitemap.xml                                      module development.
To do it successfully,
                                                                           So where is the issue? As of time of this writing, the
  1. FTP to the server                                                     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
  2. create sitemap folder                                                 a prepareForCart method signature from app/code/core/
  3. chmod the folder to 777                                               Mage/Catalog/Model/Product/Type/Abstract.php (line 239,
                                                                           Magento version 1.2.1.2):
On some servers, previous steps will not be required, but it is
                                                                           Notice the difference? Although this might not look like
better to create the file first so that Magento can edit it.
                                                                           “that big of a deal” suppose you had implemented override
Let’s go to Magento administration now and click on “Add                   functionality like
Sitemap” button. Just insert the default values.
                                                                           In the above code, we override the prepareForCart method to
After this step, we just told Magento where to create sitemap              to some custom stuff for us. This peace of code would work
file. It is not yet created.                                               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
2. Configure Sitemap
                                                                           To me, stuff like this is a serious downside towards building
Sitemap can be configured from the interface System ->
                                                                           advanced modules. Changing core files and core functionality
Configuration -> Catalog->Google Sitemap. If you are not sure
                                                                           can have serious impact on custom made modules each
what does it all mean, check XML Tag definitions section from
                                                                           Magento upgrade. Therefore, one should keep an eye open
“Sitemaps XML format” document.
                                                                           on what modules he will throw into the shop. Personally I
3. Create Sitemap Manually                                                 consider online stores very serious and have strong feelings
                                                                           about each store owner having somewhat of dedicated
Looks like Magento folks were thinking that sitemap should                 developer that will be in charge even for stuff like adding new
only be created by a cron job. Yes, it can be done that way                modules.
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,           Just consider the financial loss for a store owner of any more
quit your search for “Create Sitemap” button. You will not find            serious web shop if he decides to download the and install
it. But there is a workaround. You can enter manual URL to                 module himself just to realize that for incompatibility reasons
execute sitemap creation:                                                  this new module made his shop fully nonfunctional.
http://www.yourstore.com/index.php/admin/sitemap/
generate/sitemap_id/[ID of Sitemap from step 1]                            How to transfer large Magento database
Of course, replace the content with square brackets with actual            from live to development server and
Sitemap ID.
                                                                           other way round
There are 9 comments
                                                                           I have been involved in Magento development for almost a
                                                                           year now. God knows I had (and still have) my moments of
Observer pitfalls of building serious                                      pain with it     . If you are in professional, everyday, PHP
modules in Magento                                                         development that focuses mainly on Magento then your life
                                                                           probably isn’t all flowers and bees. Magento is extremely rich
Unlike good old WordPress that “every kid in the block” knows              eCommerce platform, but its main downside IMHO is its size
how to create a plugin for, Magento is a whole new system. It              and code complexity. If you download Magento via SVN, you
requires extensive knowledge of OOP, ORM’s, MVC, and few                   will sound find out it has around 11 600 and more files. This
other stuff. This is why not “every kid in the block” can write a          is no small figure. Transferring that much of files over the
module for Magento, and this is why I love it. However, unlike             FTP can be a real night mare. Luckily we have SSH and tar
WordPress, Drupal and other community driven systems out                   command to handle this really neat.
there who keep in mind backward compatibility things with
                                                                           But what about database. Today I worked on database with
Magento things are a bit different.
                                                                           more than 20 000 products in store and with extremely
                                                                           large number of categories. What seemed like easy database
Created using zinepal.com. Go online to create your own zines or read what others have already published.                                12
September 8th, 2009                                                                                                       Published by: inchoo
transfer from live site to local developer machine to do a test            Affiliates for all, are modules I consider loosely related to core.
and fix on few issues tunerd out to be an issue for itself.                They are in one or another way connected to Magento but they
Without further delay, here is my favorite tool to handle all              are self standing, independent, applications.
database related work from now on: Navicat.                                Installation of Affiliate module is a trivial task. It mostly
Among my favorite features is the Data transfer. Directly                  comes down to extracting downloaded archive file to a web
moving one database to another among different MySQL                       accessible directory (to your server, hosting) and configuring
servers works like a charm. I find yourself strangled among                the config.inc file. (For security reasons, try renaming
often database recommended action I suggests you test the                  the config.inc to config.inc.php, plus changing the /lib/
trial version of this tool.                                                bootstrap.php on line 23 to include config.inc.php). After
                                                                           importing affiliates.sql into the database our installation is
Here are some screenshots of Navicat Data transfer in Action.
                                                                           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
There are 4 comments                                                       columns, we wish to have boxes. Blank Theme does just that:
                                                                           provides a layout, but without any heavy styling. This makes

Affiliates for all – Magento integration
                                                                           it excellent base ground for a new Magento project. It doesn’t
                                                                           come with default installation, so you will have to use Magento
Recently one of our clients needed and info on Affiliate module            Connect to get it.
for Magento. When it comes to Magento, word “module” is                    http://www.magentocommerce.com/extension/518/blank-
loosely related. Sure, every module needs config files in order            theme
to report it’s “connection” to Magento core. Modules like this,

Created using zinepal.com. Go online to create your own zines or read what others have already published.                                  13
September 8th, 2009                                                                                                    Published by: inchoo
Magento community member Ross gave a good review
comment:
                                                                           Create a Color Switcher in Magento
This is a great theme to use for wire-framing or as a base                 Magento comes packed with a lot of options. But no matter
for developing a custom theme! It looks like a lot of work has             how many options you put into some product you can never
gone in to slimming down the HTML and CSS, which makes                     cover all of them. One of such options (for now) is a color
it much easier to work with compared to the default theme.                 switcher in Magento. To be more precise, an image switcher
I particularly appreciate the well structured and commented                based on color selection.
CSS. The only things I would want different at this stage is
                                                                           Recently I’ve made a screencast on my site on this subject,
for the ‘callouts’ to be taken out (and removal of associated
                                                                           with somewhat different title. The idea is to have a dropdown
media images), and for this theme to be included in the main
                                                                           box from which you choose a color and based on the color
Magento download (I would even like it to be the ‘default’). 5
                                                                           selection product image changes. All of this is to be based on
stars from me!
                                                                           some simple javascript (in my case, jQuery).
Take a sneak peak of how does product info page looks line
                                                                           Before we continue, you might want to see color switcher in
with no styling, but in finished layout. I’m sure that the CSS
                                                                           action. We used this solution on our Kapitol Reef project.
wizards will find this invaluable.
                                                                           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:




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.



Created using zinepal.com. Go online to create your own zines or read what others have already published.                               14
September 8th, 2009                                                                                                     Published by: inchoo
After this is done we go to the code part. There are three things          After some additional styling you can get some impressive
you need to do here.                                                       results for this. Hope you find it useful.
Upload the jQuery and save it into the /js/jquery/jquery.js.               You can see complete screencast at:
One important note on jQuery; for some reason I had to use                 http://activecodeline.com/wp-content/uploads/videos/
jQuery 1.2.3 to get this example working. Latest version 1.2.6             MagentoProductColorChooser.swf
(as of time of this writing) did not work. You can see the exact
error it gave me on my screencast.                                         There are 28 comments
Now you need to modify /template/page/html/head.phtml

                                                                           Magento’s Onepage Checkout in a
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)
                                                                           nutshell
And finaly, you need to modify the /template/catalog/                      For the last two days I’ve been working on a custom checkout
product/view/media.phtml file to grab all of the product                   page for one of our clients. Basicaly a page can be shown
images and dump them into some div. Here is my sample                      in Magento using simple Core_Template type. Basically all
(media.phtml) so just copy paste the code.                                 code is set inside the .phtml file so it can be shown on every
                                                                           possible page or block, meaning it’s object independent, no
And some additional screenshots for you to see final result
                                                                           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.




Created using zinepal.com. Go online to create your own zines or read what others have already published.                                15
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts
Inchoo s magento posts

Weitere ähnliche Inhalte

Was ist angesagt?

Fixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiFixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiMeet Magento Spain
 
How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?damienwoods
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for MagentoIvan Chepurnyi
 
Blocks In Drupal
Blocks In DrupalBlocks In Drupal
Blocks In Drupalguest6fb0ef
 
Dress Your WordPress with Child Themes
Dress Your WordPress with Child ThemesDress Your WordPress with Child Themes
Dress Your WordPress with Child ThemesLaurie M. Rauch
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalMax Pronko
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPRupesh Kumar
 
Object Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin DevelopmentObject Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin Developmentmtoppa
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentTammy Hart
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Ivan Chepurnyi
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchRuss Weakley
 
Statecharts - Controlling the behavior of complex systems
Statecharts - Controlling the behavior of complex systemsStatecharts - Controlling the behavior of complex systems
Statecharts - Controlling the behavior of complex systemsLuca Matteis
 
How to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.xHow to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.xAndolasoft Inc
 
Creating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsCreating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsMark Jaquith
 

Was ist angesagt? (16)

Fixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiFixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan Chepurnyi
 
How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
 
Blocks In Drupal
Blocks In DrupalBlocks In Drupal
Blocks In Drupal
 
Dress Your WordPress with Child Themes
Dress Your WordPress with Child ThemesDress Your WordPress with Child Themes
Dress Your WordPress with Child Themes
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_Final
 
Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPP
 
Object Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin DevelopmentObject Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin Development
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
 
PHP & MVC
PHP & MVCPHP & MVC
PHP & MVC
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
 
Statecharts - Controlling the behavior of complex systems
Statecharts - Controlling the behavior of complex systemsStatecharts - Controlling the behavior of complex systems
Statecharts - Controlling the behavior of complex systems
 
How to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.xHow to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.x
 
Creating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsCreating and Maintaining WordPress Plugins
Creating and Maintaining WordPress Plugins
 

Ähnlich wie Inchoo s magento posts

TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
PrestaShop Kathmandu Ecommerce Meetup #2
PrestaShop Kathmandu Ecommerce Meetup #2PrestaShop Kathmandu Ecommerce Meetup #2
PrestaShop Kathmandu Ecommerce Meetup #2Hem Pokhrel
 
How to create multi language store in magento 2
How to create multi language store in magento 2How to create multi language store in magento 2
How to create multi language store in magento 2AppJetty
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress sitereferences
 
How to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionHow to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionLitExtension
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Maurizio Pelizzone
 
How to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtensionHow to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtensionLitExtension
 
Html 5, a gentle introduction
Html 5, a gentle introductionHtml 5, a gentle introduction
Html 5, a gentle introductionDiego Scataglini
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?Mage Titans ES
 
How to move Interspire to Magento using LitExtension tool
How to move Interspire to Magento using LitExtension toolHow to move Interspire to Magento using LitExtension tool
How to move Interspire to Magento using LitExtension toolLitExtension
 
Top Wordpress dashboard hacks
Top Wordpress dashboard hacks Top Wordpress dashboard hacks
Top Wordpress dashboard hacks Pankaj Subedi
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - LondonMarek Sotak
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5Ketan Raval
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5ketanraval
 

Ähnlich wie Inchoo s magento posts (20)

TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
PrestaShop Kathmandu Ecommerce Meetup #2
PrestaShop Kathmandu Ecommerce Meetup #2PrestaShop Kathmandu Ecommerce Meetup #2
PrestaShop Kathmandu Ecommerce Meetup #2
 
How to create multi language store in magento 2
How to create multi language store in magento 2How to create multi language store in magento 2
How to create multi language store in magento 2
 
Steps to Setup Magento Multi-Stores
Steps to Setup Magento Multi-StoresSteps to Setup Magento Multi-Stores
Steps to Setup Magento Multi-Stores
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
hellowired_instructions
hellowired_instructionshellowired_instructions
hellowired_instructions
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Wave Workshop
Wave WorkshopWave Workshop
Wave Workshop
 
How to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionHow to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtension
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
How to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtensionHow to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtension
 
Html 5, a gentle introduction
Html 5, a gentle introductionHtml 5, a gentle introduction
Html 5, a gentle introduction
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?
 
puissance-2roue
puissance-2rouepuissance-2roue
puissance-2roue
 
How to move Interspire to Magento using LitExtension tool
How to move Interspire to Magento using LitExtension toolHow to move Interspire to Magento using LitExtension tool
How to move Interspire to Magento using LitExtension tool
 
Top Wordpress dashboard hacks
Top Wordpress dashboard hacks Top Wordpress dashboard hacks
Top Wordpress dashboard hacks
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 

Inchoo s magento posts

  • 1. September 8th, 2009 www.besthosting4magento.com Published by: inchoo 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 Step 1: Name the structural block blocks. This article tells what needs to be in place to create new Open the file layout/page.xml in your active theme folder. structural block. Inside you will find lines like: What are structural blocks? <block type="core/text_list" name="left" as="left"/> They are the parent blocks of content blocks and serve to <block type="core/text_list" name="content" as="content"/> <block type="core/text_list" name="right" as="right"/> position its content blocks within a store page context. Take a look at the image below. These structural blocks exist in the Let’s mimic this and add a new line somewhere inside the same forms of the header area, left column area, right column…etc. block tag. which serve to create the visual structure for a store page. Our goal is to create a new structural block called “newreference”. <block type="core/text_list" name="newreference" as="newrefe 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. Created using zinepal.com. Go online to create your own zines or read what others have already published. 1
  • 2. September 8th, 2009 Published by: inchoo Let’s assume we wish the “newreference” block to be placed TRUNCATE `sales_order_entity_datetime`; below 2 columns, but above the footer. In this case, our TRUNCATE `sales_order_entity_decimal`; TRUNCATE `sales_order_entity_int`; updated file could look like this: TRUNCATE `sales_order_entity_text`; TRUNCATE `sales_order_entity_varchar`; <!-- start middle --> TRUNCATE `sales_order_int`; <div class="middle-container"> TRUNCATE `sales_order_text`; <div class="middle col-2-right-layout">< ?php getChildHtml('breadcrumbs') ?> TRUNCATE `sales_order_varchar`; <!-- start center --> TRUNCATE `sales_flat_quote`; <div id="main" class="col-main"><!-- start global messages --> TRUNCATE `sales_flat_quote_address`; < ?php getChildHtml('global_messages') ?> TRUNCATE `sales_flat_quote_address_item`; <!-- end global messages --> TRUNCATE `sales_flat_quote_item`; <!-- start content --> TRUNCATE `sales_flat_quote_item_option`; < ?php getChildHtml('content') ?> TRUNCATE `sales_flat_order_item`; <!-- end content --></div> TRUNCATE `sendfriend_log`; <!-- end center --> TRUNCATE `tag`; TRUNCATE `tag_relation`; <!-- start right --> TRUNCATE `tag_summary`; <div class="col-right side-col">< ?php getChildHtml('right') ?></div> TRUNCATE `wishlist`; <!-- end right --></div> TRUNCATE `log_quote`; <div>< ?php getChildHtml('newreference') ?></div> TRUNCATE `report_event`; </div> <!-- end middle --> ALTER TABLE `sales_order` AUTO_INCREMENT=1; Step 3: Populating structural block ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1; ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1; ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1; We have the block properly placed, but unfortunately nothing ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1; is new on the frontsite. Let’s populate the new block with ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1; something. We will put new products block there as an ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1; example. Go to appropriate layout XML file and add this block ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1; to appropriate place. ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1; ALTER TABLE `sales_order_int` AUTO_INCREMENT=1; <reference name="newreference"> ALTER TABLE `sales_order_text` AUTO_INCREMENT=1; <block type="catalog/product_new" name="home.product.new" ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1; template="catalog/product/new.phtml" /> </reference> 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 That’s it. I hope it will help someone ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1; There are 15 comments 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; How to delete orders in Magento? | ALTER TABLE `tag` AUTO_INCREMENT=1; ALTER TABLE `tag_relation` AUTO_INCREMENT=1; Inchoo ALTER TABLE `tag_summary` AUTO_INCREMENT=1; ALTER TABLE `wishlist` AUTO_INCREMENT=1; ALTER TABLE `log_quote` AUTO_INCREMENT=1; You got a Magento project to develop, you created a Magento ALTER TABLE `report_event` AUTO_INCREMENT=1; theme, you placed initial products and categories and you also placed some test orders to see if Shipping and Payment -- reset customers methods work as expected. Everything seems to be cool and TRUNCATE `customer_address_entity`; the client wishes to launch the site. You launch it. When you TRUNCATE `customer_address_entity_datetime`; TRUNCATE `customer_address_entity_decimal`; enter the administration for the first time after the launch, you TRUNCATE `customer_address_entity_int`; will see all your test orders there. You know those should be TRUNCATE `customer_address_entity_text`; deleted. But how? TRUNCATE `customer_address_entity_varchar`; TRUNCATE `customer_entity`; If you try to delete orders in the backend, you will find out TRUNCATE `customer_entity_datetime`; that you can only set the status to “cancelled” and the order is TRUNCATE `customer_entity_decimal`; still there. Unfortunately, Magento doesn’t enable us to delete TRUNCATE `customer_entity_int`; those via administration, so you will not see any “Delete order” TRUNCATE `customer_entity_text`; TRUNCATE `customer_entity_varchar`; button. This can be quite frustrating both to developers and TRUNCATE `log_customer`; the merchants. People coming from an SAP world find the TRUNCATE `log_visitor`; inability to delete to have some merit but there should be a TRUNCATE `log_visitor_info`; status that removes the sales count from the reports i.e. sales, inventory, etc. ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1; ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMEN SET FOREIGN_KEY_CHECKS=0; ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1; TRUNCATE `sales_order`; ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1; TRUNCATE `sales_order_datetime`; ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT TRUNCATE `sales_order_decimal`; ALTER TABLE `customer_entity` AUTO_INCREMENT=1; TRUNCATE `sales_order_entity`; ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1; Created using zinepal.com. Go online to create your own zines or read what others have already published. 2
  • 3. September 8th, 2009 Published by: inchoo ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1; ?> ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1; ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1; < ?php if (!empty($result)): ?> ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1; <table id="relatedProductsList"> ALTER TABLE `log_customer` AUTO_INCREMENT=1; < ?php foreach ($result as $item): ?> ALTER TABLE `log_visitor` AUTO_INCREMENT=1; <tr class="productInfo"> ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1; <td><a href="<?php echo $storeUrl ?>/< ?php echo $item->url_ <td>< ?php _e('Starting at') ?> $ < ?php echo floatval($item -- Reset all ID counters </tr> TRUNCATE `eav_entity_store`; < ?php endforeach; ?> ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1; </table> < ?php endif; ?> SET FOREIGN_KEY_CHECKS=1; Hope some of you find this useful. Especially those who refuse After you have it executed, the test orders will not be in the to use Web Services for connecting different systems. database any more. Keep in mind that this will delete ALL orders, in the database. So, you should execute this queries Download connect2MAGE WordPress plugin. immediately after launch. There are 6 comments connect2MAGE | WordPress plugin for Custom checkout cart - How to send easy Magento database connection email after successful checkout in Hi everyone. I wrote this little plugin while working on one Magento | Inchoo of our projects. If you know your way around WordPress then you know what $wpdb variable stands for. Imagine the Recently I have been working on a custom checkout page for following scenario. You have WordPress installation on one one of our clients in Sweden. I had some trouble figuring out database, Magento on another. You know your way around how to send default Magento order email with all of the order SQL. You can always make new object based on WPDB class info. After an hour or so of studying Magento core code, here inside your template files giving it database access parameters, is the solution on how to send email after successful order has or you can use this plugin and use $MAGEDB the same way been made. you use $wpdb. Not sure how useful this alone will be for you, so I’ll throw a Below is a little example of using $MAGEDB to connect to little advice along the way. When trying to figure how to reuse Magento database and retrieve some products by reading id’s Magento code, separate some time to study the Model classes from custom field of some post inside your WordPress. with more detail. Then “tapping into” and reusing some of them should be far more easier. Place this code inside one of your templates, like single.php. < ?php Latest News RSS box in Magento using global $MAGEDB; $MAGEDB->show_errors(true); Zend_Feed_Rss | Inchoo You would like to have a eCommerce power of Magento, but /** BASIC SETUP */ also have a blog to empower your business? In this case, //$storeUrl = 'http://server/shop/index.php/'; you probably know that Magento doesn’t have some article $storeUrl = get_option('connect2MAGE_StoreUrl'); manager in the box. Many clients seek for supplementary solution like Wordpress to accomplish this goal. Ok, so you //$urlExt = '.html'; created a blog on same or different domain and you would $urlExt = get_option('connect2MAGE_UrlExt'); like those articles to appear somewhere in Magento (probably /** END OF BASIC SETUP */ sidebar). This article will explain how to do it. Let’s create a $entityIds = get_post_custom_values(get_option('connect2MAGE_CustomFieldName')); file called latest_news.phtml in app/design/frontend/default/[your_theme]/template/ $result = array(); callouts/latest_news.phtml Now we will create a PHP block that will display the list if(!empty($entityIds)) of articles from RSS feed. We will use Inchoo RSS for { $entityIds = $entityIds[0]; demonstration purposes. In your scenario, replace it with your $sql = "SELECT `e`.*, `_table_price`.`value` AS `price`, own valid RSS URL. IFNULL(_table_visibility.value, _table_visibility_default.va $result = $MAGEDB->get_results($sql); var_dump($result); < ?php $channel = new Zend_Feed_Rss('http://feeds.feedburner } <div class="block block-latest-news"> else <div class="block-title"> { <h2>< ?php echo $this->__('Latest News') ?></h2> </div> echo '<p class="relatedProductInfo">No related products available...</p>'; } <div class="block-content"> Created using zinepal.com. Go online to create your own zines or read what others have already published. 3
  • 4. September 8th, 2009 Published by: inchoo <ol id="graybox-latest-news"> • use the http://somestore.domain/catalogsearch/ < ?php foreach ($channel as $item): ?> partnumber as a link <li><a href="<?php echo $item->link; ?>">< ?php echo $item->title; ?></a></li> < ?php endforeach; ?> • show only custom_partnumber field on the search form </ol> </div> First, we have to see where does the /advanced come from. </div> Lets open our template folder at Step 2 appdesignfrontenddefaultdefaulttemplate Now, we should decide where to place it. I assume you already catalogsearch know how Magento blocks and references work. Let’s assume there you will see the /advanced folder. Make a copy of that you would like to place it in right column by default for whole entire folder, in the same location, and name it to something catalog. In this case open your app/design/frontend/default/ like /custom. [your_theme]/layout/catalog.xml file and under “default” tag update “right” reference with something similar. Now your /custom folder should have 2 files: form.phtml and result.phtml. That’s it. You should be able to see the list of articles from RSS feed with the URLs. Hope this will help someone. 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 Advanced search in Magento and how to <catalogsearch_advanced_index> tag there. Make the copy of it (including all of the content it hold with the closing tag also). use it in your own way Put the copy of that entire small chunk of code right below. Now rename all of the occurrences of “advanced” to “custom” It’s been a while since my last post. I’ve been working on there like on code below: Magento quite actively last two months. I noticed this negative <catalogsearch_custom_index> trend in my blogging; more I know about Magento, the less <!– Mage_Catalogsearch –> I write about it. Some things just look so easy now, and they start to feel like something I should not write about. Anyhow…. <reference name=”root”> time to share some wisdom with community Our current client uses somewhat specific (don’t they all) store <action set. When I say specific, i don’t imply anything bad about it. method=”setTemplate”><template>page/2columns- One of the stand up features at this clients site is the advanced right.phtml</template></action> search functionality. One of the coolest features of the built in advanced search is the possibility to search based on attributes </reference> assigned to a product. <reference name=”head”> To do the search by attributes, your attributes must have that option turned on when created (or later, when editing an <action method=”addItem”><type>js_css</ attribute). In our case we had a client that wanted something type><name>calendar/calendar-win2k-1.css</ like name><params/><!–<if/ http://somestore.domain/catalogsearch/partnumber ><condition>can_load_calendar_js</condition>–></ or action> http://somestore.domain/catalogsearch/brand <action method=”addItem”><type>js</ instead of the default one type><name>calendar/calendar.js</name><!–<params/ http://somestore.domain/catalogsearch/advanced ><if/><condition>can_load_calendar_js</condition>– with all of the searchable fields on form. ></action> Some of you might say why not use the default and call it a day. <action method=”addItem”><type>js</ Well, default one does not get very user friendly when large type><name>calendar/lang/calendar-en.js</name><!– number of custom added searchable attributes are added in <params/><if/><condition>can_load_calendar_js</ Magento admin interface. Then the frontend search form gets condition>–></action> cluttered and users are easily to get confused. So in our example we would like to use the advanced search <action method=”addItem”><type>js</ and all of it’s behaviour and logic but to use it on somewhat type><name>calendar/calendar-setup.js</name><!– special link and to hide unnecessary fields. Therefore, our <params/><if/><condition>can_load_calendar_js</ custom pages he would have only one input field on form and condition>–></action> the submit button. How do we set this up? Well, all of the logic and functionality is already there. </reference> What we need is to: <reference name=”content”> Created using zinepal.com. Go online to create your own zines or read what others have already published. 4
  • 5. September 8th, 2009 Published by: inchoo <block type=”catalogsearch/custom_form” This might not be the best method of reusing already written name=”catalogsearch_custom_form” code, however I hope it’s any eye opener to somewhat more template=”catalogsearch/custom/form.phtml”/> elegant aproach. Enyoj. </reference> There are 14 comments </catalogsearch_custom_index> Do the same for <catalogsearch_advanced_result> tag. Related products Now go to the appcodecoreMageCatalogSearchBlock There are three types of product relations in Magento: folder. And make a copy of /Advanced folder naming Up-sells, Related Products, and Cross-sell Products. When it /Custom. Open /Custom/Form.php and replace viewing a product, Upsells for this product are items that your class name Mage_CatalogSearch_Block_Advanced_Form customers would ideally buy instead of the product they’re with Mage_CatalogSearch_Block_Custom_Form, then viewing. They might be better quality, produce a higher profit open /Custom/Result.php and replace class margin, be more popular, etc. These appear on the product name Mage_CatalogSearch_Block_Advanced_Result with info page. Related products appear in the product info page Mage_CatalogSearch_Block_Custom_Result. as well, in the right column. Related products are meant to Inside Form.php there is getModel() function. DO NOT be purchased in addition to the item the customer is viewing. replace the Mage::getSingleton(’catalogsearch/advanced’); Finally, Cross-sell items appear in the shopping cart. When with Mage::getSingleton(’catalogsearch/custom’);. The point a customer navigates to the shopping cart (this can happen is to use the default advanced search logic here. Same goes for automatically after adding a product, or not), the cross-sells getSearchModel() function inside Result.php file. block displays a selection of items marked as cross-sells to the Next in line, controllers. We need to make items already in the cart. They’re a bit like impulse buys – like the copy of AdvancedController.php and name it magazines and candy at the cash registers in grocery stores. CustomController.php, then open it and replace the class name Mage_CatalogSearch_AdvancedController with Upsells Mage_CatalogSearch_CustomController. This is the example of the Up-sell. Ideally, the visitor is supposed to analyze those products as they should be relevant Inside this CustomController.php there is a function to the one that is just loaded. 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 templatecatalogsearchcustom folder and open form.phtml file. Inside that file, there is one foreach loop that goes like There are 2 comments <?php foreach ($this->getSearchableAttributes() as $_attribute): ?> File upload in Magento All we need to do now is to place one if() condition Now, Magento already have frontend and admin part of file right below it. If your custom attribute name (code) is upload option implemented in themes. Since backend part is “my_custom_attribute” then your if() condition might look still missing, understand that this still doesn’t work, however, something like if you’re interested how it looks, read on .. <?php foreach ($this->getSearchableAttributes() as We are coding module of similar functionality for one of our $_attribute): ?> clients as we speak, but we have our fingers crossed to see this <?php if($_code == ‘my_custom_attribute’): ?> option in next Magento version! … <?php endif; ?> <?php endforeach; ?> And you are done. Now you have somewhat more custom url, and only one custom field displayed on that url. Created using zinepal.com. Go online to create your own zines or read what others have already published. 5
  • 6. September 8th, 2009 Published by: inchoo Inchoo TV – Magento channel 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 Making use of Magento getSingleton logical so most of the time you will probably find stuff you need in few minutes or so. method In one of my previous articles I showed you how to use Figuring out Magento object context getModel and getData methods in Magento. Although we One of the problems working under the hood of the Magento should not put those to methods at the same level, since I’d say CMS is determining the context of $this. If you are about the getModel is a bit more higher. Higher in sense, you first to do any advanced stuff with your template, besides layout use the geModel to create the instance of object then you use changes, you need to get familiar with Magento’s objects getData to retrieve the data from that instance. I have said it (classes). 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 Let’s have a look at the /app/design/frontend/default/ widely seen in CMS solutions. default/template/catalog/product/view.phtml file. If you open this file and execute var_dump($this) your browser will One of the architectural goodies of Magento is it’s Singleton return empty page after a short period of delay. By page I mean design pattern. In short, Singleton design pattern ensures a on the product view page; the one you see when you click on class has only one instance. Therefore one should provide a Magetno product. Experienced users will open PHP error log global point of access to that single instance of a class. and notice the error message caused by var_dump(). Error So why would you want to limit yourself to only one instance? message: Let’s say you have an application that utilizes database PHP Fatal error: Allowed memory size of 134217728 bytes connection. Why would you create multiple instance of the exhausted (tried to allocate 121374721 bytes) same database connection object? What if you had references I like using print_r() and var_dump(), mostly because so far to an object in multiple places in your application? Wouldn’t I had no positive experience using fancy debug or any other you like to avoid the overhead of creating a new instance of debugger with systems like Magento. that object for each reference? Then there is the case where you might want to pass the object’s state from one reference Why is PHP throwing errors then? If you google out the to another rather than always starting from an initial state. error PHP has thrown at you, you’ll see that PHP 5.2 has memory limit. Follow the link http://www.php.net/ Inside the Mage.php file of Magento system there is a manual/en/ini.core.php#ini.memory-limit to see how and getSingleton method (function if you prefer). Since it’s what exactly. footprint is rather small, I’ll copy paste the code for you to see it. Google search gave me some useful results trying to solve my problems. I found Krumo at http://krumo.sourceforge.net/. First, notice the word static. In PHP and in other OOP It’s a PHP debugging tool, replacement for print_r() and languages keyword static stands for something like “this can var_dump(). After setting up Krumo and running it on be called on non objects, directly from class”. Now let me show Magento it gave me exactly what I wanted. It gave me the you the footprint of the getModel method. object type of the dumped file; in this case it gave me object Do you notice the parameters inside the brackets? They are the type of $this. same for both of theme. Where am I getting with this? Well, If you’re using an IDE studio with code completion support I already showed you how to figure out the list of all of the like NuSphere PhpED, ZendStudio or NetBeans and you available parameters in one of my previous articles on my site. decide to do something like $this-> you won’t get any methods So all we need to do at this point is, play with those parameters listed. I haven’t yet seen the IDE that can perform this kind of using getSingleton() method and observe the results. smart logic and figure out the context of $this by it self. Most important thing you need to remember is that using What you can do is use the information obtained getSingleton you are calling already instantiated object. So if by krumo::dump($this). Performing krumo::dump($this) you get the empty array as a result, it means the object is on /app/design/frontend/default/default/template/catalog/ empty. Only the blueprint is there, but nothing is loaded in it. product/view.phtml file will return object type, We had the similar case using getModel(’catalog/product‘) Mage_Catalog_Block_Product_View. 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 Now if you do method to load some data into our newly instantiated object. Mage_Catalog_Block_Product_View:: What I’m trying to say, you need to play with it your IDE supporting code completion will give you to get the feeling. Some models will return data rich a drop down of all the available methods, let’s say objects some will return empty arrays. If we were to do canEmailToFriend(); Created using zinepal.com. Go online to create your own zines or read what others have already published. 6
  • 7. September 8th, 2009 Published by: inchoo Mage_Catalog_Block_Product_View::canEmailToFriend(); What is “Best Value” filed? Now all you need to do is to replace When you go to Category page in Magento administration, you Mage_Catalog_Block_Product_View with $this like will see “Category Products” tab. From there, you will see the $this->canEmailToFriend(); list of products that are associated to this category. The last And you’re done. All of this may look like “why do I need this”. column in “Position”. That is how “Best Value” is determined. What you need it a smart IDE, one that can figure out the So, best value is not something that is dynamically calculated. context of $this by it self and call the methods accordingly. No You can tailor it to your likings. 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 How to change default Sort Order we had is to show product review info on pages independent The file you need to look at is: /app/code/core/Mage/Catalog/ of product review page. Let’s say you wish to show review info Block/Product/List/Toolbar.php Since we’ll modify it, make a on home page for some of the products. After few weeks with copy to /app/code/local/Mage/Catalog/Block/Product/List/ working with Magento, one learns how to use the model stuff Toolbar.php directly from view files. Although this might not be the “right” way, it’s most definitely the fastest way (and I doubt most of One there, you will notice this code at the beginning of the file: your clients would prefer any other , especially if it’s some $this->_availableOrder = array( minor modification). 'position' => $this->__('Best Value'), 'name' => $this->__('Name'), 'price' => $this->__('Price') Simple random banner rotator in ); Magento using static blocks Default order takes the first value available. So, all you have to do is to either: This is my first post here and I’ll write about my first challenge regarding Magento since I came to work at Inchoo. • reorder it if you want to have a selection in the Toolbar or Please note that you are not restricted only to images, you • set only one value of choice if you will remove the could use text, video or whatever you want here, but I’ll focus selection from the toolbar on images with links as title says. In order to show this block, you should be familiar with I hope this will help somebody. Magento layouts. There are 4 comments Since that is out of scope for this article, I’ll show you how to put it below the content on cms pages. Couple of days ago we launched a new Magento project: Changing default category sort order in Pebblehill Designs. This site utilizes Magento features and turns it into a very powerful online catalog. You won’t notice Magento the Shopping Cart or checkout process yet. Even without those, this site shows exactly what Pebblehill has to offer: the Category toolbar has many options. By default is shows how most popular styles of custom upholstered furniture. many items are in the category, you can choose how many You can customize the furniture collection to express your products you wish to be displayed per page, you can change own unique style made with the highest quality materials and the listing type (List or Grid) and you may choose Sort Order. craftsmanship available. This “Sort Order” can be confusing. The default “Sort Order” is “Best Value”. What does it mean? How is the Best value Pebble Hill Designs’ parsons chairs are “American made” with determined? Can we change the default sort order? pride in Georgia. The quality speaks for itself. Your products are pre-assembled and ready for use when you receive them. Created using zinepal.com. Go online to create your own zines or read what others have already published. 7
  • 8. September 8th, 2009 Published by: inchoo 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. 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 TeraFlex PLUS, another Magento + standard osCommerce platform. After three or four projects, I started to work with CRE Loaded and used it frequently for Wordpress duo years. Although it was also an osCommerce fork, it had many After we launched TeraFlex Suspensions website few months advantages. I switched to Magento™ early this year and this ago, we created a new similar website for Teraflex PLUS. is my final choice. Although the name is similar, this is not the same company. Google™ Trends is a great tool to check some platforms The primary goal of this site is to help Jeep owners to upgrade popularity by comparing it to the competition. For my short their pets with parts and accessories for any type of adventure. analysis, I compared: 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 http://www.teraflexplus.com/ As you can see, osCommerce still remains the most popular eCommerce platform. However, you can notice that this Created using zinepal.com. Go online to create your own zines or read what others have already published. 8
  • 9. September 8th, 2009 Published by: inchoo popularity is fading. ZenCart is stable for the past two years. also tutorial about this on Magento Wiki. However i don’t like And my previous favorite, CRE Loaded (much better solution approach of duplicating and overriding Mage files from /local, than ZenCart in my opinion), is very low. Its popularity is also if it can be avoided, so i decided to write this small and useful fading even after their team put great effort into a new website example of adding or overriding default Magento settings and identity. through separated config files. And yes, Magento values can be overridden this way. Default layouts config can be found Now, take a look at blue line. My prediction is that sometime in app/code/core/Mage/Cms/etc/config.xml along with used in Q1 2009, Magento will become most popular eCommerce xml code structure, so check it out. Thank you for listening! platform. It will surely kick osCommerce off the throne where that fat duck was sitting for many years. It was about time. Drupal to Magento integration, simple First of all, let me inform you that this article is for those of link tweak with multilingual site you who are just starting with Magento. If you are a Magento expert, you will probably know this. Consider it just a reminder I see my coworker and friend Željko Prša made a nice little post for those who use Magento for first time. There are three on Adding a new language in Magento so I figure I’ll jump with common mistakes that most people do when they try to use a little Drupal to Magento integration trick concerning link Magento for first time, so read this article and you won’t be issues and multilingual sites. Here is a piece of code you can one of them.:) use in your Drupal templates to do the proper switching from Drupal site to Magento while keeping the selected language of • More experienced PHP developers will first read site. Note, this tweak assumes you have the desired language Magento Designers Guide before they try to style setup on both Drupal and Magento side. Magento, but others won’t and that’s the mistake This part goes to some of your Drupal theme file 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 global $language ; Magento is top copy the whole theme to a new folder, $lname = ($language->language == null) ? 'en' : $language->l $storeView = null; don’t do that. Copy only the files you will need: from / if($lname == 'de') { $storeView = '?___store=german&amp;amp; design/frontend/default/default/ directory to /design/ ??> frontend/default/YOUR_NEW_THEME directory. Do the same thing with /skin/frontend/default/default/ </p><p style="text-align: left;"><a id="main_menu_shop" href ... Congratulations, you have your own theme just like that. All that left is to apply new theme (System- Note the $storeView variable; GET ___store holds the value >Configuration->Design) and you are ready to do with of code name of the view you assigned in Magento, while GET your theme files whatever you want. ___from_store variable is used as helper to Magento inner workings. You can basically omit the other one. Your links to • Third mistake is modifying Magento core files. What files Shop from Drupal to Magento should now activate the proper are core ones? All what is in app/code/core folder. If you language, the same one you have active on Drupal side. have a need to modify some of those ones, you just need to duplicate that file in the same directory path to app/ There are 1 comments code/local. For example, if you need to modify the file app/code/core/Mage/Checkout/Block/Success.php Adding a new language in Magento copy it to As anything in Magento adding a new language is something that requires a certain procedure which we will explain right app/code/local/Mage/Checkout/Block/Success.php now and for future reference. and leave the core file intact. This way your Magento will • 3. Now go to: Configuration -> Current Configuration be more bullet-proof to future updates. Scope (Select your language from the dropdown) and on the right side under “Locale options” choose the desired language. Custom CMS page layout in Magento | Inchoo That’s it, now when you go to the frontend of the site, you’ll notice a dropdown menu allowing the language switching. 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 Access denied in Magento admin extension with only config file in it: app/code/local/Inchoo/ Some of you may encountered this problem. You install new AdditionalCmsPageLayouts/etc/config.xml Magento extension through downloader, try to access its Add your page/custom-static-page-1.phtml template file (or configuration settings and Magento throws “Access denied” page at you. Although you’re administrator of the system. copy some default one for start) and you’re done There is Created using zinepal.com. Go online to create your own zines or read what others have already published. 9
  • 10. September 8th, 2009 Published by: inchoo 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 So what happened here? Magento just doesn’t have stored tables. Therefore, an understanding of EAV principles and privileges for this new extension. how they have been modeled into Magento it is HIGHLY First just try to logout and login again. If that doesn’t work, recommended before making changes to the Magento you need to reset admin privileges. data or the Magento schema (Wikipedia: Entity-attribute- value_model). Varien has simplified the identification of EAV Navigate to System->Permissions->Roles and click related tables with consistent naming conventions. Core EAV Administrators role. 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. Check your Role Resources settings just in case, Resource Access dropdown should be already set to All for Database diagrams and documents found in this post are administrators. 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 Without changing anything just click “Save Role” button, so For those of you who are into kinky stuff I made a simple, that Magento re-saves all permissions. more of a proof of concept, application that sits in Widnows You should be able to access your new extension now without taskbar and shows the order info in balloon popup. Took me problems. little more than half of hour to get this working. Almost forgot how great C# is Created using zinepal.com. Go online to create your own zines or read what others have already published. 10
  • 11. September 8th, 2009 Published by: inchoo 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. 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 And here is the application it self simpleorderpreview and full (default way), the simple product will not be associative to the source code (Visual Studio 2008 Express C#, entire solution grouped product. Let’s see what needs to be changed in that project) acmnewproducts. case. When you un-archive files from simpleorderpreview there is On Magento site, there is a nice tutorial how to create a only one thing you need to do prior to running .exe file. You grouped product. Please read it first to become familiar with need to open ACMNewProducts.exe.config and set username, the process. If you don’t have to assign simple products with password and url of your own Magento shop. That’s it. Now custom options to a grouped product, that tutorial will be you can run the app. enough. 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 Manually create Google Sitemap in options in grouped product in Magento | Magento | Inchoo Inchoo Most of you probably know this, but let’s define what the Does the title sound complicated? Grouped Products display sitemaps are. Sitemaps are a simple way for site creators to several products on one page. For example – if you’re selling give search engines the information about pages on their site chef’s knives and you have the same knife in four sizes, you can that are available for public. Basically, those are just 1 or more make a grouped product to display all four sizes. Customers XML files that lists URLs for a site along with additional meta can select the size(s) they want and add to cart from this page. informatio about each URL (like last update, how often it Another example would be a themed bedroom set – you can changes, its importance relevant to other pages). With this in create a grouped product and sell the sheets, comforter, and mind, search engines can be more clever while crawling the pillow cases all from the same page. 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. Created using zinepal.com. Go online to create your own zines or read what others have already published. 11
  • 12. September 8th, 2009 Published by: inchoo How do we create Google Sitemap in Magento? One of the things that caught my eye and made me wonder about the consequences is the Observer and override 1. Sitemap File Configuration functionality that probably most of the serious custom made Magento modules will utilize. Utilizing Observers enables you First we need to create sitemap file in Magento. This is to observe and execute some action inside the “customer work basically pointer to tell Magento where to create sitemap file flow” or even some admin stuff. Such functionality is heavily and how to name it. Log in to Magento Administration and go known is systems like WordPress and it’s called “hooks”. to: Besides hooking, another useful an very powerful feature Catalog -> Google Sitemap which is actually related more to the OOP concept itself is the Check to see if the sitemap file is already present. Lets overriding. Personally i find the combination of observers and assume we wish to create sitemap in the URL: http:// overrides to be the coolest and most powerful stuff in Magento www.yourstore.com/sitemap/sitemap.xml module development. To do it successfully, So where is the issue? As of time of this writing, the 1. FTP to the server 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 2. create sitemap folder a prepareForCart method signature from app/code/core/ 3. chmod the folder to 777 Mage/Catalog/Model/Product/Type/Abstract.php (line 239, Magento version 1.2.1.2): On some servers, previous steps will not be required, but it is Notice the difference? Although this might not look like better to create the file first so that Magento can edit it. “that big of a deal” suppose you had implemented override Let’s go to Magento administration now and click on “Add functionality like Sitemap” button. Just insert the default values. In the above code, we override the prepareForCart method to After this step, we just told Magento where to create sitemap to some custom stuff for us. This peace of code would work file. It is not yet created. 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 2. Configure Sitemap To me, stuff like this is a serious downside towards building Sitemap can be configured from the interface System -> advanced modules. Changing core files and core functionality Configuration -> Catalog->Google Sitemap. If you are not sure can have serious impact on custom made modules each what does it all mean, check XML Tag definitions section from Magento upgrade. Therefore, one should keep an eye open “Sitemaps XML format” document. on what modules he will throw into the shop. Personally I 3. Create Sitemap Manually consider online stores very serious and have strong feelings about each store owner having somewhat of dedicated Looks like Magento folks were thinking that sitemap should developer that will be in charge even for stuff like adding new only be created by a cron job. Yes, it can be done that way modules. 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, Just consider the financial loss for a store owner of any more quit your search for “Create Sitemap” button. You will not find serious web shop if he decides to download the and install it. But there is a workaround. You can enter manual URL to module himself just to realize that for incompatibility reasons execute sitemap creation: this new module made his shop fully nonfunctional. http://www.yourstore.com/index.php/admin/sitemap/ generate/sitemap_id/[ID of Sitemap from step 1] How to transfer large Magento database Of course, replace the content with square brackets with actual from live to development server and Sitemap ID. other way round There are 9 comments I have been involved in Magento development for almost a year now. God knows I had (and still have) my moments of Observer pitfalls of building serious pain with it . If you are in professional, everyday, PHP modules in Magento development that focuses mainly on Magento then your life probably isn’t all flowers and bees. Magento is extremely rich Unlike good old WordPress that “every kid in the block” knows eCommerce platform, but its main downside IMHO is its size how to create a plugin for, Magento is a whole new system. It and code complexity. If you download Magento via SVN, you requires extensive knowledge of OOP, ORM’s, MVC, and few will sound find out it has around 11 600 and more files. This other stuff. This is why not “every kid in the block” can write a is no small figure. Transferring that much of files over the module for Magento, and this is why I love it. However, unlike FTP can be a real night mare. Luckily we have SSH and tar WordPress, Drupal and other community driven systems out command to handle this really neat. there who keep in mind backward compatibility things with But what about database. Today I worked on database with Magento things are a bit different. more than 20 000 products in store and with extremely large number of categories. What seemed like easy database Created using zinepal.com. Go online to create your own zines or read what others have already published. 12
  • 13. September 8th, 2009 Published by: inchoo transfer from live site to local developer machine to do a test Affiliates for all, are modules I consider loosely related to core. and fix on few issues tunerd out to be an issue for itself. They are in one or another way connected to Magento but they Without further delay, here is my favorite tool to handle all are self standing, independent, applications. database related work from now on: Navicat. Installation of Affiliate module is a trivial task. It mostly Among my favorite features is the Data transfer. Directly comes down to extracting downloaded archive file to a web moving one database to another among different MySQL accessible directory (to your server, hosting) and configuring servers works like a charm. I find yourself strangled among the config.inc file. (For security reasons, try renaming often database recommended action I suggests you test the the config.inc to config.inc.php, plus changing the /lib/ trial version of this tool. bootstrap.php on line 23 to include config.inc.php). After importing affiliates.sql into the database our installation is Here are some screenshots of Navicat Data transfer in Action. 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 There are 4 comments columns, we wish to have boxes. Blank Theme does just that: provides a layout, but without any heavy styling. This makes Affiliates for all – Magento integration it excellent base ground for a new Magento project. It doesn’t come with default installation, so you will have to use Magento Recently one of our clients needed and info on Affiliate module Connect to get it. for Magento. When it comes to Magento, word “module” is http://www.magentocommerce.com/extension/518/blank- loosely related. Sure, every module needs config files in order theme to report it’s “connection” to Magento core. Modules like this, Created using zinepal.com. Go online to create your own zines or read what others have already published. 13
  • 14. September 8th, 2009 Published by: inchoo Magento community member Ross gave a good review comment: Create a Color Switcher in Magento This is a great theme to use for wire-framing or as a base Magento comes packed with a lot of options. But no matter for developing a custom theme! It looks like a lot of work has how many options you put into some product you can never gone in to slimming down the HTML and CSS, which makes cover all of them. One of such options (for now) is a color it much easier to work with compared to the default theme. switcher in Magento. To be more precise, an image switcher I particularly appreciate the well structured and commented based on color selection. CSS. The only things I would want different at this stage is Recently I’ve made a screencast on my site on this subject, for the ‘callouts’ to be taken out (and removal of associated with somewhat different title. The idea is to have a dropdown media images), and for this theme to be included in the main box from which you choose a color and based on the color Magento download (I would even like it to be the ‘default’). 5 selection product image changes. All of this is to be based on stars from me! some simple javascript (in my case, jQuery). Take a sneak peak of how does product info page looks line Before we continue, you might want to see color switcher in with no styling, but in finished layout. I’m sure that the CSS action. We used this solution on our Kapitol Reef project. wizards will find this invaluable. 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: 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. Created using zinepal.com. Go online to create your own zines or read what others have already published. 14
  • 15. September 8th, 2009 Published by: inchoo After this is done we go to the code part. There are three things After some additional styling you can get some impressive you need to do here. results for this. Hope you find it useful. Upload the jQuery and save it into the /js/jquery/jquery.js. You can see complete screencast at: One important note on jQuery; for some reason I had to use http://activecodeline.com/wp-content/uploads/videos/ jQuery 1.2.3 to get this example working. Latest version 1.2.6 MagentoProductColorChooser.swf (as of time of this writing) did not work. You can see the exact error it gave me on my screencast. There are 28 comments Now you need to modify /template/page/html/head.phtml Magento’s Onepage Checkout in a 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) nutshell And finaly, you need to modify the /template/catalog/ For the last two days I’ve been working on a custom checkout product/view/media.phtml file to grab all of the product page for one of our clients. Basicaly a page can be shown images and dump them into some div. Here is my sample in Magento using simple Core_Template type. Basically all (media.phtml) so just copy paste the code. code is set inside the .phtml file so it can be shown on every possible page or block, meaning it’s object independent, no And some additional screenshots for you to see final result 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. Created using zinepal.com. Go online to create your own zines or read what others have already published. 15