Tag Archives: Magento

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

New Feature: Make the Store Address’s First Line Stand Out on Magento PDF Invoices

Want to make your store name stand out on your PDF invoice (example to the right)?

By default, Magento’s PDF invoice displays your entire store address/information block using the same font/font size. Now, Ben Gribaudo’s Customizable PDF Invoice Module gives you separate font/font size settings for both the store address’s first line and the rest of the address. Continue reading

Released: Customizable PDF Invoice Module for Magento

It’s released! Use Ben Gribaudo’s Customizable PDF Invoice Module to style your Magento PDF invoices.

  • Choose the font/font size for each component on the invoice. Use one font for store info, another for item details, make the totals section larger….
  • Set the page size and margin. If you’d like, output invoices as letter-sized instead of Magento’s A4 default. Continue reading

New Module Feature: Customize Magento PDF Invoice Item Columns

New feature—the forthcoming PDF invoice customization module allows item columns (item name, SKU, price each, tax, etc.) to be customized in three ways:

  • Show/Hide: Selectively remove item columns from the invoice. Perhaps your products are sales tax exempt—use this module to hide the tax column. If you sell your products only in quantities of one, use this module to remove the quantity column.
  • Width: Change column widths. Specify values in points or percentage.
  • Text Align: Set to left, center or right on a per-column basis. Continue reading

Wiring Up a Custom Select Control Options List for the Magento Admin Interface

Yesterday, while building the admin interface for a Magento module, I wanted to populate a select control (a.k.a. combobox or drop-down list) with a custom list of options. Inserting the select control was simple. Building the custom options class also was easy. However, figuring out how to wire in the custom options list took a little bit of time. Continue reading

Magento PDF Invoice Customization

Over the past month or so, I’ve been building a Magento eCommerce module allowing PDF invoices to be customized in four areas:

  • Page Size: By default, Magento PDF invoices are rendered as A4 pages. Most of us in the US would probably prefer that these PDFs be outputted using the letter page size (8.5″ * 11″) to match the paper we use. This module allows easy configuration of the invoice’s page size.
  • Logo Size: By default, Magento requires that your logo be 200 pixels by 50 pixels. With this module, your logo can be any size that will fit on the page. Continue reading