1
我在模塊的模型類中使用方法時遇到問題。
我有一個公共函數觸發2個受保護的方法。問題是隻有第一個返回一個值。
這裏是我的課:現在Magento:在1個模型中使用各種方法
<?php
class Osdave_Points_Model_Mysql4_Points_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
const POINTS_CONFIRMED = 2;
const POINTS_REDEEMED = 4;
protected $_customer;
public function _construct()
{
parent::_construct();
$this->_init('points/points');
$this->_customer = Mage::getSingleton('customer/session')->getCustomer();
}
public function getCustomerAvailablePoints()
{
$confirmed = $this->_getCustomerConfirmedPoints();
$redeemed = $this->_getCustomerRedeeemedPoints();
$balance = ($confirmed - $redeemed);
return $balance;
}
protected function _getCustomerConfirmedPoints()
{
$availablePoints = $this->addFieldToFilter('customer_id', $this->_customer->getId())
->addFieldToFilter('points_status', self::POINTS_CONFIRMED)
->addFieldToSelect('points_pending')
->addExpressionFieldToSelect('available_points', 'SUM({{points_pending}})', 'points_pending');
return $availablePoints->getFirstItem()->getAvailablePoints();
}
protected function _getCustomerRedeeemedPoints()
{
$redeemedPoints = $this->addFieldToFilter('customer_id', $this->_customer->getId())
->addFieldToFilter('points_status', self::POINTS_REDEEMED)
->addFieldToSelect('points_pending')
->addExpressionFieldToSelect('redeemed_points', 'SUM({{points_pending}})', 'points_pending');
return $redeemedPoints->getFirstItem()->getRedeemedPoints();
}
}
,如果在_getCustomerRedeeemedPoints(),我更換$this
通過Mage::getResourceModel('points/points_collection')
它工作正常。但是因爲我已經在課堂上了,所以我不明白爲什麼我必須通過法師來舉例說明:據我所知,$this
只有一次。
那麼,我做錯了什麼?
在此先感謝。
嗡嗡聲,這是奇怪的:我剛打開電腦,而現在它的正常工作,沒有做任何事情......我不明白爲什麼,但無論如何,回答感謝名單喬。 – OSdave 2011-01-15 11:49:57