PHP, Magento, Codigniter, Opencart and Wordpress Developer. Contact for school and college projects on PHP, Codiegniter, Wordpress, Mysql etc.
Friday, 5 February 2016
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)