Creative web design,
Dependable results.

Get a business website you're proud to show off. Contact us today.

FreshBooks

Remote backup, rsync, automatic daily backups
Zend Framework setup Mac OS X with macports
Tuesday, 01 March 2011 10:46

I have the following items previously configured:

  • Macports install of PHP 5.2, MySQL, and Apache under /opt/local
  • Zend Studio 8 with default workspace at /Users/stacey/Zend/workspaces/DefaultWorkspace7
  • Zend Debugger installed (64-bit version)
  • Running my Macbook in 64-bit mode

For a training class I am taking, I wanted to download and install the Zend Framework and create a new project. 

You can also, of course, use Zend Studio to create a new Zend Framework project.  This exercise is to understand how the Zend_Tool works, even without Zend Studio.

Here are the steps I needed to take to do so and also use my previously installed stack (rather than downloading Zend Server).

  1. Download the latest version of Zend Framework from http://www.zend.com/community/downloads.  I downloaded Zend Framework 1.11 full
  2. Extract the downloaded file.
  3. Move the contents of the library directory to your php include path.  With my Macports install, this location is /opt/local/lib/php
  4. Move the contents of the bin directory to your executable path.  For me this is /opt/local/bin
  5. Create a symbolic link to the Zend Framework command line script (zf.sh)
    ln -s /opt/local/bin/zf.sh /opt/local/bin/zf
  6. Test it out by typing the command below.  You should see a listing of options for the zf command.
    zf --help
  7. You can configure the storage path for the Zend_Tool.  By default, it will create it in your $HOME directory, i.e. /Users/stacey.  I wanted to change this to store it with my Zend Studio files.  To do so, you need to add an environment variable like so:
    export ZF_HOME=/Users/stacey/Zend/workspaces/DefaultWorkspace7
  8. Next type the following:
    zf --setup storage-directory

    zf --setup config-file

    zf --info
  9. The last command (zf --info) shows the current setup for the Zend_Tool.  My results:
    shell$> zf --info

    Zend_Tool & CLI Setup Information
    (available via the command line "zf --info")
    * Home directory found in environment variable ZF_HOME with value /Users/stacey/Zend/workspaces/DefaultWorkspace7
    * Storage directory assumed in home directory at location /Users/stacey/Zend/workspaces/DefaultWorkspace7/.zf/
    * Config file assumed in home directory at location /Users/stacey/Zend/workspaces/DefaultWorkspace7/.zf.ini
    To change the setup of this tool, run: "zf --setup"
  10. Note:  I also initially got the following warning:
    Failed loading opt/local/apache2/modules/ZendDebugger.so:  (null)

    To fix this, I first verified that I had the right version of Zend Debugger installed (64-bit for me).  This was fine and I verified it was loading by looking at phpinfo().  To get rid of this error, I needed to edit the zf.sh file. You will need a tool like TextWrangler to be able to save your changes.  Modify this line:
    "$PHP_BIN" -d safe_mode=Off -f "$PHP_DIR/zf.php" -- "$@"
    to
    "$PHP_BIN" -n -d safe_mode=Off -f "$PHP_DIR/zf.php" -- "$@"
    Save and restart Apache.
  11. Next try creating a project.
    zf create project HelloWorld
    You should now see a HelloWorld directory in your Storage directory (for me this is /Users/stacey/Zend/workspaces/DefaultWorkspace7/).
 
Print Coupon Code or Gift Certificate on Magento Invoice PDF
Monday, 21 February 2011 15:51

One of my clients recently requested adding any applied coupon codes or gift certificate codes to the invoice printed from Magento.  This is actually a pretty quick and easy change.  Below are the steps required to implement this change in Magento 1.4.1.1.

  1. Copy /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php to /app/code/local/Mage/Sales/Model/Order/Pdf/Invoice.php
  2. Find the line $page = $this->insertTotals($page, $invoice); in the getPdf function.  This was line 107 for me.
  3. Add the following:
    /* added by Wright Creative Labs */
    /* print coupon code on invoice */
    if($order->getCouponCode()!=""){
    $this->y -=12;
    $page->drawText('Coupon Used: '.$order->getCouponCode(), 450, $this->y, 'UTF-8');
    }
    /* print gift certificate code on invoice */
    if($order->getGiftcertCode()!=""){
    $this->y -=12;
    $page->drawText('Coupon Used: '.$order->getGiftcertCode(), 450, $this->y, 'UTF-8');
    }
  4. Save.
  5. That's it!  Go to the backend to test it out... Sales > Invoices and then try to print an invoice with a coupon code or gift certificate.
 
Subversion tools - Beanstalk and Versions
Monday, 21 February 2011 15:05

Beanstalk AppBeanstalk is my latest love. So easy to setup and use, even to a subversion newbie.  Beanstalk allows designers and developers to store source code, track changes, and collaborate with team.  Plus, you can setup multiple deployment environments for each repository to automate the process of deploying changes to your Staging and Production environments. 

