thoughtbot-giantrobots:
It’s been two and a half years since my last laptop. It’s neat to look back and see how much has improved since then for setting up a Ruby development environment.
Of particular note, Homebrew, RVM, and Bundler did not exist back then.
Here’s how I set up an OS X 10.7 (Lion) thoughtbot laptop…
Filed under ruby laptop mac os x os x lion rvm bundler xcode install rails
I have recently spent quite a lot of time fixing minor errors with Magento when it decides not to play ball.
I have found quite a few pages with handy commands to run to get Magento back up and running and decided to make a list of the ones that worked and I find myself using regularly here.
Fixing Permissions
- find . -type f -exec chmod 644 {} \;
- find . -type d -exec chmod 755 {} \;
- chmod 550 pear
- chmod 550 mage #for magento 1.5+
If you find that you’re having trouble with Magento Connect and permissions then run this:
- find . -type f -exec chmod 777 {} \;
followed by this:
- find . -type f -exec chmod 644 {} \;
Clear cache and temporary files
- rm -rf downloader/pearlib/cache/*
- rm -rf downloader/pearlib/download/*
- rm -rf var/cache/*
- rm -rf var/session/*
- rm -rf var/report/*
- rm -rf var/tmp/*
- rm -rf var/locks/*
Improving your stores search accuracy
Recently we have been working with Magento a lot. The accuracy [or lack of] of the search has come up in conversation with our clients quite a lot.
When you use the built in search feature in Magento the search results aren’t ordered by relevance. There is a simple way of fixing this.
Within your template, find the following file /catalogsearch/form.mini.phtml.Open up that file and find the following line:
<form id="search_mini_form" ... >
Underneath the above line add the following code:
<input type="hidden" name="order" value="relevance"> <input type="hidden" name="dir" value="desc">
This orders the results by relevance and then by description.
You should also change the search type to like rather than fulltext. This setting can be found in the Administration panel.
Hope this helps someone as much as it helped us!
Disable all thumbnail images in your Magento store
Today we came across a Magento store that had around 20,000 products, each with only one image. Somehow almost all of the images had included a thumbnail of the same image. Obviously it would take a lifetime to manually remove all of the thumbnail images so we looked for an alternative.
Once of our previous posts shows you how to enable thumbnails for all products and then disable them for any product with more than one picture, however, in this case, none of the products had more than one image so we wanted to simply disable the thumbnail for all products using a SQL command.
UPDATE catalog_product_entity_media_gallery_value SET disabled = 1;
Nice and simple.
Simple bulk image settings with Magento
From time to time we need to bulk import products and images into Magento. As you can imaging when you import more than around 2,000 products, each with at least one image, things get a little bit awkward to change. Not just because importing and exporting takes more and more time but because if you wan’t to make changes to the images for each product it would take an age.
We came across the following SQL commands whilst tidying up a catalog with around 4,000 products. They helped us cut down time editing products one by one hugely.
Auto-set default base, thumb, small image to first image.
If you have multiple images per product from your import, Magento might have set the LAST one as the default base, small, and thumb image for all of your products! This can be an issue if you want the FIRST image to be the default!
This script updates your images and makes the FIRST image (image order 1) your default BASE, SMALL, and THUMB image for ALL products in your database. Can save you lots of hours if you were planning on doing this task manually!
UPDATE catalog_product_entity_media_gallery AS mg, catalog_product_entity_media_gallery_value AS mgv, catalog_product_entity_varchar AS ev SET ev.value = mg.value WHERE mg.value_id = mgv.value_id AND mg.entity_id = ev.entity_id AND ev.attribute_id IN (70, 71, 72) AND mgv.position = 1;
Auto-enable thumbs for multi-image and auto-disable for single-image products
Ok, so you imported 5,000 new products into your Magento store, and some have 1 product image, and the rest have 2+ images. If you’re like me, you want the multi-image products to have thumbnails enabled on the product page, and if you only have 1 image, you want no thumbnails (kind of silly to switch between an image and itself LOL).
So this script runs 2 updates. The first enables all images for thumbnails, then the second disables any thumbnails for images associated to products having only a total count of 1image.
UPDATE catalog_product_entity_media_gallery_value SET disabled = 0; UPDATE catalog_product_entity_media_gallery_value AS mgv, (SELECT entity_id, COUNT(*) as image_count, MAX(value_id) AS value_id FROM catalog_product_entity_media_gallery AS mg GROUP BY entity_id HAVING image_count = 1) AS mg SET mgv.disabled = 1 WHERE mgv.value_id = mg.value_id
Source: http://www.magentocommerce.com/boards/viewthread/59440/
Introduction
A post-commit hook is basically a piece of information that can be sent to a third party software service to notify and/or trigger an event at their end. A simple case use I am going to explain would be sending a message to a Campfire chat room every time a new record is created. Remember, a record can be anything you want i.e. a blog post or a new medical record. It just depends on what your Rails application actually does.
Example Use / Case Study
I have an application that has a model called Kases (Cases is a reserved word in Rails, so we have to use Kases). Put simply, imagine a lawyer and what they use Cases for.
Each case hold various bit of data that’s important to the Lawyer. However, this lawyer is part of a partnership – his colleagues all chat in Campfire all day to keep in touch with each other in their remote offices. What we need to do, is send a simple message to their company Campfire room whenever someone creates a new case in our application to let the others know.
Pre-Requisites
To follow this basic guide you must have a Campfire account with 37signals. You need your accounts subdomain, your accounts API access key and the numerical ID of the room you want to send the message to. You can get this number by visiting the room and copying the number from the URL. It should be the only number in the URL, after the final forward slash.
Setup
Add the following to the Kase.rb model.
# Campfire Post-Commit def sendtocampfire post_commit :campfire do authorize :subdomain => "YourSubDomain", :token => "YourAPIToken", :room => 'YourRoomNumber' post "Enter your message here.", :type => :text end end
Add the following to kases_controller.rb.
# POST /kases # POST /kases.xml def create @company = Company.find(params[:kase][:company_id]) respond_to do |format| @kase.sendtocampfire if params[:send_to_campfire] #flash[:notice] = 'Record was successfully created.' flash[:notice] = fading_flash_message("Record was successfully created.", 5) format.html { redirect_to(@kase) } format.xml { render
ml => @kase, :status => :created, :location => @kase } end end
Note: If you have already generated the scaffold for your model, just add the following to the def create part.
@kase.sendtocampfire if params[:send_to_campfire]
Finally, and optionally, add the following to your view just before the submit button.
< % = check _box_tag :send_to_campfire, 1, true %> Send Case to Campfire?
Fin.
Now whenever someone creates a Kase/Case a message will be sent to Campfire, but only if the “Send Case to Campfire?” select box is ticked.
Campfire accepts the following hooks:
post "Some message" post "Some message", :type => :text post "Some pasted code", :type => :paste post "http://twitter.com/johndoe/statuses/12345", :type => :twitter
In case this helps anyone else, this is the format FreeagentCentral requires to import CSV files:
01/01/2010, 50.00, "Explanation here" 02/02/2010, 28.21, "Explanation here"
or
01/01/2010, -50.00, "Explanation here" 02/02/2010, -28.21, "Explanation here"
Obviously, the top is for deposits and the bottom for expenditure.
I have found that working with CSV’s exported from MS Excel is as follows:
Import into Numbers
Arrange columns as required (Date, Value, Explanation)
Save as CSV
Open in Coda
Blockedit the columns to alter date format and add symbols where necessary
http://www.freeagentcentral.com
Up until the end of 2009 I created folder upon folder of website iterations and versions. Numbering them by version number and crying if I messed the numbering system up (which was a regular occurrence). If a client wanted to go back to a previous version of the content but couldn’t remember how the content was worded I would spend ages sifting through the folders hoping to hell I had kept the folder that we needed.
Every time the Apple online store went ‘down’ while the magicians worked in the background I wondered how they instantly switched from one version to another. With changes on every page of the store plus additions to categories etc. they can’t have been doing a simple folder removal and upload via FTP, mainly because it would have taken hours. Never mind if something went wrong, how would they fix the problem in less than a few hours. I strongly suspect that the Apple store is actually usually offline for longer than necessary to instill media hype around potential new products and services. Even so, however they pull this off – its smart.
I asked on Designate Online how people though this was done, I suspected it was SVN but I didn’t really know what SVN actually was. As usual, the folks at DO offered a fair amount of advice and suggestions. To be honest, I didn’t really understand most of it – but the bits I did pointed me in the right direction. As stupid and rash as it seems, I purchased Versions for Mac pretty much immediately. Even though I didn’t fully understand SVN, I did want to use the right tools and I really learn best when playing around – rather than reading tutorial after tutorial and getting swamped with information.
It was immediately apparent that I didn’t know enough to set my own versioning server up so I had to find someone who had been through all this before and had used their knowledge to make my life easier – enter Beanstalk.
Put simply Beanstalk is the behind the scenes magic that I wanted – just like Apple use. As you can imagine Apple won’t use a setup such as Beanstalk – they most probably have racks of servers just for that, but, I’m not Apple. I have neither the funds nor the knowledge to create a setup like that. Beanstalk are the wheels and Versions for Mac is the interface to make it all work like it should.
Unlike most Mac users – I very rarely use Terminal.app. I don’t know why way around OS X, nor do I really need to learn. So, how the hell do I make things work – well – frankly, its a little bit of a botch job, but in the main its all pretty smooth and I have to be honest I’m loving it.
Update: NetTuts have just created a really useful screencast explaining the basics to Versions in the Git format.
http://net.tutsplus.com/videos/screencasts/terminal-git-and-github-for-the-rest-of-us-screencast/