Tuesday, 28 July 2015

Remove All Products, Category, Customers and Sales order

Make a BACKUP First complete Database.

  1.     Remove all products
  2.     Remove all attributes
  3.     Remove all attribute sets
  4.     Remove all categories
  5.     Remove all orders, shipments, transactions etc.

Remove All Poduct data

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
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`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `catalog_category_product`;
DELETE FROM catalog_product_flat_1;
DELETE FROM catalog_product_flat_10;
DELETE FROM catalog_product_flat_11;
DELETE FROM catalog_product_flat_12;
DELETE FROM catalog_product_flat_13;
DELETE FROM catalog_product_flat_14;
DELETE FROM catalog_product_flat_15;
DELETE FROM catalog_product_flat_16;
DELETE FROM catalog_product_flat_17;
DELETE FROM catalog_product_flat_18;
DELETE FROM catalog_product_flat_19;
DELETE FROM catalog_product_flat_2;
DELETE FROM catalog_product_flat_20;
DELETE FROM catalog_product_flat_21;
DELETE FROM catalog_product_flat_22;
DELETE FROM catalog_product_flat_23;
DELETE FROM catalog_product_flat_24;
DELETE FROM catalog_product_flat_25;
DELETE FROM catalog_product_flat_26;
DELETE FROM catalog_product_flat_27;
DELETE FROM catalog_product_flat_28;
DELETE FROM catalog_product_flat_29;
DELETE FROM catalog_product_flat_3;
DELETE FROM catalog_product_flat_30;
DELETE FROM catalog_product_flat_31;
DELETE FROM catalog_product_flat_32;
DELETE FROM catalog_product_flat_33;
DELETE FROM catalog_product_flat_34;
DELETE FROM catalog_product_flat_35;
DELETE FROM catalog_product_flat_36;
DELETE FROM catalog_product_flat_37;
DELETE FROM catalog_product_flat_4;
DELETE FROM catalog_product_flat_5;
DELETE FROM catalog_product_flat_6;
DELETE FROM catalog_product_flat_7;
DELETE FROM catalog_product_flat_8;
DELETE FROM catalog_product_flat_9;
SET FOREIGN_KEY_CHECKS = 1;

insert  into `catalog_product_link_type`(`link_type_id`,`code`) values (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
insert  into `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) values (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
insert  into `cataloginventory_stock`(`stock_id`,`stock_name`) values (1,'Default');


Remove All Category Data

***********for categories********************
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;

INSERT  INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
INSERT  INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1);
INSERT  INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');
SET FOREIGN_KEY_CHECKS=1;

*****************for customers*****************


SET FOREIGN_KEY_CHECKS=0;

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 `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `tag_properties`;          
TRUNCATE `wishlist`;
TRUNCATE `log_customer`;

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 `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `tag_properties` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;

TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `report_event`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `sendfriend_log`;

ALTER TABLE `log_url` AUTO_INCREMENT=1;
ALTER TABLE `log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
ALTER TABLE `report_viewed_product_index` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;


Remove All Customer Data

SET FOREIGN_KEY_CHECKS=0;

##############################
# SALES RELATED TABLES
##############################
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
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_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;           
TRUNCATE `sales_invoiced_aggregated_order`;       
TRUNCATE `log_quote`;

ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` 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_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_payment` 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 `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;

#########################################
# DOWNLOADABLE PURCHASED
#########################################
TRUNCATE `downloadable_link_purchased`;
TRUNCATE `downloadable_link_purchased_item`;

ALTER TABLE `downloadable_link_purchased` AUTO_INCREMENT=1;
ALTER TABLE `downloadable_link_purchased_item` AUTO_INCREMENT=1;

#########################################
# RESET ID COUNTERS
#########################################
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

Friday, 24 July 2015

Resolved Magento notify a customer by an email on its group change by admin.

