Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

25 August 2014

Code - Những hàm thường dùng trong Magento

Get the path of your magento page.
1
echo $this->getUrl('mypage');
Get the path of the image in your skin folder.
1
echo $this->getSkinUrl('images/yourimage.gif');
Get the product link.
1
echo $this->getProductData()->getProductUrl();
Get the product name.
1
echo $this->htmlEscape($this->getProductData()->getName());
Call a static block in .phtml file.
1
echo $this->getLayout()->createBlock('cms/block')->setBlockId('YOURBLOCKID')->toHtml();
Get Image url of current category.
1
echo $this->getCurrentCategory()->getImageUrl();
Check whether the current category is Top category.
1
echo $this->IsTopCategory();
Get description of current category.
1
echo $this->getCurrentCategory()->getDescription();
Display products list page (list.phtml).
1
echo $this->getProductListHtml();
Display CMS block page.
1
echo $this->getCmsBlockHtml();

Get current store id.
1
echo $storeId = Mage::app()->getStore()->getId();
Get current store name.
1
echo $storeName = Mage::app()->getStore()->getName();
Get current store code.
1
echo $storeCode = Mage::app()->getStore()->getCode();
Get website name.
1
echo $websiteName = Mage::app()->getWebsite()->getName();
Get session id.
1
echo $sessionId = Mage::getModel('core/session')->getSessionId();
Get customer id.
1
echo $customerId = Mage::getModel('customer/session')->getCustomerId();
Get guest id.


1
echo $vistitorId = Mage::getModel('core/session')->getVisitorId();

23 August 2014

Code - Các hàm lấy đường dẫn URL trong Magento trong file template .phtml

A. Các hàm get Url magento sử dụng trong file template .phtml

1. Get Base Url magento:
Mage::getBaseUrl();

2. Get Magento Skin Url magento:
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

3. Get Media Url magento:
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

4. Get Js Url magento:
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

5. Get Store Url magento:
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

6. Get Current Url magento:
Mage::helper('core/url')->getCurrentUrl();

7. Get Home Url magento :
Mage::helper('core/url')->getHomeUrl();

B. Các hàm Get Url magento trong CMS Pages hoặc Static Block:

1. Get Base Url magento :
{{store url=""}}

2. Get Skin Url magento:
{{skin url='images/imagename.jpg'}}

3. Get Media Url magento :
{{media url='/imagename.jpg'}}

4. Get Store Url magento :
{{store url='mypage.html'}}

Code - Quy ước viết code trong Magento

=== Model === 
Mage::getModel() // for models. 

=== Helper === 
Mage::helper() // for helpers.

=== Block ==== 
Mage::app()->getLayout()->createBlock() // Tạo Block mới
Mage::getResourceModel()//