In: Magento
15 Apr 2013If you ever find a need to, as a result of your custom action, display the 404 page to customer, you can do it by using the following code inside your controller class
1 2 3 | $this->getResponse()->setHeader('HTTP/1.1','404 Not Found'); $this->getResponse()->setHeader('Status','404 File not found'); $this->_forward('defaultNoRoute'); |
This way you’ll be calling the default Magento dispatcher and it will set the 404 headers and display the 404 page you set as a default 404 page in your Magento admin.
In: SSH/Linux
2 Mar 2013If you’d like to check if process is running on Linux OS, you can do it by using code from following snippet:
command = "sidekiq" running = `ps ax | grep -v grep | grep $command | wc -l` if [running -gt 0]; then echo "Sidekiq is running!" else echo "Sidekiq is not running..." fi |
In: PHP
16 Feb 2013To check if Zend_Registry key exists, you should simply use following snippet:
1 2 3 4 5 | if(Zend_Registry::isRegistered('my_key')) { echo 'Zend Registry key exists, and value is: ' . Zend_Registry::get('my_key'); } else { echo 'Zend Registry key does not exist.'; } |
In: Rails
18 Oct 2012In order to run Rails server in production mode, you need to use following line:
1 | rails s -e production |
However, please notice that Rails assumes that you have your files precompiled for production environment. If you want to change this and have compiling during runtime in production you must change config.assets.compile in config/environments/production.rb to following:
1 | config.assets.compile = true |
In: Rails
17 Oct 2012Rake migrate doesn’t detect the current environment once you setup app on your production server, so in order to run it with proper profile, you can do following:
rake db:migrate RAILS_ENV="production" |
In: Magento
11 Oct 2012Suppose you want to display all the attributes of one product. You can easily get the id of the value by call the unversal method
1 | $attributeValueId = $_product->getResource()->getColor(); |
where color is the name of the attribute. If you’ve already loaded the whole product into the variable $_product then you don’t need the getResource() part. Also, attributes should be named with lowcase letters, and their respectful methods are formed with the prefix get and capital first letter, but if you have two-word named attribute (for example my_attribute – remember, no whitespaces in the object names in Magento!) then you could get it with the method getMyAttribute() which follows the standard Zend naming convention.
Now, in order to display je value meaningful to the user, and not just the id, you can fetch all the values into the associative array
1 2 3 | $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); foreach ($attribute->getSource()->getAllOptions(true, true) as $instance) { $myArray[$instance['value']] = $instance['label']; |
and simply use it in your display!
4 5 6 7 8 | $_product->load($idOfTheProduct); $attributeValueId = $_product->getColor(); echo 'This shirt is ' . $myArray[$attributeValueId]; |
In: SSH/Linux
10 Oct 2012So – you have a BitNami stack on your server, and would like to restart Apache?
There is a simple way to restart apache on your BitNami installation. Just use a following snippet.
BitNami restart Apache:
sudo /opt/bitnami/ctlscript.sh restart apache |
Sometimes you need to get product by its attribute SKU. To do this, you can simply use following snippet and you will have Magento to load product by SKU.
$productSku = 'my-product-sku'; $_product = Mage::getModel('catalog/product')->load($productSku, 'sku'); |
It happens from time to time to forget Magento admin password. When it happens you should be able to recover from it with no problems. Use this simple MySQL script to reset admin password in Magento.
Magento reset admin password:
UPDATE admin_user SET password=CONCAT(MD5('random_stringyour_new_password'), ':random_string') WHERE username='admin'; |
In: Magento
14 Jun 2012Can be easily activated through couple of SQL queries.
First time you can enable it by running
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/debug/template_hints', 1), ('default', 0, 'dev/debug/template_hints_blocks', 1); |
If you want to disable it, just run
UPDATE core_config_data SET value = 0 WHERE scope = 'default' AND scope_id = 0 AND path in ('dev/debug/template_hints','dev/debug/template_hints_blocks') |
And if you want to enable it again, run
UPDATE core_config_data SET value = 1 WHERE scope = 'default' AND scope_id = 0 AND path in ('dev/debug/template_hints','dev/debug/template_hints_blocks') |