混在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) · PHP · Magento
Magento 后台配置中实现日期选择 (Date picker)
首先,创建一个新的Form Field 类: [code="php"] $element->getName(), 'html_id' => $element->getId(), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'time' => true ); $date->setData($data); $date->setValue($element->getValue(), $format); $date->setFormat('yyyy-MM-dd HH:mm:ss'); $date->setForm($element->ge…
2012-12-28 15:07 · Magento · 评论(0) · Magento
获得指定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) · order · product · magenta
将缺货产品放在产品列表后面
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) · product · magenta · out of stock
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) · nginx · PHP · Mac · php-fpm
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) · CMS · PHP · Go · XML
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) · PHP
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 proccessOrder($args) { $order = Mage::getModel('sales/order'); $order->setData($args['row']); echo $o…
2011-01-19 12:58 · Magento · 评论(0) · PHP
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) · PHP
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) · Exchange · PHP
Magento二次开发的利器:Rewrite
Magento是一个十分优秀的电子商务系统,但是有时候我们需要增加一些新的功能或者修改原有的功能,一般情况下通过自己开发的扩展模块(module)可以满足要求。如果需要修改系统的一些默认行为(如结账,注册等),不提倡直接修改Magento本身模块里的代码(修改后无法升级,因为升级后所做的修改会被升级后的文件覆盖),这时候Magento提供的rewrite机制可以满足我们的要求。 Magento中可以rewrite的对象有:Block, Controller(frontend 和admin)以及Model。 最常用的是rewrite controller,参见:[url=http://mage…
2010-12-08 17:15 · Magento · 评论(0) · 电子商务 · PHP · Blog · XML
增加Magento后台管理功能三:在后台设置(System/Configuration)中加入自定义设置
在模块的etc目录下新建system.xml配置文件,内容如下: [code="xml"] Settings 1 text 500 1 0 0 Enabled select adminhtml/system_config_source_yesno 10 1 0 0 Settings2 text 2 1 1 0 [/code] 可以通过Mage::getStoreConfig('[section 标识符]/[group标识符]/[field标识符]')来获取设置的值。 Mage::getStoreConfigFlag方法用来返回bool类型的结果,通过用于开关模块的设置。 如果是自定义sect…
2010-11-30 16:17 · Magento · 评论(0) · XML · 配置管理
增加Magento后台管理功能二:开发后台Controller
在模块的controllers目录下创建Adminhtml目录,新建一个Controller类。 [code="php"] class Glamour_CustomerMessage_Adminhtml_MessageController extends Mage_Adminhtml_Controller_Action { //设置当前激活的菜单 protected function _initAction(){ $this->loadLayout() ->_setActiveMenu('customer/message') ->_addBreadcrumb(Mage::helper('ad…
2010-11-30 16:02 · Magento · 评论(0) · PHP · XML
增加Magento后台管理功能一:在后台管理界面加入菜单
在模块的etc目录下增加adminhtml.xml配置文件,用于加入自定义的菜单项。文件内容如下: [code="xml"] Customer Message adminhtml/message 120 Customer Message 120 [/code]
2010-11-30 15:47 · Magento · 评论(0) · CMS · XML · 配置管理
Magento在CMS Page中增加用户信息变量
Magento的cms页面和static block页面中可以用一些指示符来得到相应的信息,如{{skin url=".."}} {{media url="..."}}等。 在Mage_Cms_Block_Page类的_toHtml方法中可以找到下面的代码: [code="php"] $helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter($this->getPage()->getContent()); ... [/code] 先获得…
2010-11-26 10:14 · Magento · 评论(0) · HTML · CMS · 工作 · PHP · XML