2014-10-20 49 views
1

與以下帖子相關我需要在文檔準備就緒後,通過ajax加載心願單中的所有項目。我創建了一個外部腳本,我通過jQuery調用,但沒有得到任何結果。像...通過ajax加載心願單項目(外部腳本)

include_once '../app/Mage.php'; 
Mage::app(); 

我已經嘗試了幾個片段加載數組中的wishlist項,但我從來沒有得到一個結果。我以前用php加載信息,但是我們使用全頁面緩存擴展,我需要更新類別視圖中的心臟圖標。

Example from our catalog view

有誰知道如何得到的結果?

Magento Wishlist - Remove item

回答

0

嘗試下面的代碼。我已經在magento 1.9下測試過,像魅力一樣工作

<?php 

// result buffer 
$result = array(); 

// init magento 
require_once('app/Mage.php'); 
umask(0); 
Mage::app('default'); 

// init session 
Mage::getSingleton('core/session', array('name'=>'frontend')); 
$session = Mage::getSingleton('customer/session', array('name'=>'frontend')); 

// get wishlist if logged in 
if ($session->isLoggedIn()) { 

    $wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($session->getCustomer()); 
    $wishListItemCollection = $wishList->getItemCollection(); 

    foreach ($wishListItemCollection as $item) 
    { 
     $result[] = array(
      'name' => $item->getName(), 
      'id' => $item->getId(), 
      'price' => $item->getPrice(), 
      'qty' => $item->getQty() 
     ); 

    } 
} 

// return 
header('Cache-Control: no-cache, must-revalidate'); 
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Content-Type: application/json'); 

echo json_encode($result);