


Magento commonly used functions, magento commonly used functions_PHP tutorial
magento 常用的函数,magento常用函数
1.Magento eav_attribute表中source如何指定自定义数据来源
如果你引用的类名为yebihai_usermanage_model_entity_school你必须完整的给出地址,不能usermanage/entity_school,这样默认是在Mage下面去找的。
如:
2.Magento getPrice()的结果小数点位数的处理
echo Mage::helper('core')->currency($_product->getPrice());
输出格式:888.673 => 888.67
3.Magento config.xml中global节点中的block重写与blocks下面的命名标签必须小写,如:
4.Magento获取列表当前排序方式ASC or DESC?
获取当前排序:$this->getAvailableOrders()
获取当前分页:$this->getCurrentPage()
列表页的各种内容获取都在:Mage_Catalog_Block_Product_List_Toolbar这个类里面,有需要直接去这里面找。
5.Magento Collection添加排序?
6.Magento Collection where里面的或条件如何实现?
7.Magento操作某条数据下面的多个字段,使用场景如下:
本
人在做订单备注的时候在监听类里面通过Magento系统的addStatusHistoryComment方法把订单内容能成功写入
sales_flat_order_status_history表,但是我的需求是还要修改is_visible_on_front此字段的值,让内容
在前台可见。头痛的问题来了,想了各种方法最后按下面的方式解决了。
监听类全部源码:
订单备注: ' .$_comments); $_order->addStatusHistoryComment('订单备注: ' .$_comments)->setIsVisibleOnFront(1); } return $this; } }
8.Magento个人中心左侧菜单控制
关于个人中心的主要功能都是在customer这个模块进行,需要修改相应的功能,直接去你的模板customer文件夹去修改。
左侧菜单模板路径:customer/account/navigation.phtml
9.Magento把html转换为转义字符,用什么方法?
core助手里面有一个escapeHtml方法,使用如下:
Mage::helper('core')->escapeHtml("yebihai
加油
The actual location of the method: in the Mage_Core_Helper_Abstract class.
ps: Some common operation methods are encapsulated in the core module. If necessary, you can analyze the source code.
10.Magento dynamically creates blocks and references actions?
The following is the layout (Layout) configuration file of one of my modules. I now need to dynamically call checkoutcart through Ajax. Direct calling is definitely not possible. How to solve it? Yes?
Step 1: Call a custom controller through ajax, such as:
jQuery.post('getUrl('gouwuche/cart/updateQuickShoppingCar') ?>', function(data){ jQuery('#shopping-cart-table thead').after(data); }); Step 2: Dynamically create a block in the controller method, such as: public function updateQuickShoppingCarAction(){ $block = $this->getLayout()->createBlock('checkoutrewrite/quickcart')->setTemplate('quickbuy/cart/cart.phtml'); echo $block->toHtml(); }
Step 3: Create a new block file (quickcart), and initialize the action content in the configuration file in the construct method in this file, such as:
public function __construct() { parent::__construct(); $this->addItemRender('simple', 'checkout/cart_item_renderer', 'quickbuy/cart/item/item_view.phtml'); }
PS: When proceeding to the second step, the cart.phtml template has been loaded. The third step is just to load the action under the cart block.
11. What should we pay attention to in the parameters of Magento getTable method?
Instance, the method of querying the specified table and conditions in the database is as follows:
The parameter settings of the getTable method need to be noted as follows. excelmanage is the name of your module, and excelkukunjiage is the name of the entity node you operate. My entity configuration is as follows:
The parameters after "/" are derived from the entity names in front of the table.
12. How to update the specified ID information in the data table?
$excelModel = Mage::getModel('excelmanage/excelkukunjiage')->load(1);
$excelModel->setExcelAdddate(Mage::getModel('core/date')- >timestamp(time()));
$excelModel->setIsActive(0);
$excelModel->save();
The above code is to modify the data table information with ID 1 .
Extension: How to add and modify specified table information in Magento?
13. How to change the default sorting field of product list?
Set the path at: System-->Directory-->Advanced Product Management-->Default List Status
14. Get the number of items in a data set?
Get the number of _productCollection data sets, the case is as follows:
$this->setStoreId($storeId);
$this->_productCollection = Mage::getResourceModel('catalog/product_collection'); //Get the data set
$this->_productCollection = $this->_productCollection->addAttributeToSelect('*')
->addAttributeToSelect('manufacturer') //Add query attribute
->setStoreId($storeId) //Set the store
->addAttributeToFilter('cuxiaobiaoqian',array('eq'=>39)) //Attribute filtering specification
->addStoreFilter($storeId) //Add store filter conditions
->setPageSize(6); //Get the number of items
15. Query the specified data table through the select() method. How to control the number of items read?
The code application background is as follows:
$selfread = $this->_getConnection('yafo_bbs_setup'); //Database connection object
$table = $this->zixunTablePrefix."forum_post"; //Table to be queried
$result = $selfread->select()->from( array('a'=>$table), array('tid','subject')) //Specify the table and the object to be queried Field
->limit($size) //Read the specified number of items
->order("a.dateline DESC") //Specify sorting conditions
->where( $selfwhere ); //Add filter conditions
Return $selfread->fetchAll($result); //Return query results
16. Modify the specified product price and group price (code operation)?
$selfPrc = Mage::getModel('catalog/product')->load(614); $selfData = $selfPrc->getData(); $selfData['price'] = 25; $selfData['group_price'] = array( 0 => Array( "website_id" => 0, "all_groups" => 0, "cust_group" => 0, "price" => 97.0000, "website_price" => 97.0000 ), 1=> Array ( "website_id" => 0, "all_groups" => 0, "cust_group" => 1, "price" => 27.0000, "website_price" => 27.0000 ), 2=> Array ( "website_id" => 0, "all_groups" => 0, "cust_group" => 2, "price" => 17.0000, "website_price" => 17.0000 ), 3=> Array ( "website_id" => 0, "all_groups" => 0, "cust_group" => 3, "price" => 67.0000, "website_price" => 67.0000 ), 4=> Array ( "website_id" => 0, "all_groups" => 0, "cust_group" => 4, "price" => 66.0000, "website_price" => 66.0000 )); $selfPrc->setData($selfData); $selfPrc->save();
17.修改指定产品库存(代码操作)?
18. How to output sql statement
$result = $selfread->select()->from(array('ft'=>$flatTable),array ())
19. Background form configuration, how to add comments in the code?
20. Instantiate the model and how to get the value of the specified content of the specified field through the load method?
$dictModel=Mage::getModel('catalogsearchrewrite/cikumanage')->load($dictname,'dict_name'); //Parameter 1: Specify the value, Parameter 2: Specify the field
$dictModel->getDictName(); //Get the returned specified field value

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

The benefits of functions returning reference types in C++ include: Performance improvements: Passing by reference avoids object copying, thus saving memory and time. Direct modification: The caller can directly modify the returned reference object without reassigning it. Code simplicity: Passing by reference simplifies the code and requires no additional assignment operations.

The difference between custom PHP functions and predefined functions is: Scope: Custom functions are limited to the scope of their definition, while predefined functions are accessible throughout the script. How to define: Custom functions are defined using the function keyword, while predefined functions are defined by the PHP kernel. Parameter passing: Custom functions receive parameters, while predefined functions may not require parameters. Extensibility: Custom functions can be created as needed, while predefined functions are built-in and cannot be modified.

Reference parameters in C++ functions (essentially variable aliases, modifying the reference modifies the original variable) and pointer parameters (storing the memory address of the original variable, modifying the variable by dereferencing the pointer) have different usages when passing and modifying variables. Reference parameters are often used to modify original variables (especially large structures) to avoid copy overhead when passed to constructors or assignment operators. Pointer parameters are used to flexibly point to memory locations, implement dynamic data structures, or pass null pointers to represent optional parameters.
