Skip to content

Instantly share code, notes, and snippets.

@JeansBolong
Last active June 13, 2023 15:25
Show Gist options
  • Save JeansBolong/1557efe396732b8046f45524230c6e65 to your computer and use it in GitHub Desktop.
Save JeansBolong/1557efe396732b8046f45524230c6e65 to your computer and use it in GitHub Desktop.
Magento CheatSheet

Magento Snippets

Download extension manually using pear/mage

Pear for 1.4, mage for 1.5. File downloaded into /downloader/.cache/community/

./pear download magento-community/Shipping_Agent
./mage download community Shipping_Agent

Clear cache/reindex

<?php
// clear cache
Mage::app()->removeCache('catalog_rules_dirty');
// reindex prices
Mage::getModel('index/process')->load(2)->reindexEverything();
/*
1 = Product Attributes
2 = Product Attributes
3 = Catalog URL Rewrites
4 = Product Flat Data
5 = Category Flat Data
6 = Category Products
7 = Catalog Search Index
8 = Tag Aggregation Data
9 = Stock Status
*/
?>

Load category by id

<?php
$_category = Mage::getModel('catalog/category')->load(89);
$_category_url = $_category->getUrl();
?>

Load product by id or sku

<?php
$_product_1 = Mage::getModel('catalog/product')->load(12); // won't include a valid stock item
$_product_2 = Mage::getModel('catalog/product')->loadByAttribute('sku','cordoba-classic-6-String-guitar'); // will include a valid stock item
?>

Get Configurable product's Child products

<?php
// input is $_product and result is iterating child products
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
?>

Get Configurable product's Children's (simple product) custom attributes

<?php
// input is $_product and result is iterating child products
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($col as $simple_product){
	var_dump($simple_product->getId());
}
?>

Log to custom file

<?php Mage::log('Your Log Message', Zend_Log::INFO, 'your_log_file.log'); ?>

Call Static Block

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block-name')->toHtml(); ?>

Add JavaScript to page

First approach: page.xml - you can add something like

<action method="addJs"><script>path/to/my/file.js</script></action>

Second approach: Find page/html/head.phtml in your theme and add the code directly to page.html.

Third approach: If you look at the stock page.html mentioned above, you'll see this line

<?php echo $this->getChildHtml() ?>

Normally, the getChildHtml method is used to render a specific child block. However, if called with no paramater, getChildHtml will automatically render all the child blocks. That means you can add something like

<!-- existing line --> <block type="page/html_head" name="head" as="head">
	<!-- new sub-block you're adding --> <block type="core/template" name="mytemplate" as="mytemplate" template="page/mytemplate.phtml"/>
	...

