Magento 创建新的数据实体 model 、 resource 和 collection 文件


一、创建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());





转载于:https://www.cnblogs.com/caryfang/p/5110249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值