enter the pirate

A poorly maintained blog of technology

Magento Payment Methods

Let’s talk about Magento payment methods, three words that strike fear in the hearts of many.

Recently I was contracted to develop a payment method for Magento that would have very similar functionality to PayPal Standard, with a bit of a ghetto rigged twist. Because of the insane amount of OOP, creating the methods can be a bit of a chore, especially considering the lack of good documentation.

There are many pieces involved in creating a payment method. This is an example of the file structure of my working method:

/root
  /app
    /code
      /local
         /Mage
           /MyMethod
              /Block
                 /Standard
                    /Form.php
                    /Redirect.php
              /controllers
                 /StandardController.php

Hate yourself yet? If not, there are four (4) more folders in the “MyMethod” directory that are full of adventure and hell. Keep in mind that these folder names are case sensitive. I’ll post a tutorial on how to create your own payment method soon enough.

All in all, as far as open source eCommerce goes, Magento is incredibly robust and feature rich. Once you learn the black magic of Magento, it can be a pretty powerful tool.

Creating Classes in Prototype, MooTools

I come from the object oriented world, as I’m sure many of you do. Creating a class is a great way to write portable code that is easy to understand, and easy for other developers to work with.

This is just a brief overview of how two of the more popular JavaScript frameworks implement classes. Prototype v.1.6.0.2 and MooTools v.1.11 is assumed. This is a class used in an application that is passing data back to server-side code via the ASP.NET ClientScript.RegisterClientScriptBlock functionality.

MooTools

Let’s create a new class, and add a method to the class that we’ll use later in a project.

var Filter = new Class({
initialize: function(type, value) {
this.type = type;
this.value = value;
}
});

Now let’s add our method for the class.

Filter.implement({
toReq: function() {
return this.type + ':' + this.value;
}
});

I’m using MooTools in the live application, and I’m very happy with the performance. Now let’s take a look at how to do the same thing in Prototype.

Prototype

With Prototype, we’ll create our class and it’s constructor as well as our method in the same block of code.

var Filter = Class.create({
initialize: function(type, value) {
this.type = type;
this.value = value;
},
toReq: function() {
return this.type + ':' + this.value;
}
});

The preference is entirely up to the programmer and their background, personal experience.

Prototype JavaScript framework

I’ve made up my mind (at least until tomorrow). The Prototype JavaScript framework is by far my favorite JS framework. It’s not the lightest framework available, but it makes up for that with functionality.

I’ve spent the past few days comparing mootools 1.11 with Prototype 1.6.0.2, and while I like the effects of mootools, from a programming standpoint I prefer Prototype.

The online documentation for Prototype is outstanding (They also have a downloadable PDF and CHM version of the documentation). The code for creating classes is logical and fully featured. One thing that impressed me in comparing mootools to Prototype was that Prototype supports class creation as well as inheritance, and overriding, whereas mootools does not.

The Perfect Solution

Perfect might be a stretch; but, from what I can tell it’s pretty close. moo.fx (by the creator of mootools), is a super-lightweight JavaScript effects framework that can be used in combination with Prototype. Using the two frameworks together would allow you to harness the robust functionality of Prototype, and the rich interface effects of mootools.

I Hate ASP.NET AJAX

There!! I’ve said it!!!

Don’t look at me like that, you know you’ve all been thinking it!

I just overcame the wonderful “[Method Error 500]” error while working with a set of ASP.NET AJAX CascadingDropDowns. What a lame error. Spend some time researching the problem and you’ll find a uniform response: “That error could mean that anything is wrong”. Fantastic!! That’s exactly how I wanted to spend two hours of my time. (That’s sarcasm, by the way)

Everyone’s solution is different because everyone’s problem is different; but, here’s what solved it for me.

I’m using a ContextKey to select data specific to the user who is accessing the application. Since (inspired by true genius… more sarcasm [hopefully you'll pick up the I'm somewhat sarcastic]) the ContextKey attribute of the CascadingDropDown can’t be DataBound, you have to set the ContextKey property of the CascadingDropDown object on Page Load. Well, I added another CDD and forgot to set the ContextKey in the Page Load even handler.

Bada-Bing!! That was it.

Sure, I should have remembered that adding a new CDD to the page meant setting it’s ContextKey on Page Load; but I didn’t. Because the code never reached the web service function, there was no way to step through with the VS 2005 debugger. Fun!

Remember, “[Method Error 500]” could mean your dog just died.

Discovering Web 2.0

Well, I’m officially late to the party. Spending the last two years focused on desktop software development, I let the progress of web development pass me by. As the primary source of production for a very small development company, keeping up with the progress of both technologies was a luxury I couldn’t afford.

So here I am, playing catch up in the web world.

Having worked with Microsoft technologies for more than five years, ASP.NET AJAX is where I started to discover Web 2.0. (Honestly, I can’t stand the term Web 2.0… it’s a buzzword for managers) I understood that the foundation of this new generation of web technology was asynchronous data access, allowing for partial page load and ridding our applications of crunchy postbacks.

For developers that are new to the idea of Asynchronous JavaScript and XML (AJAX) and have a good working knowledge of .NET technologies, Microsoft’s ASP.NET AJAX Control Toolkit is a good way to get started. Using either Visual Studio 2005 or Visual Web Developer (a free Visual Studio product aimed at the beginning web developer) you can drag and drop your way to your first AJAX experience. The all important “Hello World”.

When you’re done frustrating yourself with the ASP.NET AJAX Control Toolkit, here are some JavaScript frameworks that I can recommend:

mootools

Prototype JavaScript Framework

dojo Toolkit

script.aculo.us

Follow

Get every new post delivered to your Inbox.