0

Well folks, I need a way to grab the full contents of the wishlist and then log them for examination.

What's the best way to do this?

4
  • you mean wishlist products data. Commented Nov 25, 2014 at 7:13
  • @Manik okay. I'd still like an answer to this Q. Commented Nov 25, 2014 at 14:09
  • Did you solved? Waiting for your answer. Commented Nov 27, 2014 at 6:01
  • @Manik No, i'll put a bounty on it. Commented Nov 28, 2014 at 13:04

3 Answers 3

2
+50

Try something like this:

foreach(Mage::getModel("wishlist/wishlist")->getItemCollection() as $item) {
    Mage::log($item->getData());
}

Haven't tested it, but in case it doesn't work, try Mage::log(print_r($item->getData(), true));

Later edit: I've done some testing (you made me curious) and it seems you're not loading the collection properly. Check Mage_Wishlist_Block_Abstract for more details, but for debugging you can use the following:

   $collection = Mage::app()->getLayout()->createBlock('wishlist/customer_wishlist')->getWishlistItems();
   foreach($collection as $item) {
          Mage::log($item->getName(), null, 'wishlist.log', true);
   }

Instead of $item->getName() you can use getData, getProductName, debug, print_r($tem->getData(),true) and so on.

PS: I've tested this in Wishlist/IndexController:indexAction while logged in.

8
  • This is logging an 'undefined index' error in my catalog/block/product/price.phtml file. However, I may accept this answer as it seems to be correct -- perhaps it's just an issue with my blocks. Maybe it's possible to bypass similar issues by just getting the name of the item instead of the totality of the item information? Commented Nov 28, 2014 at 13:36
  • it shouldn't throw such an error, the code doesn't access arrays. you could try to log specific data ($item->getData('something')). and i'd suggest using a separate log, like Keyul mentioned - it might be a bit more difficult to follow the info in system.log.
    – Cristi
    Commented Nov 28, 2014 at 13:40
  • I changed the log location and it is not created / no information is logged. Commented Nov 28, 2014 at 13:56
  • Mage:log('string', null, 'wishlist.log', true) doesn't produce anything? if it doesn't, the code doesn't get executed.
    – Cristi
    Commented Nov 28, 2014 at 13:58
  • I positioned the log('string') function outside of the foreach loop and that produces a result in the 'wishlist.log' log file. Commented Nov 28, 2014 at 14:05
1

Assuming you wish to output a Magento model and you aren't sure what data may be returned by getData (specifically if objects may be in the data array), the Varien_Object::debug() function is useful.

foreach(Mage::getModel("wishlist/wishlist")->getItemCollection() as $item) {
    Mage::log($item->debug());
}

In the case of a wishlist item, getData would probably work though.

0

You can Create your New log file and log the content in this way

foreach(Mage::getModel("wishlist/wishlist")->getItemCollection() as $item) {
    Mage::log(print_r($item->getData(),true),null,'wishlist.log');
}

Mage::log(print_r(Mage::getModel("wishlist/wishlist")->getItemCollection(),true),null,'wishlist.log');

To see this log file please look into var/log/wishlist.log file.

5
  • getting the same fatal error as below: 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 49904868 bytes)' Commented Nov 28, 2014 at 13:18
  • I have update the code
    – Keyul Shah
    Commented Nov 28, 2014 at 13:28
  • I copied your code exactly into the addAction (so it will be called before an item is added to the wishlist) and nothing is added the wishlist.log file isn't generated / populated. Commented Nov 28, 2014 at 13:57
  • they you have to fetch value using observer
    – Keyul Shah
    Commented Nov 28, 2014 at 14:08
  • I'm just going to scatter it around the indexcontroller path of action and see if it sticks. That is a pain in the ass to create an observer just to log wishlist data. I'm trying to debug some erroneous wishlist functionality that we're observing. It shouldn't be that complex to just see what it is in the wishlist at each step of the addition / deletion process. Commented Nov 28, 2014 at 14:12

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.