混在Magento
cgzhang · 共 38 篇文章
Magento随机生成sales rule的coupon code
在Magento中可以使用SalesRule模块下的Mage_SalesRule_Model_Coupon_Codegenerator类随机生成coupon code。 首选获得code genetator实例,可以调用Mage_SalesRule_Model_Rule的静态方法: $codeGenerator = Mage_SalesRule_Model_Rule::getCouponCodeGenerator() 也可以自己通过下面的方法: $codeGenerator = Mage::getSingleton('salesrule/coupon_codegenerator', arra…
2013-01-02 22:09 · Magento · 评论(0)
Magento 后台配置中实现日期选择 (Date picker)
首先,创建一个新的Form Field 类: <?php class Glamour_Glscore_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field { protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) { $date = new Varien_Data_Form_Element_Date; $format = 'yyyy-MM-dd HH:mm:ss'; …
2012-12-28 15:07 · Magento · 评论(0)
获得指定customer 购买的产品数据
获得指定customer 购买的产品信息,如果是configurable的,则取configurable的名字。 $orderedProductsForCustomerData = array(); $orderTable =Mage::getSingleton('core/resource')->getTableName('sales/order'); $orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item'); $orderedProductsForCustomers = …
2011-12-10 20:54 · Magento · 评论(0)
将缺货产品放在产品列表后面
Rewrite Mage_Catalog_Model_Layer: 加入以下代码: <?php class Rayfox_Catalog_Model_Layer extends Mage_Catalog_Model_Layer { public function prepareProductCollection($collection) { if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { Mage::getModel('cataloginventory/stock_item')->addCata…
2011-12-10 20:50 · Magento · 评论(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/nginx.conf。 启动nginx: nginx 或者 sudo nginx 注意:若nginx的监听端口为1024以下,则需要使用sudo,否则会出现Permission denied. 停止 nginx (sudo)nginx -…
2011-12-10 16:01 · Magento · 评论(0)
How to customize Magento as CMS system (1.5.0 CE)
Before install: 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_Directory (need by customer module and system country option) Mage_Customer Mage_Log Mage_Backup Mage_Poll Mage_Rating …
2011-03-06 22:42 · Magento · 评论(0)
How to redirect to another url in block or template
In Block class: public function _toHtml(){ Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri()); if (!Mage::getSingleton('customer/session')->isLoggedIn()){ header("Status: 301"); header('Location: '.$this->getUrl('customer/account/login')) ; // send to the…
2011-02-25 13:47 · Magento · 评论(0)
Use call back function to proccess Magento large collection
$orders = Mage::getModel('sales/order')->getCollection(); Mage::getSingleton('core/resource_iterator')->walk($orders->getSelect(), array(array($this,'proccessOrder'))); public function proccessOrder($args) { $order = Mage::getModel('sales/order'); $order->setData($args['row']); echo $order->getIncr…
2011-01-19 12:58 · Magento · 评论(0)
How to remove unnecessary columns in Magento collection
$orders = Mage::getModel('sales/order')->getCollection(); $orders->getSelect()->reset('columns'); $orders->getSelect()->columns(array('total_amount'=>'sum(grand_total)'));
2011-01-19 12:56 · Magento · 评论(0)
How to calculate currency according to reward points rate in Magento
$rate = Mage::getModel('enterprise_reward/reward_rate'); $rate->fetch(1, Mage::app()->getStore()->getId(),Enterprise_Reward_Model_Reward_Rate::RATE_EXCHANGE_DIRECTION_TO_CURRENCY); echo $rate->calculateToCurrency(100);
2011-01-13 18:03 · Magento · 评论(0)
Magento二次开发的利器:Rewrite
Magento是一个十分优秀的电子商务系统,但是有时候我们需要增加一些新的功能或者修改原有的功能,一般情况下通过自己开发的扩展模块(module)可以满足要求。如果需要修改系统的一些默认行为(如结账,注册等),不提倡直接修改Magento本身模块里的代码(修改后无法升级,因为升级后所做的修改会被升级后的文件覆盖),这时候Magento提供的rewrite机制可以满足我们的要求。 Magento中可以rewrite的对象有:Block, Controller(frontend 和admin)以及Model。 最常用的是rewrite controller,参见: Magento重载Contro…
2010-12-08 17:15 · Magento · 评论(0)
增加Magento后台管理功能三:在后台设置(System/Configuration)中加入自定义设置
在模块的etc目录下新建system.xml配置文件,内容如下: <?xml version="1.0"?> <config> <sections> <!--要加入的section的标识符,此处为sales, 也可以加入自己的section --> <sales> <groups> <my_settings translate="label"> <label>Settings 1</label> <frontend_type>text</frontend_type> <sort_order>500</sort_order> <show_in_default>1</show_in_defaul…
2010-11-30 16:17 · Magento · 评论(0)
增加Magento后台管理功能二:开发后台Controller
在模块的controllers目录下创建Adminhtml目录,新建一个Controller类。 class Glamour_CustomerMessage_Adminhtml_MessageController extends Mage_Adminhtml_Controller_Action { //设置当前激活的菜单 protected function _initAction(){ $this->loadLayout() ->_setActiveMenu('customer/message') ->_addBreadcrumb(Mage::helper('adminhtml')->__…
2010-11-30 16:02 · Magento · 评论(0)
增加Magento后台管理功能一:在后台管理界面加入菜单
在模块的etc目录下增加adminhtml.xml配置文件,用于加入自定义的菜单项。文件内容如下: <?xml version="1.0"?> <config> <menu> <!-- 父菜单项标识,此处是在标题为Customers的菜单下加入子菜单--> <!-- Magento一级管理菜单标识和显示标题--> <!-- dashboard =>Dashboard catalog=>Catalog sales=>Sales customer=>Customers newsletter=>Newsletter cms=>CMS report=>Reports --> <customer> <…
2010-11-30 15:47 · Magento · 评论(0)
Magento在CMS Page中增加用户信息变量
Magento的cms页面和static block页面中可以用一些指示符来得到相应的信息,如{{skin url=".."}} {{media url="..."}}等。 在Mage_Cms_Block_Page类的_toHtml方法中可以找到下面的代码: $helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter($this->getPage()->getContent()); ... 先获得负责页面解析的processor对象,然后…
2010-11-26 10:14 · Magento · 评论(0)