Pages

Monday 2 February 2015

Magento:: Scroll To Top functionality

Scroll To Top functionality in Magento
Open your header.phtml file and write below code..
<a title="Scroll To Top" class="scrollup" href="javascript:void(0);" style="display: none;">Scroll</a>
<script type="text/javascript">
jQuery(document).scroll(function(){
if (jQuery(this).scrollTop() > 100) {
jQuery('.scrollup').fadeIn();
} else {
jQuery('.scrollup').fadeOut();
}
});
jQuery('.scrollup').click(function(){
jQuery("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
</script>

Wednesday 21 January 2015

Magento:: Delete all orders

Run the below Sql Script to your database for delete all orders
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

Magento :: Mini Login Form in header section

Let’s open app/design/frontend/your_package/your_theme/layout/customer.xml 
and just add the following line after <customer_logged_out>
<reference name="header">
            <block type="customer/form_login" name="header_customer_form_mini_login"  template="customer/form/mini.login.phtml"/>
        </reference>
Like:
<customer_logged_out>
        <reference name="header">
            <block type="customer/form_login" name="header_customer_form_mini_login"  template="customer/form/mini.login.phtml"/>
        </reference>
        <!---<reference name="right">
            <block type="customer/form_login" name="customer_form_mini_login" before="-" template="customer/form/mini.login.phtml"/>
        </reference>-->
        <reference name="top.links">
            <action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
        </reference>
        <remove name="reorder"></remove>
    </customer_logged_out>
Now open app/design/frontend/your_package/Your_theme/template/page/html/header.phtml and add the following lines where yoy want to display login button:
<div id="header-login" class="" style="position:relative;">
            <?php if (! Mage::getSingleton('customer/session')->isLoggedIn()): ?<?php echo $this->__('Login') ?>
            <?php echo $this->getChildHtml('header_customer_form_mini_login') ?>
            <?php else: ?>
          <a href="<?php echo Mage::helper('customer')->getLogoutUrl(); ?>" title="Log Out" class="login"><?php echo $this->__('Log Out') ?></a>
          <?php endif; ?>
        </div>
And, lastly, open app/design/frontend/your_package/your_theme/template/customer/form/mini.login.phtml and modify the file according the following file:
<style>
 #dropdown
 {
  position: absolute;
    border:1px solid #ccc;
    padding:20px;
  top: 20px;
  left: 0px;
  visibility: hidden;
    background:white;
    z-index:1111;
 }
 #header-login:hover #dropdown
 {
  visibility: visible;
 }
</style>
<div class="block block-login" id="dropdown">
    <div class="block-title">
        <strong><span><?php echo $this->__('Login') ?></span></strong>
    </div>
    <form action="<?php echo $this->getUrl('customer/account/loginPost'); ?>" method="post">
        <?php echo $this->getBlockHtml('formkey'); ?>
        <div class="block-content">
            <label for="mini-login"><?php echo $this->__('Email:') ?></label><input type="email" autocapitalize="off" autocorrect="off" spellcheck="false" name="login[username]" id="mini-login" class="input-text" />
            <label for="mini-password"><?php echo $this->__('Password:') ?></label><input type="password" name="login[password]" id="mini-password" class="input-text" />
            <div class="actions">
                <button type="submit" class="button"><span><span><?php echo $this->__('Login') ?></span></span></button>
            </div>
        </div>
    </form>
</div>
Note: In the customer.xml I am using core/template block instead of customer/form_login. The reason for this is that the latter sets the page title to ‘Customer login‘ on all pages it’s being displayed on.

As i am using different block, so now i can’t use methods of the customer/form_login block. Because we’re using $this->getUrl(‘customer/account/loginPost’) as a form action instead of $this->getPostActionUrl().

Tuesday 20 January 2015

Magento:: Social sharing buttons

  • Open app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/product/view.phtml
  • Find the place where you want to add your links/buttons and add the following:
<?php $productName = $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
<?php $productUrl = $_helper->productAttribute($_product, $_product->getProductUrl(), 'product_url'); ?>
<?php $productImage = $_product->getImageUrl() ?>
  • Add the following code below the variables we defined in the previous step:
// Google Plus
<a href="javascript:popWin('https://plus.google.com/share?url=<?php echo urlencode($productUrl); ?>', 'google', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('Share on Google Plus') ?>">Google Plus</a>
// Facebook
<a href="javascript:popWin('https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($productUrl); ?>&t=<?php echo urlencode($productName); ?>', 'facebook', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('Share on Facebook') ?>">Facebook</a>
// Twitter
<a href="javascript:popWin('http://twitter.com/home/?status=<?php echo urlencode($productName . ' (' . $productUrl . ')'); ?>', 'twitter', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('Tweet') ?>">Twitter</a>
// Pinterest
<a href="javascript:popWin('https://pinterest.com/pin/create/button/?url=<?php echo urlencode($productUrl); ?>&media=<?php echo urlencode($productImage); ?>&description=<?php echo urlencode($productName); ?>', 'pinterest', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('Pin it') ?>">Pinterest</a>
Adding OpenGraph meta tags to your Magento store is quite easy. Just add the following code below the last meta tag (should be a meta tag named “robots” if you are using a default Magento head file) in app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/page/html/head.phtml
<?php $product = Mage::registry('current_product');
if ($product): ?>
<meta property="og:title" content="<?php echo $product->getName(); ?>" />
<meta property="og:type" content="product" />
<meta property="og:url" content="<?php echo $this->helper('catalog/product')->getProductUrl($product); ?>" />
<meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(300, 300); ?>" />
<meta property="og:description" content="<?php echo strip_tags($product->getShortDescription()); ?>" />
<meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName() ?>" />
<?php endif; ?>

Magento:: Add jQuery Class based on php variable

<?php
 if($sub_cat_count > 2){
 ?>
    <script>
        jQuery(document).ready(function(){
            //alert('hiiiiiii');
        jQuery("#product-listing").addClass("scroll");
        
        }); 
    </script>
<?php
    }
?>