Magento notes/Records (1)

Source: Internet
Author: User

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:


<global><!--St Rewrite block configuration--><blocks>    <catalog>          & nbsp <rewrite>                <!--label symbol case sensitive, category_view must be lowercase  -->& nbsp               <category_view>yebihai_categorylist_block_category_view </category_view>            </rewrite>    </catalog></ blocks><!--End Rewrite block configuration-->       <blocks>          & nbsp    <!--categorylist can only be-->                <categorylist>                      <class>yebihai_categorylist_block</ class>                </categorylist>       </blo Cks>  </global> 


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 (' <br/><strong> order notes:</strong> '. $_comments);$_order-> Addstatushistorycomment (' Order notes: '. $_comments)->setisvisibleonfront (1);} return $this;}}

8.Magento Personal Center left menu control
The main function of the personal center is in the customer this module, need to modify the corresponding function, go directly to your template customer folder to modify.
Left Menu Template path: customer/account/navigation.phtml
9.Magento convert HTML to escape character, what's the method? The
Core Helper has a escapehtml method, using the following:
Mage::helper (' core ')->escapehtml ("<b>yebihai</b> <span> refueling </span><div style= ' display:block;font-size:18px; >go</div> ");
Method Actual Location: Mage_core_helper_abstract this class inside.
PS: Some common methods of operation 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?

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

<block type= "Checkout/cart" name= "Checkout.cart" as= "Checkoutcart" template= "quickbuy/cart/cart.phtml" > &L T;action method= "Additemrender" ><type>simple</type><block>checkout/cart_item_renderer</ Block><template>quickbuy/cart/item/item_view.phtml</template></action> </block>
The first step: invoking a custom controller via Ajax, such as:
Jquery.post (' <?php echo $this->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:

<!--St Database resource model configuration-<excelmanage_resource_mysql4> <class>yebihai_excelmanage_model_resource_ mysql4</class> <entities> <excelkucunjiage> <table>excelkucunjiage</table> & Lt;/excelkucunjiage></entities> </excelmanage_resource_mysql4>
<!--End Database resource model configuration--

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 (                    and nbsp                                  Webs ite_id "= 0,                           " All_grou PS "= + 0,                           " Cust_group " = = 0,                            "Price" = 97. 0000,                          Website_price "=&gt" ; 97.0000                       ),       &NB Sp     &NBSP;      1=> array                        ( )                           "website_id" = 0,  &nb Sp                         "all_groups" = 0,    &nbs P                       "cust_group" = 1,      &NBS P                     "price" = 27.0000,        &NB Sp                   "website_price" = 27.0000        &NB Sp              ),                   &NB Sp;2=> array                        (      &N) Bsp                     "website_id" = 0,        &NB Sp                   "all_groups" = 0,          &NBS P                 "cust_group" = 2,            &NBS P               "price" = 17.0000,              &NB Sp             "website_price" = 17.0000              &NB Sp        ),                    3=> array                        (            &N Bsp             "website_id" = 0,                &NB SP           "all_groups" = 0,                  &NBS P         "Cust_group" + 3,                    &NBS P       "price" = 67.0000,                      &NB Sp     "Website_price" = 67.0000                      &NB SP;),                    4=> array        &N Bsp               (                    &NB Sp       "website_id" = 0,                      &NBS P     "all_groups" = 0,                        &NBSp   "Cust_group" = 4,                          &NBS P; " Price "=" 66.0000,                            "web Site_price "+ 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 ') -&GT;__ (' 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

Reprinted from: http://www.yebihai.com/magento/397.html

Magento notes/Records (1)

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.