to page.xml, and then add the mytemplate.phtml file. Any block added to the head block will be automatically rendered. (this automatic rendering doesn't apply for all layout blocks, only for blocks where getChildHtml is called without paramaters).

Check if customer is logged in

<?php $logged_in = Mage::getSingleton('customer/session')->isLoggedIn(); // (boolean) ?>

Get the current category/product/cms page

<?php
$currentCategory = Mage::registry('current_category');
$currentProduct = Mage::registry('current_product');
$currentCmsPage = Mage::registry('cms_page');
?>

Run Magento Code Externally

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// Run you code here
?>

Programmatically change Magento’s core config data

<?php
// find 'path' in table 'core_config_data' e.g. 'design/head/demonotice'
$my_change_config = new Mage_Core_Model_Config();
// turns notice on
$my_change_config->saveConfig('design/head/demonotice', "1", 'default', 0);
// turns notice off
$my_change_config->saveConfig('design/head/demonotice', "0", 'default', 0);
?>

Changing the Admin URL

Open up the /app/etc/local.xml file, locate the <frontName> tag, and change the ‘admin’ part it to something a lot more random, eg:

<frontName><![CDATA[supersecret-admin-name]]></frontName>

Clear your cache and sessions.

Magento: Mass Exclude/Unexclude Images

By default, Magento will check the 'Exclude' box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view.

# Mass Unexclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '0' WHERE `disabled` = '1';
# Mass Exclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '1' WHERE `disabled` = '0';

getBaseUrl – Magento URL Path

<?php
// http://example.com/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
// http://example.com/js/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
// http://example.com/index.php/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
// http://example.com/media/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
// http://example.com/skin/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
?>

Get The Root Category In Magento

<?php
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$_category = Mage::getModel('catalog/category')->load($rootCategoryId);
// You can then get all of the top level categories using:
$_subcategories = $_category->getChildrenCategories();
?>

Get The Current URL In Magento

<?php echo Mage::helper('core/url')->getCurrentUrl(); ?>

Create Custom Navigation without child

Cara di bawaj ini adalah untuk membuat category di magento tanpa subchild

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>

<?php //echo Zend_Debug::dump($_categories, 'debug'); ?>


<div class="mobile-link-menu">
    <ul>
<?php foreach($_categories as $_category): ?>
        <li><a href="<?php echo $_helper->getCategoryUrl($_category); ?>"><?php echo $this->__($_category->getName()) ?></a></li>
<?php endforeach; ?>
    </ul>
 </div>

Category Navigation Listings in Magento

Make sure the block that you’re working is of the type catalog/navigation. If you’re editing catalog/navigation/left.phtml then you should be okay.

<div id="leftnav">
	<?php $helper = $this->helper('catalog/category') ?>
	<?php $categories = $this->getStoreCategories() ?>
	<?php if (count($categories) > 0): ?>
		<ul id="leftnav-tree" class="level0">
			<?php foreach($categories as $category): ?>
				<li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">
					<a href="<?php echo $helper->getCategoryUrl($category) ?>"><span><?php echo $this->escapeHtml($category->getName()) ?></span></a>
					<?php if ($this->isCategoryActive($category)): ?>
						<?php $subcategories = $category->getChildren() ?>
						<?php if (count($subcategories) > 0): ?>
							<ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
								<?php foreach($subcategories as $subcategory): ?>
									<li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
										<a href="<?php echo $helper->getCategoryUrl($subcategory) ?>"><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a>
									</li>
								<?php endforeach; ?>
							</ul>
							<script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
						<?php endif; ?>
					<?php endif; ?>
				</li>
			<?php endforeach; ?>
		</ul>
		<script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
	<?php endif; ?>
</div>

Debug using zend

<?php echo Zend_Debug::dump($thing_to_debug, 'debug'); ?>

$_GET, $_POST & $_REQUEST Variables

<?php
// $_GET
$productId = Mage::app()->getRequest()->getParam('product_id');
// The second parameter to getParam allows you to set a default value which is returned if the GET value isn't set
$productId = Mage::app()->getRequest()->getParam('product_id', 44);
$postData = Mage::app()->getRequest()->getPost();
// You can access individual variables like...
$productId = $postData['product_id']);
?>

Get methods of an object

First, use get_class to get the name of an object's class.

<?php $class_name = get_class($object); ?>

Then, pass that get_class_methods to get a list of all the callable methods on an object

<?php
$class_name = get_class($object);
$methods = get_class_methods($class_name);
foreach($methods as $method)
{
	var_dump($method);
}
?>

Is product purchasable?

