All About Magento

Load a Category and it’s Products

Posted by in Magento

There will come a time when you’ll want to programmatically work on a category or it’s products. Let’s first look at loading a category: In the above example, we’ve also included the store ID. This isn’t strictly necessary if it’s already defined in the scope of your code, but if you’re working outside of Magento it’s vital (especially if you have more than one store). Once your category is loaded, you’re free to use it’s attributes and even change and save them. Now let’s grab the products for this category….read more

0

How to Correctly Set the State of an Order

Posted by in Magento

Programmatically setting the state/status of an order is something that is covered by many other blogs, but they never really work properly. The problem is, although they “work” and really do change the state/status of the order, it all falls over when you want to progammatically hold the order and then, later, change the status again on the backend. Below is an example of what I’m talking about: In the above example, the following happens: The order model is retrieved from the sales/order collection. A series of variables are set,…read more

0

Get Order and Item Details

Posted by in Magento

Since Magento is an e-commerce platform, at some point you’re going to have to deal with customer’s orders. At time of writing, Magento doesn’t allow you to really edit an order that’s already placed (such as removing and adding items purchased) without using a third-party extension or fiddling directly in the database. Sure, you can cancel the order and recreate it with the same increment ID, but it’s still actually a whole new order. As for now, you can change an order’s status/state, and add comments and invoices, but anything…read more

0

Reindexing From the Terminal

Posted by in Magento

Personally, I find it horrible reindexing anything on a Magento site through the admin HTML interface. You select the indexes you want to rebuild, and then sit there waiting for it to finish, without any indication of how it went until after it’s done. If you’re doing the whole lot, you’ve got yourself quite a long wait. Reindexing from the terminal seems to work better than using the web interface, in my opinion. If you have shell access to your server, you can do this too by making your way…read more

0

Get the Stock Quantity of a Product

Posted by in Magento

Anyone who has dealt with product objects knows that the quantity, one of the most important details of the product, isn’t included in the object. You can tell a product can be sold by using $_product->isSalable() (notice the misspelling of ‘saleable’) but that only tells you whether or not the product has a quantity of zero, or whether or not the product has been set as “out of stock”. The reason behind this is because the quantities of products are stored in an entirely different model. Instead of being in…read more

0

Dealing with Product Collections

Posted by in Magento

Below is an example of how to get a simple product collection: This is a “catch all” example. It gets all your products together in one collection, selects all the product attributes, and shows the name of every single one on separate lines. Ideally, unless you really need to get every single product, you would be more selective with the products and details you want. Depending on what you’re after, there are a number of ways to do this. I’ve included a couple of examples below. As you can see,…read more

0

Getting Product Details

Posted by in Magento

One of the main things you may want to do in Magento is to get details of a specific product. This is how you do it: This accesses the catalog/product model and loads the object for a specific product, identified by it’s entity ID. You can then access the attributes of $_product as much as you want: Above are a few examples of the kind of information you can get for your given product. If you ever get stuck, you can always use the following line to show all the…read more

0

Get a Product’s image

Posted by in Magento

Let’s start with something simple for this new blog! Let’s say you’re writing some custom code and working with a product object, and you want to get the main product image. How do you do that? If you want the product’s image, assuming your product object is called $product, the quickest way to do it is: This returns a string showing the relative URL of the main product image. However, this usually points to the original image you uploaded for the product. Since you’re trying to sell the product, it’s…read more

0

Introducing the All About Magento blog

Posted by in Magento

In mid-2011, I was thrown head first into an e-commerce platform that I’d never heard of before. It was the backbone of an ever-growing community, as the documentation for it was pretty much non-existent! The learning curve for this platform was considered by most to be extremely steep. I hadn’t even done e-commerce before, so I was terrified at what I was letting myself in for. I am, of course, talking about Magento. Anyone who’s worked with Magento knows it’s built on the Zend Framework. However, many of Zend’s Libraries…read more

0