1

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.

2
  • 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
    Commented May 2, 2017 at 15:24
  • Edited my answer
    – LeCodeur
    Commented May 3, 2017 at 10:45

1 Answer 1

2
<?php 
include('app/Mage.php');
Mage::app();

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

foreach($col as $item)
  echo $item->getOrder()->getCustomerName().' bought '. $item->getProduct()->getSku()."\n";
5
  • 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
    Commented May 3, 2017 at 10:57
  • please see the updated code. Just copy paste. Commented May 3, 2017 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
    Commented May 4, 2017 at 11:12
  • 1
    please include ini_set('memory_limit','2048M'); after Mage::app() Commented May 4, 2017 at 15:51
  • you are very welcome! Commented May 5, 2017 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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