You are currently browsing the archives for the PHP category


A helpful reference of Magento static methods

From Prattski.com:

http://prattski.com/2010/10/25/magento-mage-static-functions/

Magento Admin Login not working

Just set up a Magento site for a project at work (internal, on a non-production server). I was baffled for a few minutes because I couldn’t get logged into the admin section. I would enter my username and password, but then I’d get redirected back to the login page.

There was nothing in the error log that would indicate a problem.

After checking a few things, I noticed the time on the server was not set correctly. I reset it using the ‘date’ command, and voila, the login worked.

Turns out the server was setting an ‘expires’ value in the cookie based on the date and time on the server. This date was being set 6 hours behind, which is just over the allowed login time before you need to log back in.

Downloading Magento Connect Extensions from the command line

I’m not a big fan of Magento’s Magento Connect Manager. It’s a web based tool designed to let you download an install extensions from a web interface.

For it to work, you need to allow write access to your entire Magento codebase so the web server can overwrite files. This just makes me nervous, and there’s no concise explanation on how to set permissions back again. (I have a little script for fixing Magento permissions, which I’ll post a link to later).

Today I figured out a preferable way to download extensions from Magento connect. It’s by using the pear executable that comes with Magento. The trick is to initialize the downloader to use the Magento Connect servers.

To do that you need to run the mage-setup command with the pear client in your Magento root.


$ ./pear mage-setup

This will add the Magento “channels” to your configuration. Now, if you run:


$ ./pear download [Extension Key]

the compressed tarball for your extension will be downloaded to your Magento root directory. At that point you can open it up, inspect, and install it manually, if that’s your preference.

Skumerals

For my SKU application that I’m writing (SKUtee) I’m creating a custom base 3334 numbering system, consisting of the digits 0-9, and the letters A-Z, without I, L, or O.

class Application_Model_Abstract
{
    protected $_id;
    protected $_value;
    protected $_committed;
    protected $_archived;
    protected $_skumerals = array();

    public function __construct()
    {
        $this->_skumerals = array(
            '0','1','2','3','4','5','6','7','8','9','A',
            'B','C','D','E','F','G','H','J','K','L','M','N',
            'P','Q','R','S','T','U','V','W','X','Y','Z',
            );
    }

[...]

}

Oh for fun…

[Update]

L’s now included!!! We want to be able to have LG and XL as codes for sizes, so we need to include L’s.

What I'm working on this month

I’ve got an aggressive schedule lined up at Probus OneTouch this month, one that I’m really excited about. The goal in front of me is to fully automate order processing, and set up integration between Magento and SAP Business One.

First, however, I’m working on a little database application that we’re going to use to help us keep track of our SKUs. I call it SKUtee. I’m writing it in PHP using Zend Framework. While I’ve had a bunch of exposure to Zend Framework by working with Magento this is my first project from scratch using ZF.

I’ll write more about SKUtee in the next couple of weeks as a case study of writing a small custom application to solve a unique business problem.

After SKUtee is done, I’ll be implementing an addon to Magento to import customer orders from Ebay and Amazon. In the past we’ve used another application in house to funnel orders from Ebay, Amazon, and Magento into a single database to use for order processing. This addon will import all orders into Magento, so our customer service staff will have a single place to go for all orders. Getting this set up is a priority for our SAP implementation project as we’re only planning on integrating SAP with Magento — not with Ebay or Amazon. Orders from those channels will come into the SAP system from the Magento feed for processing.

Later this month, I’ll be adding a product called Help Desk Ultimate to our Magento install to enable our Customer Service staff to more easily keep track of customer requests. This product will also get integrated with SAP, as we’ll link “service calls” in SAP with customer tickets on Magento. Our customer service agents will use Help Desk Ultimate to manage their open issues with customers. Our tech service crew will use SAP for anything that involves receiving returns or pulling items from stock for repairs. Our goal is to better track cost of service and identify warranty issues to charge back to our factories, while also making it easier for customer service to keep track of who needs help and who doesn’t.

Looking at the calendar, it looks like there’s only about 3 more weeks in the month, so I’m going to be busy! I’m hoping I can get this all banged out in time because Jenny and I have a baby on the way. If he decides to come ahead of schedule, then some of this stuff might have to happen in June. We’ll see! It’s good to be busy.

Installing Apache and PHP from source on Leopard

For as long as I can remember, I’ve done web development by working directly on a system running a web server, so that I’m editing files directly in a live document root. For a good part of my career, this has meant that I’ve worked on a Linux system running Apache, PHP, and MySQL.

For the past 6 months, though, I’ve had an Apple MacBook running Mac OS Leopard. Leopard comes pre-installed with Apache and PHP as part of the OS, so for many people the task of installing this web platform is already complete.

If you need any custom options in either Apache or PHP, however, and many people do, you’ll have to download and compile the source yourself. I haven’t found this to be very well documented. So, for the sake of all mankind (but for my own memory, really), I am documenting the process here.

Step 1. Installing Apache

Download the latest source from http://www.apache.org/. I have a directory called ~/src, and I’ll untar the downloaded file in there.

Here are the commands, from the base of the httpd source directory:

$ ./configure --enable-layout=Darwin --enable-so --with-included-apr
$ make
$ sudo make install

Step 2. Installing PHP

PHP has tons of available config options, and I have many of them turned on for my machine. On a production system, best practice would dictate that you identify which options you acutally need, and only compile those in. But in this case, we want to have a bunch of stuff turned on.

To make it easier on myself, I create a file called “config.txt” which contains a configure command with all of the options I use. I copy this into each new version of the PHP source that I compile.

Here’s the contents of that file:

./configure \
–prefix=/usr \
–sysconfdir=/etc \
–with-config-file-path=/etc \
–localstatedir=/var \
–mandir=/usr/share/man \
–infodir=/usr/share/info \
–with-apxs2=/usr/sbin/apxs \
–with-mcrypt=/usr/local \
–with-ldap=/usr \
–with-kerberos=/usr \
–enable-cli \
–enable-soap \
–with-zlib-dir=/usr \
–enable-exif \
–enable-ftp \
–enable-mbstring \
–enable-mbregex \
–enable-sockets \
–with-iodbc=/usr \
–with-curl=/usr \
–with-config-file-path=/etc \
–with-mysql-sock=/tmp/mysql.sock \
–with-mysqli=/usr/local/mysql/bin/mysql_config \
–with-mysql=/usr/local/mysql \
–with-openssl=/usr \
–with-xmlrpc \
–with-xsl=/usr \
–with-libxml-dir=/usr \
–with-iconv=/usr \
–with-pdo-mysql=/usr/local/mysql/bin/mysql_config \
–with-gd \
–with-jpeg-dir=/usr/local \
–with-png-dir=/usr/local \
–with-freetype-dir=/usr/local

Notice there are a few things at the end, jpeg, png, and freetype, as well as mysql. These are things that I’ve installed previously. If you don’t have them on your system, you should pull these config options out, otherwise you’ll probably get errors.

To compile, I do:

$ sh < config.txt
$ make
$ sudo make install

That first command will execute the ./configure command in the text file. Why don’t I do a .sh file and make it a shell script? I just don’t.

Step 3. Get back to work

That’s it! At least when fixing a clobbered install from a security update. If you want to know how to install MySQL or any of the other stuff let me know in the comments and I’ll dive further into this. I hope you find this useful!