2016-09-21 20 views
1

對於壞英語感到抱歉的人。 我使用我的心願工作Magento企業存在的路徑在覈心功能如何在magento中獲得最新的心願

C:\ XAMPP \ htdocs中\項目\ baab.bh \程序\代碼\核心\法師\收藏\助手\ Data.php

getWishlist() 

當我調用此函數從前端PHTML文件它給了我正確的心願,但是,當我從控制器調用這個函數得到的心願它給我違約願望清單不只是目前的願望清單這裏是這個函數

public function getWishlist() 
    { 
     if (is_null($this->_wishlist)) { 
      if (Mage::registry('shared_wishlist')) { 
       $this->_wishlist = Mage::registry('shared_wishlist'); 
      } elseif (Mage::registry('wishlist')) { 
       $this->_wishlist = Mage::registry('wishlist'); 
      } else { 
       $this->_wishlist = Mage::getModel('wishlist/wishlist'); 
       if ($this->getCustomer()) { 
        $this->_wishlist->loadByCustomer($this->getCustomer()); 
       } 
      } 
     } 
     return $this->_wishlist; 
    } 

我用同樣的代碼調用它的代碼,但它從前端PHTML文件,並從控制器表現不同。我怎樣才能從控制器獲得當前的願望清單?

+0

當前用戶的心願? – Noman

+0

我在願望清單頁面我需要當前願望清單對象我需要願望清單名稱 – OBAID

回答

1

對於這一點,你會得到所有客戶的願望單:

public function getWishlist() 
{ 
    $customer = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*'); 

    $wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer); 
    $wishListAllItem = $wishList->getItemCollection(); 

    if (count($wishListAllItem)) { 
     $arrOfProductIds = array(); 

     foreach ($wishListAllItem as $item) { 
      $arrOfProductIds[] = $item->getProductId(); 
     } 
    } 

    return $arrOfProductIds; 
} 

對於這一點,你可以得到當前用戶的心願:

$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer) 
$wishListAllItem = $wishList->getItemCollection(); 

if (count($wishListAllItem)) { 
    $arrOfProductIds = array(); 

    foreach ($wishListAllItem as $item) { 
     $product = $item->getProduct(); 
     $arrOfProductIds[] = $product->getId(); 
    } 
} 
+0

但我不想收集花花公子我只需要最新的願望清單名稱 – OBAID

+0

@OBAID當用戶點擊願望清單,所以你想獲得最新的願望清單名稱?米對嗎? – Noman

+0

其實我在wishlist頁面有一個按鈕,當用戶點擊它發送一個ajax函數在該函數我需要這個願望清單對象 – OBAID