Magento 2 Index Management

|| Magento2 reindex on local server

You can’t reindex from admin web. you have to reindex from command line

  1. go to command line from magento2 installation root directory

  2. php bin/magento indexer:reindex

if you got any error like ‘php’ is not recognized as an internal or external command,

so you need to Add E:\xampp\php to your PATH Environment Variable.

final command:
E:\xampp\htdocs\magento2>php bin/magento indexer:reindex

Image uploading Problem

|| File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini file

|| solved: Go to the file directory public_html wp-admin then put the php.ini file, and include following code


upload_max_filesize = 64M;
post_max_size = 32M;
safe_mode = off;

Image upload error

|| Magento 1.9.2 and php7 – image upload error:
check console: Uncaught Error: Function name must be a string in store.com/lib/Varien/File/Uploader.php:259

$params['object']->$params['method']($this->_file['tmp_name']);

to

$params['object']->{$params['method']}($this->_file['tmp_name']);

Catalogsearch form:

Catalogsearch > form.mini.phtml


$category = Mage::getModel('catalog/category');
if (is_object(Mage::registry('current_category'))) {
    $current_category_path = Mage::registry('current_category')->getPathIds();
} else {
    $current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',', $children_string);
$extra_options = '';
foreach ($children as $c) {
    $selected = (in_array($c, $current_category_path)) ? 'SELECTED' : '';
    $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";
}
?>
 
<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
    <fieldset>
        <legend><?php echo $this->__('Search Site') ?></legend>
        <span style="float: left; position: relative; top: 8px; left: 15px;">Search</span>
        <div class="mini-search">
            <select name="cat" id="cat" class="input-text">
                <option value="">All Products</option>
                <?= $extra_options ?>
            </select>
            <input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>"  placeholder="<?php echo $this->quoteEscape($this->__('Search entire store here...')) ?>" />
            <button type="submit" title="<?php echo $this->quoteEscape($this->__('Search')) ?>" class="button search-button" value="Go"><span><span><?php echo $this->__('Search') ?></span></span></button>
            <div id="search_autocomplete" class="search-autocomplete"></div>
            <script type="text/javascript">
                //<![CDATA[
                var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Search your products') ?>');
                searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
                //]]>
            </script>
        </div>
    </fieldset>
</form>




Installation Problem:

|| Fatal error: Uncaught Error: Function name must be a string in /var/www/html/magento/app/code/core/Mage/Core/Model/Layout.php:555

$out .= $this->getBlock($callback[0])->$callback[1]();

to

$out .= $this->getBlock($callback[0])->{$callback[1]}();

|| Maximum execution time of 30 seconds exceeded in magento installation.

/* solve */
go to xampp/php/php.ini and search by 

max_execution_time=30  replace to 600
max_input_time=60      replace to 600
memory_limit=128M      replace to 1000m

|| PHP extension soap must be loaded

I edited php.ini and removed the leading semicolon ( ; ) from extension=php_soap.dll.
After restarting Apache I was able to proceed with the installation without any other issues.

Upgrade magento from 1.7 to latest 1.9.2.4

1st way to upgrade :

Use the Magento Connect method:
Within each Magento installation, you can easily upgrade Magento via Magento Connect. The steps to upgrade via Magento Connect include:

  • Login to the Magento admin
  • Move to system- Magento Connect- Connect manager
  • Login to Magento Connect
  • Click on ‘check for upgrades’
  • Upgrade ‘Mage _All_Latest’. This will upgrade Magento.

