Magento common functions, Magento common functions _php tutorials

Source: Internet
Author: User

Magento commonly used functions, Magento common functions


1.Magento eav_attribute table in how source specifies a custom data source
If you refer to the class name Yebihai_usermanage_model_entity_school you must give the address completely, not usermanage/entity_school, so the default is to find under Mage.
Such as:

$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 ' and 1 , ' source ' = ' yebihai_usermanage_model_entity_school ',//data source, text is left blank);


2.Magento GetPrice () The result of the number of decimal places processed
echo mage::helper (' core ')->currency ($_product->getprice ());
Output format: 888.673 = 888.67

3. The block rewrite in the global node in theMagento config. Blocks and the named tag below must be lowercase, such as:


yebihai_categorylist_block_category_view Yebihai_categor Ylist_block


4.Magento get list current sort by ASC or DESC?
Get current sort: $this->getavailableorders ()
Get current page: $this->getcurrentpage ()
The various contents of the list page are obtained in: Mage_catalog_block_product_list_toolbar This class, there is a need to go directly to the face to find.

5.Magento Collection Add sort?

$subCategories = Mage::getmodel (' catalog/category ')->getcollection (); $subCategories setorder (' position ', ' ASC ');


6.Magento Collection where is the OR condition implemented?

$result = $selfread->select ()->from ($table, array (' ID '))->where (' Reid = '. $reid, ' Topid = '. $reid);//reid=$ Reid or Topid= $reid


