Tuesday, 4 December 2012

How To call Shop By brand in magento


 first you make one phtml file path is app/design/frontend/base/default/template/catalog/navigation/vert_brand.phtml

put below code in this phtml file

<div class="leftbrand_menu">
             <?php
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($product->getResource()->getTypeId())->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
?>
<ul id="manufacturer_list"><?php foreach ($manufacturers as $manufacturer): ?>
<li><a href="<?php echo $this->getUrl('shop-by-brand')."?manufacturer=".$manufacturer['value'] ?>"><?php echo $manufacturer['label'] ?></a>
</li>
<?php endforeach; ?>   </ul>
            </div>

call this page in left side so open  catalog.xml file inleft part put below xml

<block type="catalog/navigation" name="catalog.vertnav" template="catalog/navigation/vert_brand.phtml" />

and after  make a cms page like brand

in this page in content part put below code

{{block type="catalog/product_list" template="catalog/product/shop_by_brand.phtml"}}

put identifier(url key) is shop-by-brand in the page.and last one make a another phtml page path is
         app/design/frontend/base/default/template/catalog/product/shop_by_brand.phtml

put below code

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?php
    $bid = $_GET['manufacturer']; // the brand / manufacturer ID
    $products = Mage::getModel('catalog/product')->getCollection();
    $products->addAttributeToFilter('manufacturer', array('in' => array($bid)));
    $products->addAttributeToSelect('*');
    $products->load();   
    ?>





<div class="page-title category-title">
<h1><?php echo $this->__('Shop By') ?>
<?php $aaa = $_REQUEST['manufacturer']; ?>

<?php
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($product->getResource()->getTypeId())->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
foreach ($manufacturers as $manufacturer): ?>
<?php $bbb = $manufacturer['value'];

if($aaa  ==  $bbb)
{
echo $manufacturer['label'];
}
 ?>

<?php endforeach; ?> <?php echo $this->__('Brand') ?></h1>
</div>


