
Magento
cgzhang2008
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Magento模块开发 第一部分
1.模块配置文件 基本的模块配置文件有2个,一个是etc下面的config.xml, 还有一个在app/etc/modules下面,以YourPackageName_ YourModuleName.xml命名。 Magento里面的模块都属于不同的包(Package), 每个包又分属于不同的代码池中(Code Pool)。Magento 中的 代码池有core, community和local...2010-07-20 16:51:24 · 101 阅读 · 0 评论 -
How to redirect to another url in block or template
In Block class: [code="php"] public function _toHtml(){ Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri()); if (!Mage::getSingleton('customer/se...2011-02-25 13:47:50 · 101 阅读 · 0 评论 -
How to customize Magento as CMS system (1.5.0 CE)
Before install: 1. Go to app/etc/modules, edit Mage_All.xml, only set the following modules active. Mage_Core Mage_Eav Mage_Page Mage_Install Mage_Admin Mage_Adminhtml Mage_Cron Mage_Directo...2011-03-06 22:42:00 · 148 阅读 · 0 评论 -
Maegen获得后台当前用户的信息
[code="php"] $admin = Mage::getSingleton('admin/session')->getUser(); if($admin){ return $admin->getId(); } [/code] 注意,只在后台相应的类中有效,前台经测试无法获得。...2010-11-08 16:53:42 · 165 阅读 · 0 评论 -
Magento让后台数据列表中的action列链接在新窗口打开
[code="php"] 'actions' => array( array( 'caption' => Mage::helper('productfaq')->__('Edit'), 'url' => array( ...2010-11-08 16:56:20 · 146 阅读 · 0 评论 -
Magento根据不同的浏览器自动切换package或 theme
在后台设置中: System > Configuration > Design 切换Package: 在Package设定里面: 添加 exception: Matched expression: iPhone|iPod Value: (新建的package名字,如mobile, /magento/app/design/frontend/mobile) 如果要自动切...2010-11-26 10:05:54 · 157 阅读 · 0 评论 -
Magento在CMS Page中增加用户信息变量
Magento的cms页面和static block页面中可以用一些指示符来得到相应的信息,如{{skin url=".."}} {{media url="..."}}等。 在Mage_Cms_Block_Page类的_toHtml方法中可以找到下面的代码: [code="php"] $helper = Mage::helper('cms'); $processor...2010-11-26 10:14:51 · 172 阅读 · 0 评论 -
增加Magento后台管理功能一:在后台管理界面加入菜单
在模块的etc目录下增加adminhtml.xml配置文件,用于加入自定义的菜单项。文件内容如下: [code="xml"] Customer Mess...2010-11-30 15:47:02 · 380 阅读 · 0 评论 -
增加Magento后台管理功能二:开发后台Controller
在模块的controllers目录下创建Adminhtml目录,新建一个Controller类。 [code="php"] class Glamour_CustomerMessage_Adminhtml_MessageController extends Mage_Adminhtml_Controller_Action { //设置当前激活的菜单 protecte...2010-11-30 16:02:52 · 219 阅读 · 0 评论 -
增加Magento后台管理功能三:在后台设置(System/Configuration)中加入自定义设置
在模块的etc目录下新建system.xml配置文件,内容如下: [code="xml"] Settings 1 text 500 ...2010-11-30 16:17:26 · 249 阅读 · 0 评论 -
Magento二次开发的利器:Rewrite
Magento是一个十分优秀的电子商务系统,但是有时候我们需要增加一些新的功能或者修改原有的功能,一般情况下通过自己开发的扩展模块(module)可以满足要求。如果需要修改系统的一些默认行为(如结账,注册等),不提倡直接修改Magento本身模块里的代码(修改后无法升级,因为升级后所做的修改会被升级后的文件覆盖),这时候Magento提供的rewrite机制可以满足我们的要求。 Magent...2010-12-08 17:15:48 · 208 阅读 · 0 评论 -
Mac Lion上安装配置Nginx PHP PHP-FPM
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> Install Nginx And PHP-FPM On Mac Lion 安装Nginx 方法1:使用brew. brew install nginx 按提示操作,安装完成后nginx的配置文件在/usr/local/etc/nginx/ngin...2011-12-10 16:01:08 · 165 阅读 · 0 评论 -
将缺货产品放在产品列表后面
Rewrite Mage_Catalog_Model_Layer: 加入以下代码: [code="php"]2011-12-10 20:50:38 · 152 阅读 · 0 评论 -
获得指定customer 购买的产品数据
获得指定customer 购买的产品信息,如果是configurable的,则取configurable的名字。 [code="php"] $orderedProductsForCustomerData = array(); $orderTable =Mage::getSingleton('core/resource')-...2011-12-10 20:54:42 · 190 阅读 · 0 评论 -
Magento 后台配置中实现日期选择 (Date picker)
首先,创建一个新的Form Field 类: [code="php"]2012-12-28 15:07:02 · 244 阅读 · 0 评论 -
Magento中用子类替换Block
Step 1:创建一个新的Module Step 2: 编辑模块的config.xml配置文件: [code type="xml"] 0.1.0 Glamour_Glscatalog_Block_Adminhtml_Product_Edit_Tab_Related ...2010-10-15 10:47:13 · 204 阅读 · 0 评论 -
Magento中添加带有选项的属性
下面的代码为Customer实体添加了性别属性,有两个可选值 Male和Female [code="php"] $installer->startSetup(); $installer->addAttribute('customer', 'gender', array( 'label' => 'Gender', 'visible' =>...2010-10-14 14:49:06 · 160 阅读 · 0 评论 -
Magento模块开发第二部分
4. 创建Block 4.1 Block类 在config.xml中的global段中有下面的block声明: [code="xml"] [/code] 我们加入以下块声明: [code="xml"] Glamour_HelloWorld_Block [/code] 其中,helloworld标签用于调用createBlock方法时传入的参数...2010-07-27 11:03:54 · 98 阅读 · 0 评论 -
Magento获得指定客户的所有订单
[code="PHP"] $customerId=客户Id; $limit=10; $orders=Mage::getResourceModel('sales/order_collection'); $orders->addAttributeToFilter('customer_id', $customerId)->getSelect()->order('e.entity_id desc...2010-07-27 16:25:08 · 239 阅读 · 0 评论 -
Magento重载Controller的方法
重载购物车页 Mage_Checkout_CartController::indexAction(). 第一步:建立相应的文件 app/code/local/MyNameSpace/MyModule/etc/config.xml app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php a...原创 2010-07-30 14:52:24 · 162 阅读 · 0 评论 -
Magento中Model和ResourceModel(非EAV)中两个_init方法参数意义
Magento中非EAV Model继承自Mage_Core_Model_Abstract,需要实现_construct方法 [code="PHP"] protected function _construct(){ $this->_init('Model tag 名/ResourceModel tag名'); }[/code] 先通过mod...2010-08-06 14:27:43 · 232 阅读 · 0 评论 -
Magento中获得设置时区的当前时间
Magento中默认时区为GMT, 不能直接使用time(), date()等方法,否则会出现时间差。 用下面的方法取当前时间(和后台设置的时区一致): [code="PHP"]date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));[/code] 获得UTC时间 [code="PHP"] $date = Mag...2010-08-06 17:07:48 · 305 阅读 · 0 评论 -
Magento中获得可配置产品(Configurable)的所有简单产品
[code="java"] if(product->isConfigurable()){ } $allProducts=$product->getTypeInstance(true)->getUsedProducts(null, $product); echo count($allProducts); foreach($allProducts as $simpleProduct){ ...2010-08-20 17:11:48 · 290 阅读 · 0 评论 -
Magento中获得Product所有属性的Values和Labels
[code="php"]$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id'); foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){ attrubuteArray[$opti...2010-09-10 18:11:16 · 143 阅读 · 0 评论 -
Magento中为Block启用Cache
在Block类的_construct(不是构造方法)方法中加入以下代码: [code="php"] public function _construct() { $this->addData( array( 'cache_lifetime' => 3600, 'cache_tags' => array(Mage_Catalog_Mod...2010-09-14 17:12:19 · 143 阅读 · 0 评论 -
Magento通过简单产品获得所属的可配置产品
[code="php"] $product = Mage::getModel(‘catalog/product’) ->setStoreId(Mage::app()->getStore()->getId()) ->load($productId); if($product->type_id==“simple”) { $parentId=$product->loadParen...2010-09-15 17:46:57 · 166 阅读 · 0 评论 -
Magento中通过访问Url把产品加入购物车
Magento中可以通过访问Url把产品加入购物车。 1 添加简单产品(Simple Product) (1) 通过产品id checkout/cart/add?product=[id]&qty=[qty] (2) 通过产品sku $cProd = Mage::getModel('catalog/product'); $id = $cProd->getIdByS...2010-09-17 17:50:38 · 198 阅读 · 0 评论 -
Magento为后台用户保存操作日志(企业版)
[code="PHP"] protected function _logAdminAction($username, $userId, $details) { $eventCode = 'catalog_products'; //可用的event code 参见后台Admin Actions Log中Aciton G...2010-09-19 17:00:51 · 354 阅读 · 0 评论 -
How to calculate currency according to reward points rate in Magento
[code="php"] $rate = Mage::getModel('enterprise_reward/reward_rate'); $rate->fetch(1, Mage::app()->getStore()->getId(),Enterprise_Reward_Model_Reward_Rate::RATE_EXCHANGE_DIRECTION_TO_CURRENCY);...2011-01-13 18:03:22 · 167 阅读 · 0 评论 -
How to remove unnecessary columns in Magento collection
[code="php"] $orders = Mage::getModel('sales/order')->getCollection(); $orders->getSelect()->reset('columns'); $orders->getSelect()->columns(array('total_amount'=>'sum(grand_total)')); ...2011-01-19 12:56:44 · 128 阅读 · 0 评论 -
Use call back function to proccess Magento large collection
[code="php"] $orders = Mage::getModel('sales/order')->getCollection(); Mage::getSingleton('core/resource_iterator')->walk($orders->getSelect(), array(array($this,'proccessOrder'))); public function...2011-01-19 12:58:16 · 108 阅读 · 0 评论 -
Magento随机生成sales rule的coupon code
在Magento中可以使用SalesRule模块下的Mage_SalesRule_Model_Coupon_Codegenerator类随机生成coupon code。 首选获得code genetator实例,可以调用Mage_SalesRule_Model_Rule的静态方法: [code="php"] $codeGenerator = Mage_SalesRule_Model_Ru...2013-01-02 22:09:15 · 271 阅读 · 0 评论