Thursday, August 16, 2012

Magento:: delete all Custom Option by sql



>>      SET FOREIGN_KEY_CHECKS=0;

         TRUNCATE TABLE `catalog_product_option`;
         TRUNCATE TABLE `catalog_product_option_price`;
         TRUNCATE TABLE `catalog_product_option_title`;
         TRUNCATE TABLE `catalog_product_option_type_price`;
         TRUNCATE TABLE `catalog_product_option_type_title`;
         TRUNCATE TABLE `catalog_product_option_type_value`;
       
         SET FOREIGN_KEY_CHECKS=1;
   
                  ***********         Good Luck        **********


Magento:: add javascript in admin form


>>    $eventElem=$fieldset->addField('nocode', 'checkbox', array(
                'label' => Mage::helper('customer')->__('Event Element'),
                'name'  => 'eventelem',
                'id'    => 'eventelem',
                'value'=>1,
                'onclick'=>'modifyTargetElement(this)',
            ));

        $eventElem->setAfterElementHtml('<script>
            function modifyTargetElement(checkboxElem){
                if(checkboxElem.checked){
                    $("target_element").disabled=true;
                }
                else{
                    $("target_element").disabled=false;
                }
            }
        </script>');
   
                  ***********         Good Luck        **********


Magento:: Change items count in List page for every category


>> Go to the admin Category. On the custom design tab in Custom Layout Update section place the follwing code:
         <reference name="product_list">
                  <action method="setTemplate"><template>catalog/product/list-only.phtml</template></action>
         </reference>
       
         <reference name="product_list_toolbar">
                  <action method="setDefaultListPerPage"><limit>20</limit></action>
                  <action method="addPagerLimit"><mode>list</mode><limit>20</limit></action>
                  <action method="addPagerLimit"><mode>list</mode><limit>40</limit></action>
                  <action method="addPagerLimit"><mode>list</mode><limit>60</limit></action>
                  <action method="addPagerLimit"><mode>list</mode><limit>80</limit></action>
                 
                  <action method="setDefaultGridPerPage"><limit>20</limit></action>
                  <action method="addPagerLimit"><mode>grid</mode><limit>20</limit></action>
                  <action method="addPagerLimit"><mode>grid</mode><limit>60</limit></action>
                  <action method="addPagerLimit"><mode>grid</mode><limit>90</limit></action>
                  <action method="disableViewSwitcher" />
         </reference>


  >>  Sometime you need to customize a product listing page. But others will be as usual.
Using this code you can call a separate page for list, toolbar, pager as follows:

<reference name="product_list">
      <action method="setTemplate"><template>vendor/classified.phtml</template></action>
</reference>
<reference name="product_list_toolbar">
      <action method="setTemplate"><template>vendor/toolbar.phtml</template></action>
</reference>
<reference name="product_list_toolbar_pager">
      <action method="setTemplate"><template>vendor/pager.phtml</template></action>
</reference>


>>  You can also change the Pager Frame length as you want. By default it set to 5.
e.g. Prev 1 2 3 4 5 Next
You can also manage it from Admin=>System=>Configuration=>Design=>Pagination=> Set value in Pagination Frame. You can do it in your new template which you have set with the above xml code.
Using this code in template/page/html/pager.phtml you can change the page frame.

<?php $this->setFrameLength(8); ?>


   
   
                  ***********         Good Luck        **********


Magento:: New module OR link in customer dashboard


:: create a new module to add a new link in My Dashboard and then showing some information ::

    >>  Using 'Magento Module Creator' I just create a new module named 'custommodule'

         Now if you want to bring this new module in the customer account dashboard (in the navigation panel) as well
       
         First edit the custommodule.xml file in app/design/frontend/default/default/layout/
       
         Previous content will be like as
       
         <?xml version="1.0"?>
         <layout version="0.1.0">
         <default>
         </default>
         <custommodule_index_index>
         <reference name="content">
         <block type="custommodule/custommodule" name="custommodule" template="custommodule/custommodule.phtml" />
         </reference>
         </custommodule_index_index>
         </layout>
       
         Replace with =================================
       
         <?xml version="1.0"?>
         <layout version="0.1.0">
         <default>
         </default>
       
         <customer_account>
         <reference name="customer_account_navigation">
         <action method="addLink" translate="label" module="custommodule"><name>custommodule</name><path>custommodule/</path><label>Custom Module</label></action>
         </reference>
         </customer_account>
       
         <customer_account_index>
         <reference name="right">
         <action method="unsetChild"><name>custommodule</name></action>
         </reference>
         </customer_account_index>
       
         <custommodule_index_index>
         <update handle="customer_account"/>
         <reference name="content">
         <block type="custommodule/custommodule" name="custommodule" template="custommodule/custommodule.phtml" />
         </reference>
         <reference name="right">
         <action method="unsetChild"><name>custommodule</name></action>
         </reference>
         </custommodule_index_index>
         </layout>
       
                 
                           ***********         Good Luck        **********


Re Index programmatically Magento::


>> if you want to reindex "Category Products" only then you can do as follows:-
         $process = Mage::getModel('index/process')->load(6);
         $process->reindexAll();
       
         If you want to reindex all data then you can loop through these indices and then reindex them:-
         for ($i = 1; $i <= 9; $i++) {
             $process = Mage::getModel('index/process')->load($i);
             $process->reindexAll();
         }


Add related products to order success page Magento::


Suppose you want to show the related products of the products that ordered. In the order success page you will see those related products. lets do this & enjoy :

>> Create a block in checkout.xml
    <reference name="right">
            <block type="catalog/product_list_relatedsuccess" name="catalog.product.relatedsuccess" before="-" template="catalog/product/list/related.phtml"/>
        </reference>
>> Then create the Relatedsuccess.php page copy from Related.php under app/code/core/Mage/Catalog/Block/Product/List

>> Change the class name Mage_Catalog_Block_Product_List_Related to Mage_Catalog_Block_Product_List_Relatedsuccess

>> Then find this method _prepareData()  and replace with following...
    protected function _prepareData()
        {
            $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
        $order = Mage::getModel('sales/order');
        $order->loadByIncrementId($order_id);
        $items = $order->getAllItems();
        $relIds = array();
        foreach($items as $_item){
            $relprodColl = Mage::getModel("catalog/product")->load($_item->getProductId())->getRelatedProductCollection();
            foreach($relprodColl as $prod){
                array_push($relIds, $prod->getId());
            }
        }
        $this->_itemCollection = Mage::getSingleton('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => array_unique($relIds)));

            return $this;
       }

>> And load the product in the related.phtml page to get all contents.   


Tuesday, August 7, 2012

Create simple image slider using jQuery


<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var speed = 1000;    // sliding speed
var show  = 5;
var img_width = 125;    // Adjust the width here if you change the width of li......



jQuery(document).ready(function(){
    var count = 1;
    var size = jQuery("#slideshow ul>li").size();
    var liwidth     = img_width;
    /*var liwidth      = jQuery("#slideshow ul>li").width();
    var limarginL = parseInt(jQuery("#slideshow ul>li").css("marginLeft"));
    var limarginR = parseInt(jQuery("#slideshow ul>li").css("marginRight"));
    liwidth = liwidth + limarginL + limarginR;*/
    var ul      = jQuery("#slideshow ul");
    var width = size*liwidth;
    var margin = -41;
   
    ul.css({width : width, marginLeft : margin});
    jQuery("#slideshow ul").parent().css("width", show * liwidth);
    if(show >= size){
            jQuery("#slideshow a.previous").addClass("disable");
            jQuery("#slideshow a.next").addClass("disable");
    }
    jQuery("#slideshow a.previous").click(function(){
        if(count < size-show){
            ul.animate({marginLeft : margin -= liwidth},speed);   
            count++;
        }
    });
    jQuery("#slideshow a.next").click(function(){
        if(count > 1){
            ul.animate({marginLeft : margin += liwidth},speed);
            count--;
        }
    });
});

</script>
<style type="text/css">

#slideshow { position:absolute; background-color:#CCC; width:900px;}
#slideshow .disable{ display:none;}
.slideshow-box {
    margin: 0 auto;
    overflow: hidden;
    padding-top: 2px;
    position: relative;
    width: 790px;
}
#slideshow li{
    float: left;
    margin:0 2px;
    text-align: center;
    width: 121px;
    height: 100px;
    background-color:#FFFFFF;
}
#slideshow ul{
    overflow:hidden;
    height: 100px;
    width: 800px;
}
#slideshow a.previous{
    float:left;
    top:24px;
    position:relative;
}
#slideshow a.next{
    float:right;
    bottom:36px;
    position:relative;
}
</style>

<div id="slideshow" class="slideshow">
    <a href="#" class="previous">Previous</a>
    <div class="slideshow-box">
        <ul>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
        </ul>
    </div>
    <a href="#" class="next">Next</a>
</div>