Category Archives: Magento

How To Add A JS File Via Layout Block For Magento

How to add a custom or third JS file via layout block for Magento

You can use “action” element with “method” attribute from your Magento template XML file or backend – Page Layout (CMS) / Custom Design (Category)/ Custom Layout Update (Product) to append a custom or third JS file for your Magento

<reference name="blockname">
    <action method="addItem">
        <type>skin_js</type>
        <name>js/file.js</name>
        <params />
    </action>
</reference>

I Have Enabled Magento 1.9 Cache But Cache Folder Still Empty

I have enabled My Magento 1.9 store’s cache feature, however when I was checking the cache folder e.g var/cache, nothing in there. Its empty.

1, If you are using different cache storage like Memcached, Redis for your Magento 1.9 store, the cache data will not be saved in var/cache folder

2. Your var/cache folder was not set to correct write permission, so Magento can not write cache files to var/cache folder

How To Create A New Magento Admin Account Programmatically

I would like to create a new Magento admin account, How can I do it programmatically

You need to use ‘admin/user’ model to create a new admin account and assign Magento role to new Magento admin account

$user = Mage::getModel('admin/user')->setData(array(
    'username'  => 'adminusername',
    'firstname' => 'admin first name',
    'lastname'  => 'admin last name',
    'email'     => 'admin@example.com',
    'password'  => 'password',
    'is_active' => 1
))->save();

$user->setRoleIds(array(1)) //Administrator role id is 1
->setRoleUserId($user->getUserId())
->saveRelations();

How Can I Get Magento Upsell Products By Product Id Programatically

How can I get Magento upsell products list if only have product id

Have to load Magento product object first and call “getUpSellProductCollection” method to retrieve Magento upsell products list

$product_id = 1;
$pobject = Mage::getModel('catalog/product');
$product = $pobject->load($product_id);
$upsell_product = $product->getUpSellProductCollection()->addAttributeToSort('position', Varien_Db_Select::SQL_ASC)->addStoreFilter();

How Can I Get Magento SEO Friendly Product URL

I tried to use getProductUrl to get Magento product url, but it returns SEO unfriendly url. How can I retrieve the SEO friendly URL of a Magento product

You can use method “getUrlPath” to get the SEO friendly URL of a Magento product

/** Load Magento product by ID **/

$_product = Mage::getModel('catalog/product')->load($productID);
$url = $_product->getUrlPath();