2nd way to upgrade:

  1. Take a backup of current database and current 1.7 code. place maintenance.flag file inside 1.7 code folder to put website offline.
  2. Download latest magento from the http://www.magentocommerce.com/download
  3. Remove all folders and files from your 1.7 code except maintenance.flag (but you should have backup somewhere) and place all folders and files from the 1.9.
  4. Now from your 1.7 merge your following custom folders into the 1.9
    • Community app/code/community
    • Local app/code/local
    • Media
    • your theme or package (app/design/frontend/default/<your theme> or app/design/frontend/<your package>)
    • custom folders from Skin (both for adminhtml and frontend).
    • copy your custom xml files from app/etc/modules/ to current app/etc/modules/
    • any custom admin theme folder from adminhtml/default/yourtheme.
    • copy your custom folders from adminhtml/default/default/ (1.7) to adminhtml/default/default/ (1.9).
    • custom js files if any from app/js/.
  5. Now go to app/etc/local.xml.Edit database details their.put your database username and password and database name.
  6. Remove maintenance.flag file and check the site in the browser. it is done.

Magento mysql dump file

Importing phpMyAdmin Database Dump File

When importing a MySQL dump file that’s been generated using phpMyAdmin, you need to put the following at the beginning of the file:

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;
SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;
SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;
SET NAMES utf8;
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;


And the following at the end of the file:

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT;
SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS;
SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;
SET SQL_NOTES=@OLD_SQL_NOTES;

WordPress Help Code


|| favicon icon:
   <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />

|| shortcode
   [bestwebsoft_contact_form]
   <?php echo do_shortcode('[bestwebsoft_contact_form]'); ?>

|| Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
   Please contact the server administrator webmaster@...

--How to Fix the Internal Server Error--
. At first check admin > settings > permalinks > select post name
. check for the corrupted .htaccess file
  /* http://www.wpbeginner.com/wp-tutorials/how-to-fix-the-internal-server-error-in-wordpress/ */


|| Cause of Free theme uses, footer link redirect
   wp index.php?theme_license=true

   This problem have to do solve:
   <?php
	/*  function.php just notice this following code in the end*/
		function wp_initialize_the_theme_load() { if (!function_exists("wp_initialize_the_theme")) {--------}
	 
	/*  replace up this code */
	 
		function wp_initialize_the_theme_load(){ 
			if (!function_exists("wp_initialize_the_theme")) { wp_initialize_the_theme_message(); die; } 
		} 

		function wp_initialize_the_theme_finish() {$uri = strtolower($_SERVER["REQUEST_URI"]); 
			if(is_admin() || substr_count($uri, "wp-admin") > 0 || substr_count($uri, "wp-login") > 0 ) { /* */ } else { /* */ } 
		} 
			wp_initialize_the_theme_finish();
	 
	/* now can change footer.php powered by link */ 

	/* if you want, You can remove this code. lib>Themater.php,*/
		if (!empty($_REQUEST["theme_license"])) {----}
		
	 
   ?>


Dynamic category show in a page:
==================================
<?php
 wp_list_categories('hide_empty=0&show_count=1&title_li=
 <h3>' . __('All Categories') . '</h3>' ); 
?>

WordPress Fix – Add Media Button Not Working:
=============================================
Basically you need to open your “wp-config.php” file in the root of your WordPress Install.
Search for this line:
  <?php require_once(ABSPATH . 'wp-settings.php'); ?>

And just before it add this code:
  <?php define('CONCATENATE_SCRIPTS', false ); ?>

/****************************/

Woocommerce:
===============

|| How To Change Product Images Size?
   1st woocommerce > setting > product > Display > Product Images
   2nd Regenerate Thumbnails plugins install and active
   tutorial link: https://www.youtube.com/watch?v=YVLb3eG0JdI
   

|| product detail page sku and category
   wp-content\plugins\woocommerce\templates\single-product\meta.php

|| Product listing page product name
   content-product.php
   <a href="<?php the_permalink(); ?>">---- </a>

|| product view page review tab remove

<?php
	add_filter( 'woocommerce_product_tabs', 'sb_woo_remove_reviews_tab', 98);
	function sb_woo_remove_reviews_tab($tabs) {

	 unset($tabs['reviews']);

	 return $tabs;
	}
?>

|| product view short description:
   woocommerce/single-product/short-description.php

|| breadcrumbs slash '/' replace as '>'
   function.php

<?php
	add_filter( 'woocommerce_breadcrumb_defaults', 'my_change_breadcrumb_delimiter' );
	function my_change_breadcrumb_delimiter( $defaults ) {
	 // Change the breadcrumb delimiter from '/' to '>'
	 $defaults['delimiter'] = ' > ';
	 return $defaults;
	}
?>

|| Default breadcrumbs remove from product page:
   function.php
   <?php remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);?>

|| prodcut view page related product remove
   function.php
   <?php remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );?>

