Magento clear all test data from database

***********for categories********************
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’);

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

SET FOREIGN_KEY_CHECKS=0;
— 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;
SET FOREIGN_KEY_CHECKS=1;

SET FOREIGN_KEY_CHECKS=0;
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 `sales_payment_transaction`;
TRUNCATE `sales_order_aggregated_created`;
TRUNCATE `sales_order_tax`;
TRUNCATE `sales_order_tax_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
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 `sales_payment_transaction` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_tax` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_tax_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;
SET FOREIGN_KEY_CHECKS=1;

Send custom email into Mail Chimp List Programmatically in magento

If you have custom collection and you wish to send it into mailchimp , Below if code that help you.

       $defaultList = Mage::getStoreConfig(Ebizmarts_MageMonkey_Model_Config::GENERAL_LIST, 1);
       $mergeVars = array(
                            'EMAIL' => 'santoshmeets@gmail.com',
                            'FNAME' => 'Santosh',
                            'LNAME' => 'Yadav',
                            'CGROUP' => 'General'
        );
         Mage::getSingleton('monkey/api')->listSubscribe($listId, $email, $mergeVars, 'html', false, TRUE);

Don’t forget to write feedback on this trick. Thanks in adavance.

Magento add custom block to product page

Depend upon the position where we would like to insert your custom block you can insert your custom block.

Below is xml to insert custom block into product page

<catalog_product_view>
            <reference name="product.info.extrahint">
                <block type="tag/product_list" name="product_tag_list" before="-" template="tag/list.phtml"/>
            </reference>


            <reference name="product.info">
                <block type="catalog/product_list_related" before="-"  name="catalog.product.related" as="related_products" template="catalog/product/list/related.phtml" >
                        <action method="addToParentGroup"><group>detailed_info</group></action>
                </block>
                    </reference>
    </catalog_product_view>

Magento add attachment to email

Hello All,
I have found working code to send email with attachment.

$attachmentFilePath = Mage::getBaseDir('media'). DS.$filpath; //filepath is path of file inside media directory
$mailTemplate = Mage::getModel('core/email_template');
if(file_exists($attachmentFilePath)){ 
                    $fileContents = file_get_contents($attachmentFilePath);
                    $attachment   = $mailTemplate->getMail()->createAttachment($fileContents,Zend_Mime::TYPE_OCTETSTREAM,Zend_Mime::DISPOSITION_ATTACHMENT,Zend_Mime::ENCODING_BASE64,basename($attachmentFilePath));
              
                }

$postObject = new Varien_Object();
//Below code require you understandtsthe term used
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        $template_id,  //template id of email template
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                        null,
                        array('data' => $postObject)
    );

Create new theme in wordpress

At the very minimum, a WordPress Theme consists of two files:

  1. style.css
  2. index.php

style.css contains information about theme.

/*
Theme Name: My Theme
Theme URI: https://santoshyadavcse.wordpress.com/
Author: Santosh Yadav
Author URI: https://santoshyadavcse.wordpress.com/about-santosh/
Description: This is simple theme used for theme creation demo.
Version: 1.0
License: GNU General Public License
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/* add your css below */

index.php file is main file loaded for your theme.

<?php
/* Write your code here */
?>

For more detail on them development you may refer to this page https://codex.wordpress.org/Theme_Development

Custom page template in wordpress

WordPress come with default template  for any of the post, page ,category etc.For example we have template category.php for category and page.php for pages.

Below is method two change default template

1.How to change page template.

Method 1

Create custom page template. For eg : use below code to create page template.Create a php file in your them and put below code to create new template

<?php
/*
Template Name: Full Width Page with No Sidebar
*/
get_header(); ?>
    <div id="primary" class="site-content">
        <div id="content" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', 'page' ); ?>
                <?php comments_template( '', true ); ?>
            <?php endwhile; // end of the loop. ?>
        </div><!-- #content -->
    </div><!-- #primary -->
<?php get_footer(); ?>

Edit page and select page template Full Width Page with No Sidebar From right template list.

