So, Tridian has been doing quite a bit of Magento development work lately, and in keeping with the spirit of “open source” software, we thought we’d share a module that we recently developed that addresses a very common need when creating an e-store with Magento. The requirements are to get the X most recently products added to the store (108 in this case) and display them in their own “New Arrivals” category, but make it so that the cart will automatically display the newest products based on the product’s creation date, without the site admin having to manually assigned them into and out of a “New Arrivals” category.
In order to create “New Arrivals” functionality on my client’s Magento store (which is 1.1.6, but this code also works for all versions of Magento through the current 126.96.36.199), I created the following module. My approach was to override the normal category behavior for my “New Arrivals” category and display a custom product collection instead.
Step 1: In the admin, create a category called “New Arrivals” and leave it empty.
Step 2: Find the code that generates the product listings on the Category pages. Turns out the code that does this is in the class Mage_Catalog_Block_Product_List. Great. But now, in order to get the cart to do what we want, we have to override this class and add my own custom code to handle the creation of the product collection for the empty category “New Arrivals”. To do this, I created a new block file called Tridian_Newarrivals_Block_Newarrivals, which extends the original, and saved it here: app/code/local/Tridian/Newarrivals/Block/Newarrivals.php.