- 浏览: 200442 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
guji528:
使用Python通过正则表达式替换很方便:
sprin ...
Python正则表达式指南 -
guji528:
很实用,先keep再看
Python正则表达式指南 -
yushine:
1,2,3,5 已经做了剩下的本来也正准备做。
2012, 每一个软件工程师必须做的11件事 -
mynetstudy:
用导出不就可以了吗
递归删除SVN工作目录下的.svn目录
1:获取session
$session = Mage::getSingleton('customer/session');
2:Request对象
Mage::app()->getRequest()
3:调用Model对象
Mage::getModel('infinity/model');
4:获取当前时间
Mage::getModel('core/date')->date();
date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
5:session,cookie设置
5.1 Model:
Mage::getModel(‘core/cookie’);
Mage::getModel(‘core/session’);
5.2 Set Method:
Mage::getSingleton(‘core/cookie’)->set(‘name’,'value’);
Mage::getSingleton(‘core/session’)->set(‘name’,'value’);
5.3 Get method:
Mage::getSingleton(‘core/cookie’)->get(‘name’);
Mage::getSingleton(‘core/session’)->get(‘name’);
6:输出配置文件
//header(‘Content-Type: text/xml’);
header(‘Content-Type: text/plain’);
echo $config = Mage::getConfig()
->loadModulesConfiguration(‘system.xml’)
->getNode()
->asXML();
exit;
7:Get URL for a Magento
Category
Mage::getModel('catalog/category')->load(17)->getUrl();
8:build your URL with valid keys
Mage::helper("adminhtml")->getUrl("mymodule/adminhtml_mycontroller/myaction/",array("param1"=>1,"param2"=>2));
9:create key values
Mage::getSingleton('adminhtml/url')->getSecretKey("adminhtml_mycontroller","myaction");
10:disable security feature in the admin panel
admin panel -> System -> Configuration -> Admin section: “Add Secret key to Urls”.
11:后台模块跳转:
Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/promo_quote/index"));
12:产品属性操作
$product = Mage::getModel('catalog/product')->getCollection()->getFirstItem();
foreach($product->getAttributes() as $att)
{
$group_id = $att->getData('attribute_group_id');
$group = Mage::getModel('eav/entity_attribute_group')->load($group_id);
var_dump($group);
}
$attrSetName = 'my_custom_attribute';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
->load($attrSetName, 'attribute_set_name')
->getAttributeSetId();
13:get a drop down lists options for a mulit-select attribute
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id');
foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
$attributeArray[$option['value']] = $option['label'];
}
14:或取栏目图片
public function getImageUrl($category)
{
return Mage::getModel('catalog/category')->load($category->getId())->getImageUrl();
}
public function getThumbnailUrl($category)
{
$image=Mage::getModel('catalog/category')->load($category->getId())->getThumbnail();
if ($image) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
}
return $url;
}
15:产品缩略图
$_thumb = Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(50, 50)->setWatermarkSize('30x10');
16:判断是否首页:$this->getIsHomePage()
Mage::getSingleton('cms/page')->getIdentifier() == 'home' &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'
)
17:
$cms_id = Mage::getSingleton('cms/page')->getIdentifier();
$cms_title = Mage::getSingleton('cms/page')->getTitle();
$cms_content = Mage::getSingleton('cms/page')->getContent();
18 :
$attributes = $_product->getAttributes();
$themeColor = $attributes['theme_color']->getFrontend()->getValue($_product);
19:获取configurable产品simple product
if($_product->getTypeId() == "configurable"):
$ids = $_product->getTypeInstance()->getUsedProductIds();
foreach ($ids as $id) :
$simpleproduct = Mage::getModel('catalog/product')->load($id);
$simpleproduct->getName()." - ".(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
20: get the attributes of Configurable Product.
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
21:当前路径
$currentUrl = $this->helper('core/url')->getCurrentUrl();
22:通过资源配置方式创建目录
$installer = $this;
$installer->startSetup();
// make directory for font cache
try {
$domPdfFontCacheDir = join(DS, array('lib', 'Symmetrics', 'dompdf', 'fonts'));
$domPdfFontCacheDir = Mage::getBaseDir('var') . DS . $domPdfFontCacheDir;
if (!file_exists($domPdfFontCacheDir)) {
mkdir($domPdfFontCacheDir, 0777, true);
}
} catch(Exception $e) {
throw new Exception(
'Directory ' . $domPdfFontCacheDir . ' is not writable or couldn't be '
. 'created. Please do it manually.' . $e->getMessage()
);
}
$installer->endSetup();
23:
wishlist_linkHomeHometrue0HelphelpHelptrue90My AccountMy Account10example
exampleexampletrue100class="top-link-example"
24:在controllers 实现跳转
Mage::app()->getFrontController()
->getResponse()
->setRedirect('http://your-url.com');
25:获取当前站点货币符号
$storeId = (int) $this->getRequest()->getParam('store', 0);
$store=Mage::app()->getStore($storeId);
$currencyCode=$store->getBaseCurrency()->getCode()
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeData = $attribute->getData();
$frontEndLabel = $attributeData['frontend_label'];
$attributeOptions = $attribute->getSource()->getAllOptions();
26:获取产品属性集
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
27:magento
使用sql
$resource = Mage::getSingleton('core/resource');
$read= $resource->getConnection('core_read');
$tempTable = $resource->getTableName('infinity_contacts');
$_storeid = Mage::app()->getStore()->getId();
$wheres = "`status`=1 AND ( FIND_IN_SET(0, `store_id`)>0 OR FIND_IN_SET($_storeid, `store_id`)>0 )";
$select = $read->select()
->from($tempTable, array('count(*) as num'))
->where($wheres);
28:设置meta信息
$template = Mage::getConfig()->getNode('global/page/layouts/'.Mage::getStoreConfig("featuredproducts/general/layout").'/template');
$this->loadLayout();
$this->getLayout()->getBlock('root')->setTemplate($template);
$this->getLayout()->getBlock('head')->setTitle($this->__(Mage::getStoreConfig("featuredproducts/general/meta_title")));
$this->getLayout()->getBlock('head')->setDescription($this->__(Mage::getStoreConfig("featuredproducts/general/meta_description")));
$this->getLayout()->getBlock('head')->setKeywords($this->__(Mage::getStoreConfig("featuredproducts/general/meta_keywords")));
$this->renderLayout();
29.加载某个attribute:
$attributeCode=Mage::getModel('catalog/resource_eav_attribute')
->load($attrbuteId)
->getData("attribute_code");
30.获取某个attribute的所有option:
$attributeObject=Mage::getModel('eav/config')->getAttribute('catalog_product')->load($attributeId);
$options = $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
$table = $attributeObject->getBackend()->getTable();
public function getAttributeOptionsByAttributeCode($entityType, $attributeCode){
$entityType = Mage::getSingleton('eav/config')->getEntityType($entityType);
$attributeObject = Mage::getModel('customer/attribute')->loadByCode($entityType, $attributeCode);
return $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
}
或者:
$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attr_model->getId())
->setStoreFilter($storeId, false)
->load();
31.获取某个attribute的所有多语言label:
$attributeLabelsArray= Mage::getResourceModel('eav/entity_attribute')
->getStoreLabelsByAttributeId($attrbuteId);
32.获取所有的产品属性的attribute:
$attributes = Mage::getResourceModel ( 'catalog/product_attribute_collection' )
->addFieldToFilter ( "frontend_input", "select" )
->load ();
33.获取某个product的所有attribute:
注:如果是在collection中获取自定义的attribute,必须加addAttributeToSelect(), 如下:
product=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect("dropdownlistone");
34.利用静态block
getLayout()->createBlock('clientnumber/widget_name')
->setObject($this->getAddress())
->toHtml() ?>
35.获取某个种类的所有attribute:
$entityTypeId = Mage::getSingleton('eav/config')
->getEntityType('catalog_product')
->getEntityTypeId();
$items = Mage::getResourceSingleton('catalog/product_attribute_collection')
->setEntityTypeFilter($entityTypeId)
->getItems();
36.获取某个attribute_set的所有attribute:
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attribute_set_id)
->load();
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
->load();
37.获取attribute 对象 by attribute code
$muarqspFrom = Mage::getSingleton('eav/config')->getAttribute('catalog_product', '
muarqsp_from');
$attrCollection = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter($attributeCode)
->load();
$session = Mage::getSingleton('customer/session');
2:Request对象
Mage::app()->getRequest()
3:调用Model对象
Mage::getModel('infinity/model');
4:获取当前时间
Mage::getModel('core/date')->date();
date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
5:session,cookie设置
5.1 Model:
Mage::getModel(‘core/cookie’);
Mage::getModel(‘core/session’);
5.2 Set Method:
Mage::getSingleton(‘core/cookie’)->set(‘name’,'value’);
Mage::getSingleton(‘core/session’)->set(‘name’,'value’);
5.3 Get method:
Mage::getSingleton(‘core/cookie’)->get(‘name’);
Mage::getSingleton(‘core/session’)->get(‘name’);
6:输出配置文件
//header(‘Content-Type: text/xml’);
header(‘Content-Type: text/plain’);
echo $config = Mage::getConfig()
->loadModulesConfiguration(‘system.xml’)
->getNode()
->asXML();
exit;
7:Get URL for a Magento
Category
Mage::getModel('catalog/category')->load(17)->getUrl();
8:build your URL with valid keys
Mage::helper("adminhtml")->getUrl("mymodule/adminhtml_mycontroller/myaction/",array("param1"=>1,"param2"=>2));
9:create key values
Mage::getSingleton('adminhtml/url')->getSecretKey("adminhtml_mycontroller","myaction");
10:disable security feature in the admin panel
admin panel -> System -> Configuration -> Admin section: “Add Secret key to Urls”.
11:后台模块跳转:
Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/promo_quote/index"));
12:产品属性操作
$product = Mage::getModel('catalog/product')->getCollection()->getFirstItem();
foreach($product->getAttributes() as $att)
{
$group_id = $att->getData('attribute_group_id');
$group = Mage::getModel('eav/entity_attribute_group')->load($group_id);
var_dump($group);
}
$attrSetName = 'my_custom_attribute';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
->load($attrSetName, 'attribute_set_name')
->getAttributeSetId();
13:get a drop down lists options for a mulit-select attribute
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id');
foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
$attributeArray[$option['value']] = $option['label'];
}
14:或取栏目图片
public function getImageUrl($category)
{
return Mage::getModel('catalog/category')->load($category->getId())->getImageUrl();
}
public function getThumbnailUrl($category)
{
$image=Mage::getModel('catalog/category')->load($category->getId())->getThumbnail();
if ($image) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
}
return $url;
}
15:产品缩略图
$_thumb = Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(50, 50)->setWatermarkSize('30x10');
16:判断是否首页:$this->getIsHomePage()
Mage::getSingleton('cms/page')->getIdentifier() == 'home' &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'
)
17:
$cms_id = Mage::getSingleton('cms/page')->getIdentifier();
$cms_title = Mage::getSingleton('cms/page')->getTitle();
$cms_content = Mage::getSingleton('cms/page')->getContent();
18 :
$attributes = $_product->getAttributes();
$themeColor = $attributes['theme_color']->getFrontend()->getValue($_product);
19:获取configurable产品simple product
if($_product->getTypeId() == "configurable"):
$ids = $_product->getTypeInstance()->getUsedProductIds();
foreach ($ids as $id) :
$simpleproduct = Mage::getModel('catalog/product')->load($id);
$simpleproduct->getName()." - ".(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
20: get the attributes of Configurable Product.
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
21:当前路径
$currentUrl = $this->helper('core/url')->getCurrentUrl();
22:通过资源配置方式创建目录
$installer = $this;
$installer->startSetup();
// make directory for font cache
try {
$domPdfFontCacheDir = join(DS, array('lib', 'Symmetrics', 'dompdf', 'fonts'));
$domPdfFontCacheDir = Mage::getBaseDir('var') . DS . $domPdfFontCacheDir;
if (!file_exists($domPdfFontCacheDir)) {
mkdir($domPdfFontCacheDir, 0777, true);
}
} catch(Exception $e) {
throw new Exception(
'Directory ' . $domPdfFontCacheDir . ' is not writable or couldn't be '
. 'created. Please do it manually.' . $e->getMessage()
);
}
$installer->endSetup();
23:
wishlist_linkHomeHometrue0HelphelpHelptrue90My AccountMy Account10example
exampleexampletrue100class="top-link-example"
24:在controllers 实现跳转
Mage::app()->getFrontController()
->getResponse()
->setRedirect('http://your-url.com');
25:获取当前站点货币符号
$storeId = (int) $this->getRequest()->getParam('store', 0);
$store=Mage::app()->getStore($storeId);
$currencyCode=$store->getBaseCurrency()->getCode()
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeData = $attribute->getData();
$frontEndLabel = $attributeData['frontend_label'];
$attributeOptions = $attribute->getSource()->getAllOptions();
26:获取产品属性集
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
27:magento
使用sql
$resource = Mage::getSingleton('core/resource');
$read= $resource->getConnection('core_read');
$tempTable = $resource->getTableName('infinity_contacts');
$_storeid = Mage::app()->getStore()->getId();
$wheres = "`status`=1 AND ( FIND_IN_SET(0, `store_id`)>0 OR FIND_IN_SET($_storeid, `store_id`)>0 )";
$select = $read->select()
->from($tempTable, array('count(*) as num'))
->where($wheres);
28:设置meta信息
$template = Mage::getConfig()->getNode('global/page/layouts/'.Mage::getStoreConfig("featuredproducts/general/layout").'/template');
$this->loadLayout();
$this->getLayout()->getBlock('root')->setTemplate($template);
$this->getLayout()->getBlock('head')->setTitle($this->__(Mage::getStoreConfig("featuredproducts/general/meta_title")));
$this->getLayout()->getBlock('head')->setDescription($this->__(Mage::getStoreConfig("featuredproducts/general/meta_description")));
$this->getLayout()->getBlock('head')->setKeywords($this->__(Mage::getStoreConfig("featuredproducts/general/meta_keywords")));
$this->renderLayout();
29.加载某个attribute:
$attributeCode=Mage::getModel('catalog/resource_eav_attribute')
->load($attrbuteId)
->getData("attribute_code");
30.获取某个attribute的所有option:
$attributeObject=Mage::getModel('eav/config')->getAttribute('catalog_product')->load($attributeId);
$options = $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
$table = $attributeObject->getBackend()->getTable();
public function getAttributeOptionsByAttributeCode($entityType, $attributeCode){
$entityType = Mage::getSingleton('eav/config')->getEntityType($entityType);
$attributeObject = Mage::getModel('customer/attribute')->loadByCode($entityType, $attributeCode);
return $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
}
或者:
$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attr_model->getId())
->setStoreFilter($storeId, false)
->load();
31.获取某个attribute的所有多语言label:
$attributeLabelsArray= Mage::getResourceModel('eav/entity_attribute')
->getStoreLabelsByAttributeId($attrbuteId);
32.获取所有的产品属性的attribute:
$attributes = Mage::getResourceModel ( 'catalog/product_attribute_collection' )
->addFieldToFilter ( "frontend_input", "select" )
->load ();
33.获取某个product的所有attribute:
注:如果是在collection中获取自定义的attribute,必须加addAttributeToSelect(), 如下:
product=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect("dropdownlistone");
34.利用静态block
getLayout()->createBlock('clientnumber/widget_name')
->setObject($this->getAddress())
->toHtml() ?>
35.获取某个种类的所有attribute:
$entityTypeId = Mage::getSingleton('eav/config')
->getEntityType('catalog_product')
->getEntityTypeId();
$items = Mage::getResourceSingleton('catalog/product_attribute_collection')
->setEntityTypeFilter($entityTypeId)
->getItems();
36.获取某个attribute_set的所有attribute:
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attribute_set_id)
->load();
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
->load();
37.获取attribute 对象 by attribute code
$muarqspFrom = Mage::getSingleton('eav/config')->getAttribute('catalog_product', '
muarqsp_from');
$attrCollection = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter($attributeCode)
->load();
发表评论
-
Magento: Overriding Core Files (Blocks, Models, Resources, Controllers)
2013-04-07 11:03 1009When building custom module ... -
Magento模板及布局文件中引用Static Block的方法
2013-03-21 10:25 1287Static Block是Magento提供的非常实用的一种 ... -
Magento2, 我们在等你
2013-03-07 10:49 1252文章前面我要说明,Magento2.0和1.X是完全不同的 ... -
magento admin form 表单元素大全
2013-03-05 11:01 9511.input type=”t ... -
magento几种全页缓冲加速Full Page Cache插件试用心得
2013-03-04 23:47 4031magento的速度确实比较慢,但有全页缓冲,速度很快的由于 ... -
magento开发必备插件列表汇总
2013-02-22 13:27 2659magento和wordpress一样,因为开放而倍加优秀 ... -
[转载]magento事件清单
2012-07-31 10:50 1606Magento Community Edition事 ... -
Magento - 返回不带Layout的页面输出
2012-07-26 17:47 1075你至少有三种方法可以返回不带Layout的页面输出 1. ... -
Magento获取文件路径函数(参考大全)
2012-05-30 15:46 1538假设网站根目录为:E:\www\magentoeye.com\ ...
相关推荐
总的来说,熟悉Magento的常用方法和插件,不仅包括对核心框架的理解,还要掌握模块化开发、事件驱动、布局和模板引擎的使用,以及插件开发和调试技巧。同时,利用合适的开发工具可以极大地提升开发效率和代码质量。...
`Varien_Data_Collection`是Magento中最常用的数据集合类,它为开发者提供了一种高效的方式来管理多个对象。其主要特点包括: - **数据存储**:集合中的数据通常是以对象的形式存储的,这些对象可以是任何继承自`...
总之,《Magento Extension Developers Guide 1.0》是一本非常全面且详细的Magento扩展开发指南,不仅覆盖了从基础知识到高级技巧的各个方面,而且还提供了丰富的示例和实用建议,非常适合希望深入学习Magento开发的...
#### 二、Magento请求分发与控制器(MVC) **2.1 传统PHP的MVC框架** 在传统的PHP MVC框架中,模型(Model)负责数据逻辑处理,视图(View)负责用户界面显示,控制器(Controller)则作为两者之间的桥梁,处理...
以下是关于Magento常用设置的一些详细解释: 1. **添加页面JS和CSS头文件调用**: Magento不鼓励直接在`.phtml`模板文件中添加JS或CSS,而是推荐在布局更新XML文件中进行操作。这提供了更好的组织结构,并允许在...
“magento概述.txt”应该是对Magento 1.9的一个全面介绍,涵盖了它的主要特性、架构、以及与其他电子商务平台的对比,帮助读者理解为什么选择Magento。 “线上参考信息.txt”可能包含了一些有用的在线资源链接,如...
如何进行Magento聚会 英文版 议程: 晚上7点左右开始 从简短介绍开始 每30分钟2个演讲或45分钟1个演讲 完成“正式”的谈话。 小组讨论更多问题 联网 晚上10:30左右结束 发布聚会 使用。 如果您与联系,则可以使用...
3. 框架与库:介绍流行的PHP框架,如Laravel、Symfony、Yii等,以及常用的工具库,如Composer依赖管理、PHPUnit测试框架等。 4. Web开发实践:分享基于PHP的Web应用开发经验,包括前端技术结合、RESTful API设计、...
3. **文件与目录操作**: 如`fopen()`打开文件,`fwrite()`写入文件,`mkdir()`创建目录,`chdir()`改变当前工作目录等,这些都是PHP在处理Web服务时常用的功能。 4. **数据库交互**: PHP支持多种数据库连接,如...
【女性时尚网站模板】是一种专为女性用户设计的在线平台,旨在展示时尚资讯、潮流搭配、美妆技巧等内容,吸引并留住关注时尚的女性用户群体。此类网站模板通常具有优雅、简洁且富有女性特色的设计风格,色彩搭配柔和...