Magento – “Accepting Orders” vs. “Not In Stock” vs. “In Stock”

Introduction

I have several different ways I need to handle product, and nearly chief among these – from a marketing/ credibility standpoint – is the ability to accept “pre-orders” for product that will be arriving very shortly from the manufacturer.

Why is this important? It’s important to establish that yes, we are on the leading edge of the technology, we are authorized dealers. These are typically very high-ticket items, and people do want to order before the product is even out so they can be among the first to get it.

Accepting Pre-Orders

Again, I’m loathe to change very much in code – I’d much rather flip a switch in the Magento configuration somewhere. Backorders are backorders – I want to treat a Pre-Order as a separate, distinct entity. So here’s what I decided to do:

First, I went into Magento admin, and set “Manage Inventory” to “No” for my pre-order items. Conceptually, this feels right – I have the items on order, they’ll be here imminently, but until I have that first Receiving done, I really don’t have any inventory to manage yet. Importantly, I can always use the Product API to give me all products that I’ve set to “Don’t Manage Inventory,” so I can stay on top of it.

I want the net effect to be that products in this state have ‘use_config_manage_stock‘ and ‘manage_stock‘ both off (that is, set to zero).

Code Changes

Turned out to be rather simple to code, but I had a heck of a time finding out how to access the data I needed, and ended up doing a lot of print_r debugging. This is Magento-safe, as verified 12/19/08 by Unirgy (see comments).

In app/design, in my default/template/catalog/product/view/type/simple.phtml file, I made a little change:

Changed From

35
36
37
<?php if($_product->isSaleable()): ?>
 <p class="availability"><?php echo $this->__('Availability: In stock.') ?></p>
 <?php else: ?>

Changed To

37
38
39
40
41
<?php
$__mxwA = $_product->getStockItem()->getUseConfigManageStock();
$__mxwB = $_product->getStockItem()->getManageStock();
echo ($__mxwA=="0" && $__mxwB=="0" ) ? $this->__('Accepting Orders' ) : $this->__('Availability: In stock.')
?>

Details

On line 38, I’ve retrieved the product’s use_config_manage_stock value. On line 39, I’ve retrieved its manage_stock value. My implicit rule – which I’ve made explicit through our internal documentation – is that when both of these values are 0, I display ‘Accepting Orders’. If they aren’t, I would display ‘Availability: In Stock’.

Note that the code is inside the “if($_product->isSaleable()):” block. The “else” of this block will display ‘Availability: Out of stock.’

EDIT 16:50 12/19/2008: Thanks to Unirgy for pointing out the Magento-Safe way of obtainig the StockItem configuration variables. Previous edits of this post were using the incorrect method!

Magento – Mail-In Rebates

Introduction

A Mail-In Rebate is a piece of paper that says “Buy this to Get $x Back!,” and provides a few rules of the program. This means there’s no real programming genius required, other than to provide a link to the rebate form and maybe relieve it from the site after it’s expired.

Doesn’t look like Magento has much in the way of managing Mail-In rebates (at least not yet), so I did some twiddling about today to see what we can do instead. My motto is always try to take the path of least resistance – it’s usually right. My gut reaction was to try an attribute.

And indeed, it did just what I wanted it to. Sorta.

Attribute “rebate_url”

I created an attribute called “rebate_url” :

For internal use. Must be unique with no spaces
Declare attribute value saving scope
Not shared with other products


Frontend Properties

Can be used only with catalog input type Dropdown, Multiple Select and Price
Position of attribute in layered navigation block

In the Label/ Options Tab, I just added “Current Rebate(s)” as the Title in the Admin box. That’ll propogate forward (I’m an English-only store at present):

Admin English French German

Add the rebate_url attribute to whichever set you need. Then, you’re ready to add to product.

Specifying the Rebate URL on the Product

I’d put the rebate_url into the “General” tab of my attribute set, and filled it in like this:

$25 Mail In Rebate! <a href=”pathToPDF”>Download Rebate Form</a> Expires Jan 31, 2012