|| Add to cart remove:
        <?php
		/* product listing page add to cart remove */
		function remove_loop_button(){
			remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
		}
		add_action('init','remove_loop_button');
			or
		remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
		
		/* product detail page add to cart remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
		
	?>

|| Price Remove
       <?php
		/* product listing page price remove */
		remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
		/* product detail page price remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
		
	?>

|| Where to go to edit shop/products page:

Editing the layout of items within the shop page (or any other product archive such as category, tag, etc) can be done through template files.
you need to add a folder to your theme named "woocommerce" and copy the contents from the woocommerce plugin folder under "templates"
the loop folder contains the files you want to use - that and archive-product.php
so, in your theme, you'd have something like
themefolder/woocommerce/archive-product.php
themefolder/woocommerce/loop/...
<?php
	do_action( 'woocommerce_sidebar' )
?>


|| Dynamic Product Category in sidebar:
   Appearance > Widget:
   drag and drop (WooCommerce Product Categories) in (primary sidebar) or (secondary widget area)

|| Dynamic product category anywhere:
   function.php

<?php
	/* product category */
	function wooCommerceCategories() {

		$taxonomy     = 'product_cat';
		$orderby      = 'name';  
		$show_count   = 0;      // 1 for yes, 0 for no
		$pad_counts   = 0;      // 1 for yes, 0 for no
		$hierarchical = 1;      // 1 for yes, 0 for no  
		$title        = '';  
		$empty        = 0;

		$args = array(
			'taxonomy'     => $taxonomy,
			'orderby'      => $orderby,
			'show_count'   => $show_count,
			'pad_counts'   => $pad_counts,
			'hierarchical' => $hierarchical,
			'title_li'     => $title,
			'hide_empty'   => $empty
		);
		$all_categories = get_categories( $args );
		 foreach ($all_categories as $cat) {
			if($cat->category_parent == 0) {
				$category_id = $cat->term_id;       
				echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>'; 
				$args2 = array(
						'taxonomy'     => $taxonomy,
						'child_of'     => 0,
						'parent'       => $category_id,
						'orderby'      => $orderby,
						'show_count'   => $show_count,
						'pad_counts'   => $pad_counts,
						'hierarchical' => $hierarchical,
						'title_li'     => $title,
						'hide_empty'   => $empty
				);
				$sub_cats = get_categories( $args2 );
				if($sub_cats) {
					foreach($sub_cats as $sub_category) {
						echo  $sub_category->name ;
					}   
				}
			}       
		}
	}
	/**/
?>

/* function call */

<div class="product_category col-lg-1 col-md-2">
     <?php if(function_exists("wooCommerceCategories")) wooCommerceCategories(); ?>
</div>


/************************************/

|| Dashboard page href link
   <a href="index.php?page_id=###"></a>

|| separate menu click then separate content show
   twentythirteen > page.php 


|| Add Font Awesome CDN To WordPress Without A Plugin

   /* Add the Following Code to Your Theme’s functions.php File: */
   <?php
	add_action( 'wp_enqueue_scripts', 'prefix_enqueue_awesome' );
	/**
	 * Register and load font awesome CSS files using a CDN.
	 *
	 * @link   http://www.bootstrapcdn.com/#fontawesome
	 * @author FAT Media
	 */
	function prefix_enqueue_awesome() {
		wp_enqueue_style( 'prefix-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', array(), '4.0.3' );
	}
   ?>


