Wednesday, October 29, 2014

Generate an order number for your cart in EPiServer Commerce

Many payment services, such as PayEx, require that you pass in an order number when processing payments. This makes it very easy to track payments as you instantly know which order the payment belongs to. At the same time, if you don't want to generate an order before the payment has been processed, where does this order number come from? In this blog post, I'll show you how to can generate an order number for your Cart and then later generate a purchase order with the same order number.

The Cart in EPiServer Commerce has a CreateOrderNumber delegate you can use to define how the order number for your PurchaseOrder will be generated. EPiServer has a great overview of how this works in their Changing order number sequence article. As the article states, the method you define for the CreateOrderNumber delegate is run in the SaveAsPurchaseOrder method, but we don't want to run this method until after the payment is already processed. So what do we do?

We'll still use the CreateOrderNumber delegate, but we've added a lambda expression:

public void BeforeProcessingPayment(Cart cart)
{
   var orderNumber = GenerateOrderNumber(cart.OrderGroupId);
   cart.OrderNumberMethod = c => orderNumber;

   // Save cart and process payment, passing in the required orderNumber
}

// This is the default order number generator in EPiServer Commerce, 
// you can change this around if you want a different format
private string GenerateOrderNumber(int orderGroupId)
{
   string str = new Random().Next(1000, 9999).ToString();
   return string.Format("PO{0}{1}", orderGroupId, str);
}

In the BeforeProcessingPayment method, we're generating an order number and using a lambda expression to set the OrderNumberMethod delegate to this value. This means that you can process the payment and call cart.SaveAsPurchaseOrder() after the payment has successfully been processed. The PurchaseOrder will then receive the same order number as you generated for your Cart.

Now, that wasn't too hard, was it?

Thursday, October 23, 2014

"Oh, a woman, she must be the project manager"

Coffee in one hand, laptop in the other, you're entering a conference room to spend the next hour or so with a handful of people you've never met before. You greet the lot by a quick handshake, first the women and then the two men, before you sit down.

You're there to supply the details as to how the other attendees can integrate their systems against yours, and the woman starts firing away questions. Half an hour of discussions passes and the questions get more and more technical, the woman is still the one who initiates most of them while the two men contribute with their opinions.

The big question is: "When you are to ask a question in return, a question which a developer must answer, who do you direct it to?"

This scenario played out in one of my meetings yesterday and the guy made it quite clear.

"I'm going to address you as you look like the developer", he said and turned to my male colleague.

"We're all developers", my champ colleague replied as I could feel the blood pumping from frustration. I decided to let the comment slip, and I continued to ask questions for another hour.

Gender equality has come quite far in Norway compared to most other countries in the world, even in the tech industry. So encounters such as yesterday's meeting are rare, but they do happen occasionally. When they do, how do you react?

I chose not to say anything and continue the meeting in peace. I didn't feel as though he was intentionally rude, he was simply ignorant. Ignorant of the fact that there are female developers out there, so clearly I must have been the project manager. Had he been mean, I would have said something. But the problem with speaking up about these issues is that you quickly replace your "she's a women, she can't be a developer" label with the "she's an emotional, hysterical feminist" label. And I believe that label does more harm than good.

So my strategy is to prove them all wrong. Like I did earlier this year when I ran into my "you only got this job because you're a woman" ex-colleague before my session at NDC Oslo. One by one, I'm going to prove to them that I'm capable of being an awesome developer AND a woman. Because, believe it or not: There's no testosterone requirement to our profession.

Friday, October 17, 2014

My first six months as a female tech speaker

I'm not the only one who thinks getting up on stage is scary, if not terrifying. Most of us recognize the feeling of not being brave enough or good enough. "Why would someone want to watch my presentation when there are so many out there who know more about this than I?" This is what a lot of developers feel and so did I over a year ago. But that has changed, and I'd like to tell you the story of how it all turned around.

There's a difference between being good at writing code and being able to talk about code, or technical concepts for that matter. I probably owe half my career to a couple of recent and present colleagues who have taught me a lot by talking about code. Talking about code inspires me, but at the beginning of my career I was uncomfortable doing it. What if I used the wrong word? What if I said something wrong? I decided to turn the question around: what would my colleagues do if I said something wrong? Well, some wouldn't say anything at all, other would correct me and one would ask me the right questions so I would realize and correct the mistake myself. No one would laugh, talk behind my back, or label me as useless.

