Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 45 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
45
Dung lượng
1,86 MB
Nội dung
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 1
Inchoo's Magento Posts
You're reading the 200th blog post edition of Inchoo's
Magento e-book. It collects all of our blog posts on
Magento. We want to thank everyone for staying with
us so far and hope we will live to see 1000th blog post
anniversary. :)
Inchoo is an ecommerce design and development
company specialized in building Magento online stores.
Boost the speed of your Magento
One of the drawbacks of Magento is currently its speed if
default configuration is used. There are certain ways of making
it run faster. The best one is to enable GZip compression by
changing .htaccess file a little. You just need to uncomment
part of the code. In my case, the speed increase was exactly
235%.
Add custom structural block / reference
in Magento | Inchoo
If you already performed some Magento research, you will
know that it is built on a fully modular model that gives
great scalability and flexibility for your store. While creating
a theme, you are provided with many content blocks that you
can place in structural blocks. If you are not sure what they
are, please read Designer’s Guide to Magento first. Magento
provides few structural blocks by default and many content
blocks. This article tells what needs to be in place to create new
structural block.
What are structural blocks?
They are the parent blocks of content blocks and serve to
position its content blocks within a store page context. Take
a look at the image below. These structural blocks exist in the
forms of the header area, left column area, right column…etc.
which serve to create the visual structure for a store page. Our
goal is to create a new structural block called “newreference”.
Step 1: Name the structural block
Open the file layout/page.xml in your active theme folder.
Inside you will find lines like:
<block type="core/text_list" name="left" as="left"/>
<block type="core/text_list" name="content" as="content"/>
<block type="core/text_list" name="right" as="right"/>
Let’s mimic this and add a new line somewhere inside the same
block tag.
<block type="core/text_list" name="newreference" as="newreference"/>
Good. Now we told Magento that new structural block exists
with the name “newreference”. Magento still doesn’t know
what to do with it.
Step 2: Tell Magento where to place it
We now need to point Magento where it should output this
new structural block. Let’s go to template/page folder in our
active theme folder. You will notice different layouts there.
Let’s assume we want the new structural block to appear only
on pages that use 2-column layout with right sidebar. In that
case we should open 2columns-right.phtml file.
www.besthosting4magento.com
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 2
Let’s assume we wish the “newreference” block to be placed
below 2 columns, but above the footer. In this case, our
updated file could look like this:
<! start middle >
<div class="middle-container">
<div class="middle col-2-right-layout">< ?php getChildHtml('breadcrumbs') ?>
<! start center >
<div id="main" class="col-main"><! start global messages >
< ?php getChildHtml('global_messages') ?>
<! end global messages >
<! start content >
< ?php getChildHtml('content') ?>
<! end content ></div>
<! end center >
<! start right >
<div class="col-right side-col">< ?php getChildHtml('right') ?></div>
<! end right ></div>
<div>< ?php getChildHtml('newreference') ?></div>
</div>
<! end middle >
Step 3: Populating structural block
We have the block properly placed, but unfortunately nothing
is new on the frontsite. Let’s populate the new block with
something. We will put new products block there as an
example. Go to appropriate layout XML file and add this block
to appropriate place.
<reference name="newreference">
<block type="catalog/product_new" name="home.product.new" template="catalog/product/new.phtml" />
</reference>
That’s it. I hope it will help someone
There are 15 comments
How to delete orders in Magento? |
Inchoo
You got a Magento project to develop, you created a Magento
theme, you placed initial products and categories and you
also placed some test orders to see if Shipping and Payment
methods work as expected. Everything seems to be cool and
the client wishes to launch the site. You launch it. When you
enter the administration for the first time after the launch, you
will see all your test orders there. You know those should be
deleted. But how?
If you try to delete orders in the backend, you will find out
that you can only set the status to “cancelled” and the order is
still there. Unfortunately, Magento doesn’t enable us to delete
those via administration, so you will not see any “Delete order”
button. This can be quite frustrating both to developers and
the merchants. People coming from an SAP world find the
inability to delete to have some merit but there should be a
status that removes the sales count from the reports i.e. sales,
inventory, etc.
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 3
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
After you have it executed, the test orders will not be in the
database any more. Keep in mind that this will delete ALL
orders, in the database. So, you should execute this queries
immediately after launch.
connect2MAGE | WordPress plugin for
easy Magento database connection
Hi everyone. I wrote this little plugin while working on one
of our projects. If you know your way around WordPress
then you know what $wpdb variable stands for. Imagine the
following scenario. You have WordPress installation on one
database, Magento on another. You know your way around
SQL. You can always make new object based on WPDB class
inside your template files giving it database access parameters,
or you can use this plugin and use $MAGEDB the same way
you use $wpdb.
Below is a little example of using $MAGEDB to connect to
Magento database and retrieve some products by reading id’s
from custom field of some post inside your WordPress.
Place this code inside one of your templates, like single.php.
< ?php
global $MAGEDB;
$MAGEDB->show_errors(true);
/** BASIC SETUP */
//$storeUrl = 'http://server/shop/index.php/';
$storeUrl = get_option('connect2MAGE_StoreUrl');
//$urlExt = '.html';
$urlExt = get_option('connect2MAGE_UrlExt');
/** END OF BASIC SETUP */
$entityIds = get_post_custom_values(get_option('connect2MAGE_CustomFieldName'));
$result = array();
if(!empty($entityIds))
{
$entityIds = $entityIds[0];
$sql = "SELECT `e`.*, `_table_price`.`value` AS `price`, IFNULL(_table_visibility.value, _table_visibility_default.value) AS `visibility`, IFNULL(_table_status.value, _table_status_default.value) AS `status`, `_table_url_key`.`value` AS `url_key`, IFNULL(_table_name.value, _table_name_default.value) AS `name` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_entity_decimal` AS `_table_price` ON (_table_price.entity_id = e.entity_id) AND (_table_price.attribute_id='99') AND (_table_price.store_id=0) INNER JOIN `catalog_product_entity_int` AS `_table_visibility_default` ON (_table_visibility_default.entity_id = e.entity_id) AND (_table_visibility_default.attribute_id='526') AND _table_visibility_default.store_id=0 LEFT JOIN `catalog_product_entity_int` AS `_table_visibility` ON (_table_visibility.entity_id = e.entity_id) AND (_table_visibility.attribute_id='526') AND (_table_visibility.store_id='1') INNER JOIN `catalog_product_entity_int` AS `_table_status_default` ON (_table_status_default.entity_id = e.entity_id) AND (_table_status_default.attribute_id='273') AND _table_status_default.store_id=0 LEFT JOIN `catalog_product_entity_int` AS `_table_status` ON (_table_status.entity_id = e.entity_id) AND (_table_status.attribute_id='273') AND (_table_status.store_id='1') INNER JOIN `catalog_product_entity_varchar` AS `_table_url_key` ON (_table_url_key.entity_id = e.entity_id) AND (_table_url_key.attribute_id='481') AND (_table_url_key.store_id=0) INNER JOIN `catalog_product_entity_varchar` AS `_table_name_default` ON (_table_name_default.entity_id = e.entity_id) AND (_table_name_default.attribute_id='96') AND _table_name_default.store_id=0 LEFT JOIN `catalog_product_entity_varchar` AS `_table_name` ON (_table_name.entity_id = e.entity_id) AND (_table_name.attribute_id='96') AND (_table_name.store_id='1') WHERE (e.entity_id in (".$entityIds.")) AND (_table_price.value >= 0 and _table_price.value < = 999999999999) AND (IFNULL(_table_visibility.value, _table_visibility_default.value) in (2, 4)) AND (IFNULL(_table_status.value, _table_status_default.value) in (1)) AND (_table_url_key.value not in ('P1FHN3G0LRWGMYZ3')) AND (IFNULL(_table_name.value, _table_name_default.value) not in ('P1FHN3G0LRWGMYZ3'))";
$result = $MAGEDB->get_results($sql);
var_dump($result);
}
else
{
echo '<p class="relatedProductInfo">No related products available </p>';
}
?>
< ?php if (!empty($result)): ?>
<table id="relatedProductsList">
< ?php foreach ($result as $item): ?>
<tr class="productInfo">
<td><a href="<?php echo $storeUrl ?>/< ?php echo $item->url_key ?>< ?php echo $urlExt ?>">< ?php echo $item->name ?></a></td>
<td>< ?php _e('Starting at') ?> $ < ?php echo floatval($item->price) ?></td>
</tr>
< ?php endforeach; ?>
</table>
< ?php endif; ?>
Hope some of you find this useful. Especially those who refuse
to use Web Services for connecting different systems.
Download connect2MAGE WordPress plugin.
There are 6 comments
Custom checkout cart - How to send
email after successful checkout in
Magento | Inchoo
Recently I have been working on a custom checkout page for
one of our clients in Sweden. I had some trouble figuring out
how to send default Magento order email with all of the order
info. After an hour or so of studying Magento core code, here
is the solution on how to send email after successful order has
been made.
Not sure how useful this alone will be for you, so I’ll throw a
little advice along the way. When trying to figure how to reuse
Magento code, separate some time to study the Model classes
with more detail. Then “tapping into” and reusing some of
them should be far more easier.
Latest News RSS box in Magento using
Zend_Feed_Rss | Inchoo
You would like to have a eCommerce power of Magento, but
also have a blog to empower your business? In this case,
you probably know that Magento doesn’t have some article
manager in the box. Many clients seek for supplementary
solution like Wordpress to accomplish this goal. Ok, so you
created a blog on same or different domain and you would
like those articles to appear somewhere in Magento (probably
sidebar). This article will explain how to do it.
Let’s create a file called latest_news.phtml
in app/design/frontend/default/[your_theme]/template/
callouts/latest_news.phtml
Now we will create a PHP block that will display the list
of articles from RSS feed. We will use Inchoo RSS for
demonstration purposes. In your scenario, replace it with your
own valid RSS URL.
< ?php $channel = new Zend_Feed_Rss('http://feeds.feedburner.com/Inchoo'); ?>
<div class="block block-latest-news">
<div class="block-title">
<h2>< ?php echo $this->__('Latest News') ?></h2>
</div>
<div class="block-content">
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 4
<ol id="graybox-latest-news">
< ?php foreach ($channel as $item): ?>
<li><a href="<?php echo $item->link; ?>">< ?php echo $item->title; ?></a></li>
< ?php endforeach; ?>
</ol>
</div>
</div>
Step 2
Now, we should decide where to place it. I assume you already
know how Magento blocks and references work. Let’s assume
you would like to place it in right column by default for whole
catalog. In this case open your app/design/frontend/default/
[your_theme]/layout/catalog.xml file and under “default” tag
update “right” reference with something similar.
That’s it. You should be able to see the list of articles from RSS
feed with the URLs. Hope this will help someone.
Advanced search in Magento and how to
use it in your own way
It’s been a while since my last post. I’ve been working on
Magento quite actively last two months. I noticed this negative
trend in my blogging; more I know about Magento, the less
I write about it. Some things just look so easy now, and they
start to feel like something I should not write about. Anyhow….
time to share some wisdom with community
Our current client uses somewhat specific (don’t they all) store
set. When I say specific, i don’t imply anything bad about it.
One of the stand up features at this clients site is the advanced
search functionality. One of the coolest features of the built in
advanced search is the possibility to search based on attributes
assigned to a product.
To do the search by attributes, your attributes must have that
option turned on when created (or later, when editing an
attribute). In our case we had a client that wanted something
like
http://somestore.domain/catalogsearch/partnumber
or
http://somestore.domain/catalogsearch/brand
instead of the default one
http://somestore.domain/catalogsearch/advanced
with all of the searchable fields on form.
Some of you might say why not use the default and call it a day.
Well, default one does not get very user friendly when large
number of custom added searchable attributes are added in
Magento admin interface. Then the frontend search form gets
cluttered and users are easily to get confused.
So in our example we would like to use the advanced search
and all of it’s behaviour and logic but to use it on somewhat
special link and to hide unnecessary fields. Therefore, our
custom pages he would have only one input field on form and
the submit button. How do we set this up? Well, all of the logic
and functionality is already there.
What we need is to:
• use the http://somestore.domain/catalogsearch/
partnumber as a link
• show only custom_partnumber field on the search form
First, we have to see where does the /advanced come from.
Lets open our template folder at
app\design\frontend\default\default\template
\catalogsearch\
there you will see the /advanced folder. Make a copy of that
entire folder, in the same location, and name it to something
like /custom.
Now your /custom folder should have 2 files: form.phtml and
result.phtml.
Next in line is the /layout folder in our template. You need
to open catalogsearch.xml file. Go to line 64. Do you see the
<catalogsearch_advanced_index> tag there. Make the copy of
it (including all of the content it hold with the closing tag also).
Put the copy of that entire small chunk of code right below.
Now rename all of the occurrences of “advanced” to “custom”
there like on code below:
<catalogsearch_custom_index>
<!– Mage_Catalogsearch –>
<reference name=”root”>
<action
method=”setTemplate”><template>page/2columns-
right.phtml</template></action>
</reference>
<reference name=”head”>
<action method=”addItem”><type>js_css</
type><name>calendar/calendar-win2k-1.css</
name><params/><!–<if/
><condition>can_load_calendar_js</condition>–></
action>
<action method=”addItem”><type>js</
type><name>calendar/calendar.js</name><!–<params/
><if/><condition>can_load_calendar_js</condition>–
></action>
<action method=”addItem”><type>js</
type><name>calendar/lang/calendar-en.js</name><!–
<params/><if/><condition>can_load_calendar_js</
condition>–></action>
<action method=”addItem”><type>js</
type><name>calendar/calendar-setup.js</name><!–
<params/><if/><condition>can_load_calendar_js</
condition>–></action>
</reference>
<reference name=”content”>
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 5
<block type=”catalogsearch/custom_form”
name=”catalogsearch_custom_form”
template=”catalogsearch/custom/form.phtml”/>
</reference>
</catalogsearch_custom_index>
Do the same for <catalogsearch_advanced_result> tag.
Now go to the app\code\core\Mage\CatalogSearch\Block
folder. And make a copy of /Advanced folder naming
it /Custom. Open /Custom/Form.php and replace
class name Mage_CatalogSearch_Block_Advanced_Form
with Mage_CatalogSearch_Block_Custom_Form, then
open /Custom/Result.php and replace class
name Mage_CatalogSearch_Block_Advanced_Result with
Mage_CatalogSearch_Block_Custom_Result.
Inside Form.php there is getModel() function. DO NOT
replace the Mage::getSingleton(’catalogsearch/advanced’);
with Mage::getSingleton(’catalogsearch/custom’);. The point
is to use the default advanced search logic here. Same goes for
getSearchModel() function inside Result.php file.
Next in line, controllers. We need to make
the copy of AdvancedController.php and name it
CustomController.php, then open it and replace the
class name Mage_CatalogSearch_AdvancedController with
Mage_CatalogSearch_CustomController.
Inside this CustomController.php there is a function
called resultAction(). You need to replace the ( …
Mage::getSingleton(’catalogsearch/advanced’) … ) string
‘catalogsearch/advanced’ with ‘catalogsearch/custom’. This is
the one telling the browser what page to open.
Now if you open your url link in browser with /index.php/
catalogsearch/custom instead of /index.php/catalogsearch/
advanced you will see the same form there.
And for the final task… As we said at the start, the point of all
this is to 1) get more custom link in url and 2) display only one
custom searchable attribute field in form. Therefore, for the
last step we need to go to the template\catalogsearch\custom
folder and open form.phtml file.
Inside that file, there is one foreach loop that goes like
<?php foreach ($this->getSearchableAttributes() as
$_attribute): ?>
All we need to do now is to place one if() condition
right below it. If your custom attribute name (code) is
“my_custom_attribute” then your if() condition might look
something like
<?php foreach ($this->getSearchableAttributes() as
$_attribute): ?>
<?php if($_code == ‘my_custom_attribute’): ?>
…
<?php endif; ?>
<?php endforeach; ?>
And you are done. Now you have somewhat more custom url,
and only one custom field displayed on that url.
This might not be the best method of reusing already written
code, however I hope it’s any eye opener to somewhat more
elegant aproach.
Enyoj.
There are 14 comments
Related products
There are three types of product relations in Magento:
Up-sells, Related Products, and Cross-sell Products. When
viewing a product, Upsells for this product are items that your
customers would ideally buy instead of the product they’re
viewing. They might be better quality, produce a higher profit
margin, be more popular, etc. These appear on the product
info page. Related products appear in the product info page
as well, in the right column. Related products are meant to
be purchased in addition to the item the customer is viewing.
Finally, Cross-sell items appear in the shopping cart. When
a customer navigates to the shopping cart (this can happen
automatically after adding a product, or not), the cross-sells
block displays a selection of items marked as cross-sells to the
items already in the cart. They’re a bit like impulse buys – like
magazines and candy at the cash registers in grocery stores.
Upsells
This is the example of the Up-sell. Ideally, the visitor is
supposed to analyze those products as they should be relevant
to the one that is just loaded.
There are 2 comments
File upload in Magento
Now, Magento already have frontend and admin part of file
upload option implemented in themes. Since backend part is
still missing, understand that this still doesn’t work, however,
if you’re interested how it looks, read on
We are coding module of similar functionality for one of our
clients as we speak, but we have our fingers crossed to see this
option in next Magento version!
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 6
Inchoo TV – Magento channel
Making use of Magento getSingleton
method
In one of my previous articles I showed you how to use
getModel and getData methods in Magento. Although we
should not put those to methods at the same level, since I’d say
the getModel is a bit more higher. Higher in sense, you first
use the geModel to create the instance of object then you use
getData to retrieve the data from that instance. I have said it
before, and I’m saying it again; Magento is a great peace of
full OOP power of PHP. It’s architecture is something not yet
widely seen in CMS solutions.
One of the architectural goodies of Magento is it’s Singleton
design pattern. In short, Singleton design pattern ensures a
class has only one instance. Therefore one should provide a
global point of access to that single instance of a class.
So why would you want to limit yourself to only one instance?
Let’s say you have an application that utilizes database
connection. Why would you create multiple instance of the
same database connection object? What if you had references
to an object in multiple places in your application? Wouldn’t
you like to avoid the overhead of creating a new instance of
that object for each reference? Then there is the case where
you might want to pass the object’s state from one reference
to another rather than always starting from an initial state.
Inside the Mage.php file of Magento system there is a
getSingleton method (function if you prefer). Since it’s
footprint is rather small, I’ll copy paste the code for you to see
it.
First, notice the word static. In PHP and in other OOP
languages keyword static stands for something like “this can
be called on non objects, directly from class”. Now let me show
you the footprint of the getModel method.
Do you notice the parameters inside the brackets? They are the
same for both of theme. Where am I getting with this? Well,
I already showed you how to figure out the list of all of the
available parameters in one of my previous articles on my site.
So all we need to do at this point is, play with those parameters
using getSingleton() method and observe the results.
Most important thing you need to remember is that using
getSingleton you are calling already instantiated object. So if
you get the empty array as a result, it means the object is
empty. Only the blueprint is there, but nothing is loaded in it.
We had the similar case using getModel(’catalog/product‘)
on some pages. If we done var_dump or print_r we could
saw the return array was empty. Then we had to use the load
method to load some data into our newly instantiated object.
What I’m trying to say, you need to play with it
to get the feeling. Some models will return data rich
objects some will return empty arrays. If we were to do
Mage::getSingleton(’catalog/session) on view.phtml file we
would retrieve an array with some useful data in it. Do
not get confused with me mentioning the view.phmtl file,
it’s just he file i like to use to test the code. Using
Mage::getSingleton(’core/session) would retrieve us some
more data. You get the picture. Test, test, test… What’s great
about the whole thing is that naming in Magento is perfectly
logical so most of the time you will probably find stuff you need
in few minutes or so.
Figuring out Magento object context
One of the problems working under the hood of the Magento
CMS is determining the context of $this. If you are about
to do any advanced stuff with your template, besides layout
changes, you need to get familiar with Magento’s objects
(classes).
Let’s have a look at the /app/design/frontend/default/
default/template/catalog/product/view.phtml file. If you
open this file and execute var_dump($this) your browser will
return empty page after a short period of delay. By page I mean
on the product view page; the one you see when you click on
Magetno product. Experienced users will open PHP error log
and notice the error message caused by var_dump(). Error
message:
PHP Fatal error: Allowed memory size of 134217728 bytes
exhausted (tried to allocate 121374721 bytes)
I like using print_r() and var_dump(), mostly because so far
I had no positive experience using fancy debug or any other
debugger with systems like Magento.
Why is PHP throwing errors then? If you google out the
error PHP has thrown at you, you’ll see that PHP 5.2
has memory limit. Follow the link http://www.php.net/
manual/en/ini.core.php#ini.memory-limit to see how and
what exactly.
Google search gave me some useful results trying to solve my
problems. I found Krumo at http://krumo.sourceforge.net/.
It’s a PHP debugging tool, replacement for print_r() and
var_dump(). After setting up Krumo and running it on
Magento it gave me exactly what I wanted. It gave me the
object type of the dumped file; in this case it gave me object
type of $this.
If you’re using an IDE studio with code completion support
like NuSphere PhpED, ZendStudio or NetBeans and you
decide to do something like $this-> you won’t get any methods
listed. I haven’t yet seen the IDE that can perform this kind of
smart logic and figure out the context of $this by it self.
What you can do is use the information obtained
by krumo::dump($this). Performing krumo::dump($this)
on /app/design/frontend/default/default/template/catalog/
product/view.phtml file will return object type,
Mage_Catalog_Block_Product_View.
Now if you do
Mage_Catalog_Block_Product_View::
your IDE supporting code completion will give you
a drop down of all the available methods, let’s say
canEmailToFriend();
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 7
Mage_Catalog_Block_Product_View::canEmailToFriend();
Now all you need to do is to replace
Mage_Catalog_Block_Product_View with $this like
$this->canEmailToFriend();
And you’re done. All of this may look like “why do I need this”.
What you need it a smart IDE, one that can figure out the
context of $this by it self and call the methods accordingly. No
IDE currently does that, if I’m not missing on something. For
now I see no better solution to retrieve the object context of
$this across all those Magento files.
If you need some help setting up Krumo with Magento
you can read my other, somewhat detailed article on
activecodeline.com.
Hope this was useful for you.
There are 2 comments
Get product review info (independent) of
review page
Here at Inchoo, we are working on a private project, that
should see daylight any time soon. One of the requirements
we had is to show product review info on pages independent
of product review page. Let’s say you wish to show review info
on home page for some of the products. After few weeks with
working with Magento, one learns how to use the model stuff
directly from view files. Although this might not be the “right”
way, it’s most definitely the fastest way (and I doubt most of
your clients would prefer any other , especially if it’s some
minor modification).
Simple random banner rotator in
Magento using static blocks
This is my first post here and I’ll write about my first challenge
regarding Magento since I came to work at Inchoo.
Please note that you are not restricted only to images, you
could use text, video or whatever you want here, but I’ll focus
on images with links as title says.
In order to show this block, you should be familiar with
Magento layouts.
Since that is out of scope for this article, I’ll show you how to
put it below the content on cms pages.
Changing default category sort order in
Magento
Category toolbar has many options. By default is shows how
many items are in the category, you can choose how many
products you wish to be displayed per page, you can change
the listing type (List or Grid) and you may choose Sort Order.
This “Sort Order” can be confusing. The default “Sort Order”
is “Best Value”. What does it mean? How is the Best value
determined? Can we change the default sort order?
What is “Best Value” filed?
When you go to Category page in Magento administration, you
will see “Category Products” tab. From there, you will see the
list of products that are associated to this category. The last
column in “Position”. That is how “Best Value” is determined.
So, best value is not something that is dynamically calculated.
You can tailor it to your likings.
How to change default Sort Order
The file you need to look at is: /app/code/core/Mage/Catalog/
Block/Product/List/Toolbar.php Since we’ll modify it, make a
copy to /app/code/local/Mage/Catalog/Block/Product/List/
Toolbar.php
One there, you will notice this code at the beginning of the file:
$this->_availableOrder = array(
'position' => $this->__('Best Value'),
'name' => $this->__('Name'),
'price' => $this->__('Price')
);
Default order takes the first value available. So, all you have to
do is to either:
• reorder it if you want to have a selection in the Toolbar or
• set only one value of choice if you will remove the
selection from the toolbar
I hope this will help somebody.
There are 4 comments
Couple of days ago we launched a new Magento project:
Pebblehill Designs. This site utilizes Magento features and
turns it into a very powerful online catalog. You won’t notice
the Shopping Cart or checkout process yet. Even without
those, this site shows exactly what Pebblehill has to offer: the
most popular styles of custom upholstered furniture.
You can customize the furniture collection to express your
own unique style made with the highest quality materials and
craftsmanship available.
Pebble Hill Designs’ parsons chairs are “American made” with
pride in Georgia. The quality speaks for itself. Your products
are pre-assembled and ready for use when you receive them.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 8
The love and the passion for beautiful home interiors
translates into a high-quality product with a sophisticated
style manufactured in the USA. Pebblehill Designs has
assembled some of the most popular styles of custom
upholstered furniture to offer to our customers. All styles are
available in every fabric shown or you can provide your own
fabric. You can customize the furniture collection to express
your own unique style made with the highest quality materials
and craftsmanship available.
TeraFlex PLUS, another Magento +
Wordpress duo
After we launched TeraFlex Suspensions website few months
ago, we created a new similar website for Teraflex PLUS.
Although the name is similar, this is not the same company.
The primary goal of this site is to help Jeep owners to upgrade
their pets with parts and accessories for any type of adventure.
The secondary goal is to create a Jeep enthusiast community
in Utah, USA and surroundings. The site is powered by
Wordpress and Magento combination.
Magento is a superb Shopping Cart, but it lacks some of the
CMS features. Wordpress is a superb CMS, but it fails to
provide the needs for the eCommerce goals. The combination
of these can create a very powerful website. We present you
TeraFlex PLUS : Jeep Adventure Outfitters
http://www.teraflexplus.com/
Magento part of the site can be viewed if you click at Shop by
Vehicle or Shop by Brand tabs from the main menu, but you
will notice that some blocks seamlessly integrate between two
solutions.
We developed this site as the Surgeworks team. The design
was created by one of out top designers, Rafael Torales. We
hope you enjoy it and feel free to post your comments.
There are 6 comments
The Best Shopping Cart :: Trend analysis
of osCommerce, Magento, ZenCart and
CRE Loaded | Inchoo
If you try to ask this question on some forum or newsgroup,
you will surely get many replies. Everyone will present you
his favorite. My first developed online store was created with
standard osCommerce platform. After three or four projects,
I started to work with CRE Loaded and used it frequently for
years. Although it was also an osCommerce fork, it had many
advantages. I switched to Magento™ early this year and this
is my final choice.
Google™ Trends is a great tool to check some platforms
popularity by comparing it to the competition. For my short
analysis, I compared:
As you can see, osCommerce still remains the most popular
eCommerce platform. However, you can notice that this
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 9
popularity is fading. ZenCart is stable for the past two years.
And my previous favorite, CRE Loaded (much better solution
than ZenCart in my opinion), is very low. Its popularity is also
fading even after their team put great effort into a new website
and identity.
Now, take a look at blue line. My prediction is that sometime
in Q1 2009, Magento will become most popular eCommerce
platform. It will surely kick osCommerce off the throne where
that fat duck was sitting for many years. It was about time.
First of all, let me inform you that this article is for those of
you who are just starting with Magento. If you are a Magento
expert, you will probably know this. Consider it just a reminder
for those who use Magento for first time. There are three
common mistakes that most people do when they try to use
Magento for first time, so read this article and you won’t be
one of them.:)
• More experienced PHP developers will first read
Magento Designers Guide before they try to style
Magento, but others won’t and that’s the mistake
number two. Since Magento has great theme fallback
system there is really no need to touch default theme.
Although easiest way to make new theme for new
Magento is top copy the whole theme to a new folder,
don’t do that. Copy only the files you will need: from /
design/frontend/default/default/ directory to /design/
frontend/default/YOUR_NEW_THEME directory. Do
the same thing with /skin/frontend/default/default/
Congratulations, you have your own theme just like
that. All that left is to apply new theme (System-
>Configuration->Design) and you are ready to do with
your theme files whatever you want.
• Third mistake is modifying Magento core files. What files
are core ones? All what is in app/code/core folder. If you
have a need to modify some of those ones, you just need
to duplicate that file in the same directory path to app/
code/local. For example, if you need to modify the file
app/code/core/Mage/Checkout/Block/Success.php
copy it to
app/code/local/Mage/Checkout/Block/Success.php
and leave the core file intact. This way your Magento will
be more bullet-proof to future updates.
Custom CMS page layout in Magento |
Inchoo
Last week I had a request to add new custom layout
for few cms pages in one Magento shop. It’s really
useful for different static pages of your shop. First create
extension with only config file in it: app/code/local/Inchoo/
AdditionalCmsPageLayouts/etc/config.xml
Add your page/custom-static-page-1.phtml template file (or
copy some default one for start) and you’re done There is
also tutorial about this on Magento Wiki. However i don’t like
approach of duplicating and overriding Mage files from /local,
if it can be avoided, so i decided to write this small and useful
example of adding or overriding default Magento settings
through separated config files. And yes, Magento values can
be overridden this way. Default layouts config can be found
in app/code/core/Mage/Cms/etc/config.xml along with used
xml code structure, so check it out. Thank you for listening!
Drupal to Magento integration, simple
link tweak with multilingual site
I see my coworker and friend Željko Prša made a nice little post
on Adding a new language in Magento so I figure I’ll jump with
a little Drupal to Magento integration trick concerning link
issues and multilingual sites. Here is a piece of code you can
use in your Drupal templates to do the proper switching from
Drupal site to Magento while keeping the selected language of
site. Note, this tweak assumes you have the desired language
setup on both Drupal and Magento side.
This part goes to some of your Drupal theme file
global $language ;
$lname = ($language->language == null) ? 'en' : $language->language; /* like "en", "de" */
$storeView = null;
if($lname == 'de') { $storeView = '?___store=german&amp;amp;amp;___from_store=english'; }
??>
</p><p style="text-align: left;"><a id="main_menu_shop" href="<?php echo 'http://'.$_SERVER['HTTP_HOST'].base_path() ?>shop/index.php/someProductLink.html< ?php echo $storeView ?>">Shop</a>
Note the $storeView variable; GET ___store holds the value
of code name of the view you assigned in Magento, while GET
___from_store variable is used as helper to Magento inner
workings. You can basically omit the other one. Your links to
Shop from Drupal to Magento should now activate the proper
language, the same one you have active on Drupal side.
There are 1 comments
Adding a new language in Magento
As anything in Magento adding a new language is something
that requires a certain procedure which we will explain right
now and for future reference.
• 3. Now go to: Configuration -> Current Configuration
Scope (Select your language from the dropdown) and on
the right side under “Locale options” choose the desired
language.
That’s it, now when you go to the frontend of the site, you’ll
notice a dropdown menu allowing the language switching.
Access denied in Magento admin
Some of you may encountered this problem. You install new
Magento extension through downloader, try to access its
configuration settings and Magento throws “Access denied”
page at you. Although you’re administrator of the system.
September 8th, 2009 Published by: inchoo
Created using zinepal.com. Go online to create your own zines or read what others have already published. 10
So what happened here? Magento just doesn’t have stored
privileges for this new extension.
First just try to logout and login again. If that doesn’t work,
you need to reset admin privileges.
Navigate to System->Permissions->Roles and click
Administrators role.
Check your Role Resources settings just in case, Resource
Access dropdown should be already set to All for
administrators.
Without changing anything just click “Save Role” button, so
that Magento re-saves all permissions.
You should be able to access your new extension now without
problems.
There are 5 comments
If you worked with osCommerce, Zen Cart, CRE Loaded or any
similar eCommerce platform before, you might find Magento
database structure quite confusing when you see it for the first
time. I advise you not to rush too much figuring out what
is what by glancing through database. Try to spend first few
hours getting familiar with some background. For purposes
of flexibility, the Magento database heavily utilizes an Entity-
Attribute-Value (EAV) data model. As is often the case, the
cost of flexibility is complexity. Is there something in Magento
that is simple from developers point of view?
Data manipulation in Magento is often more knowledge
demanding than that typical use of traditional relational
tables. Therefore, an understanding of EAV principles and
how they have been modeled into Magento it is HIGHLY
recommended before making changes to the Magento
data or the Magento schema (Wikipedia: Entity-attribute-
value_model). Varien has simplified the identification of EAV
related tables with consistent naming conventions. Core EAV
tables are prefixed with “EAV_”. Diagrams in this post contain
a section labeled “EAV” which displays Magento’s core EAV
tables and thier relationships to non-EAV tables.
Database diagrams and documents found in this post are
intended to mirror the database schema as defined by Varien.
Table relationships depicted in the diagrams represent only
those relationships explicitly defined as Foreign Keys in the
Magento database. Additional informal/undiagrammed table
relationships may also exist, so when modifying the schema
or directly manipulating data it is important to identify and
evaluate possible changes to these tables as well (and the
tables they relate to, and the tables they relate to…).
The author of Database Diagram is Gordon Goodwin, IT
Consultant. You can see his info in the PDF.
There are 12 comments
Magento + .Net Framework, simple order
preview app
For those of you who are into kinky stuff I made a simple,
more of a proof of concept, application that sits in Widnows
taskbar and shows the order info in balloon popup. Took me
little more than half of hour to get this working. Almost forgot
how great C# is
[...]... Cheers ^_^ There are 5 comments Free Magento Themes vs Custom Magento Design This blog post describes pros and cons of having a free Magento theme versus having a custom Magento design from a marketing perspective Free Magento Themes: There are some pretty obvious advantages of using a free Magento theme: • It works – Most of the free Magento themes work just fine with Magento out of the box However, truth... it will be usable for all of you Magento developers who are trying to find a solution for your specific needs Snippi is a Magento related website for sharing Magento code snippets You can see it live on http://snippi.net Finding a solution for specific need can be a nightmare in Magento since you are faced with the process of heavy digging through Magento forum and Magento related blogs Very soon you... widgets in Magento Download Inchoo_CoffeeFreak extension for Magento Hope you find it useful Offline Magento problems I was working recently on a local server without internet connection (nothing can stop us !! ) and i noticed that Magento administration is extremely slow Some parts of administration took up to 10 seconds to load On every page view in admin Magento was trying to resolve widgets.magentocommerce.com... some users of French Magento forums found similar problem in downloader (Magento connect manager) I can confirm this couse i tested it myself The most funny part was that Magento cached my get request so i couldn’t get rid of my test alert box There are 7 comments Form Validation in Magento | Inchoo One of the coolest things in Magento is a form validation, and the way how it’s done Magento uses Prototype... 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. .. document There are 4 comments Affiliates for all – Magento integration Recently one of our clients needed and info on Affiliate module for Magento When it comes to Magento, word “module” is loosely related Sure, every module needs config files in order to report it’s “connection” to Magento core Modules like this, Blank Theme is a sample skeleton theme for Magento designer and a perfect way to start a new... styling This makes it excellent base ground for a new Magento project It doesn’t come with default installation, so you will have to use Magento Connect to get it http://www.magentocommerce.com/extension/518/blanktheme Created using zinepal.com Go online to create your own zines or read what others have already published 13 September 8th, 2009 Magento community member Ross gave a good review comment:... documentation for easy print This is probably the best starting tutorial for creating a fresh new Magento template I plan to write a short related tutorials in the days of 1st Magento development project, so I invite you to subscribe to RSS if you wish to be posted Custom admin theme in Magento As mentioned on Magento forums the easiest way to achieve this is with overriding adminhtml config with your local... links in the magento blocks as well as the whishlist itself Published by: inchoo There are 4 comments Magento Installation with SVN or Wget Unix command | Inchoo Those of you who know what SVN is, feel free to skip this article Those of you who are not familiar with SVN, this is a must-read If you use standard FTP to upload all Magento files, you may find this process very time consuming Magento 1.1.8... This alternative is very well explained on Magento website in Wiki section: http://www.magentocommerce.com/wiki/groups/227/ installing _magento_ via_shell_ssh Both scenarios will only place files You still need to run web based installer afterward But, that is another story There are 6 comments Custom Transactional Emails There are 3 comments Bestseller products in Magento Bestseller or best selling product