If you don’t want to show the ‘Add New’ button in the Grid. The Add New button is present in top right corner of Grid Page.
Rename ‘Add New’ button
Here are the steps to rename the ‘Add New’ text to anything you required (for example, ‘Add Report’):-
- Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
- Add the following code in the constructor of this file:-
$this->_addButtonLabel = Mage::helper('yourmodulename')->__('Add Report');
Remove ‘Add New’ button
Here are the steps to remove the ‘Add New’ button:-
- Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
- Add the following code in the constructor of this file (it should be just below the call to parent constructor):-
parent::__construct();
$this->_removeButton('add');
In edit.php
parent::__construct();
$this->_removeButton('delete');
$this->_removeButton('save');
$this->_removeButton('back');
in grid.php
parent::__construct();
$this->_removeButton('add');
Search This Blog
Tuesday, May 24, 2011
Monday, May 16, 2011
magento get last added item from session or get cart items from session
How to get all cart items from cart session in magento
$productid=Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
-----------OR----------------------------
$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
{
$productid = $item->getProductId();
$productsku = $item->getSku();
$productname = $item->getName();
$productqty = $item->getQty();
}
$productid=Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
-----------OR----------------------------
$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
{
$productid = $item->getProductId();
$productsku = $item->getSku();
$productname = $item->getName();
$productqty = $item->getQty();
}
Wednesday, May 11, 2011
Magento query to check for product visible or visibility and enable or is_enable
Magento query to check for product visible or visibility and enable or is_enable
$visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG);
$prod= Mage::getModel('catalog/product')->getCollection();
->addAttributeToFilter('visibility', $visibility);
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG);
$prod= Mage::getModel('catalog/product')->getCollection();
->addAttributeToFilter('visibility', $visibility);
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
Wednesday, April 27, 2011
Magento get last product or recent product added to cart or shopping cart
Magento get last product or recent product added to cart or shopping cart
Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
Tuesday, April 26, 2011
Add magento to wishlist code
a href="'.Mage::helper("wishlist")->getAddUrl($_product).'" class="link-cart">Add to Wishlist /a
or
if ($this->helper('wishlist')->isAllow()) :
a href="helper('wishlist')->getAddUrl($_product) ?>" class="link-cart">__('Add to Wishlist') ?> /a
endif;
or
if ($this->helper('wishlist')->isAllow()) :
a href="helper('wishlist')->getAddUrl($_product) ?>" class="link-cart">__('Add to Wishlist') ?> /a
endif;
Friday, April 22, 2011
Magento PHP Interview Questions And Answers
1) What are the different types of Errors in PHP?
Answer:
There are three basic types of runtime errors in PHP:
1. Notices: These are small, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although the default behavior can be changed.
2. Warnings: Warnings are more severe errors like attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.
2) Why Magento use EAV database model ?
Answer:
In EAV database model, data are stored in different smaller tables rather than storing 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 EAV database model for easy upgrade and development as this model gives more flexibility to play with data and attributes.
3) What is the difference between Mage::getSingletone() and Mage::getModel() in Magento
Answer:
Mage::getSingletone() always finds for an existing object if not then create that a new object but Mage::getModel() always creates a new object.
Answer:
There are three basic types of runtime errors in PHP:
1. Notices: These are small, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although the default behavior can be changed.
2. Warnings: Warnings are more severe errors like attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.
2) Why Magento use EAV database model ?
Answer:
In EAV database model, data are stored in different smaller tables rather than storing 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 EAV database model for easy upgrade and development as this model gives more flexibility to play with data and attributes.
3) What is the difference between Mage::getSingletone() and Mage::getModel() in Magento
Answer:
Mage::getSingletone() always finds for an existing object if not then create that a new object but Mage::getModel() always creates a new object.
Get Product ID and Product Name in Magento
load($productid); //getting product object for particular product id
echo $_product->getShortDescription(); //product's short description
echo $_product->getDescription(); // product's long description
echo $_product->getName(); //product name
echo $_product->getPrice(); //product's regular Price
echo $_product->getSpecialPrice(); //product's special Price
echo $_product->getProductUrl(); //product url
echo $_product->getImageUrl(); //product's image url
echo $_product->getSmallImageUrl(); //product's small image url
echo $_product->getThumbnailUrl(); //product's thumbnail image url
?>
------OR------------
getCollection(); //products collection
foreach ($collection as $product) //loop for getting products
{
$model->load($product->getId());
$pname = $model->getName();
if(strcmp($pname,$product_name)==0)
{
$id = $product->getId();
}
}
echo 'Required ID->'.$id; //id of product
?>
echo $_product->getShortDescription(); //product's short description
echo $_product->getDescription(); // product's long description
echo $_product->getName(); //product name
echo $_product->getPrice(); //product's regular Price
echo $_product->getSpecialPrice(); //product's special Price
echo $_product->getProductUrl(); //product url
echo $_product->getImageUrl(); //product's image url
echo $_product->getSmallImageUrl(); //product's small image url
echo $_product->getThumbnailUrl(); //product's thumbnail image url
?>
------OR------------
getCollection(); //products collection
foreach ($collection as $product) //loop for getting products
{
$model->load($product->getId());
$pname = $model->getName();
if(strcmp($pname,$product_name)==0)
{
$id = $product->getId();
}
}
echo 'Required ID->'.$id; //id of product
?>
Subscribe to:
Posts (Atom)