<?php if($_product->isSaleable()) { // do stuff } ?>

Load Products by Category ID

<?php
$_category = Mage::getModel('catalog/category')->load(47);
$_productCollection = $_category->getProductCollection();
if($_productCollection->count()) {
	foreach( $_productCollection as $_product ):
		echo $_product->getProductUrl();
		echo $this->getPriceHtml($_product, true);
		echo $this->htmlEscape($_product->getName());
	endforeach;
}
?>

Update all subscribers into a customer group (e.g. 5)

UPDATE
	customer_entity,
	newsletter_subscriber
SET
	customer_entity.`group_id` = 5
WHERE
	customer_entity.`entity_id` = newsletter_subscriber.`customer_id`
AND
	newsletter_subscriber.`subscriber_status` = 1;

Get associated products

In /app/design/frontend/default/site/template/catalog/product/view/type/

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_associatedProducts = $this->getAllowProducts() ?>
<?php //var_dump($_associatedProducts); ?>
<br />
<br />
<?php if (count($_associatedProducts)): ?>
	<?php foreach ($_associatedProducts as $_item): ?> 
		<a href="<?php echo $_item->getProductUrl() ?>"><?php echo $_helper->productAttribute($_item, $_item->getName(), 'name') ?> | <?php echo $_item->getName() ?> | <?php echo $_item->getPrice() ?></a>
		<br />
		<br />
	<?php endforeach; ?>
<?php endif; ?>

Get An Array of Country Names/Codes in Magento

<?php
$countryList = Mage::getResourceModel('directory/country_collection')
                    ->loadData()
                    ->toOptionArray(false);
     
    echo '<pre>';
    print_r( $countryList);
    exit('</pre>');
?>

Create a Country Drop Down in the Frontend of Magento

<?php
$_countries = Mage::getResourceModel('directory/country_collection')
                                    ->loadData()
                                    ->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
    <select name="country" id="country">
        <option value="">-- Please Select --</option>
        <?php foreach($_countries as $_country): ?>
            <option value="<?php echo $_country['value'] ?>">
                <?php echo $_country['label'] ?>
            </option>
        <?php endforeach; ?>
    </select>
<?php endif; ?>

Create a Country Drop Down in the Magento Admin

<?php
    $fieldset->addField('country', 'select', array(
        'name'  => 'country',
        'label'     => 'Country',
        'values'    => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
    ));
?>

Return Product Attributes

<?php
$_product->getThisattribute();
$_product->getAttributeText('thisattribute');
$_product->getResource()->getAttribute('thisattribute')->getFrontend()->getValue($_product);
$_product->getData('thisattribute');
// The following returns the option IDs for an attribute that is a multiple-select field: 
$_product->getData('color'); // i.e. 456,499
// The following returns the attribute object, and instance of Mage_Catalog_Model_Resource_Eav_Attribute: 
$_product->getResource()->getAttribute('color'); // instance of Mage_Catalog_Model_Resource_Eav_Attribute
// The following returns an array of the text values for the attribute: 
$_product->getAttributeText('color') // Array([0]=>'red', [1]=>'green')
// The following returns the text for the attribute
if ($attr = $_product->getResource()->getAttribute('color')):
    echo $attr->getFrontend()->getValue($_product); // will display: red, green
endif;
?>

Cart Data

<?php
$cart = Mage::getModel('checkout/cart')->getQuote()->getData();
print_r($cart);
$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
print_r($cart);
$session = Mage::getSingleton('checkout/session');
foreach ($session->getQuote()->getAllItems() as $item) {
    echo $item->getName();
    Zend_Debug::dump($item->debug());
}
?>

Get Simple Products of a Configurable Product

<?php
if($_product->getTypeId() == "configurable") {
    $ids = $_product->getTypeInstance()->getUsedProductIds();
?>
<ul>
    <?php
    foreach ($ids as $id) {
        $simpleproduct = Mage::getModel('catalog/product')->load($id);
    ?>
        <li>
        	<?php
        	echo $simpleproduct->getName() . " - " . (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
        	?>
        </li>				
    <?php
    }
    ?>
</ul>
<?php
}
?>

Turn template hints on/off

UPDATE
`core_config_data`
SET
`value` = 0
WHERE
`path` = "dev/debug/template_hints"
OR
`path` = "dev/debug/template_hints_blocks";

or copy link below to page/html/head.phtml

<?php if(Mage::app()->getRequest()->getParam('th', false)) self::$_showTemplateHints = true; ?>

Delete all products

TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

Getting Configurable Product from Simple Product ID in Magento 1.5+

<?php
$simpleProductId = 465;
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
    ->getParentIdsByChild($simpleProductId);
$product = Mage::getModel('catalog/product')->load($parentIds[0]);
echo $product->getId(); // ID = 462 (aka, Parent of 465)
?>

Passing flash messages to the user

<?php
// Notice
Mage::getSingleton('core/session')->addNotice('Message');
// Error
Mage::getSingleton('checkout/session')->addNotice('Message');

Return json response

<?php
return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($data));

Get database connection

<?php
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');

Insert phtml page/form kedalam cms-page / static-block

{{block type="core/template" block_id="payment-guide-0" template="cms/pages/payment-guide.phtml"}}

Add breadcrumb to page

Code di bawah di masukin kedalam file xml

<contacts_index_index>
        <reference name="breadcrumbs">
            <action method="addCrumb">
                <crumbName>Home</crumbName>
                <crumbInfo>
                    <label>Home</label>
                    <title>Home</title>
                    <link>/</link>
                </crumbInfo>
            </action>
            <action method="addCrumb">
                <crumbName>Contact Us</crumbName>
                <crumbInfo>
                    <label>Contact Us</label>
                    <title>Contact Us</title>
                </crumbInfo>
            </action>
        </reference>
</contacts_index_index>

First

  1. find file at base/default/template/catalog/category/view.phtml
  2. copy that file and move to your template folder
  3. find this code below and comment it
$_imgHtml   = '';
    if ($_imgUrl = $_category->getImageUrl()) {
      $_imgHtml = '<div class="category-image-container"><div class="category-image-container-inner"><p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p></div></div>';
        $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
    }

Second

  1. Open your default layout for category page (2columns-left.phtml)
  2. Add code below after getChildHtml('breadcrumbs') ?> or put above div.class="main"
<?php
$_category  = Mage::registry('current_category');
if($_category){
  $_helper    = Mage::helper('catalog/output');
  $_imgHtml   = '';
    if ($_imgUrl = $_category->getImageUrl()) {
      echo   $_imgHtml = '<div class="category-image-container1"><div class="category-image-container-inner"><p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p></div></div>';
      $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
    }
}
?>
<!-- Gets the current store's details -->
$store = Mage::app()->getStore();
<!-- Gets the current store's id -->
$storeId = Mage::app()->getStore()->getStoreId();
<!-- Gets the current store's code -->
$storeCode = Mage::app()->getStore()->getCode();
<!-- Gets the current website's id -->
$websiteId = Mage::app()->getStore()->getWebsiteId();
<!-- Gets the current store's group id -->
$storeGroupId = Mage::app()->getStore()->getGroupId();
<!-- Gets the current store's name -->
$storeName = Mage::app()->getStore()->getName();
<!-- Gets the current store's sort order -->
$storeSortOrder = Mage::app()->getStore()->getSortOrder();
<!-- Gets the current store's status -->
$storeIsActive = Mage::app()->getStore()->getIsActive();
<!-- Gets the current store's locale -->
$storeLocaleCode = Mage::app()->getStore()->getLocaleCode();
<!-- Gets the current store's home url -->
$storeHomeUrl = Mage::app()->getStore()->getHomeUrl();
<?xml version="1.0"?>
<layout>
<default>
<!--Root/Default Layouts-->
<reference name="root">
<!--Appending Block-->
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
</reference>
<!--CSS and JS Files-->
<reference name="head">
<!--Add CSS and JS, skin Folder-->
<action method="addItem"><type>skin_css</type><name>css/styles.css</name></action>
<action method="addItem"><type>skin_js</type><name>js/functions.js</name></action>
<!--Remove CSS and JS, skin Folder-->
<action method="removeItem"><type>skin_js</type><name>scripts/functions.js</name></action>
<action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action>
<!--Remove JS, js Folder-->
<action method="removeItem"><type>js</type><name>scripts/functions.js</name></action>
</reference>
<!--Header-->
<reference name="header">
<!--Append CMS Block-->
<block type="cms/block" name="header.cms.block" as="headerCmsBlock">
<action method="setBlockId"><block_id>header_cms_block</block_id></action>
</block>
</reference>
<!--Change Block's Template if some Configuration is Set-->
<reference name="catalog.topnav">
<action method="setTemplate" ifconfig="pronav/pronavconfig/pronav_status">
<template>pronav/navigation_top.phtml</template>
</action>
</reference>
<!--Magento's Default Sidebar Blocks-->
<remove name="cart_sidebar"/> <!--Cart Sidebar-->
<remove name="catalog.product.related"/> <!--Related products sidebar-->
<remove name="wishlist_sidebar"/> <!--Wishlist Sidebar-->
<remove name="catalog.compare.sidebar"/> <!--Compare Items Sidebar-->
<remove name="right.permanent.callout"/> <!--Right Callout Sample Data-->
<remove name="left.permanent.callout"/> <!--Left Callout Sample Data-->
<remove name="right.reports.product.viewed"/> <!--Viewed Products-->
<remove name="right.reports.product.compared"/> <!--Compared Products-->
<remove name="catalog.leftnav"/> <!--Layered Navigation-->
<remove name="left.newsletter"/> <!--Sidebar Newsletter-->
<remove name="right.poll"/> <!--Poll-->
<remove name="tags_popular"/> <!--Popular Tags-->
<remove name="paypal.partner.right.logo"/> <!--Paypal logo Sample Data-->
<remove name="catalogsearch.leftnav"/> <!--Layered navigation on search result page-->
<remove name="sale.reorder.sidebar"/> <!--Reorder Sidebar When User Logged, in Dashboard-->
<remove name="customer_account_navigation"/> <!--Customer Navigation-->
</default>
<!--Home Page-->
<cms_index_index>
</cms_index_index>
<!--All Cms Pages-->
<cms_page>
</cms_page>
<!--Category View-->
<catalog_category_view>
<!--Set Page Template-->
<reference name="root">
<action method="setTemplate">
<template>page/3columns.phtml</template>
</action>
</reference>
</catalog_category_view>
<!--Category View With Layered Navigation-->
<catalog_category_layered>
</catalog_category_layered>
<!--Onepage Checkout Index Page-->
<checkout_onepage_index>
</checkout_onepage_index>
<!--Onepage Checkout Success Page-->
<checkout_onepage_success>
</checkout_onepage_success>
<!--Customer Accound Pages-->
<customer_account>
<!--Adds Body Class For All Dashboard Pages - MUST when Dashboard is present-->
<reference name="root">
<action method="addBodyClass"><className>customer-account-page</className></action>
</reference>
</customer_account>
<!--Customer Logged In-->
<customer_logged_in>
</customer_logged_in>
<!--Customer Logged Out-->
<customer_logged_out>
</customer_logged_out>
<!--Product View-->
<catalog_product_view>
<!--Product Information Block-->
<reference name="product.info">
<!--Recently Viewed Products-->
<block type="reports/product_viewed" name="product.viewed" template="reports/recently-viewed.phtml" />
</reference>
</catalog_product_view>
<!--Catalogsearch Result Page-->
<catalogsearch_result_index>
</catalogsearch_result_index>
<!--Advanced Search Result Page-->
<catalogsearch_advanced_result>
</catalogsearch_advanced_result>
<!--Advanced Search Page-->
<catalogsearch_advanced_index>
</catalogsearch_advanced_index>
<!--Cart-->
<checkout_cart_index>
</checkout_cart_index>
<!--Contacts Page-->
<contacts_index_index>
</contacts_index_index>
</layout>
<!-- get skin url -->
<?php echo $this->getSkinUrl('images/logo.png'); ?>
<!-- add phtml to other phtml -->
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('folder/targetPage.phtml')->toHtml(); ?>
<!-- add static-block(admin generate) to other phtml -->
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml(); ?>
<!-- yourPackage/YourTemplate/customer/account/navigation.phtml -->
<!-- remove myAccount menu -->
<?php
$_count = count($_links); /* Add or Remove Account Left Navigation Links Here -*/
unset($_links['account']); /* Account Info dashboard */
unset($_links['account_edit']); /* Account Info */
unset($_links['tags']); /* My Tags */
unset($_links['invitations']); /* My Invitations */
unset($_links['reviews']); /* Reviews */
unset($_links['wishlist']); /* Wishlist */
unset($_links['newsletter']); /* Newsletter */
unset($_links['orders']); /* My Orders */
unset($_links['address_book']); /* Address */
unset($_links['enterprise_customerbalance']); /* Store Credit */
unset($_links['OAuth Customer Tokens']); /* My Applications */
unset($_links['enterprise_reward']); /* Reward Points */
unset($_links['giftregistry']); /* Gift Registry */
unset($_links['downloadable_products']); /* My Downloadable Products */
unset($_links['recurring_profiles']); /* Recurring Profiles */
unset($_links['billing_agreements']); /* Billing Agreements */
unset($_links['enterprise_giftcardaccount']); /* Gift Card Link */
?>
<!-- active templateHint by url http://domain/url?th=false (ditaro di header) -->
<?php if(Mage::app()->getRequest()->getParam('th', false)) self::$_showTemplateHints = true; ?>
<!-- toolbar shorthanded -->
<?php
$toolbar = $this->getChild('product_list')->getToolbarBlock();
$toolbar->setCollection($this->getChild('product_list')->getLoadedProductCollection());
echo $toolbar->toHtml();
?>
<!-- get total price in cart -->
<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?>
<!-- How to run a SQL query -->
<?php
$db = Mage::getResourceSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT 'entity_id' FROM 'catalog_product_entity');
if (!$result) {
return FALSE;
}
$rows = $result->fetch(PDO::FETCH_ASSOC);
if (!$rows) {
return FALSE;
}
print_r($rows);
?>
<!-- add product via url -->
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]&options[id]=[value]
<!-- query untuk rubah base url magento -->
SELECT * FROM core_config_data WHERE path LIKE '%base%url%';
<!-- akses erroe magento url -->
[magento_base_url]/errors/report.php
SELECT * FROM core_config_data WHERE path LIKE '%base%url%';

