Pages

Saturday 30 March 2013

Show customer in front-end

Follow my steps for showing our customer in front-end:
First of all create one file in our directory:
app/design/frontend/ [ base/default]  /Theme.../template/catalog/product/customers.phtml
And past bellow code:




<?php
function getcustomers() {
 /* Magento's Mage.php path 
  * Mage Enabler users may skip these lines
  */
 // require_once ("../magento/app/Mage.php");
Mage::App('base'); 
 umask(0);
 Mage::app("default");
 /* Magento's Mage.php path */
 
 /* Get customer model, run a query */
 $collection = Mage::getModel('customer/customer')
      ->getCollection()
      ->addAttributeToSelect('*');
 
 $result = array();
 foreach ($collection as $customer) {
  $result[] = $customer->toArray();
 }
 
 return $result;
}
?>
<html>
<head>
<title>Customers</title>
<style>
table {
 border-collapse: collapse;
}
td {
 padding: 5px;
 border: 1px solid #000000;
}
</style>
</head>
<body>
<table>
<tr>
 <td>ID</td>
 <td>Lastname</td>
 <td>Firstname</td>
 <td>Email</td>
 <td>Is Active?</td>
 <td>Date Created</td>
 <td>Date Updated</td>
</tr>
<?php
$result = getcustomers();
if(count($result) > 0){
 foreach($result as $key => $value){
  echo "<tr>";
   echo "<td>".$value['entity_id']."</td>";
   echo "<td>".$value['lastname']."</td>";
   echo "<td>".$value['firstname']."</td>";
   echo "<td>".$value['email']."</td>";
   echo "<td>";
   echo $value['is_active'] == 1 ? "Yes" : "No";
   echo "</td>";
   echo "<td>".$value['created_at']."</td>";
   echo "<td>".$value['updated_at']."</td>";
  echo "</tr>";
 }
}else{
 echo "<tr><td colspan=\"7\">No records found</td></tr>";
}
?>
</table>
</body>
</html>
 
How to call all customer in front-end   Using CMS page :
{{block type="catalog/product" template="catalog/product/customers.phtml"}}

Also we can call customers using static block:
{{block type="catalog/product" template="catalog/product/customers.phtml"}}
--------------------------------------------------------
Use code and Enjoy.......:) 
 

Friday 29 March 2013

Show all products in magento

Please follow my Instructions for showing all products in magento

You have to create some directories for it.

1) Add Special.php on the following location :
app/code/core/Mage/Catalog/Block/Product/Special.php

2) Create Folder Special and Add Toolbar.php on the following location :
app/code/core/Mage/Catalog/Block/Product/Special/Toolbar.php

3) After you are done with this you have to now move to
/app/design/frontend/YourTheme/YourTheme/template/catalog/product
folder and add special.phtml

4) Now you can go to Admin Panel->CMS->Pages create a New Page and in the content paste this line and call your cms page also you can call using static block.
{{block type="catalog/product_special" template="catalog/product/special.phtml"}} 

---------------------------------------------------------------------------------
First step:
app/code/core/Mage/Catalog/Block/Product/Special.php 
Create Special.php and past bellow code:
===============================
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * New products block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_Abstract
{
    protected $_productsCount = null;

    protected $_defaultToolbarBlock = "catalog/product_list_toolbar";
     
    const DEFAULT_PRODUCTS_COUNT = "";

    protected function _beforeToHtml()
    {    
        $toolbar = $this->getToolbarBlock();
         
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        
        $collection = Mage::getResourceModel("catalog/product_collection");
        Mage::getSingleton("catalog/product_status")->addVisibleFilterToCollection($collection);
        Mage::getSingleton("catalog/product_visibility")->addVisibleInCatalogFilterToCollection($collection);
        
        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()

            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;
        $this->setProductCollection($collection);
        
         if ($orders = $this->getAvailableOrders()) {
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }

        // set collection to tollbar and apply sort
        $toolbar->setCollection($collection);

        $this->setChild("toolbar", $toolbar);
        Mage::dispatchEvent("catalog_block_product_list_collection", array(
            "collection"=>$collection,
        ));
        
        return parent::_beforeToHtml();
    }
    
    public function getToolbarBlock()
    {
        if ($blockName = $this->getToolbarBlockName()) {
            if ($block = $this->getLayout()->getBlock($blockName)) {
                return $block;
            }
        }
        $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
        return $block;
    }
    
    public function setProductsCount($count)
    {
        $this->_productsCount = $count;
        return $this;
    }

    public function getProductsCount()
    {
        if (null === $this->_productsCount) {
            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
        }
        return $this->_productsCount;
    }
    
    
     public function getMode()
    {
        return $this->getChild("toolbar")->getCurrentMode();
    }

    public function getToolbarHtml()
    {
        return $this->getChildHtml("toolbar");
    }
}  