In my case, I keep my development environment on my laptop.  I also have setup two branches - staging and production.  The staging branch is setup in Beanstalk to automatically deploy to the Staging server when I perform an svn commit.  The production environment is similarly setup.  I found this article on deployment best practices helpful - http://blog.beanstalkapp.com/post/754555821.

I use Versions, a subversion client for Mac, on my laptop.  I have bookmarks to my Beanstalk repositories and have the project trunk and branches checked out locally.  When I am ready to deploy to Staging, I merge the trunk and staging branch, then commit the changes to staging branch. Here are the steps to merge the changes in the development environment (trunk) to the staging branch:

  1. In the terminal, go to the staging branch directory.
    cd /Users/myuser/Zend/workspaces/DefaultWorkspace7/myproject-branches/staging
  2. Merge changes from the trunk into the staging branch.  E.g.
    svn merge /Users/myuser/Zend/workspaces/DefaultWorkspace7/myproject-trunk
  3. When you are ready to deploy, go back to Versions and commit the staging branch.  The deployment will be added to Beanstalk's deployment queue. You can view the status of the deployment by logging into Beanstalk, going to the repository, and viewing the Deployments tab.
  4. If you get errors from Beanstalk about how a file or folder cannot be created, you may need to update permissions on your server before deployment so that all of the files/directories can be written.  You can switch the permissions back to normal afterwards.
Sign-up with Beanstalk and get 10% off your first month's payment!
 
Useful Linux Commands
Friday, 18 February 2011 16:48

Here are a collection of Linux commands that I frequently use when managing my servers and Magento projects.  Enjoy!

Create a compressed file

Usage: tar -cvxf [filename.tar.gz] [location]

Example:

tar -cvxf myfiles.tar.gz *

Create a MySQL database dump

Usage:  mysqldump -h DBHOST -u DBUSER -pDBPASS DBNAME > data.sql

Example:

mysqldump -h localhost -u mysqlusr -pmypassword mydatabase > mydatabase.sql

Import a MySQL database dump into a database

Usage:  mysql -h DBHOST -u DBUSER -pDBPASS DBNAME < backup/data.sql

Example:

mysql -h localhost -u newdbuser -pnewdbpassword newdatabasename < "/path/to/my/database/dump/mydatabase.sql"

Open permissions for Magento Connect

This example is for PHP running as an Apache module (mod_php, DSO).  First navigate to your root magento directory.

find . -type d -exec chmod 777 {} \;
chmod 666 downloader/config.ini
chmod 777 downloader/pearlib/download/package.xml

If you still get errors, try deleting downloader/pearlib/pear.ini.

Reset Magento permissions

find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
chmod o+w var var/.htaccess includes includes/config.php app/etc sitemap/sitemap.xml
chmod 550 pear
chmod -R o+w media

Find recently modified files

Usage:  find /path/to/search -type f -mtime -DAYS -print

Example to find files changed in the last 14 days:

find /home/mysite/public_html -type f -mtime -14 -print

Recursively delete all .svn directories

find /path/to/search -name .svn -print0 | xargs -0 rm -rf

Search for text in files (grep)

Usage:  grep [options] [search phrase] [destination]

Example:

grep -R "*wcltestserver2.us*"

 

 
Paypal error "Wrong Order ID" on Magento 1.4 checkout
Friday, 07 January 2011 10:50

After migrating a Magento store to a new server, an exception stating "Wrong Order Id" followed by the Order Id was showing up in the logs.  The store is using Paypal Website Payments Pro and Magento is version 1.4.1.1. 

I found the lines of code in app/code/core/Mage/Paypal/Model/Ipn.php that generate the error being logged:

    protected function _getOrder()
{
if (empty($this->_order)) {
// get proper order
$id = $this->_request['invoice'];
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($id);
if (!$this->_order->getId()) {
throw new Exception(sprintf('Wrong order ID: "%s".', $id));
}
...

This code appears to first try and look up the order id by getting the invoice number.  In the case of my store, the invoice number and order number are not the same.  On this hunch however, I reset the invoice number to be in sync with the order number.  This was done by editing the eav_entity_store table, which stores the last id number for the orders and invoices.  I raised the increment_last_id value for the invoice (entity_type 16) to be the same as that for the order (entity_type 11).  Note that the entity types are defined in the eav_entity_type table.  Look there if you are not sure which row to change.

After this change, I placed an order and presto... no more "Wrong Order ID" errors!

Update:

I spoke to soon.  Each time I apply this fix the error does not appear for a while.  But it always pops back up again, I presume as soon as the Order Id and Invoice Id get out of sync.  The error is logged, but does not seem to be causing any other problems, so for now I'm planning to leave it be. I'll post again if I find out more!

 
<< Start < Prev 1 2 3 4 Next > End >>

Page 1 of 4