step 1

tambahin tag <nav> di topmenu.phtml, lalu tambahkan css

nav {
    width: 100%;
    padding: 0;
    margin: 0;
    position:relative;
}

nav ul ul {
    position: absolute;
    width: 100%;
}

step 2

buka styles.css css default magento lalu cari css tag position:relative hapus semua
ada di line 623 627

lalu hapus position:absolute di line 640 dan set width:100%

Get Url in phtml files

Get URL
<?php echo Mage::getUrl('about-us'); ?>

Get Base Url :
<?php echo Mage::getBaseUrl(); ?>

Get Base Url ada link tambahan :
<?php echo Mage::getBaseUrl(); ?>customer/account/login ?>

Get Skin Url :
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?>
(a) Unsecure Skin Url :
<?php echo $this->getSkinUrl('images/imagename.jpg'); ?>
(b) Secure Skin Url :
<?php echo $this->getSkinUrl('images/imagename.gif', array('_secure'=>true)); ?>

Get Media Url :
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); ?>

Get Media JS:
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); ?>

Get Store Url : 
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>

Get Current Url:
<?php echp Mage::helper('core/url')->getCurrentUrl(); ?>

Get Url in cms pages or static blocks

Get Base Url :
{{store url=""}}

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

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

Get Store Url :
{{store url='mypage.html'}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment