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)

Magento: Get store address, phone number or other config information

Here is how to get the the store config information for the phone number:

<?php echo Mage::getStoreConfig(‘general/store_information/phone’);?>

And for the address:

<?php echo Mage::getStoreConfig(‘general/store_information/address’);?>

In fact you can get all sorts of interesting “config” data out using this  getStoreConfig method.

Continue reading Magento: Get store address, phone number or other config information

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 Error: Integrity constraint violation: 1062 Duplicate entry ‘123456’ for key ‘PRIMARY’

Following a database export/import as part of a migration  or copy to a new development environment some database problems can occur, even if the entire db is copied.  Sometimes the problem can be the log files references, as is likely with the error:

Integrity constraint violation: 1062 Duplicate entry  ‘123456’ for key ‘PRIMARY’

Where 123456 is some number.
Continue reading Magento Error: Integrity constraint violation: 1062 Duplicate entry ‘123456’ for key ‘PRIMARY’

Mysql: Change the full text index minimum word length

So you are trying to do a fulltext search but your searches for “cat” or “dog” always return zero results, even though you have articles all about cats and dogs. By default the minimum search text length for full index searches is 4 characters, anything less than that returns nothing, zip, nada, jack-all.  You need to change the minimum word length.

This can throw people using something like Magento whose product types or names are short, such as “bag”,”cup”, or “mug”.  The problem isn’t actually in Magento but a server setting. You might be kind of stuck if you are using a shared hosting environment – you can contact your hosting service and ask nicely.

Continue reading Mysql: Change the full text index minimum word length

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’);
}
?>

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 Cookies not Working in Chrome or Opera on Frontend

So, I was testing the “this site is using cookies” functionality in Magento. It worked fine on a local environment but failed to work on a test “live” IP address site. I say failed, but it worked fine in IE and Firefox whereas in Chrome hitting the “I agree to cookies” button didn’t set a cookie and redirected. I eventually solved it. Continue reading Magento Cookies not Working in Chrome or Opera on Frontend