Magento the widely known eCommerce store gives its users the facility to group its customers. This feature comes in handy when details need to be displayed to specific group related to some discount or offer valid for a small number. However, the problem arises when the customers are not aware of this subtle distinction and miss a chance to avail the brownie points. This happens because Magneto is not having a default feature to signal the customer regarding the group change.
To resolve this issue one can create a module by going through the following steps:

Step 1.
Create Module xml file app\etc\modules\Magcustom_Customergroup.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Magcustom_Customergroup>
            <active>true</active>
            <codePool>community</codePool>
        </Magcustom_Customergroup>
    </modules>
</config>

Step2.
Create a Observer app\code\community\Magecustom\Customergroup\etc\config.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Magcustom_Customergroup>
            <version>0.1.0</version>
        </Magcustom_Customergroup>
         <customergroup>
            <class>Magcustom_Customergroup_Model</class>
        </customergroup>
    </modules>
   
    <global>
        <events>
            <customer_save_after>
                <observers> 
                    <stockalert> 
                        <type>singleton</type>
                            <class>Magcustom_Customergroup_Model_Observer</class>
                            <method>checkDisplay</method>
                    </stockalert>
                </observers>
            </customer_save_after>
        </events>
    </global>
</config>

 Create a Observer app\code\community\Magecustom\Customergroup\Model\Observer.php

<?php
class Magcustom_Customergroup_Model_Observer
{
    public function checkDisplay(Varien_Event_Observer $observer){

        $customer=$observer->getEvent()->getCustomer();
        Mage::log('My log entry'.$customer->getId(), null, 'Magento37890.log');
        /* if customer  is old customer */
       
        if($customer->getId()){
       
            if($customer->getOrigData('group_id')!= $customer->getData('group_id')){            
                $oldgroupname = Mage::getModel('customer/group')->load($customer->getOrigData('group_id'))->getCustomerGroupCode();
                $groupname = Mage::getModel('customer/group')->load($customer->getData('group_id'))->getCustomerGroupCode();
                $name= $customer->getName();
           
            /* here you write your code to send whenever you have change the group */
           

            $templateId = 2;

            $sender  = array(
            'name' => Mage::getStoreConfig('trans_email/ident_support/name', Mage::app()->getStore()->getId()),
            'email' => Mage::getStoreConfig('trans_email/ident_support/email', Mage::app()->getStore()->getId())
            );
           
            $vars  = array(
            'CustomerName' => $customer->getName(),
            'CustomerEmail' => $customer->getEmail(),
            'CustomerGroupname' => $groupname,           
            'CustomerOldGroupname' => $oldgroupname
            );
           
   
            $customerEmail=$customer->getEmail();
            $customerName=$name;
           Mage::getModel('core/email_template')->sendTransactional($templateId, $sender, $customerEmail, $customerName, $vars, $storeId);
                    }
        }else{
        /* New Customer */

        }
    }
}


Step 3.

Create a email template system-> Transactional Emails

Template Name  : Custom Group Change Email
Template Subject  : Group Change, {{var CustomerName}}!

Template Content:

{{template config_path="design/email/header"}}
{{inlinecss file="email-inline.css"}}

<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="action-content">
            <h1>Dear  {{var CustomerName}},</h1>
            <p> Your group has changed from <strong> {{var CustomerOldGroupname}}</strong> to <strong>{{var CustomerGroupname}}</strong>.</p>
            <p>
                If you have any questions, please feel free to contact us at
                <a href="mailto:{{var store_email}}">{{var store_email}}</a>
                {{depend store_phone}} or by phone at <a href="tel:{{var phone}}">{{var store_phone}}</a>{{/depend}}.
            </p>
        </td>
    </tr>
</table>

{{template config_path="design/email/footer"}}

Resolved Magento adding a tax class to all products using mysql

First you need to run below query

SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'tax_class_id'

then get attribute id example attribute_id  '121'

SELECT *
FROM `catalog_product_entity_int`
WHERE `attribute_id` =121

the update `catalog_product_entity_int` your tax id like 1 or 2 based on attribute_id

  UPDATE `catalog_product_entity_int` SET value=2 WHERE `attribute_id`='121'