Thursday, October 25, 2012

Creating virtual host in ubuntu

Suppose, the configuration file name is domain.com and local IP address is 127.0.0.1. Type following command in terminal
gksudo gedit /etc/apache2/sites-available/domain.com

Add following lines in configuration file
<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/test
    ServerName domain.com
    ServerAlias test.domain.com
    ServerAdmin admin@domain.com
</VirtualHost>

Save and close it. Then create a symbolic link of this configuration file to /etc/apache2/sites-enabled directory in order to enable it
cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/domain.com .

Then, add a virtual domain with a specific local IP to hosts file that is located in /etc/hosts. You can also add the port using a colon with the IP.
sudo nano /etc/hosts
add this line
127.0.0.1 test.domain.com
Save and close it. After all restart the apache service.

Magento : MySQL commands to clear all orders

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
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_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` 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 `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` 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;

-- reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;

ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;

-- Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

Wednesday, October 3, 2012

Magento : add massDelete action in coupon code

First override Mage_Adminhtml_Block_Promo_Quote_Grid class and add following code
protected function _prepareMassaction()
    {
        $this->setMassactionIdField('rule_id');
        $this->getMassactionBlock()->setFormFieldName('rule');

        $this->getMassactionBlock()->addItem('delete', array(
             'label'    => Mage::helper('rule')->__('Delete'),
             'url'      => $this->getUrl('*/*/massDelete'),
             'confirm'  => Mage::helper('rule')->__('Are you sure?')
        ));
         return $this;
    }


then override Mage_Adminhtml_Promo_QuoteController class and add following code
public function massDeleteAction()
    { //exit;
        $rulesIds = $this->getRequest()->getParam('rule');
        if(!is_array($rulesIds)) {
             Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select rule(s).'));
        } else {
            try {
                $model = Mage::getModel('salesrule/rule');
                foreach ($rulesIds as $rulesId) {
                //echo $rulesId; exit;
                    $model->load($rulesId);
                    $model->delete();
                }
                Mage::getSingleton('adminhtml/session')->addSuccess(
                    Mage::helper('adminhtml')->__(
                        'Total of %d record(s) were deleted.', count($rulesIds)
                    )
                );
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
        }

        $this->_redirect('*/*/index');
    }

Magento : lazyloading in catloag page

Download lazyload js from below link
http://www.appelsiini.net/projects/lazyload
And save in js/lazyload/jquery.lazyload.js

Then create lazyload.phtml in template/lazyload/lazyload.phtml with following code
<script type="text/javascript" charset="utf-8">
    jQuery("img").load(function(){if(jQuery(this).attr("src")!=="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); ?>blank.png"){jQuery(this).removeAttr("height")}});

    jQuery(function() {
      jQuery("img").lazyload({
          effect : "fadeIn",     
      });
    });
</script>


And add following code in catalog.xml
<reference name="head">
    <action method="addJs"><script>jquery.lazyload.min.js"></script></action>
</reference>
<reference name="after_body_start">
      <block type="core/template" template="lazyloader/lazyload.phtml" name="lazyloader_init" />
</reference>

Remember that jquery must be included in site.

Magento : Add/Remove js file

Use following code
Add js through layout file
<reference name="head" as="head">
<action method="addJs"><script>folder_name/file_name.js</script></action>
</reference>
and through php code
echo $this->getLayout()->getBlock('head')->addJs('folder_name/file_name.js');

Remove js through layout file
<reference name="head" as="head">
<action method="removeItem"><type>js</type><name>folder_name/file_name.js</name</action>
</reference>
and though php code
$this->getLayout->getBlock('head')->removeItem('js','folder_name/file_name.js');

Monday, October 1, 2012

Magento : Zaakpay Payment Gateway Integration

Download kit from following link
https://www.zaakpay.com/developers/guide

And follow instructions given in ReadMe file.