一、创建model文件
class Bestbuy_PrepaidCard_Model_Used extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init('prepaidcard/used');
}
}
二、创建resource文件
class Bestbuy_PrepaidCard_Model_Resource_Used extends Mage_Core_Model_Resource_Db_Abstract
{
/**
* Initialize resource model
*
*/
protected function _construct()
{
$this->_init('prepaidcard/used', 'id');
}
}
三、创建Collection文件
class Bestbuy_PrepaidCard_Model_Resource_Used_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('prepaidcard/used', 'id');
}
}
最后看一下三个文件的目录层次路径:
只有这样,才能在代码中使用这样的语句来操作实体:
//giftcard $giftcard_model = Mage::getModel('enterprise_giftcardaccount/history'); $giftcard_info = $giftcard_model->getCollection() ->join(array('g' => 'giftcardaccount'),'main_table.giftcardaccount_id = g.giftcardaccount_id','*') ->addFieldToFilter('additional_info','订单 # '.$order_info->getData('increment_id').'.')->load(); //prepaycard $prepaycard_model = Mage::getModel('prepaidcard/used'); $prepaycard_info = $prepaycard_model->getCollection() ->addFieldToFilter('order_id',$this->getRequest()->getParam('order_id'))->load(); print_r($prepaycard_info->getFirstItem()->getData());