I put on a brave smile and some fake confidence, and I started discussing code with my colleagues. It didn't take long before the fake confidence became real, and it grew fast. Discussing and talking about code had a side effect I hadn't thought about, suddenly my learning curve sky rocketed. Being able to understand new technical concepts explained to you without seeing them written down gives you possibilities you didn't know existed.

After a while, I felt comfortable and confident  talking about code with my colleagues, and I had become somewhat addicted to the learning experience that comes with it. I wanted more, but how?

I used to love public speaking when I was younger. Being part of the European Youth Parliament, I got a high from standing on a stage in front of hundreds of my peers. But somehow, over the years, that love had disappeared. The thought of doing that sort of thing again terrified me, but there was a small part of me hoping I could rekindle the fascination I once had.

I gave it a shot, I signed up for a course on public speaking on Coursera and I spent months creating presentations, recording them and having people all over the world give me feedback on the content and my performance. Of course, speaking to a web camera, recording yourself is not as scary as standing on a stage, you mostly just feel silly. So at the end of the course, I gave myself an exam: To submit a lightning talk abstract to Booster Conference 2014 in Bergen.

Weeks passed and I received the message that I'd been accepted as a speaker. I flew to Bergen and back, completely exhausted after a great conference. The talk was fine, given that it was my first. In hindsight, I've realized how hard it is to say something useful in 10 minutes. As for the performance, it seems like I completely forgot how to smile and  relax.

A couple of months later, I found myself standing on stage at NDC Oslo, nauseous, wondering why the hell I would torture myself like this. My presentation was at the same time as Hanselman and Crockford, so I was amazed that someone turned up for mine. But people showed up one by one, and I survived my first full hour on stage. Still, my performance was stiff and rehearsed, and the content not much better than satisfactory.

That was all about to change though. I'd been asked to speak for the .NET user group in Oslo and I had decided it was time for a completely new presentation. The one I'd held so far simply didn't do the trick. I had worked on the presentation for a couple of weeks when my grandpa had a heart attack and was put into a coma. I can't remember much of the following weeks, but the day of the .NET user group meetup I'd spent the day in the hospital saying goodbye to him. I wanted nothing more than to go home and sleep, my mind and body completely shattered from trying to understand how someone could just disappear without any warning. But I had spent so much time preparing this presentation, and I didn't want all that to be a waste of time. So I went through with it.

Going through a crisis, you quickly find yourself with new perspectives. That happened to me on my way to the .NET user group: I realized that in the larger picture, this presentation didn't matter. Who would care if I said something wrong? If the presentation turned out terrible, if I made a complete arse of myself, I could simply quit. I could walk away from this speaker project I've thrown myself into at any time, no one is forcing me to go on.

Thinking all these things took away my fear and I was no longer nervous. As a matter of fact, speaking to a room full of developers was a nice break from the rest of the terrible events I'd gone through that day. Did I say something wrong? Yes, I did. And the audience corrected me when I did, which I really appreciated. But still, being a pretty inexperienced speaker, I rocked the presentation! It didn't seem rehearsed, I engaged with the audience and we had some nice discussions going. I think I might have cracked the code, figured out the secret.

The secret is to realize that it doesn't matter if you blow it, being a speaker is (for most people) not the most important thing in your life. For me, it's actually quite far down on the list, I do it for fun.

Since the .NET user group meetup, I've done the same presentation at Code Pub Oslo. Later this month I'll be speaking for the developers at NRK. In November, I'm on for TechDays Sweden and in December it's NDC London. So many amazing opportunities I'm extremely grateful for being given!

Then what? Who knows, but it doesn't really matter, does it? If I still enjoy this at the end of the year, I'll go on. So what's my tips to all of you out there who want to become a speaker? There are plenty:

1) Creating a presentation takes a lot of time, more time than you think! For my last presentation, I've probably spent about 40-50 hours doing research, putting it all together and rehearsing. When you're done though, you can use your presentation several times.

2) Don't rehearse too much. This is what I did for my first presentations and the result is that you're not able to show your true self up on that stage.

3) Find a thought that makes you relax and that takes away your nerves. For me that thought was: "All this doesn't really matter"

4) Talk to experienced speakers and don't be afraid to ask questions. I've received some great advice from Johannes Brodwall, Niall Merrigan, Hadi Hariri and Troy Hunt when I've asked for it.

5) Don't be disappointed if you submitted a paper for a conference and don't get accepted. This happens to everyone, it has happened to me twice already. You should be glad all conferences are different, imagine how boring conferences would become it they all had the same speakers?

