Don't Be a Dunce, Save Your Orders

There are some gotchas that you think that you will always see coming. One such gotcha is the need to save an object to the datastore to persist any changes you may have made to that object.

While it seems like a reasonable concept at the base level, there are times that the need to save an object completely escapes your mind. It seems that for many non-developers, this occurs when they have been working a long time on a file, typically a Microsoft Word document, shortly before their computer blue screens, losing all of their work.

In this case, it luckily had nothing to do with Microsoft Word or a blue screen. Instead, I was trying to programmatically add a comment to an order in Magento. I kept triggering the code that should add the comment over and over, unable to find the comment on the order, and noticing that there is nothing logged to any of the Magento log files. Finally, after spinning my wheels for a bit, and checking with a co-worker, it became obvious that the issue was that I was not saving the order, ensuring the comment that I just successfully added to the order was lost forever.

In case you wanted to know how to properly add a comment to an order without notifiying the customer or allowing the customer to see the comment on the frontend, here it is:

$order->addStatusHistoryComment('Order Comment Here', false)
    ->setIsVisibleOnFront(false)
    ->setIsCustomerNotified(false);

Related Posts

Apr 4, 2014
2 minutes

Creating a Best-Sellers Category with Magento

Magento allows you to organize products in categories, and a single product can be a member of quite a few separate categories. As a result, you can create a category that is specifically for your top selling products. You could manually keep track of which products sell the best, either by number of sales completed, or by the actual quantity of each product that were sold. If you want to spend all your time managing this category, then this is the way to go. However, there is a much easier way to manage the products in the category.

Jan 9, 2015
3 minutes

Authorize.Net Directpost is Overly Complex

One of the necessary evils that every ecommerce website that wants to accept credit card transactions must deal with is some sort of payment processing company. It just so happens that Authorize.net is one of the largest payment processors around, and they allow you to choose from a few different ways to integrate their payment processing functionality into your website. One of their ways is via DirectPost, which allows an eCommerce website to process a credit card transaction without the credit card information ever being sent through the website’s servers.

Oct 23, 2014
5 minutes

Do you have too many big balls?

Managing a software development team can be a difficult task when everything is moving along exactly as expected. When you add in the paradigm shift of Agile Software Development with Scrum, management doesn’t always have the same insights into what makes up an efficient use of a development team’s time. For the rest of this post, lets assume that we are working with a 2 week sprint, with the first day half-used for sprint planning, and the last day half used for the sprint retrospective.