Lo and behold, a link appears on the product’s detail page!

Problems

The most obvious problem to me is that we have no automated way to effectively manage expirating rebates. In my particular case I opted to use a shared Google Spreadsheet, with an Expiration Date field; I simply exported to csv to upload all of the rebates quickly.

Questions?

Drop me a line! Er, I mean, comment.


Magento – Export Orders – A function to return USPS state abbreviation

It seems the Magento SOAP API is only returning the full state name to me (country being United States). I know that Magento knows the abbreviation – I see it in the source on the customer/address/edit page.

But I’m only getting the full state name via SOAP for my SOAP Order Exporter. No matter, here’s a function that’ll return the state abbreviation. Thank you to the USPS for the state listing. The array is all uppercase because that’s how it came in from the USPS, and I just pasted into my vi editor and used it as-is.

function
getStateAbbreviation( $stateIn ) {
  $stateArray = array (
    "ALABAMA"=>"AL",
    "ALASKA"=>"AK",
    "AMERICAN SAMOA"=>"AS",
    "ARIZONA"=>"AZ",
    "ARKANSAS"=>"AR",
    "ARMED FORCES AFRICA"=>"AE",
    "ARMED FORCES AMERICAS"=>"AA",
    "ARMED FORCES CANADA"=>"AE",
    "ARMED FORCES EUROPE"=>"AE",
    "ARMED FORCES MIDDLE EAST"=>"AE",
    "ARMED FORCES PACIFIC"=>"AP",
    "CALIFORNIA"=>"CA",
    "COLORADO"=>"CO",
    "CONNECTICUT"=>"CT",
    "DELAWARE"=>"DE",
    "DISTRICT OF COLUMBIA"=>"DC",
    "FEDERATED STATES OF MICRONESIA"=>"FM",
    "FLORIDA"=>"FL",
    "GEORGIA"=>"GA",
    "GUAM"=>"GU",
    "HAWAII"=>"HI",
    "IDAHO"=>"ID",
    "ILLINOIS"=>"IL",
    "INDIANA"=>"IN",
    "IOWA"=>"IA",
    "KANSAS"=>"KS",
    "KENTUCKY"=>"KY",
    "LOUISIANA"=>"LA",
    "MAINE"=>"ME",
    "MARSHALL ISLANDS"=>"MH",
    "MARYLAND"=>"MD",
    "MASSACHUSETTS"=>"MA",
    "MICHIGAN"=>"MI",
    "MINNESOTA"=>"MN",
    "MISSISSIPPI"=>"MS",
    "MISSOURI"=>"MO",
    "MONTANA"=>"MT",
    "NEBRASKA"=>"NE",
    "NEVADA"=>"NV",
    "NEW HAMPSHIRE"=>"NH",
    "NEW JERSEY"=>"NJ",
    "NEW MEXICO"=>"NM",
    "NEW YORK"=>"NY",
    "NORTH CAROLINA"=>"NC",
    "NORTH DAKOTA"=>"ND",
    "NORTHERN MARIANA ISLANDS"=>"MP",
    "OHIO"=>"OH",
    "OKLAHOMA"=>"OK",
    "OREGON"=>"OR",
    "PALAU"=>"PW",
    "PENNSYLVANIA"=>"PA",
    "PUERTO RICO"=>"PR",
    "RHODE ISLAND"=>"RI",
    "SOUTH CAROLINA"=>"SC",
    "SOUTH DAKOTA"=>"SD",
    "TENNESSEE"=>"TN",
    "TEXAS"=>"TX",
    "UTAH"=>"UT",
    "VERMONT"=>"VT",
    "VIRGINIA"=>"VA",
    "VIRGIN ISLANDS"=>"VI",
    "WASHINGTON"=>"WA",
    "WEST VIRGINIA"=>"WV",
    "WISCONSIN"=>"WI",
    "WYOMING"=>"WY"
    );
 
    $key = strtoupper($stateIn);
    return( $stateArray[$key] );
}

Just a quickie, but it sure does help.