For Layout
=============
<?php
|| style.css

/*
Theme Name: LenzKarft
Theme URI: http://fsb.com.bd/
Description: A clean theme completely compatible with WordPress 4.1
Author: FSB
Author URI: http://fsb.com.bd/
Version: 1.4
*/
--------------------------
?>

|| header
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

<!-- BEGIN html head -->
	<head profile="http://gmpg.org/xfn/11">
		<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
		<meta name="viewport" content="width=device-width">
		<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
		<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_url'); ?>" />
		<?php wp_head(); ?>		
	</head>
<!-- END html head -->

<!-- Start Body from here -->
	<body>
		<div id="wrapper">
			<div id="header"></div>
------------------------------------


|| Footer	
			<div class="clear"></div>
			<div id="footer"></div>
		</div><!-- End wrapper-->
	</body><!-- End Body -->
</html>
------------------------------------
|| if this get css, you have to go wordpress>wp-includes>admin-bar.php
search this: /*function _admin_bar_bump_cb()*/

html{margin-top:32px;}

--------------------------------------------

Custom page Create
==================
1st step: include this in custom page
<?php 
/*
 Template name:Demo
*/
get_header() ;

?>

2nd step: Then go to backend add new page > right side > page attribute > Template

---------------------------------------------------------------------------------

Custom widget page Create
==========================
1st step: include this in custom page

<?php 
get_header() ;
/*
Template Name:demo_2;
*/
?>

2nd step: Then go to backend add new page> right side> page attribute>Template

3rd step:
<?php
function twentythirteen_widgets_init() {
    register_sidebar( array(
   	 'name'      	=> __( 'Main Widget Area', 'twentythirteen' ),
   	 'id'        	=> Demo2',
   	 'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
   	 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   	 'after_widget'  => '</aside>',
   	 'before_title'  => '<h3 class="widget-title">',
   	 'after_title'   => '</h3>',
    ) );
}

?>

4th step: go to backend widgets>
--------------------------------------------------------
Register widget areas.
==========================
<?php
/**
 * Register widget areas.
 */
function twentyfourteen_widgets_init() {
	
	register_sidebar( array(
		'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
		'id'            => 'sidebar-1',
		'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
		'id'            => 'sidebar-2',
		'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
		'id'            => 'sidebar-3',
		'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
}
add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
?>
---------------------------------------------------------------

Pages based Navigation Menu
===============================
<!-- Start Navigation Menu -->
	<div id="nav-menu">
		<ul>
			<li class="page_item"><a class="first" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('description'); ?>"><?php _e('Home', 'w3p'); ?></a></li>
			<?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
		</ul>
	</div>
<!-- End Navigation Menu -->


Dashboard Appearance > Menu
================================
<!-- This code include in functions.php file-->
	<?php
		add_action('admin_menu', 'my_plugin_menu');
		
		function my_plugin_menu() {
			add_theme_page('My Plugin Theme', 'My Plugin', 'edit_theme_options', 'my-unique-identifier', 'my_plugin_function');
		}
	?>

Appearance menu show in header.php file
========================================
<?php wp_nav_menu(array('theme_location' => 'primary', 'container_class' => 'w3-menu', 'container' => 'nav')); ?>

Page Content anywhere
========================
<?php
	$id = 20;
	$p = get_page($id);
	echo apply_filters('the_content', $p->post_content);
?>

ALL post show
=====================
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
	the_content();
	endwhile; else: ?>
	<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>

Single post show By ID
=======================
---Post Title---
<?php echo get_the_title($ID); ?> 

---Only Post----
<?php
	$my_postid = 1;//This is page id or post id
	$content_post = get_post($my_postid);
	$content = $content_post->post_content;
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]&gt;', $content);
	echo $content;
?>