Saturday, 23 April 2016

Magento : STOCK QUANTITY ON MAGENTO PRODUCT PAGE

Warning: This is a quick-n-dirty hack and will not work on all product types.

Instead of just showing the “in stock” and “out of stock” messages, we want to have an in-between message to show that stock levels are running low. This is easily done, by editing the following file:

app/design/frontend/base/default/template/catalog/product/view/type/default.phtml

We change the contents of the file to the following:

<?php
$_product = $this->getProduct();
$_quantity = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
?>

<?php if ($_product->isAvailable()): ?>
  <?php if ( intval($_quantity) < 10 ): ?>
    <p class="availability last-stock"><?php echo $this->__('Availability:') ?>
      <span><?php echo $this->__('Only '); echo $_quantity; echo $this->__(" left"); ?></span>
    </p>
  <?php else : ?>
    <p class="availability in-stock"><?php echo $this->__('Availability:') ?>
      <span><?php echo $this->__('In stock') ?></span>
    </p>
  <?php endif; ?>
<?php else: ?>
  <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?>
    <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>

<?php echo $this->getChildHtml('product_type_data_extra') ?>
<?php echo $this->getPriceHtml($_product) ?>


That’s it!

We just created a warning-type level once stock drops to less than 10 items. Meanwhile, both the “in-stock” and “out-of-stock” messages are preserved. This can be easily styled using CSS. Note we added the class “last-stock” to our new p-tag

Magento : Disable/ Remove “Estimate Shipping and Tax”

We can solve this issue two way.
First way :
Create local.xml file with below code and upload your theme layout folder
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<layout>
<checkout_cart_index>
<reference name=”content”>
<block name=”checkout.cart”>
<remove name=”checkout.cart.shipping”/>
</block>
</reference>
</checkout_cart_index>
</layout>
Second way :
Remove the following code from /app/design/frontend/yourtheme/layout/checkout.xml
<block type=”checkout/cart_shipping” name=”checkout.cart.shipping” as=”shipping” template=”checkout/cart/shipping.phtml”/>
Done! :)

Sunday, 20 March 2016

Magento : How to Rename the Attribute Code?

Connect to your Magento database using your favourite database GUI (PHPMyAdmin, HeidiSQL, MySQL Workbench, etc.).
Caution: backup your database
Go to the table eav_attribute and edit the column attribute_code. You can rename the attribute code here.
Once you have renamed the attribute code in the database, go to the Magento admin and re-index (System > Index Management) all indexes.

Magento : Get Logged In Customer’s Group ID

<?php
/* Check if customer is logged in */
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) :
    /* Get the logged in customer's group ID */
    $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    /* Check if the logged in customer's group ID matches with the ID you are after */
    /* Customer group IDs are listed against each group under Admin > Customers > Customer Groups */
    if($customerGroupId == 3) :
        echo 'Welcome Retailer';
    endif;
endif;
?>

You can also write static blocks or custom variables to contain group specific information. You can name the static block identifier based on the $customerGroupId and retrieve it on the front end.

Magento : Check if CMS Static Block is Enabled / Active

Static blocks in Magento are really useful. They offer an easy way to insert content into various parts of the template. You are only limited by your imagination. You can check if the static blocks are enabled, before printing them to screen.
<?php 
if(Mage::getModel('cms/block')->load('static-block-identifier')->getIsActive()) : 
    echo Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('static-block-identifier')->toHtml(); 
endif; 

?>

Magento : Get CMS Static Block Model Data (Title, Status, Content)

You can store template and HTML data in Magento’s static blocks. If you want to pull it into your PHTML templates, just call load up the model and use the data fields.

<?php
$staticBlock = Mage::getModel('cms/block')->load('static-block-identifier');
echo $staticBlock->getTitle();
echo $staticBlock->getIdentifier();
echo $staticBlock->getIsActive();
echo $staticBlock->getContent();

?>

Magento : Get Current Package Name and Theme Name

// To get the current package name of the Magento store / site
Mage::getSingleton('core/design_package')->getPackageName();

// To get the current theme of the Magento store / site
Mage::getSingleton('core/design_package')->getTheme('frontend');

// You can pass 'locale', 'layout', 'template', 'default', or 'skin' into the above function.