Dreamforce 2013!
Magento code snippets: mix up customer emails
Sometimes when you working on Magento project you need to have some live data on your local machine to test functionality. So, you need to import live DB. But you don’t want to accidentally send any emails to existing live customers of course.
Here is the mysql query that will mixup a customer emails:
1 |
update customer_entity set email = concat('customer_', entity_id, '@localhost.dev'); |
1 |
update customer_entity set email = concat('local_', email); |
Choose one you like. The only difference is a produced emails. First variant produce customer_12345@localhost.dev
alike emails. The second one will produce local_real@email.com
alike emails to preserve email original values for further work on them.
Simple Magento .gitignore file
Every time I start a new Magento project I struggle with the git repository setup. After discovering and a few trials, I found a solution that works perfectly with any Magento project. So in this article we’ll talk about how to create a simple Magento .gitignore file.
Here are the basics of setup: Create an empty git repo and then copy Magento files into it.
Let’s start by ignoring the media
and var
folders.
First, backup original folders and create empty ones instead:
1 2 3 4 |
mv media media_bak mv var var_bak mkdir media mkdir var |
Then move .htaccess
files (we need to keep those) from original to the empty folders:
1 2 |
mv media_bak/.htaccess media/ mv var_bak/.htaccess var/ |
Next add the folders to git and commit:
1 2 |
git add media/.htaccess var/.htaccess git commit -m "Commit .htaccess to media/ and var/ folders to keep them around" |
If you do not have
.htaccess
in var
and/or media
folders:
1 2 3 4 |
touch media/.gitignore touch var/.gitignore git add media/.gitignore var/.gitignore git commit -m "Commit empty .gitignore to media/ and var/ folders to keep them around" |
Now add that folders to .gitignore
and commit as well:
1 2 3 4 |
echo /media >> .gitignore echo /var >> .gitignore git add .gitignore git commit -m "Commit .gitignore for empty folders" |
Now you can move all folders from the backup folders created earlier back to the root and delete the backups.
1 2 3 |
mv media_bak/* media mv var_bak/* var rm -rf var_bak media_bak |
Lastly it is time to add the files you want to hide. If you are using a mac, add .DS_Store
. If you are using phpstorm. add .idea
, continue as needed.
At the end of the day, my .gitignore
file looks like this:
1 2 3 4 5 6 7 8 9 10 11 |
.DS_Store .idea /var/* !/var/.htaccess /media/* !/media/.htaccess /xmlconnect/ /downloadable/ /tmp/ /downloader/ app/etc/local.xml |
That’s all it takes and it works great!
Hope that helps.
Installing ssh2 extension on CentOS with nginx + php-fpm
Easy task if you have an apache server, but what about nginx + php-fpm?
Spent like 40 minutes to figure this out with 20+ tabs opened in Chrome… I have pure nginx + php-fpm install on CentOS, but most tutorials is about how to install ssh2 extension for php, not php-fpm. So the right answer is:
1 |
sudo yum install php-pecl-ssh2 |
Hope that helps.
How to set an active tab after hiding the first one in Magento
Recently I struggled with how to set an active tab after hiding the first one in Magento admin custom module. I wanted to have the view and edit tabs inside the same action, so that when it edits the page both view and edit are shown. When it’s a new action then only the edit tab will be shown (with corresponding title). Sadly, searching the internet gave me zero results, so it was time to make it by myself.
So, I’ve hide view tab when it’s new action:
1 2 3 4 5 6 7 8 9 10 11 12 |
/* app/code/local/NameSpace/ModuleName/Block/Adminhtml/Items/Edit/Tab/View.php */ .... public function canShowTab() { if ($this->getItem()->getId()) { return true; } return false; } .... |
Result:
To set this tab as active you need to add following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* app/code/local/NameSpace/ModuleName/Block/Adminhtml/Items/Edit/Tabs.php */ .... protected function _beforeToHtml() { $item = Mage::registry('item_model'); if (!$item->getId()) { $this->setActiveTab('section_edit'); } return parent::_beforeToHtml(); } .... |
And voila:
Hope that helps.