0

I want to create a script to get a list of all customers and their items inside their wishlist.

How can we achieve this in our Magento 1.9.4.1 store?

1

you can try something like this:

$mod = Mage::getModel('wishlist/wishlist')->getCollection();
$data_wishlist = array();
foreach($mod as $data)
{
    $item_array = array();
    $load = Mage::getModel('wishlist/wishlist')->load($data->getId())->getItemCollection();
    $customer = Mage::getModel('customer/customer')->load($data->getCustomerId());
    $count = 0;
    foreach($load as $item)
    {
        $product = $item->getProduct();
        $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
        $item_array[] = array(
            'product_id' => $product->getId(),
            'product_name' => $product->getName(),
            'qty_ordered' => $item->getQty(),
            'stock_available' => $stockItem->getIsInStock()
        );
        $count++;
    }
    if($count){
        $data_wishlist[] = array(
            'customer_id' => $data->getCustomerId(),
            'customer_email' => $customer->getEmail(),
            'customer_name' => $customer->getFirstname() .' '. $customer->getLastname(),
            'last_update' => $data->getUpdatedAt(),
            'item_list' => $item_array
        );
    };
}
echo '<pre>';
print_r($data_wishlist);

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.