2014-06-09

Debug layout updates in magento

For each request magento sees all layout updates (located at design layout folder) and find the appropriate handles. To get list of handles which appropriate to the current request you have to write in controller:
$this->loadLayout();
echo '<pre>';
print_r($this->getLayout()->getUpdate()->getHandles());
echo '</pre>';
exit;
The result will be something like that:
Array
(
    [0] => default
    [1] => STORE_default
    [2] => THEME_frontend_default_default
    [3] => catalog_category_view
    [4] => customer_logged_out
)
Then magento merges all layout updates for handles in the above array to one xml file. To show this file you have to write in controller (at the beginning of method):
header('Content-type: text/xml');
$this->loadLayout();
echo $this->getLayout()->getNode()->asXML();
exit;

2014-06-08

Possible values for addAttributeToFilter

Collections in Magento have the method addAttributeToFilter. It filters entities.
This method takes an attribute code and a condition.
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('sku', 'test-sku');
$products->load();
Where 'test-sku' - value of condition.
If value of condition is integer or string - exact value will be filtered with 'eq' condition).
If value of condition is array - one of the following structures is expected:
array("from" => $fromValue, "to" => $toValue)
array("eq" => $equalValue)
array("neq" => $notEqualValue)
array("like" => $likeValue)
array("in" => array($inValues))
array("nin" => array($notInValues))
array("notnull" => $valueIsNotNull)
array("null" => $valueIsNull)
array("moreq" => $moreOrEqualValue)
array("gt" => $greaterValue)
array("lt" => $lessValue)
array("gteq" => $greaterOrEqualValue)
array("lteq" => $lessOrEqualValue)
array("finset" => $valueInSet)
array("regexp" => $regularExpression)
array("seq" => $stringValue)
array("sneq" => $stringValue)

2014-06-07

Rewrite class/method in Magento

To rewrite class method you have to add rewrite config to etc/config.xml:

 
  
   
    
     SliRx_Test_Model_Category
    
   
  
 

Where tags "catalog" and "category" are assigned to Mage::getModel('catalog/category')
Than create corresponding class at app/code/local/SliRx/Test/Model/Category.php:
class SliRx_Test_Model_Category extends Mage_Catalog_Model_Category
{
    public function getChildren()
    {
        return $this->getResource()->getChildren($this, false);
    }
}

2014-06-05

Insert tabs in magento 1.9 responsive theme

For creating tabs you need to write some html:
Title 1
Content html 1
Title 2
Content html 2
Where ajax-tabs - your own class.
And include styles in your scss file:
@include bp(min-width, $bp-medium + 1) {
    .ajax-tabs {
        @include tabs;
    }
}

@include bp(max-width, $bp-medium) {
    .ajax-tabs {
        @include accordion;
        @include accordionCollapse;
    }
}

2014-05-14

Install/rescue/restore grub2

To restore grub2 run this commands:
sudo mount /dev/sda1 /mnt
where /dev/sda1 - partition for grub (with installed linux)
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo chroot /mnt
sudo grub-install /dev/sda
If output has "chroot: cannot run command `/bin/bash': Exec format error" then your live CD architecture doesn't match with restorable.

2014-05-07

SSH host alias

To create ssh alias you have to create the file ~/.ssh/config with similar lines:
Host your-host
 HostName your-server.com
 Port 22
 user your-ssh-username
Then for connecting to server: ssh your-host

2014-04-23

Delete header and footer from magento custom page

For deleting header and footer from custom page add this lines to layout configuration:
<remove name="header"/>
<remove name="footer"/>