Call the following method from the onCreate() method of your activity:


private void getOverflowMenu() {

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
         Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
         if (menuKeyField != null) {
             menuKeyField.setAccessible(true);
             menuKeyField.setBoolean(config, false);
         }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

You may be like me and have encountered errors trying to install Magento on Dreamhost. Or maybe you’d just prefer to bypass the whole web install. Either way, here’s how you can install Magento via PHP CLI. Of course, you’ll want to replace the path to PHP to match your server environment and update the values of the arguments to work with your setup.

$ /usr/local/bin/php -f install.php -- \
--license_agreement_accepted "yes" \
--locale "en_US" \
--timezone "America/Los_Angeles" \
--default_currency "USD" \
--db_host "mysql.example.com" \
--db_name "your_db_name" \
--db_user "your_db_username" \
--db_pass "your_db_password" \
--db_prefix "" \
--admin_frontname "admin" \
--url "http://www.examplesite.com/store" \
--use_rewrites "yes" \
--use_secure "no" \
--secure_base_url "" \
--use_secure_admin "no" \
--admin_firstname "your_first_name" \
--admin_lastname "your_last_name" \
--admin_email "your_email@example.com" \
--admin_username "your_admin_username" \
--admin_password "your_admin_password"

The install will take some time, so be patient. Once it’s all done (and assuming the installation is successful), you will see output similar to the following:

SUCCESS: 90f02d045c51767ccee093107b2c5eee

Hang on to that string. It’s your Magento encryption key. But if you forget, fear not, it can be found here:

app/etc/local.xml

I recently needed to install APC for a Magento project I was working on. I develop on Mac OS X (Snow Leopard), and while APC is generally a simple PECL install (or homebrew), it doesn’t work on OS X:

doug@scriptrunner:~$ pecl install apc

(Lots of verbose output eliminated for brevity)

running: make
/bin/sh /private/var/tmp/pear-build-doug/APC-3.1.9/libtool --mode=compile cc -I. -I/Users/doug/Documents/Projects/edu/php_unit/temp/APC -DPHP_ATOM_INC -I/private/var/tmp/pear-build-doug/APC-3.1.9/include -I/private/var/tmp/pear-build-doug/APC-3.1.9/main -I/Users/doug/Documents/Projects/edu/php_unit/temp/APC -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c -o apc.lo
mkdir .libs
cc -I. -I/Users/doug/Documents/Projects/edu/php_unit/temp/APC -DPHP_ATOM_INC -I/private/var/tmp/pear-build-doug/APC-3.1.9/include -I/private/var/tmp/pear-build-doug/APC-3.1.9/main -I/Users/doug/Documents/Projects/edu/php_unit/temp/APC -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c -fno-common -DPIC -o .libs/apc.o
In file included from /Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:44:
/usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory
In file included from /Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:44:
/usr/include/php/ext/pcre/php_pcre.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/php/ext/pcre/php_pcre.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/php/ext/pcre/php_pcre.h:44: error: expected specifier-qualifier-list before ‘pcre’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:393: error: expected specifier-qualifier-list before ‘pcre’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c: In function ‘apc_regex_compile_array’:
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:454: error: ‘apc_regex’ has no member named ‘preg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:454: error: ‘apc_regex’ has no member named ‘preg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:455: error: ‘apc_regex’ has no member named ‘nreg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:455: error: ‘apc_regex’ has no member named ‘nreg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c: In function ‘apc_regex_match_array’:
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:487: error: ‘apc_regex’ has no member named ‘preg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:487: error: ‘apc_regex’ has no member named ‘preg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:488: error: ‘apc_regex’ has no member named ‘nreg’
/Users/doug/Documents/Projects/edu/php_unit/temp/APC/apc.c:488: error: ‘apc_regex’ has no member named ‘nreg’
make: *** [apc.lo] Error 1
ERROR: `make' failed

The issue is that APC is expecting the PCRE headers and libraries to be installed. Fortunately, no big deal. Just head over to:

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

and grab the latest release. Or here to simply get the latest:

http://sourceforge.net/projects/pcre/files/latest/download?source=files

At the time of writing, pcre-8.30.tar.gz was the latest tarball. Nothing new here:

$ tar zxvf pcre-8.30.tar.gz
$ cd pcre-8.30 $ ./configure $ make $ sudo make install

Now you should be able to do the normal PECL install:

$ sudo pecl install apc

Or if you feel so inclined, go ahead and install from source. Grab the tarball here (which happened to be APC-3.1.9.tgz at time of writing):

http://pecl.php.net/get/APC

Once again, nothing new here (other than phpsize, perhaps):

$ tar zxvf APC-3.1.9.tgz
$ cd APC-3.19
$ phpize
$ ./configure
$ make
$ sudo make install

You now need to modify php.ini and add the following line (under Dynamic Extensions if you like) so the apc extension will get loaded at run time:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/apc.so

Now restart apache and you should be good to go.

One more thing (and there always is). APC-3.1.9 has a bug, and you may see this after you’ve restarted Apache:

Fatal error: Unknown: apc_fcntl_unlock failed: in Unknown on line 0

However, another easy fix. Update apc_lock.h (in the APC directory) and modify this line (line 157 in my case).

Change:

# define apc_lck_rdunlock(a) apc_fcntl_unlock(&a TSRMLS_CC)

to

# define apc_lck_rdunlock(a) apc_fcntl_unlock(a TSRMLS_CC)

and then you’ll need to recompile apc again.

$ cd APC-3.19
$ make clean
$ phpize
$ ./configure
$ make
$ sudo make install

Then restart Apache, and voilà, you should be good to go.

I needed to get the parent sku of a grouped product. When a grouped product is added to the cart, only the individual items are stored, so the individual product skus are available, but not the parent sku.

<?php
// Start the Magento application without controller
require_once 'app/Mage.php';
Mage::app();

// Get magento frontend core/session Singleton
Mage::getSingleton('core/session', array('name'=>'frontend'));

// Get checkout session Singleton
$session = Mage::getSingleton('checkout/session');

// Use singleton method to get all items in cart
$cart_items = $session->getQuote()->getAllItems();

// Iterate through cart items

foreach( $cart_items as $item ) {
    // Normal product data
    $sku = $item->getSku();
    $qty = $item->getQty();
    $price = $item->getBaseCalculationPrice();
    $name = $item->getName();
    $item_id = $item->getItemId();

    // Get parent sku via parent_id
    $values = unserialize($item->getOptionByCode('info_buyRequest')->getValue());
    $parent_id = $values['super_product_config']['product_id'];
    $product_details = Mage::getModel('catalog/product')->load($parent_id)->getData();
    $parent_sku = $product_details['sku'];

    echo "SKU: $sku<br />";
    echo "PARENT_SKU: $parent_sku<br /><br />";
}
?>