Wednesday, October 28, 2015

Be careful when overriding Magento Controller constructors

I've found this bug recently in one of my Magento extensions:

Fatal error: Call to a member function getActionName() on a non-object in /my_path/htdocs/app/code/core/Mage/Core/Controller/Varien/Action.php on line 200

The error was generated while I was tryting to run an action from my custom controller. My custom controller exteneded the Mage_Adminhtml_Controller_Action controller.

It was working fine until I have added a default constructor to my controller:

function __construct()
    {
   

        $this->mHelper =  Mage::helper("myextension/data");
    }

After this, I was getting the error I mentioned earlier. After checking the definition of class defined in  Core/Controller/Varien/Action.php, I have realized that it's parametrized constructor was never being called, and that caused my error later on at runtime.

I have removed my default constructor, and things went back to normal.
Hope this tip helps someone.

Sunday, October 25, 2015

VirtualBox and Ubuntu 14 - network not working in Bridged Adapter Mode

Recently, I have run into problems with Internet Connection in my Ubuntu 14 hosted in VirtualBox. The Internet Connection worked well in NAT mode, but not in Bridged Adapter mode. After some checking, I had seen that wrong network card is being used in VirtualBox Network Preferences.
After change to proper network card and an Ubuntu reboot, network was back up!

Login loop problem in Ubuntu 14.04.1

After not being able to login to my Unity Desktop in Ubuntu 14.04.1, I have tried a lot of possible fixes for "Ubuntu Login Loop" problem. None of them helped.

My /var/log/lightdm/x-0-greeter.log contains a single warning entry:
 ** (lightdm-gtk-greeter:2580): WARNING **: Failed to load user image: Failed to open file '/home/gate/.face': No such file or directory

(Where gate is username)

After awhile, I have found this to be a potential bug:

https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/1248948

The end solution I have used:
Created new user account using sudo adduser command and continued using the new account!

Tuesday, October 20, 2015

Elements with duplicate IDs in HTML/JS

Elements with duplicate IDs in HTML can be a huge problem to debug. This is due to the fact that no exception will be generated in JS console in this case.

Using JS/jQuery functions on such objects will often result in wrong objects being edited or scanned.

You can , for example, see that your checkbox always returns "unchecked" state in JS, while you are sure that it is clicked in the browser, and so on, and on.

Be sure to clean out all duplicate IDs in your code.

Tuesday, October 13, 2015

Magento - model rewrite/override not working

Your model overwrite seems to be ignored?

Please perform another careful inspection of your module's config.xml.

EXAMPLE (in config.xml , rewrite section)


This is not OK:
<order_creditmemo_item>
Gogi_Cmsubtotals_Model_Creditmemo_Item  
</order_creditmemo_item>


This is OK:
<order_creditmemo_item>Gogi_Cmsubtotals_Model_Creditmemo_Item</order_creditmemo_item>

Magento uses all whitespaces in new block name, and it cannot find the file with extra whitespaces!

This is pretty hard to debug, but you can confirm it with this call:

$creditmemoItem = Mage::getModel('sales/order_creditmemo_item');
 
 echo "A=".get_class($creditmemoItem);

If you have rewritten this class correctly, it should print out Gogi_Cmsubtotals_Model_Creditmemo_Item. If not, it will printout just thi:
A=


Also, you need to either refresh or (better) disable the cache to see the changes online!!!

I hope this tip can save you from some trouble!


Magento rewrite model debugging

The most importan file to check in Magento 1.6 when model rewrite is not working is this one:

/data/shop_test/htdocs/app/code/core/Mage/Core/Model/Config.php

function:


  public function getGroupedClassName($groupType, $classId, $groupRootNode=null)


This function reads rewrite directives. It can be debugged for problems.


PSR-1 and PSR-2 coding standards for PHP

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutte...