Magento common functions and magento common functions-PHP Tutorial

Source: Internet
Author: User
Magento and magento functions. Magento common functions: magento common functions 1. how to specify a custom data source for source in the Magentoeav_attribute table if the referenced class name is yebihai_usermanage_model_entity_school your magento common functions, magento common functions

1. how to specify custom data sources in the source table of Magento eav_attribute
If the class name you reference is yebihai_usermanage_model_entity_school, you must provide the complete address. usermanage/entity_school is not supported. by default, the class name is found under Mage.
For example:

$ Setup-> addAttribute ('customer', 'School ', array ('type' => 'int', 'input' => 'select ', 'label' => 'school ', 'global' => 1, 'visible' => 1, 'required' => 0, 'User _ defined' => 1, 'default' => '0', 'visible _ on_front '=> 1, 'source' => 'yebihai _ usermanage_model_entity_school', // data source, leave text blank ));


2. processing of the number of decimal places in the result of Magento getPrice ()
Echo Mage: helper ('core')-> currency ($ _ product-> getPrice ());
Output Format: 888.673 => 888.67

3.MaIn gento config. xml, the block rewriting in the global node and the naming label under blocks must be in lower case, for example:


Yebihai_CategoryList_Block_Category_View Yebihai_CategoryList_Block


4. Magento obtain the list. The current sorting method is ASC or DESC?
Get the current order: $ this-> getAvailableOrders ()
Get the current page: $ this-> getCurrentPage ()
All the contents on the list page are obtained in the Mage_Catalog_Block_Product_List_Toolbar class. you need to find them directly.

5. how can Magento Collection be sorted?

$ SubCategories = Mage: getModel ('catalog/category ')-> getCollection (); $ subCategories-> SetOrder ('position', 'asc ');


6. how are the conditions or conditions in the Magento Collection where implemented?

$ Result = $ selfread-> select ()-> from ($ table, array ('id')-> where ('Reid = '. $ reid, 'topid = '. $ reid); // reid = $ reid or topid = $ reid


7. Magento:
I used the addStatusHistoryComment method of the Magento system in the listener class to write the order content to the sales_flat_order_status_history table, but I need to modify the value of the field is_visible_on_front, make the content visible at the front-end. I had a headache and thought about various methods to solve the problem.
All source code of the listener class:

Class Yebihai_CustomerOrderComments_Model_Observer {public function setCustomerOrderComments (Varien_Event_Observer $ observer) {$ _ order = $ observer-> getEvent ()-> getOrder (); $ _ request = Mage: app () -> getRequest (); $ _ comments = strip_tags ($ _ request-> getParam ('mermerordercomments'); if (! Empty ($ _ comments) {$ _ order-> setCustomerNote ('
Order remarks:'. $ _ Comments); $ _ order-> addStatusHistoryComment ('Order remarks:'. $ _ comments)-> setIsVisibleOnFront (1);} return $ this ;}}

8. menu control on the left of Magento Personal Center
The main features of the Personal Center are carried out in the customer module. you need to modify the corresponding features and modify them directly in the customer folder of your template.
Left-side menu template path: customer/account/navigation. phtml
9. how does Magento convert html to escape characters?
The core assistant contains an escapeHtml method, which is used as follows:
Mage: helper ('core')-> escapeHtml ("YebihaiFuel

Go

");
Actual method location: in the Mage_Core_Helper_Abstract class.
Ps: some common operation methods are encapsulated in the core module. you can analyze the source code if necessary.

10. Magento dynamically create a block and reference the action?

The following is the Layout configuration file of one of my modules. I need to call checkoutcart dynamically through Ajax. direct call is definitely not feasible. how can I solve this problem?

Simple Checkout/cart_item_renderer Quickbuy/cart/item/item_view.phtml
Step 1: Call a custom controller through ajax, for example:
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, for example, public function updateQuickShoppingCarAction () {$ block = $ this-> getLayout () -> createBlock ('checkoutrewrite/quickcart')-> setTemplate ('quickbuy/cart. phtml '); echo $ block-> toHtml ();}
Step 3: Create a block File (quickcart) and initialize the action content in the configuration file in the construct method in this file, for example:
Public function _ construct () {parent ::__ construct (); $ this-> addItemRender ('simple', 'checkout/cart_item_renderer ', 'quickbuy/cart/item/item_view.phtml ');}

PS: In step 2, the cart. phtml template has been loaded. The third step is to load the action under the cart block.

11. What are precautions for Magento getTable method parameters?
INSTANCE. you can use the following methods to query specified tables and conditions in a database:

Public function getExcelKucunJiage ($ id, $ status) {$ selfread = $ this-> _ getConnection ('excelmanage _ READ '); $ table = $ this-> getTable ('excelmanage/excelkucunjiage'); $ result = $ selfread-> select ()-> from ($ table) -> where ('Excel _ id =? ', $ Id)-> where ('is _ active =? ', $ Status); return $ selfread-> fetchRow ($ result );}

Note the following when setting parameters for the getTable method. excelmanage is your module name. excelkucunjiage is the name of the object node you operate on. my object configuration is as follows:

Yebihai_ExcelManage_Model_Resource_Mysql4 Excelkucunjiage

"/" Is the object name that comes from the table.

12. how to update the specified ID of a data table?
$ ExcelModel = Mage: getModel ('excelmanage/excelkucunjiage')-> 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.
Extended: How does Magento add and modify specified table information?

13. how do I change the default sorting field of the product list?
Set the path to System> Directory> Advanced Product Management> default list status

14. how many data sets can be obtained?

Obtain the number of _ productCollection data sets. The example is as follows:

$ This-> setStoreId ($ storeId );

$ This-> _ productCollection = Mage: getResourceModel ('catalog/product_collection '); // Obtain a dataset

$ This-> _ productCollection = $ this-> _ productCollection-> addAttributeToSelect ('*')

-> AddAttributeToSelect ('manufacturer ') // Add query attributes

-> SetStoreId ($ storeId) // set the store

-> AddAttributeToFilter ('cuxiaobiaoqian ', array ('EQ' => 39) // specify the attribute filter

-> AddStoreFilter ($ storeId) // add store filter conditions

-> SetPageSize (6); // get the number of entries

15. how to control the number of read records when querying a specified data table through The select () method?

The background of the code application is as follows:

$ Selfread = $ this-> _ getConnection ('yafo _ bbs_setup '); // database connection object

$ Table = $ this-> zixunTablePrefix. "forum_post"; // The table to be queried.

$ Result = $ selfread-> select ()-> from (array ('a' => $ table), array ('tid', 'subobject ')) // specify the table and fields to be queried

-> Limit ($ size) // read the specified number of entries

-> Order ("a. dateline DESC") // specify the sorting condition

-> Where ($ selfwhere); // add filter conditions

Return $ selfread-> fetchAll ($ result); // return the query result

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. modify the specified product inventory (code operation )?

$ SelfPrc = Mage: getModel ('catalog/product')-> load (614); $ aa = Mage: getModel ("cataloginventory/stock_item ") -> loadByProduct ($ selfPrc); $ selfaa = $ aa-> getData (); $ selfaa ['qty '] = 23; $ aa-> setData ($ selfaa ); $ aa-> save ();


18. how to output SQL statements
$ Result = $ selfread-> select ()-> from (array ('FT '=> $ flatTable), array ())

-> Join (array ('PC' => $ prcCategory), 'Ft. entity_id = pc. entity_id ', array ('PC. value ')-> where ('Ft. attribute_set_id =? ', $ Attsetid)-> where ('PC. attribute_id =? ', $ Attid)-> group ("pc. value"); // echo $ result; exit; // output the SQL statement


19. how do I add remarks in the code for background form configuration?

$ Fieldset-> addField ('dict _ grade ', 'select', array ('name' => 'dict _ grade', 'label' => Mage :: helper ('catalogsearchrewrite')->__ ('advanced Search Ciku Manage grad'), 'title' => Mage: helper ('catalogsearchrewrite ') ->__ ('advanced Search Ciku Manage Grade '), 'type' => 'options', 'options' => Mage: getSingleton ('catalogsearchrewrite/cikumanage ') -> getCikuGradeOptionArray (), 'After _ element_html '=> Mage: helper ('catalogsearchrewrite')->__ ('Keywords Grade Description. '), // after_element_html. This attribute is used to add the remarks 'requestred' => true ,));


20. instantiate the model. how can I get the value of the specified content of a specified field through the load method?
$ DictModel = Mage: getModel ('catalogsearchrewrite/cikumanage')-> load ($ dictname, 'dict _ name'); // parameter 1: Specified value; parameter 2: field

$ DictModel-> getDictName (); // Obtain the returned value of a specified field

Http://www.bkjia.com/PHPjc/1135808.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1135808.htmlTechArticlemagento commonly used functions, magento commonly used functions 1. Magento eav_attribute table source how to specify custom data source if you reference the class name yebihai_usermanage_model_entity_school you...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.