6) If you want to get started as a speaker, then throw yourself into it. Start by presenting something for your colleagues, contact a local meetup, or submit a lightning talk to see if this is something you'd enjoy doing.

Thursday, October 16, 2014

Apple and Facebook freezing their employees eggs

I'm one of those women in IT who wants to have it all: A family and a career. Had I worked at Facebook or Apple, they would tell me that wouldn't be a problem at all. Because they give their employees "baby-cash", extended family leave and now: They can freeze your eggs.

They've decided to interfere with the most private part of a womens life, reproduction. As if freezing a womens eggs will postpone her wish for a family. As if every woman is willing to put their private life on hold for, let's say, 10 years, so that the employer can have their cut of her time. And what happens after 10 years? When the woman with the frozen eggs realizes that her employer is even more dependent on her now than they were before? Is she going to wait just a little bit longer? I mean, her eggs are already frozen, why not wait a couple of years longer? Until her body is not able to carry forth a child. Until her husband is tired of waiting. Until she's come so far in her career she decides to just forget all about those eggs.

Some women might find this to be a great solution, and that's great for them. But other women will feel pressured. Imagine a woman hoping for a promotion, and the only other candidate has made it very clear that she is willing to freeze her eggs to get the job. Will she feel pressured to do the same? My guess is, probably. If she wants children, freezing those eggs wont magically stop her wanting, there's a mental part to the equation that these companies are not thinking about.

Freezing eggs is not a solution for balancing a family and a career. It's as if we were to solve a famine crisis by supplying a pill that switched of hunger. The famine victimes would still need food, the pill would only postpone the problem and in my opinion make it worse. 

I hope Apple and Facebook will think twice about this. I hope they will address the true issue here, how to make the industry accept a women balancing her career with a family. Without discrimination, without making her feel the extra pressure. 

I have a job that I love and a beautiful family. I'm balancing for all that it's worth, and it's exhausting but it's worth it. My employer makes it possible and not once have I felt pressured or discriminated against. Surely, if they can do it, you would think Apple and Facebook could do the same?

Monday, October 13, 2014

Dev.Cast interview

Some weeks ago, I had a nice chat with Dag K├Âning from Microsoft Sweden about my presentation "How to create a Web API  no one wants to use". The podcast was released today, and you can listen to it here (in Swedish and Norwegian). Make sure you check out his other Dev.Casts as well, there's some great stuff there!



I'll be speaking about this topic at TechDays in November and at NDC London in December, so if you're attending any of the conferences, come say hi!

Wednesday, October 8, 2014

How to hide SeoInformation in EPiServer Commerce

When working with EPiServer Commerce you will see that all products, variants and categories automatically will receive a block in the Information tab called "SeoInformation". In several of our projects we don't want to display this block, we'd rather create our own SEO properties.

The SeoInformation block comes from the ISearchEngineInformation interface that all the following classes implement: NodeContent, BundleContent, PackageContent, ProductContent and VarianContent. So if you don't want the SeoInformation property to be displayed on any of your products, variants and categories, you will need to override the property on all your classes inheriting from ProductContent, VariationContent and NodeContent. 
For example: 
public abstract class BaseProductData : ProductContent
{
    [ScaffoldColumn(false)]
    public override SeoInformation SeoInformation { get; set; }
}

Now, you might be tempted to add an Ignore attribute to the property as well, but if you do that EPiServer will give the the following error when trying to publish: "Property with name 'SeoInformation' is not part of the ContentType definition"


Which of course, is logical as EPiServer won't find the SeoInformation property on the ContentType model. So if you find yourself receiving this error message, make sure you're not using the Ignore attribute on the property in question.


Thursday, October 2, 2014

Why do girls need science to be sparkly in order to find it interesting?

Is science different for men than women? Do women perceive scientifical concepts differently, or is our understanding of science any less?
No. Period.
NO!
The laws of science apply whatever your gender, religion, age or race. So why is it we keep seeing things like this?

"Science with a sparkle". Why do they think girls need science to be sparkly in order to find it interesting? And why shouldn't the boys be allowed sparkly science?

When I was a kid, I used to love chemistry sets (like this one) and electronics sets (like this one). I didn't need sparkles. Sparkles has no role in explaining how our world works, how research can give you the most amazing answers and how technology is making things we've previously only imagined possible.

Our first step of attracting young girls to the fields of science is by giving them the same education as the boys. Let them play and explore science together and that's when we'll start seeing sparkles!