Magento Quickies

All the Non-Trivial Magento Trivia

0 notes

Create Dummy Orders

An n98-magerun add on that adds a order:create:dummy command. Useful for the freelancer “I need sample data to do your ERP project/We don’t trust you with our order information until you’ve done some work for us” catch-22.

0 notes

Cross Area Session Access

Speaking of sessions, I whipped up a quick proof of concept for accessing admin sessions from the frontend of Magento — useful if you want to restrict frontend access using backend session ACL rules.

Right now it works with file and db session storage — memcache, redis, etc. would need their own Loader model implementation. The loader models are responsible for yoinking sessions out of storage by session ID. The rest of the tedious and particular session handling logic is handled by the extension code.

0 notes

Non-Deterministic PHP Session Saving in Magento

I gave this little bit of Magento code an ugh on Twitter.

#File: app/code/core/Mage/Core/Model/Resource/Session.php
public function __destruct()
{
    session_write_close();
}

Why? Because PHP automatically calls __destruct when it cleans up memory for an object, which means this code could potentially close and save the session before the PHP request finishes. This, in turn, could make sessions appear broken to a client programmer.

Now, this doesn’t happen with a stock Magento because Magento core code instantiates the session resource as a Magento singleton

Mage::getResourceSingleton('core/session');

Magento’s singleton implementation keeps a reference to the object around for the entire request, so PHP never calls __destruct.

However, if you instantiate the resource model as a regular model (because you wanted to reuse the “read/write sessions from database” code), you’ve created a potential bug if PHP garbage collects your model instance.

The solution, of course, is don’t do that, but relying on PHP’s __destruct method for something other than memory cleanup in an object that’s not guaranteed to stay a singleton seems sketchy at best, and destined to cause problems for developers who need to make customizations to session storage.

Filed under magento sessions

0 notes

How to convert Magento quote into backend order

An article explaining how to turn an existing customer’s cart (i.e. “quote”) into a Magento order via the backend. The number of workflows Magento has built in for this sort of thing are surprising — I often wonder how often someone’s taken on a custom development project only to discover most of what they wanted has already been built.

0 notes

Solr and PCI Compliance

Blog post form Inchoo on compiling the latest Solr to work around PCI compliance issues. The lesson? Vendor support for Enterprise Edition comes mainly from Magento partners, and not Magento/eBay itself.