Common methods of Magento development

Source: Internet
Author: User

Here is I do magento development commonly used methods, now summed up, the follow-up will be more useful methods summed up.

1. Direct operation of the database
Check:

$read = Mage::getsingleton ("Core/resource")->getconnection (' Core_read '); $sql = "SELECT * from ' abc '";     $result $read->fetchall ($sql);  // Fetchrow Find a

increase, delete, change

$write = Mage::getsingleton ("Core/resource")->getconnection (' Core_write '); $sql = "INSERT into ABC (name) VALUES (' Hello ')"; $write->query ($sql);

2. Get User Login Status

Mage::getsingleton (' customer/session ')->isloggedin ()

3. Get the current user

$customer = Mage::getsingleton (' customer/session ')->getcustomer ()

4. Get the IP address

$ip = mage::helper (' core/http ')->getremoteaddr ()

5. Event Distribution

Mage::d ispatchevent ($name,array$dataArray())

6. Get Product Details

$model = Mage::getmodel (' catalog/product ')$_product$model->load ($ ProductID)

7. Get all the product collections

$model = Mage::getmodel (' catalog/product ')$collection$model GetCollection ()

8. Get current Store information

$store _id = Mage::app ()->getstore (),Getstoreid ()$code = Mage::app ()->getstore ()GetCode ()$website _id = Mage::app ()->getstore (),Getwebsiteid ()$name = Mage::app ()->getstore (),getName (  )$status = Mage::app ()->getstore () getisactive () $url = Mage::app ()->getstore ()->gethomeurl ()

9. Get the current Product ID

$product _id = mage::registry (' current_product ')->getid ()

10. Get Related Products

$associatedProductId = Mage::getmodel (' catalog/product_type_grouped ')->getassociatedproductids ($ _product); $associatedProduct = Mage::getmodel (' catalog/product ')->load ($associatedProductId[0]);

12. Get the specified category product

$products = Mage::getmodel (' catalog/category ')->load ($category _id) , Getproductcollection ()->addattributetoselect (' * ')->addattributetofilter (' status ', 1) ->addattributetofilter (' visibility ', 4);

13. Quick Start Template Tips

A. Find App/code/core/mage/core/block/template. php this file b return true

14. Get Classification Sub-categories

$currCat = Mage::getmodel (' catalog/category ')->load ($id// current category $ Collection = Mage::getmodel (' catalog/category ')->getcategories ($currCat-Getentityid ());

15. Get the specified directory sub-category

if($category->haschildren ()) {//determine if there is a subdirectory $ids=$category->getchildren ();//Extract subdirectory ID list $subCategories= Mage::getmodel (' catalog/category ')getcollection ();$subCategories->getselect ()->where ("e.entity_id in ($ids)");//extract list of specified directory IDs $subCategories->addattributetoselect (' name ');//Specify the lookup directory name $subCategories-load ();foreach($subCategories  as $item) { Echo" - " ; Echo' <a href= '.$item->geturl (). ' > ';//Get Directory link Echo $item->getname ();//Get directory name Echo"</a> ("; Echo $item->getproductcount ();//get the number of products in the catalog//echo $item->getchildrencount (); Get directory subdirectory number Echo")"; Echo"<br/>"; } }

16. Ways to get URLs

Mage::getUrl (address) Mage:: GetUrl (address,array()) Mage:: Helper (' Core/url ') , Getcurrenturl () Mage:: Helper (' Core/url '),gethomeurl () Mage:: Getbaseurl (Mage_core_model_store:: Url_type_link)

Common methods of Magento development

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.