7.Magento manipulate multiple fields below a piece of data, using the following scenario:
I do the order notes in the listening class inside the Magento system through the Addstatushistorycomment method of the order content can be successfully written to sales_flat_order_status_history table, but my need is also to modify is _visible_on_front The value of this field so that the content is visible in the foreground. Headache problem came, think of a variety of methods at the end of the following way to solve.
Listening class all source code:

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 (' customerordercomments ')); if (!empty ($_comments)) {$_order->setcustomernote ('
Order Notes:'. $_comments); $_order->addstatushistorycomment (' Order notes: '. $_comments)->setisvisibleonfront (1);} return $this;}}

8.Magento Personal Center left menu control
The main functions of the personal center are in the customer this module, need to modify the corresponding functions, go directly to your template customer folder to modify.
Left Menu Template path: customer/account/navigation.phtml
9.Magento convert HTML to escape character, using what method?
The core helper has a escapehtml method that uses the following:
Mage::helper (' core ')->escapehtml ("Yebihai refueling go");
Method actual location: Mage_core_helper_abstract this class inside.
PS: About some common operation methods are encapsulated in the core of this module, we need to be able to analyze the source code.

10.Magento dynamically create block and reference action?

Here is a module of my layout configuration file, I now need to use AJAX dynamic call Checkoutcart, direct invocation is definitely not, how to solve it?

Simple checkout/cart_item_renderer quickbuy/cart/item/item_view.phtml
The first step: invoking a custom controller via Ajax, such as:
Jquery.post (' GETURL (' Gouwuche/cart/updatequickshoppingcar ')?> ', function (data) {jQuery (' #shopping-cart-table thead '). After ( (data);}); Step two: Dynamically create blocks in the controller's method, such as: Public Function updatequickshoppingcaraction () {$block = $this->getlayout () Createblock (' Checkoutrewrite/quickcart ')->settemplate (' quickbuy/cart/cart.phtml '); Echo $block->tohtml ();}
Step three: Create a new block file (Quickcart) to initialize the action content in the configuration file in the construct method in this file, such as:
Public Function __construct () {parent::__construct (); the $this->additemrender (' Simple ', ' checkout/cart_item_ Renderer ', ' quickbuy/cart/item/item_view.phtml ');}

PS: In the second step, the cart.phtml template is loaded, and the third step is to load the action below the cart block.

Magento GetTable method Parameters notice those things?
instance, the method for querying the database for specifying tables and conditions is as follows:

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);}

The parameters of the GetTable method should be noted as follows, Excelmanage is your module name, Excelkucunjiage This is the entity node name you operate, my entity configuration is as follows:

Yebihai_excelmanage_model_resource_mysql4 Excelkucunjiage

The arguments after "/" are the names of the entities that originate in front of the table.

12. How do I update the data table to specify ID information?
$excelModel = Mage::getmodel (' excelmanage/excelkucunjiage ')->load (1);
$excelModel->setexceladddate (Mage::getmodel (' core/date ')->timestamp (Time ()));
$excelModel->setisactive (0);
$excelModel->save ();
The code above is to modify the data table information with ID 1.
Extension: Magento How do I add changes to the specified table information?

13. How do I change the default sort field for a product list?
Set path in: System----Advanced product Management--default list status

14. Get the number of bars for a data set?

Get the number of _productcollection data sets, as shown in the following example:

$this->setstoreid ($storeId);

$this->_productcollection = Mage::getresourcemodel (' catalog/product_collection '); Get Data Set

$this->_productcollection = $this->_productcollection->addattributetoselect (' * ')

->addattributetoselect (' manufacturer ')//Add Query Properties

->setstoreid ($STOREID)//Set up store

->addattributetofilter (' Cuxiaobiaoqian ', Array (' EQ ' =>39)//attribute filter specified

->addstorefilter ($STOREID)//Add store filter conditions

->setpagesize (6); Get number of bars

15. How to control the number of read bars by querying the specified data table with the Select () method?

The code uses the following background:

$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 table and fields to query

->limit ($size)//Read the specified number of bars

->order ("A.dateline DESC")//Specify sorting criteria

->where ($selfwhere); Add Filter criteria

Return $selfread->fetchall ($result); Return query Results

16. Modify the specified product price and group price (code actions)?

$SELFPRC = Mage::getmodel (' catalog/product ')->load (614), $selfData = $selfPrc->getdata (); $selfData [' price '] = $selfData [' group_price '] = Array (0 = = Array ("website_id" = + 0, "all_groups" = 0, "Cust_group" = 0, "Pric E "= 97.0000," website_price "= 97.0000), 1=> Array (" website_id "= 0," all_groups "= 0," Cust_group " = 1, "Price" = 27.0000, "Website_price" and "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 "and 67.0000), 4=> Array (" website_id "= 0," all_groups "= 0," cust_group "= 4," price "= 66.0000," Website_price "and 66.0000); $SELFPRC-&G T;setdata ($selfData); $selfPrc->save ();


17. Modify the specified product inventory (code actions)?

$SELFPRC = Mage::getmodel (' catalog/product ')->load (614); $AA = Mage::getmodel ("Cataloginventory/stock_item")- >loadbyproduct ($SELFPRC); $SELFAA = $aa->getdata (); $selfaa [' qty '] = $aa->setdata ($SELFAA); $aa->save ( );


18. How to output SQL statements
$result = $selfread->select ()->from (Array (' ft ' = $flatTable), array ())

->join (' 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 SQL statements


19. Background form configuration, how to add comments in the code?

$fieldset->addfield (' Dict_grade ', ' select ', Array (' name ' = ' dict_grade ', ' label ' = = Mage::helper (' Catalogsearchrewrite ')->__ (' Advanced Search ciku Manage Grade '), ' title ' = Mage::helper (' Catalogsearchrewrite ') ->__ (' Advanced Search ciku Manage Grade '), ' type ' = ' options ', ' Options ' and Mage::getsingleton (' Catalogsearchrewrite/cikumanage ')->getcikugradeoptionarray (), ' after_element_html ' = Mage::helper (' Catalogsearchrewrite ')->__ (' Keywords Grade Description. '),//after_element_html This property is used to add remarks ' required ' = true, ));


20. Instantiate model, how do I get the value of the specified field specified by the Load method?
$dictModel =mage::getmodel (' Catalogsearchrewrite/cikumanage ')->load ($dictname, ' dict_name '); Parameter 1: Specify a value, Parameter 2: Specify a field

$dictModel->getdictname (); Gets the value of the specified field returned

http://www.bkjia.com/PHPjc/1135808.html www.bkjia.com true http://www.bkjia.com/PHPjc/1135808.html techarticle Magento commonly used functions, Magento common functions 1.Magento eav_attribute table in how source specifies a custom data source if you reference a class named 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.