How to get current logged-in user information?
Posted by sumantechno in Magento on April 26, 2012
Use the following code snippet
$customer = Mage::getSingleton(‘customer/session’);
echo $customerId = $customer->getCustomer()->getId();
echo “<br>”;
echo $email = $customer->getCustomer()->getEmail();
echo “<br>”;
echo $firstName = $customer->getCustomer()->getFirstname();
echo “<br>”;
echo $lastName = $customer->getCustomer()->getLastname();
echo “<br>”;
echo $fullName = $firstName . ” ” . $lastName;
What is the difference between _redirect() and _forward() ?
Posted by sumantechno in Zend Framework on April 26, 2012
_forward():
It is used to internal redirection in the Zend Framework.
No new HTTP request object is created.It use the existing request object._forward() send every thing to another controller action of a module.
Complete signature of _forward() is
protected function _forward($action, $controller = null, $module = null, array $params = null)
_redirect():
It forward only the header so in case of this function new HTTP request object is created.
How to get all the values of a specific attribute in Magento ?
Posted by sumantechno in Magento on November 15, 2011
Check the following code snippet
<?php
$attributeInfo = Mage::getResourceModel(‘eav/entity_attribute_collection’)
->setCodeFilter(‘product_quality‘) //Attribute Code
->getFirstItem();
$attributeOptions = $attributeInfo->getSource()->getAllOptions(false);
?>
<?php foreach($attributeOptions as $item) {?>
<option value=”<?php echo $item['value'];?>”><?php echo $item['label']?></option>
<?php }?>
This code will show all the values of the attribute having “product_quality” attribute code as a drop down.
Just replace the arribute code.
How to get all subcategory under a category in magneto ?
Posted by sumantechno in Magento on August 10, 2011
Check the following code which will store all category information inside $categoryInformation array.
$category = Mage::getModel(‘catalog/category’);
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$categoryInformation=array();
if ($ids) {
foreach ($ids as $id) {
$cat = Mage::getModel(‘catalog/category’);
$cat->load($id);
$image=$cat->getImageUrl();
$category_name=$cat->getName();
$category_url = $cat->getUrl();
$totl_res=$category_name.”//**//”.$category_url.”//**//”.$image;
array_push($categoryInformation,$totl_res);
}
}
If you want immediate all the subcategory of category use the following code
$category = Mage::getModel(‘catalog/category’);->load(3); // YOU NEED TO CHANGE 3 TO THE ID OF YOUR CATEGORY
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$categoryInformation=array();
if ($ids) {
foreach ($ids as $id) {
$cat = Mage::getModel(‘catalog/category’);
$cat->load($id);
$image=$cat->getImageUrl();
$category_name=$cat->getName();
$category_url = $cat->getUrl();
$totl_res=$category_name.”//**//”.$category_url.”//**//”.$image;
array_push($categoryInformation,$totl_res);
}
}
How Remove “shop by” from the magneto store?
Posted by sumantechno in Magento on July 2, 2011
Solution:
Procedure:1
Comment out all the codes off the file “left.phtml” located in the current theme.
For default theme the location of the file is
“/app/design/frontend/default/default/template/catalog/navigation/left.phtml”
Procedure 2:
Comment out the following code from catalog.xml located in your current theme.
<reference name=”left”>
<block type=”catalog/navigation” name=”catalog.leftnav” after=”currency” template=”catalog/navigation/left.phtml”/>
</reference>
For default theme the location of the file is
“app/design/frontend/default/default/layout/catalog.xml”
How to show price only one time in the product details page in Magneto ?
Posted by sumantechno in Magento on June 18, 2011
Solution:
In some case in the product details page in Magento price is displayed two times.(Example:for simple product having custom option,for configurable product)
The price at the top of the page is generally displayed as part of the “product type data”. Check the file at template/catalog/product/view/type/simple.phtml.
In that page $this->getPriceHtml($_product); is responsible for displaying the top price in the product page.
So if you want to remove the top price remove $this->getPriceHtml($_product)from the simple.phtml.
The price at the bottom of the catalog page is a little more complicated. If you take a look at layout/catalog.xml, the price block (product.clone_prices) is added to the block product.info.options.wrapper.bottom, which is then added to product.info.container1 and product.info.container2. Depending on the product type, one of these will be echoed on the page. You can, however, just remove the line for product.clone_prices and that should remove the price.
How do you change number of product columns in the category page in Magento?
Posted by sumantechno in Magento on June 18, 2011
Solution:
We can change the column_count property is set in catalog.xml
Suppose i want 3 column in the calegory page ,corresponding changes in the catalog.xml
<action method=”setColumnCount”><count>3</count></action>
But you can set any value you want within list.phtml:
<?php $_columnCount = 4; ?>
For a specific category suppose i want 2 column
Then we can use the following code
<?php if ($this->getCategoryId() == 12) : ?>
<?php $_columnCount = 4; ?>
<?php else :?>
<?php $_columnCount = $this->getColumnCount(); ?> How to get the number of items in the cart in Magneto?
Posted by sumantechno in Magento on June 17, 2011
How to get the number of items in the cart in Magneto?
First of all the code for getting the number of items in the cart varies depending upon which version you are using. First try method 1,2,3.
If method 1,2,3 fails procedure 4 definitly will work.
Method1:
$cart = Mage::getSingleton(‘checkout/cart’)->getItemsCount();
echo ‘Number of cart items count: ‘ . $cart;
Method2:
$cart = Mage::helper(‘checkout/cart’)->getItemsCount();
echo ‘ Number of cart items count: ‘ . $cart;
Method3:
$cart = Mage::helper(‘checkout/cart’)->getCart()->getItemsCount();
echo ‘ Number of cart items count: ‘ . $cart;
Method 4:
This procedure will give all the necessary information of the producr in the cart
require_once ‘app/Mage.php’;
$session = Mage::getSingleton(‘checkout/session’);
$number_of_product=0;
foreach ($session->getQuote()->getAllItems() as $item)
{
$sku = $item->getSku() . “<br>”;
$name = $item->getName() . “<br>”;
$description= $item->getDescription() . “<br>”;
$quentity = $item->getQty() . “<br>”;
$price $item->getBaseCalculationPrice() . “<br>”;
$number_of_product=$number_of_product+1;
}
echo “Number of product in the cart”. $number_of_product
Why Magento use EAV database model ?
Posted by sumantechno in Magento on June 10, 2011
Answer:
In EAV(Entity-Attribute-Value) database model data is not stored in the single table. Data is stored in different small tables.
For example in magneto all the product information is not stored in a single table.
- product name is stored in catalog_product_entity_varchar table
- product id is stored in catalog_product_entity_int table
- product price is stored in catalog_product_entity_decimal table
Magento use this technique for storing category,CMS content,customer etc information.
EAV database model has following advantages
I. Gives more flexibility in accessing,retrieving,storing the data and attribute.
II. EAV model enables easy upgrade .
III. It gives developer more control over the attribute and data stored in the database.
What does dirname(__FILE__) and basename(dirname(__FILE__)) do?
Posted by sumantechno in Core PHP on May 12, 2011
dirname(__FILE__) :
dirname is a function in php which returns the full directory path of a file.
Example:
<?php
$file = “/htdocs/projects/testapplication/demotest.php”;
$path = dirname($file); //
?>
Output will be “/htdocs/projects/testapplication/”
__FILE__ is a constant in php which specifies the current running script.
So dirname(__FILE__) returns the full directory path of the current running script.
Example:
Suppose in “/htdocs/projects/testapplication/demotest.php” this file i specified dirname(__FILE__).
This will return “/htdocs/projects/testapplication/”.
basename(dirname(__FILE__)) :
The basename() command is normally used in conjunction with the dirname() function to strip the parent directory from a full file name. For example “/var/www/html/abc.txt” when passed through basename() would return abc.txt. basename() also works on directories. So, basename() on “/var/www/html” would return “html” since in Linux directories are files.
Example :
Imagine __FILE__ represents /var/www/html/index.php
<?php
echo dirname(__FILE__); // returns /var/www/html
echo basename(__FILE__); //returns index.php
echo basename(dirname(__FILE__)); //returns html
?>
