I am using Magento 1.7. I want to get all the products that each one of the customers bought in the past.

Edit: I need the list of products because I am trying to design and implement a recommender system, and I need the products that the users bought in the past to try to use it as the data that will feed my system.

Any help is much appreciated.

  • do you need this via a single query, or it can be split on multiple queries? you need it for a report, for something custom? Please describe the scenario you have. – Marius May 2 '17 at 15:24
  • Edited my answer – LeCodeur May 3 '17 at 10:45

$col = Mage::getModel('sales/order_item')->getCollection();

foreach($col as $item)
  echo $item->getOrder()->getCustomerName().' bought '. $item->getProduct()->getSku()."\n";
  • Thanks for your answer, however I tried the code and it's not working. I created a file in the root directory, added the line require_once('app/Mage.php'); but got an error: Fatal error: Call to a member function getModelInstance() on null. – LeCodeur May 3 '17 at 10:57
  • please see the updated code. Just copy paste. – Konstantin Gerasimov May 3 '17 at 15:26
  • Thank you; this time I get a memory error: Fatal error: Allowed memory size of 2098200576 bytes exhausted (tried to allocate 73 bytes). But I don't understand, 73 it's less than this memory size indicated... – LeCodeur May 4 '17 at 11:12
  • 1
    please include ini_set('memory_limit','2048M'); after Mage::app() – Konstantin Gerasimov May 4 '17 at 15:51
  • you are very welcome! – Konstantin Gerasimov May 5 '17 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.