Tag Archives: PHP

Unit Testing & Magento’s Autoloader

, ,

If code written for Magento is executed outside of Magento—as occurs when running unit tests—Magento’s normal startup process (which registers its autoload functionality) is not run. Without the autoloader in place, the first time PHP encounters a request to initialize a class which it doesn’t recognize, it will error out with a “class not found” error. Also, without Magento’s startup process running, PHP doesn’t know about the Mage family of singleton methods (e.g. Mage::getModel(), Mage::helper()) which are commonly used to create class instances. Continue reading

Programmatically Setting a Magento Item’s Price When Adding It to Cart


Using code, how would we give a Magento item a one-time special price then add that item to the shopping cart?

The process is simple:

  • Create an instance of the Magento product,
    • give it a custom price by calling setSpecialPrice,
    • then save the product instance (store must be running as the admin store).
  • Next, grab the Magento cart object (a singleton),
    • add the product instance to the cart,
    • then save the cart.

Continue reading

Zend Pdf Coordinates

, ,

Thought I would share a few things I recently learned about coordinates when using Zend Framework‘s Zend Pdf library.

  • The typographical point is the unit of measurement used for all coordinates. 72 points equals 1 inch. An 8.5″ * 11″ page is 612 * 792 points.
  • The x/y coordinate origin is the bottom left corner of the page. If you are laying out a page from top to bottom, the y-coordinate will get smaller as you work your way down the page.
  • Lines are centered on their coordinates. Continue reading