I'm trying to display a history of customer's orders by products. I succeeded to display every product ordered with its date, name, price, sku and quantity. But now I'd like to display it by at least one criteria: the date.
The purpose is to offer the customer a list of his purchases per month. How could I do it? Right now, I have done this in history.phtml file:
<?php
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$orders= Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id',Mage::getSingleton('customer/session')->getCustomer()->getId());
?>
<table class="data-table" id="my-orders-table">
<thead>
<tr class="first last">
<th>Produit</th>
<th>Référence</th>
<th>Date</th>
<th><span class="nobr">Prix</span></th>
<th><span class="nobr">Quantités</span></th>
</tr>
</thead>
<tbody>
<?php
foreach($orders as $eachOrder) {
$order = Mage::getModel("sales/order")->load($eachOrder->getId());
$items = $order->getAllVisibleItems();
$i = 0;
foreach($items as $item): ?>
<tr class="first last odd">
<?php
echo "<td>" . $item->getData()['name'] . "</td>";
echo "<td>" . $item->getData()['sku'] . "</td>";
echo "<td>" . $this->formatDate($item->getData()['created_at']) . "</td>";
echo "<td>" . $item->getData()['price'] . "</td>";
echo "<td>" . intval($item->getData()['qty_ordered']) . "</td>";
?>
</tr>
<?php endforeach;
}
}
?>
</tbody>
</table>
EDIT I edited my code and now I can sort my orders by month by adding a new attribute: addAttributeToFilter('created_at', array('like' => date('Y') . '-10-%');
But I still don't know how to create a dropdown list to select the month and then refresh to sort products with the chosen month. Thank you!