magento常用方法
[toc]
记录magento常用的方法
调用助手类
Mage::helper()->functionInHelper();
获取数据对象以及可用的方法
$object = Mage::Model();
$object->getData();获取数据
$object->setData();写入数据
日志
Mage::log();
Mage::logException();
获取入参,可以设置默认值
$id = $this->getRequest()->getParam('id',null);
获取用户session对象以及可以使用的方法
$session = Mage::getSingleton('customer/session');
$session->login($user,$pass);//登录
$session->logout();//登出
$session->isLoggedIn();//判断是否登录
$customer = $session->getCustomer();
获取系统的session对象
$session = Mage::getSingleton('core/session');
获取ip
$ip = Mage::helper('core/http')->getRemoteAddr();
获取顾客对象
- 根据id获取对象
$customer = Mage::getModel('customer/customer')->load($id)
- 根据email获取对象
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($email);
获取产品对象
$product = Mage::getModel('catalog/product');
获取订单对象
$order = Mage::getModel('sales/order');
获取店铺对象
$store = Mage::app()->getStore();
获取商品库存
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
获取类名
get_class()
输出magento的配置文件
header('Content-Type: text/plain');
echo $config = Mage::getConfig()->loadModulesConfiguration('config.xml')->getNode()->asXML();
exit;
获取storeId
Mage::app()->getStore()
获取websiteId
Mage::app()->getStore()->getWebsiteId()
获取当前货币和货币符
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
Mage::app()->getLocale()->currency(Mage::app->getStore()->getCurrentCurrencyCode())->getSymbol();
原创文章转载请注明:转载自:magento常用方法
发表评论
沙发空缺中,还不快抢~