===========================================
Second step:

app/code/core/Mage/Catalog/Block/Product/Special/Toolbar.php 
Got to this directory we have to create Special name folder and in this folder we have to create one php file Toolbar.php   and past bellow code:
========================================
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * New products block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_Abstract
{
    protected $_productsCount = null;

    protected $_defaultToolbarBlock = "catalog/product_list_toolbar";
     
    const DEFAULT_PRODUCTS_COUNT = "";

    protected function _beforeToHtml()
    {    
        $toolbar = $this->getToolbarBlock();
         
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        
        $collection = Mage::getResourceModel("catalog/product_collection");
        Mage::getSingleton("catalog/product_status")->addVisibleFilterToCollection($collection);
        Mage::getSingleton("catalog/product_visibility")->addVisibleInCatalogFilterToCollection($collection);
        
        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()

            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;
        $this->setProductCollection($collection);
        
         if ($orders = $this->getAvailableOrders()) {
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }

        // set collection to tollbar and apply sort
        $toolbar->setCollection($collection);

        $this->setChild("toolbar", $toolbar);
        Mage::dispatchEvent("catalog_block_product_list_collection", array(
            "collection"=>$collection,
        ));
        
        return parent::_beforeToHtml();
    }
    
    public function getToolbarBlock()
    {
        if ($blockName = $this->getToolbarBlockName()) {
            if ($block = $this->getLayout()->getBlock($blockName)) {
                return $block;
            }
        }
        $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
        return $block;
    }
    
    public function setProductsCount($count)
    {
        $this->_productsCount = $count;
        return $this;
    }

    public function getProductsCount()
    {
        if (null === $this->_productsCount) {
            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
        }
        return $this->_productsCount;
    }
    
    
     public function getMode()
    {
        return $this->getChild("toolbar")->getCurrentMode();
    }

    public function getToolbarHtml()
    {
        return $this->getChildHtml("toolbar");
    }
}  

===================================
Third Step:

/app/design/frontend/YourTheme/YourTheme/template/catalog/product
folder and Create special.phtml   and past bellow code:
-------------------------------------------------------------------------------------------------

<?php $_productCollection=$this->getProductCollection() ?>
<div class="indent-col-main specials">
<div class="page-title category-title">
        <h1>All Products</h1>
</div>
<?php if(!$_productCollection->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 ($_productCollection as $_product): ?>
        <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
            <?php // Product Image ?>
            <a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(211, 211); ?>" width="211" height="211" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>

            <?php // Product description ?>
            <div class="product-shop">
            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName())?></a></h3>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product) ?>
                <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <?php if($_product->isSaleable()): ?>
                <p><button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button></p>
                <?php else: ?>
                <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?><br class="clear-block" />
                <div class="desc std">
                    <?php //echo nl2br($_product->getShortDescription()) ?>
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->__('Learn More') ?></a>
                </div>
                <div class="block-add-to-links"><ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a class="wishlist-link" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?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 ?>"><?php //echo $this->__('Add to Compare') ?></a></li>-->
                    <?php //endif; ?>
                </ul></div>
            </div>
            <div class="clear-block"></div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <?php endif; ?>
    <?php echo $this->getToolbarHtml() ?>
</div>
<?php endif; ?>
</div>

======================================
Finally copy and past this code in CMS page or Static block as you like
----------------------------------------------------------------------------
{{block type="catalog/product_special" template="catalog/product/special.phtml"}}  
----------------------------------------------------------
Now call your cms page or static block...it's default working in list mode not Grid mode if you want to also grid mode than we have to edit it according to grid 
Use code and enjoy.....:)

Language convert | products name change according to selected language

