PHP, Magento, Codigniter, Opencart and Wordpress Developer. Contact for school and college projects on PHP, Codiegniter, Wordpress, Mysql etc.
Wednesday, 17 February 2016
Saturday, 13 February 2016
How to display products of particular category on Home Page in Magento
If you want to display products of the category on your home page, so first need the category ID. You can easily find category ID from
Magento Admin Panel -> Catalog -> Manage Categories
On the Categories page you click on the particular category from the menu on the left and the Category ID will be displayed at the top of the screen(right side). Copy this ID. For example, in the screen above the default category ID is 2.
Now, open the CMS -> Pages. Here, you see all pages list.
Open Home Page and click on Content tab (Left Side).
Paste the following code in text editor:
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
You can change the "category_id" according to your requirement.
Now you can save your page and all products of the category will be displayed on your home page.
In case the changes are not displayed on your home page you should clear your Magento Cache from your Admin Panel
System -> Cache Management
section.
Now, your products are displaying on Home page.
How to get category name by category id in Magento
Display category name by category id in Magento.
<?php
$categoryId = 5; // Change category id according to you
// display name and other detail of all category
$_category = Mage::getModel('catalog/category')->load($categoryId);
// category name
echo $categoryName = $_category->getName();
// category description
echo $categoryDescription = $_category->getDescription();
// category url
echo $categoryUrl = $_category->getUrl();
// category thumbnail
echo $categoryThumbnail = $_category->getThumbnail();
// category level
echo $categoryLevel = $_category->getLevel();
// parent category
echo $parentCategoryId = $_category->getParentId();
?>
Wednesday, 10 February 2016
How to Enable Template/Block Hints in Admin Panel in Magento
If you want to display template path hints in Magento Admin, there is no any setting for display template path hints in Magento Admin.
But you can do manually in database.
So, Just run this query in Database:
INSERT INTO core_config_data (scope, scope_id, path, value)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);
To disable them again, run this query:
UPDATE core_config_data set value = 0 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints';
UPDATE core_config_data set value = 0 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints_blocks';
To enable again run this query:
UPDATE core_config_data set value = 1 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints';
UPDATE core_config_data set value = 1 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints_blocks';
Here is a screenshot of the Cache Management page with hints turned on:
Saturday, 6 February 2016
How to add Scroll To Top button in Magento
Scroll To Top button in Magento
Open your header.phtml file and write below code:
<a href="#" class="scrollToTop">Scroll To Top</a>
<script type="text/javascript">
jQuery(document).ready(function($){
//Check to see if the window is top if not then display button
$(window).scroll(function()
{
if ($(this).scrollTop() > 100) {
$('.scrollToTop').fadeIn();
}
else
{
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function()
{
$('html, body').animate({scrollTop : 0},800);
return false;
});
});
</script>
Add style code in styles.css file.
<style>
.scrollToTop{
width:100px;
height:100px;
padding:10px;
text-align:center;
font-weight: bold;
color: #444;
text-decoration: none;
position:fixed;
top:75px;
right:40px;
display:none;
background: url('images/arrow_up.png') no-repeat 0px 20px;
}
.scrollToTop:hover{
text-decoration:none;
}
</style>
Note: Please Download image and upload in image folder.
Friday, 5 February 2016
How to get logged in customer's details by customer's id in Magento
If you want to display customer's details by customer's id in Magento.
You can use following code:
<?php
// Check if any customer is logged in or not
if (Mage::getSingleton('customer/session')->isLoggedIn())
{
// Load the customer's data
$customer = Mage::getSingleton('customer/session')->getCustomer();
$id =$customer->getId(); // To get Customer Id
//Get Details Using Customer Id
$customer = Mage::getModel('customer/customer')->load($id)->getData();
$customer->getName();
$customer->getEmail();
}
?>
Thursday, 4 February 2016
How to get logged in customer's details in Magento
If you want to get logged in customer's details in Magento.
You can use following code:
<?php
// Check if any customer is logged in or not
if (Mage::getSingleton('customer/session')->isLoggedIn())
{
// Load the customer's data
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getPrefix();
$customer->getName(); // Full Name
$customer->getFirstname(); // First Name
$customer->getMiddlename(); // Middle Name
$customer->getLastname(); // Last Name
$customer->getSuffix();
// All other customer data
$customer->getWebsiteId();
$customer->getEntityId();
$customer->getEntityTypeId();
$customer->getAttributeSetId();
$customer->getEmail();
$customer->getGroupId();
$customer->getStoreId();
$customer->getCreatedAt();
$customer->getUpdatedAt();
$customer->getIsActive();
$customer->getDisableAutoGroupChange();
$customer->getTaxvat();
$customer->getPasswordHash();
$customer->getCreatedIn();
$customer->getGender();
$customer->getDefaultBilling();
$customer->getDefaultShipping();
$customer->getDob();
$customer->getTaxClassId();
}
?>
Wednesday, 3 February 2016
How to get customer name, customer email on order success page in Magento
If you want to display customer name and email on order success page in Magento.
So use following code on success.phtml page
(/public_html/app/design/frontend/base/default/template/checkout/success.phtml)
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
echo $order->getCustomerName();
echo $order->getCustomerEmail();
?>
How to get custom attribute value in Magento
Display custom attribute value in Magento
When we get custom attribute value in Magento through simple way like:
<?php
echo $_product->getAttributeText('custom_attribute_code');
?>
Then we will get a fatal error (as following) , if the custom attribute is not already added.
" Fatal error: Call to a member function getSource() on a non-object in ...\app\code\core\Mage\Catalog\Model\Product.php on line 1388"
So we will use following code for get custom attribute value in Magento.
The following code will first check that the custom attribute are added or not in admin. If custom attribute are added then get its value.
<?php
$attribute = $_product->getResource()->getAttribute('custom_attribute_code');
if ($attribute)
{
echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}
?>
Subscribe to:
Posts (Atom)