Showing posts with label get. Show all posts
Showing posts with label get. Show all posts

Wednesday, April 11, 2012

Thursday, March 8, 2012

How to get special price end date in magento?

Here is the code to get special price end date in magento.
$this->formatDate($product->getSpecialToDate())

How to get special price or offer price in magento?

Here is the code to get special price in magento.
$price = $_product->getPrice();
$specialprice = $_product->getFinalPrice();
if($specialprice != $price)
{
 //your stuff here
 echo $specialprice;
}

Monday, October 17, 2011

How to get products available stock quantity in magento?

Here is the code to get produts stock quantity. Place this code in your view.phtml file.
echo $qtyStock = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

Monday, September 19, 2011

How to get magento admin username, id, email and password?

Here is a quick code to get the admin user’s data (id, username, email, password, etc).
$user = Mage::getSingleton('admin/session')->getData();
$userId = $user->getUser()->getUserId();
$userEmail = $user->getUser()->getEmail();
$userFirstname = $user->getUser()->getFirstname();
$userLastname = $user->getUser()->getLastname();
$userUsername = $user->getUser()->getUsername();
$userPassword = $user->getUser()->getPassword();
Hope this helps. Thanks.

How to get configurable products attributes / super attributes details in magento?

   $productId = $_product->getId();
   $product=Mage::getModel("catalog/product")->load($prodcutId);
 
    /**
     * Get Configurable Type Product Instace and get Configurable attributes collection
     */
    $configurableAttributeCollection=$product->getTypeInstance()->getConfigurableAttributes();
 
    /**
     * Use the collection to get the desired values of attribute
     */
    foreach($configurableAttributeCollection as $attribute){
        echo "Attr-Code:".$attribute->getProductAttribute()->getAttributeCode()."
"; echo "Attr-Label:".$attribute->getProductAttribute()->getFrontend()->getLabel()."
"; echo "Attr-Id:".$attribute->getProductAttribute()->getId()."
"; }

Wednesday, September 14, 2011

How to get Parent category id in Magento?

Here is the code to get parent category id.
$current_category = Mage::registry('current_category');
echo $parent_id = $current_category->parent_id; 

Magento how to get category id in product page?

<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
    <?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
    <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>
<?php endforeach; ?> 
This will load and link all of the categories that the product is found in.

Saturday, September 10, 2011

How to get product collection based on attribute (manufacturer, brand) values in magento?

Here is the code to get products based on attribute values. For example here I used to show products based on attribute "brand". In brand attribute I have values nike, adidas. 11 is the code for nike. I here used to display only nike products.
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToFilter('brand', array('in' => array(11)));
$_productCollection->addAttributeToSelect('*');
$_productCollection->load(); 

Friday, September 9, 2011

How to get magento skin url of images?

getSkinUrl() function is used to get the image location. For example, If you want to get your image location "skin/frontend/default/Your theme/images/image.jpg" use the below code.

$this->getSkinUrl('images/image.jpg');

Monday, May 9, 2011

Get Order Increment Id in Magento

$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('sales/order')->getLastOrderId());
$lastOrderId = $order->getIncrementId();
Last real order id
Mage::getSingleton('checkout/session')->getLastRealOrderId();