How to change products name, description etc. according to selected language.
Pollow the path: app/design/frontend/base/default/template/page/switch/ language.phtml

Replace with existing code:

<?php
/**
 * Language switcher template
 *
 * @see Mage_Page_Block_Switch
 */
?>
<div class="form-language">
    <label for="select-language"><?php echo $this->__('Your Language:') ?> </label>

<!-- Google Element Translator Styling-->
        <style>
            .goog-te-combo{width: px !important;}
            .goog-te-balloon-frame{display: none !important;}
            font{background: transparent !important;}
            a font:hover{ color:  !important;}
            #google_translate_element{height: 26px !important;overflow: hidden !important;}
            .goog-te-banner-frame{display: none !important;}
            body{top: 0px !important;}
        </style>

<!-- Google Element Translator -->
    <div id="google_language_drop">
        <div id="google_translate_element" class="-blank"></div>
            <script>
                function googleTranslateElementInit() {
                    new google.translate.TranslateElement({
                        includedLanguages: 'en,de,af,sq,ar,hy,az,eu,be,bg,ca,zh-CN,zh-TW,hr,cs,da,nl,et,tl,fi,fr,gl,ka,el,ht,iw,hi,hu,is,id,ga,it,ja,ko,la,lv,lt,mk,ms,mt,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sw,sv,th,tr,uk,ur,vi,cy,yi',
                        pageLanguage: '<?php echo $this->__('af') ?>',
                        gaTrack: true,
                        gaId: 'UA-12345678-1'
                    }, 'google_translate_element');
                }
            </script>
        <script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
    </div>
</div>

Thursday 28 March 2013

Re Indexing problem | magento indexing | Re-indexing required

Here is the solution for all re-indexing But you have to follow my step.

===========================================
DROP TABLE IF EXISTS `index_process_event`;
DROP TABLE IF EXISTS `index_event`;
DROP TABLE IF EXISTS `index_process`;

//first step Complete///////

CREATE TABLE `index_event` (
`event_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`type` VARCHAR(64) NOT NULL,
`entity` VARCHAR(64) NOT NULL,
`entity_pk` BIGINT(20) DEFAULT NULL,
`created_at` DATETIME NOT NULL,
`old_data` MEDIUMTEXT,
`new_data` MEDIUMTEXT,
PRIMARY KEY (`event_id`),
UNIQUE KEY `IDX_UNIQUE_EVENT` (`type`,`entity`,`entity_pk`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

CREATE TABLE `index_process` (
`process_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`indexer_code` VARCHAR(32) NOT NULL,
`status` ENUM('pending','working','require_reindex') NOT NULL DEFAULT 'pending',
`started_at` DATETIME DEFAULT NULL,
`ended_at` DATETIME DEFAULT NULL,
`mode` ENUM('real_time','manual') NOT NULL DEFAULT 'real_time',
PRIMARY KEY (`process_id`),
UNIQUE KEY `IDX_CODE` (`indexer_code`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

///second step complete//////////////////

INSERT INTO `index_process`(`process_id`,`indexer_code`,`status`,`started_at`,`ended_at`,`mode`) VALUES (1,'catalog_product_attribute','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(2,'catalog_product_price','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(3,'catalog_url','pending','2010-02-13 19:12:15','2010-02-13 19:12:15','real_time'),(4,'catalog_product_flat','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(5,'catalog_category_flat','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(6,'catalog_category_product','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(7,'catalogsearch_fulltext','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(8,'cataloginventory_stock','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time');

CREATE TABLE `index_process_event` (
`process_id` INT(10) UNSIGNED NOT NULL,
`event_id` BIGINT(20) UNSIGNED NOT NULL,
`status` ENUM('new','working','done','error') NOT NULL DEFAULT 'new',
PRIMARY KEY (`process_id`,`event_id`),
KEY `FK_INDEX_EVNT_PROCESS` (`event_id`),
CONSTRAINT `FK_INDEX_EVNT_PROCESS` FOREIGN KEY (`event_id`) REFERENCES `index_event` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_INDEX_PROCESS_EVENT` FOREIGN KEY (`process_id`) REFERENCES `index_process` (`process_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8;

///Third  step complete complete  //////////////////

Check now, Enjoy your self.....................:)