Method 2 :
Create new template with page id – page-{$id}.php

Method 3:
Create page template with slug name.
If your page have slug name about then create page template with name page-about.php

Page template hirarchy.
Below is template order in which template are called

Custom Template — If the Page has a custom Template assigned, WordPress looks for that file and, if found, uses it.
page-{slug}.php — Else WordPress looks for and, if found, uses a specialized template named with the Page’s slug.
page-{id}.php — Else WordPress looks for and, if found, uses a specialized template named with the Page’s ID.
page.php — Else WordPress looks for and, if found, uses the Theme’s default page template.
index.php — Else WordPress uses a the Theme’s index file.

 

2.How to change category template.

Method 1
category-{$id}.php

Method 2
category-{slug}.php

Category template hirarchy
category-{slug}.php — Else WordPress looks for and, if found, uses a specialized template named with the Page’s slug.
category-{id}.php — Else WordPress looks for and, if found, uses a specialized template named with the category‘s ID.
category.php — Else WordPress looks for and, if found, uses the Theme’s default category template.
index.php — Else WordPress uses a the Theme’s index file.

 

 

If any query please drop below your below your comments.

Cheers

Add sidebar in wordpress theme

WordPress require 2 steps to use sidebar.

Step 1.Register sidebar

Register your sidebar in theme. add below code in your theme function.php. add widget to your sidebar

add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
    register_sidebar( array(
        'name' => __( 'My Sidebar', 'theme-slug' ),
        'id' => 'sidebar-id-here',
        'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
	'after_widget'  => '</li>',
	'before_title'  => '<h2 class="widgettitle">',
	'after_title'   => '</h2>',
    ) );
}

Your sidebar will be appear in Appearence>Widget menu. add
Step 2.Use sidebar in theme

Edit your theme template where you wish to call sidebar

<?php if ( is_active_sidebar( 'sidebar-id-here' ) ) : ?>
		<?php dynamic_sidebar( 'sidebar-id-here' ); ?>
<?php endif; ?>

WordPress most popular plugin

Plugin allow you to extend core of wordpress. Most popular used plugin are-

Show Custom form on website

Contact Form 7 : https://wordpress.org/plugins/contact-form-7/

For SEO

WordPress SEO By Youst : https://wordpress.org/plugins/wordpress-seo/

For Performance

WP Super  Cache : https://wordpress.org/plugins/wp-super-cache/

For E-commerce

Woo Commerce : https://wordpress.org/plugins/woocommerce/

For Easy Customization of page content

Advanced Custom Fields (ACF):https://wordpress.org/plugins/advanced-custom-fields/

Security 

Captcha : https://wordpress.org/plugins/captcha/

I will keep posting on important wordpress plugins. keep looking.

WordPress and it’s features.

WordPress is not limited to blogging but you can build everything from simple websites, to blogs, to complex portals and enterprise websites, and even applications, are built with WordPress.

The most poular features are as

  • Open Source.
  • Full Standard Complaince
  • Easy theming.
  • Compatible with devices
  • Extendable & Flexible
  • Community Support

For developer it offers variety of facilities.

  • Plugin : To Extend core files
  • Custom content type
  • Theming
  • Contributing
  • Sidebar and widgets to customize layout

 

 

Magento v2 API

Step to use Soap API V2 : Example to get customer list using soap v2 api

Step 1 : Create Role : Go to System > Web Services > SOAP/XML-RPC – Role and create Role and assign a resource to your role.
Step 2 : Craete Users: Go to System > Web Services > SOAP/XML-RPC – Use  and create User and assign created role.Note down User Name(This will be ApiUserName and ApiKey
Step 3 : Call Soap methods : Use below code to call soap methods . For eg getCustomerList


$host = 'http://magentohost/api/v2_soap?wsdl=1';
$client = new SoapClient($host);
// then get a session token
$session = $client->login('ApiUserName', 'ApiKey');
// call soap method
$result = $client->customerCustomerList($session);
print_r($result);