<?php if(!$products->count()): ?>
<p class="note-msg">
<?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">


    <?php echo $this->getToolbarHtml() ?>
    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($products as $_product): ?>
        <li class="item<?php if( ++$_iterator == sizeof($products) ): ?> last<?php endif; ?>">
            <?php // Product Image ?>
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                   
                    <h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
                    <?php /*?><h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2><?php */?>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php endif; ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <?php if($_product->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <div class="desc std">
                    <?php echo nl2br($_product->getShortDescription()) ?>
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><small><?php echo $this->__('Learn More') ?></small></a>
                        <?php /*?><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a><?php */?>
                    </div>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <?php else: ?>

    <?php // Grid Mode ?>

    <?php $_collectionSize = $products->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($products as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                <?php /*?><h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2><?php */?>
                <h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <div class="actions">
                    <?php if($_product->isSaleable()): ?>
                        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php /*?><?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?><?php */?>
                    </ul>
                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>

    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>


Wednesday, 21 November 2012

Quantity Box in the Category Products Listing Page in magento

Your Magento product ordering might seem a long process to some business owners, so we thought of making it simple, so that users can directly enter the quantity in the products listing area and click on ADD TO CART and checkout.
So, here is how you can do that.

Goto /app/design/frontend/default/your-theme/template/catalog/product/list.phtml
Open the file on a code editor and find this line,

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" onClick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

Just replace it with,

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
  <?php if(!$_product->isGrouped()): ?>
  <label for="qty"><?php echo $this->__('Qty') ?>:</label>
  <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
  <?php endif; ?>
  <button type="button" onClick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>

Wednesday, 31 October 2012

Magento : useful functions list

General functions

Function
$this->getRequest()->getServer(‘HTTP_REFERER’);

Product related functions

Function
$product->getName()
$product->getSku()
Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($_product)->getQty()
$product->getResource()->getAttribute(‘color’)->getFrontend()->getValue($product)
$product->isSaleable()
$product->isisAvailable()
Mage::getModel(‘catalogrule/rule’)->calcProductPriceRule($product,$product->getPrice())
$product->getTierPrice(1)

Newsletter related functions

Function
$subscriber = Mage::getModel(‘newsletter/subscriber’);
$subscriber->subscribe($user_mail);

Cache

Function
$tags = array(Mage_Catalog_Model_Category::CACHE_TAG); //Category block tag
Mage::app()->cleanCache($tags)

Product images

Function
$_product->getMediaGalleryImages()->getItemByColumnValue(‘label’, ‘LABEL_NAME’)->getUrl()

Customer related functions

Function
$this->helper(‘customer’)->isLoggedIn()

Magento: Very Useful Collection Functions

/**
 * Get Zend_Db_Select instance
 */
$collection->getSelect();
 
/**
 * Get collection size
 */
$collection->getSelect()->getSize();
 
/**
 * Get sql select string or object
 */
$collection->getSelect()->getSelectSql();
 
/**
 * Add select order
 */
$collection->getSelect()->setOrder($field, $direction);
 
/**
 * Add field filter to collection
 *
 * If $attribute is an array will add OR condition with following format:
 * array(
 *     array('attribute'=>'firstname', 'like'=>'test%'),
 *     array('attribute'=>'lastname', 'like'=>'test%'),
 * )
 */
$collection->getSelect()->setOrder($field, $condition);
 
/**
 * Set select distinct
 */
$collection->getSelect()->distinct($flag);
 
/**
 * Get all data array for collection
 */
$collection->getSelect()->getData();
 
/**
 * Reset loaded for collection data array
 */
$collection->getSelect()->resetData();
 
/**
 * Print and/or log query
 */
$collection->getSelect()->printLogQuery(true, true);
More functions below:-
Varien_Data_Collection_Db class extends Varien_Data_Collection class. Here are some more functions present in Varien_Data_Collection class:-
/**
 * Get current collection page
 */
$collection->getSelect()->getCurPage();
 
/**
 * Retrieve collection last page number
 */
$collection->getSelect()->getLastPageNumber();
 
/**
 * Retrieve collection page size
 */
$collection->getSelect()->getPageSize();
 
/**
 * Retrieve collection all items count
 */
$collection->getSelect()->getSize();
 
/**
 * Retrieve collection first item
 */
$collection->getSelect()->getFirstItem();
 
/**
 * Retrieve collection last item
 */
$collection->getSelect()->getLastItem();
 
/**
 * Retrieve collection items
 */
$collection->getSelect()->getItems();
 
/**
 * Clear collection
 */
$collection->getSelect()->clear();
You can also use the select functions as present in Zend_Db_Select class. This class file is present in lib/Zend/Db/Select.php

Tuesday, 9 October 2012

Magento :: get URL paths for skin, media, Js OR base URL

If anyone of you facing problems to fetch the Magento URL paths of  skin, media, Js or simple base URL of Magento while customization/programming, then following lines should be helpful for you:
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
//http://magento.demo/js/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
//http://magento.demo/index.php/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
//http://magento.demo/media/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
//http://magento.demo/skin/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
//http://magento.demo/

Wednesday, 26 September 2012

Change any page title in Magento

In page/html/head.phtml template replace default

<title>< ?php echo $this->getTitle() ?></title>
with
<title>
<?php echo ($this->getForcedTitle()) ? Mage::getStoreConfig('design/head/title_prefix').' '.$this->getForcedTitle().' '.Mage::getStoreConfig('design/head/title_suffix') : $this->getTitle() ?>
</title>


and now just set “forced” title for pages through layout files

<reference name="head">
<action method="setForcedTitle"><title>Account Dashboard</title></action></reference>
Example for My Account page in layout/customer.xml:
<customer_account>
<reference name="head">
<action method=”setForcedTitle”><title>Account Dashboard</title></action>
</reference>
…
</customer_account>

Remove ‘My Orders’ box in magento

Try to look into sales.xml:

<customer_account>
        <!-- 
Mage_Sales -->
        <
reference name="customer_account_navigation">
            <
action method="addLink" translate="label" module="sales"><name>orders</name><path>sales/order/history/</path><label>My Orders</label></action>
        </
reference>

    </
customer_account>