Clear database from tables

Fastest way to add custom category attribute to frontend menu category tree model

The simplest way to add this attribute is use XML.
This sample part of code displayed below, should be inserted in Your own module in config.xml file

<frontend>
<category>
<collection>
<attributes>
<custom_attribute_code/>
</attributes>
</collection>
</category>
</frontend>

After that You can use this attribute, in rendering method _renderCategoryMenuItemHtml defined in Mage_Catalog_Block_Navigation.
Like that:

Please remember to rewrite this class, or at least move it to app/code/local/.. directory.

Magento custom filter on column in admin grid filter_condition_callback

Magento Grid Block has useful function for advanced filtering of a collection. It is called ‘filter_condition_callback’, and it is used in declaring a column. It takes actual collection, and callback function as parameters.

Major elements:

and:

All Code:

Zend Server with XDEBUG and PHPSTORM

1. Change timeouts
file: Zend\ZendServer\etc\ZendEnablerConf.xml
change line with timeouts tag to: Timeouts connectionTimeout="120" requestTimeout="1200"

file: Zend\ZendServer\etc\php.ini
change: max_execution_time=30 to: max_execution_time=600

2. Enable vhosts
file: Zend\Apache2\conf\httpd.conf
uncomment Include conf/extra/httpd-vhosts.conf

3. Create new vhost
file : Zend\Apache2\conf\extra\httpd-vhosts.conf
You can base on exist one in this file.

4. Add new created local domain name for vhost in file: C:\Windows\System32\drivers\etc\hosts
127.0.0.1 newdomain.local.com newdomain2.local.com

5. XDEBUG library
Download library from http://xdebug.org/files/ and move to Zend\ZendServer\lib\phpext
For my OS (Windows 8.1) works this one: php_xdebug-2.2.3-5.4-vc9-nts.dll
Now open php.ini file (Zend\ZendServer\etc\php.ini), ande before line:
zend_extension="C:\Zend\ZendServer\lib\ZendExtensionManager.dll"
add this line:
zend_extension="C:\Zend\ZendServer\lib\phpext\php_xdebug-2.2.3-5.4-vc9-nts.dll"

5. Disable Zend debugger
file: Zend\ZendServer\etc\cfg\debugger.ini
comment this line:
;zend_extension_manager.dir.debugger="D:\Program Files\Zend\ZendServer\lib\debugger"

6. Enable xdebug
file: Zend\ZendServer\etc\php.ini
add on the end of file:

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.profiler_enable=0

7. Download some plugin to web browser, for chrome Xdebug helper an configure it.
8. Enable Xdebug in PHPSTORM
Settings > Project Settings > PHP > Servers > Add new one an select Xdebug
9. Done 🙂

Magento: List of available types column in adminhtml widget grid

date adminhtml/widget_grid_column_renderer_date
datetime adminhtml/widget_grid_column_renderer_datetime
number adminhtml/widget_grid_column_renderer_number
currency adminhtml/widget_grid_column_renderer_currency
price adminhtml/widget_grid_column_renderer_price
country adminhtml/widget_grid_column_renderer_country
concat adminhtml/widget_grid_column_renderer_concat
action adminhtml/widget_grid_column_renderer_action
options adminhtml/widget_grid_column_renderer_options
date adminhtml/widget_grid_column_renderer_date
checkbox adminhtml/widget_grid_column_renderer_checkbox
massaction adminhtml/widget_grid_column_renderer_massaction
radio adminhtml/widget_grid_column_renderer_radio
input adminhtml/widget_grid_column_renderer_input
select adminhtml/widget_grid_column_renderer_select
text adminhtml/widget_grid_column_renderer_longtext
store adminhtml/widget_grid_column_renderer_store
wrapline adminhtml/widget_grid_column_renderer_wrapline
theme adminhtml/widget_grid_column_renderer_theme
default type adminhtml/widget_grid_column_renderer_text

How to cheat history back

Simple just like this:
[javascript]
<script type="text/javascript">
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/backtocollection");
history.pushState(null, document.title, location.pathname);

window.addEventListener("popstate", function() {
if(location.hash === "#!/backtocollection") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
location.replace("<?php echo $_category->getUrl() ?>");
},0);
}
}, false);
}(window, location));
</script>
[/javascript]

Magento can’t login to admin Warning: Header may not contain more than a single header, new line detected

The first step that you should do to resolve this bug is check your system.log file.
In my case error looks like this:
Warning: Header may not contain more than a single header, new line detected in D:\Zend\Apache2\htdocs\project1\app\code\core\Mage\Core\Model\Session\Abstract\Varien.php on line 123
Warning: Header may not contain more than a single header, new line detected in D:\Zend\Apache2\htdocs\project1\app\code\core\Mage\Core\Model\Cookie.php on line 307
Warning: Header may not contain more than a single header, new line detected in D:\Zend\Apache2\htdocs\project1\app\code\core\Mage\Core\Model\Cookie.php on line 308
Warning: Header may not contain more than a single header, new line detected in D:\Zend\Apache2\htdocs\project1\app\code\core\Mage\Core\Model\Session\Abstract\Varien.php on line 436

Problem should disappear, after change value of web/cookie/cookie_domain in core_config_data table, or just delete it.

Magento after upgrade, the new template does not show up

Sometimes, after upgrade Magento, and introducing a new template, You may not see it.

Why?
Because each product can have a changed template to ‘default/default’.

Solutions:
1) just save product in admin panel
2) write simple SQL script, updating product attribute ‘custom_design’ to null or set it blank
3) write php code, using Magento API, upgrading ‘custom_design’ attribute
4) (best one) choose update attributes, for all products in admin panel -> manage products, and set Custom design to first option “Please select”

That’s all for today 🙂