I am building a Magento module that needs to set risk scores based upon certain responses from the Authorize.net payment gateway. In case you need to run some tests of your own, there is an easy way to get specific responses back so you can test them easily.
First think you’ll need to know is a list of all the possible responses and response reasons. You can get that here: http://developer.authorize.net/guides/AIM/
To get back a specific response, use the test VISA number of: 4222222222222. Find the response code you want to test, and set the dollar amount to the code. So if you used the test credit card number, and made a transaction for $6, you would get back a response of “The credit card number is invalid.”.
You can do that programmatically, or if you are using Magento or some other shopping cart application, you can easily make a $6 product and not charge for shipping or tax.
May 27th, 2010 in
Misc |
No Comments

I built a module a couple of weeks ago for a client who needed to be able to change the status of orders at any time, as well as having a couple of custom order statuses. It appeared that the best way to change the status or state was by using the setState() method on the order object. Before we get into that, let’s take a look at how Magento sets up the default states and statuses:
Magento sets them up in this file in the Sales model config file: app/code/core/Mage/Sales/etc/config.xml under global > sales > order. There in the ‘statuses’ tag, you’ll see the 8 default statuses (some of which you probably didn’t know existed). In the ‘states’ tag, you’ll see that Magento is setting up 7 different order states. There is also a ‘statuses’ tag as a child of the states. Here is where which statuses are able to be a part of each state. For example, under the ‘processing’ state, the only available status is ‘processing’ (as you can see, you can set the default status for any particular state by adding default=”1″ to the status).
Knowing which statuses are a part of which states is very important. When using the setState() method, you need to make sure that the status/state you are trying to change the order to. Another important thing to take note of is that the ‘complete’ and ‘closed’ states are protected, and you cannot use setState() to change an order to either of those states without overriding the order model to allow the passing of false (setState() passes your parameters to a protected function _setState() which hard-codes true into the ‘shouldProtectState’ parameter).
Ok, now on to the setState() method. This method not only allows you to change the state and status, it also adds the change to the order’s Comments History and allows you to notify the customer. This method can take up to 4 parameters, which I’ll list in order:
- $state (string): This is the state you would like to change the order to. Must match the xml tag in config.xml
- $status (string or true): This is the status you would like to change the order to. Since by default Magento only has one status per state it either has to be the correct status name, or if you pass true it will just get the default status for the state you are passing.
- $comment (string): If you want to pass in a string to add to the comments, you can do so. By default it just passes a blank string
- $isCustomerNotified (bool): Leave this parameter off if you do not want the customer to be notified, otherwise pass in true
So, if I wanted to change the order status to “Cancelled”, and I don’t want the customer notified, this is how I would do it:
$order->setState('cancelled', true, 'Cancelled order due to bad credit card');
Other statuses and states can be added by creating your own module and adding them via your config.xml. You can also add statuses to the other states. This would allow you to change the statuses of your orders right from the order view in the admin.
May 25th, 2010 in
Magento |
1 Comment

I was writing an order export module the other day, and I was needing to get some data from orders and found myself unable to get any customer information such as ->getCustomerEmail(). I was getting the order model collection with the following code:
$orders = Mage::getModel('sales/order')->getCollection();
I could have sworn that in some other context, I was able to get a bunch more information from the order model than what I was able to get from this. Then, with some help from the #magento channel on IRC, I realized that the getCollection() method seems to only return data from itself, and no other related models. It’s limited. If you just add a ‘*’ to the call, you’ll end up getting a lot more data, and I was able to then use getCustomerEmail().
$orders = Mage::getModel('sales/order')->getCollection('*');
May 25th, 2010 in
Magento |
No Comments

Currently running 1.3.2.4 for a client, I was needing to change the default sort order on the product list to “Position” instead of “Name”. Heading into the configuration on the backend, there were only three options, none of which were “Position”. There was “Name”, “Price”, and “Best Value”.
To hopefully save some headaches of a few of you out there, turns out that “Best Value” actually is the value for “Position”. Not sure why, as it doesn’t really seem to make sense, but that’s all you have to do!
And, if you don’t know, the “Position” is set by editing a category, going to the “Category Products” tab, and putting in numeric values in the “Position” column for each product. This allows you to order the products any way you want for any category.
March 25th, 2010 in
Magento |
3 Comments

I am working with a possible client about a new website, and one of the features that they have requested is to have table rate shipping based upon order total, and to have free shipping for $100 or more. This is normally easy and setup directly in the table rates. But there’s a catch.
There are a number of products that need to negate the free shipping if any of them are in the cart. Fortunately, this is doable using Shopping Cart Price rules. Here is how to do it:
Step 1:
Enable your table rates, download the CSV (making sure you are viewing the config on the website level), modify it and then upload your rates. Do not offer any free shipping in your CSV. Keep the Free Shipping method disabled.
Step 2:
Create your Shopping Cart Price rule. I’ve included images below to help explain it. Essentially, you need to set it up to look for a cart subtotal that is equal or greater than $100, and to make sure that there are no excluded products in the cart. You do this under the conditions tab. (Just change the “sku1, sku2, sku3″ etc. to the SKU’s of the products you want to exclude)
What this does is offers the free shipping method (even though it is disabled) if the shopping cart total is $100 or more and does not include any excluded products. If there are any excluded products in the cart, the free shipping method will never be offered.
March 15th, 2010 in
Magento |
4 Comments