Magento (v1.x) : Show full page action name (module_controller_action)

Sometimes, when editing a page you need to know what the full module_controller_action route is so you can modify the correct blocks in the layout files.  Here is a simple bit of code to display the full action name in the form of module_controller_action.

Continue reading Magento (v1.x) : Show full page action name (module_controller_action)

Centos: Making sure your web services auto start after reboot

Your server had to restart, either by design or after some bad event, and now your website doesn’t work – “connection failure”.  Looks like your important web services are not set to start automatically on boot up.  Here is what to do to get your httpd and mysqld services running on restart.

Continue reading Centos: Making sure your web services auto start after reboot

Magento: Programmatically added products do not appear in store until you load and save them in admin.

Ok, so you have written an import script to add a whole load of products into a store but they just don’t show on the front end.  There they are in the admin but not on the front end.  Here is one possible cause. Continue reading Magento: Programmatically added products do not appear in store until you load and save them in admin.

Magento Useful Template Snippets

Create a block object inside a phtml template file:

<?php
$myBlockObject = $this->getLayout()->getBlock(“my_block_name”);
echo $myBlockObject->blockFunction();
?>

Insert a phtml template file into another phtml file

<?php echo $this->getLayout()->createBlock(‘core/template’)->setTemplate(‘page/html/someother.phtml’)->toHtml(); ?>

Get current product from registry

<?php
if( Mage::registry(‘current_product’) ){
$product = Mage::registry(‘current_product’);
}
?>

Insert static block into phtml file

<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘block_identifier’)->toHtml();
?>

Get request (querystring) parameter

<?php
$myVar = Mage::app()->getRequest()->getParam(“myVar”);
?>

Get controller name
Can use this to check whether you are on a product or a category page

<?php
if($this->getRequest()->getControllerName()==’product’){
if(Mage::registry(‘current_product’)){
//do something useful
}
}
?>

Magento: Passing a value from a controller into the phtml

Another Magento quickie for when you want to pass a value into your phtml template file that is set/generated inside the controller.

Inside the controller you can do this:

$block->assign(array(“myVarName”=>”value”));

Where $block could be something like

$block = $this->getLayout()->getBlock(“head”) ;

if you wanted to pass the value into the head template.

You can also set a value like this:

$block->setData(“myVarName”,”value”)

Then, inside the phtml template file you can get the value like this

$this->myVarName

Note you can pass multiple variables through a single $block->assign() like this

$block->assign(array(
“myVarName”=>”value”,
“anotherVar”=>123,
“enoughVars”=>true
));

Magento – Making add to cart urls use https when site is secure

So you have got your site all nicely working with your ssl certificate ready for your site to run fully in https:// to appease Google but your padlock never stays green.  I traced this down to the various form submission URLs such as “add to cart”. Here is how I finally solved it.

Continue reading Magento – Making add to cart urls use https when site is secure