Cron job has not been configured yet

Installation extension error

PS D:\xampp\htdocs\magento2> php bin/magento setup:cron:run
#!/usr/bin/env php
setup-cron: Please check var/log/update.log for execution summary.

You can see
setup-cron.ERROR: Your current PHP memory limit is 328M. Magento 2 requires it to be set to 756M or more. As a user with root privileges, edit your php.ini file to increase memory_limit.

See if the following file exists:
Magento install dir/var/.setup_cronjob_status
If the file exists, cron has run successfully in the past.

magento-directory/setup/src/Magento/Setup/Controller/Environment.php

commented out :
//$setupCheck = $this->cronScriptReadinessCheck->checkSetup();
//$updaterCheck = $this->cronScriptReadinessCheck->checkUpdater();

and replaced it with :
$setupCheck = ['success' => 1];
$updaterCheck = ['success' => 1];

Advertisements

Magento2 Snippets

|| Call phtml file in static block or cms page

   custom file path(Based on your theme you can change it)
   app/design/frontend/{Vendor}/{theme}/Magento_Theme/templates/html/test.phtml

   calling in xml layout file
   <block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"/>

   calling in blocks and cms pages
   {{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}}

   calling in any phtml file
   <?php include ($block->getTemplateFile('Magento_Theme::html/test.phtml')) ?>

   OR
   as before 
   <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/test.phtml")->toHtml();?>


Create an Admin theme

1.Create Admin theme directory
In the app/design/adminhtml directory create a new <Vendor>/<admin_theme> directory.

2.Add a declaration theme.xml
Add or copy from an existing theme.xml to your theme directory app/design/adminhtml/Vendor/<admin_theme>

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
	<title>Ataur Admin</title> <!-- your theme's name -->
	<parent>Magento/backend</parent> <!-- the parent theme. Example: Magento/backend -->
</theme>	

3.Add registration.php
In your theme directory app/design/adminhtml/<Vendor>/<admin_theme> create a registration.php file.

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
\Magento\Framework\Component\ComponentRegistrar::register(
	\Magento\Framework\Component\ComponentRegistrar::THEME,
	'adminhtml/Ataur/my-first-admin-theme', // Example: 'adminhtml/Magento/backend'
	__DIR__
); 

4.Admin theme logo
In the default Magento/backend theme lib/web/images/magento-logo.svg is used as theme logo. To override it, in your theme directory, create a web/images sub-directory, and add your custom file named magento-logo.svg

5.Apply an Admin theme
Prerequisites:
1.Set your Magento application to the developer mode.
2.Create a custom theme for the Admin panel.
3.Add a new custom module or decide to use existing custom module. The module must load after the Magento_Theme module. To ensure this, add the following code app/code/[VendorName]/[ModuleName]/etc/module.xml

(replace placeholders with your module information):

<module name="Ataur_Override" setup_version="2.0.1"> <!-- Example: "Magento_Backend -->"
	<sequence>
		<module name="Magento_Theme"/>
	</sequence>
</module>

6.Specify the custom Admin theme in di.xml
You need to specify the admin theme to be used in the <your_module_dir>/etc/di.xml file. Add it, if the file does not yet exist in your module.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
	<!-- Admin theme. Start -->
	<type name="Magento\Theme\Model\View\Design">
		<arguments>
			 <argument name="themes" xsi:type="array">
				 <item name="adminhtml" xsi:type="string">Ataur/my-first-admin-theme</item> <!-- Example: "Magento/backend" -->
			 </argument>
		 </arguments> 
	</type>
	<!-- Admin theme. End -->
</config>

7.Update components to actually apply the Admin theme
For your changes to take effect, you need to update Magento components. For this,
run the php bin/magento setup:upgrade command in your command line. If prompted, also run
php bin/magento setup:di:compile

error face: Controller preference not working after setup:di:compile
solution: Have you tried to run php bin/magento setup:static-content:deploy afterwards?
And just in case, run again php bin/magento setup:upgrade at the very end of operations.

Magento2 Installation

Magento2 download by composer

1.You have to setup composer in your htdocs
2.Must be check magento prerequisites
3.Go to magento documentation and find on the left side Integrator installation > Get the Magento Open Source metapackage
3.Select which version is compatibility with your php
4.Avoiding so many problem just change from D:\xampp\php\php.ini

memory_limit=328M
max_input_time=300
max_execution_time=18000

extension=php_intl.dll
extension=php_soap.dll
extension=php_xsl.dll

5.Enter the following command. Obviously copy this code from Magento Open Source metapackage. Fact of (version)

php composer.phar create-project –repository-url=https://repo.magento.com/ magento/project-community-edition <installation directory name>

or

composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition <installation directory name>

6.When prompted, enter your authentication keys from your magento profile.
Your public key is your username.
your private key is your password.

7.Now you can see it’s downloading so many files. After few minutes Successfully you can see
Generating autoload files

Magento2 install by command line

D:\xampp\htdocs\magento2> composer
D:\xampp\htdocs\magento2> composer install
D:\xampp\htdocs\magento2> php bin/magento setup:install

php bin/magento setup:install –base-url=http://127.0.0.1/magento2/ –db-host=localhost –db-name=test-magento2 –db-user=root –db-password= –admin-firstname=Ataur –admin-lastname=Rahman –admin-email=appointbd@gmail.com –admin-user=webTech –admin-password=webTech1234@ –language=en_US –currency=USD –timezone=America/Chicago –use-rewrites=1

Magento 2 CLI

php bin/magento help
php bin/magento list
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento cache:disable
php bin/magento cache:enable
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy

[doest not generate files in the pub/static folder. Try to run below command]
php bin/magento setup:static-content:deploy -f

Set the Magento mode

Developer mode:
You should use the Developer mode while you are developing customizations or extensions

php bin/magento deploy:mode:show
php bin/magento deploy:mode:set developer

Production mode:
You should run Magento in Production mode once it is deployed to a production server. Production mode provides the highest performance in Magento 2.

Install sample data after Magento

Do not install sample data if your Magento application is set for production mode. Switch to developer mode first. Installing sample data in production mode fails.

php bin/magento sampledata:deploy

If you’re installing sample data after installing Magento, you must also run the following command to update the database and schema:

php bin/magento setup:upgrade

WordPress Snippets


|| wp-admin logo change, go to functions.php
   /* wp-admin logo */
   function my_login_logo_one() { 
   ?> 
   <style type="text/css"> 
	body.login div#login h1 a {
	background: url(wp-admin/images/logo.png) center top no-repeat;
	width: 150px;
   } 
   </style>

   <?php 
   } add_action( 'login_enqueue_scripts', 'my_login_logo_one' );

  /* logo link change go to wp-login.php and search h1 */

|| 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 ); ?>



|| 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;
?>

Woocommerce Snippets

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

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

|| Related products
   plugins > woocommerce > templates > single-product > related.php


|| how to move best seller product on the top
   go to storefront-template-hooks.php
   add_action( 'homepage', 'storefront_best_selling_products', 70 ); 
                      to
   add_action( 'homepage', 'storefront_best_selling_products', 10 );


|| img src directory
   <img src="<?php echo get_template_directory_uri(); ?>/assets/images/bd.jpg" width="" height="" alt="" />

|| custom css add
   <link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(). '/assets/css/custom.css' ?>">

|| Add Custom Fonts, top of the style.css file
   @font-face {
	font-family: calib;
	src: url('assets/fonts/calibrib.ttf');
}

|| search form anywhere
   <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/'  ) ); ?>">
	<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
	<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
	<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
	<input type="hidden" name="post_type" value="product" />
   </form>


|| Number of related products
   add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
   function jk_related_products_args( $args ) {
	$args['posts_per_page'] = 4; // 4 related products
	$args['columns'] = 3; // arranged in 3 columns
	return $args;
}


|| How to Remove Product Review,  go to functions.php
   	add_filter( 'woocommerce_product_tabs', 'helloacm_remove_product_review', 99);
	function helloacm_remove_product_review($tabs) {
		unset($tabs['reviews']);
		return $tabs;
	}

|| remove sidebar from product view page,  go to functions.php
   /* Storefront Theme – Remove WooCommerce Sidebar on the Single Product Page */
	add_action( 'get_header', 'bbloomer_remove_storefront_sidebar' );
	function bbloomer_remove_storefront_sidebar() {
	    if ( is_product() ) {
	        remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
	    }
	}

|| add to cart text change, go to functions.php
   
   /* custom function add for add to cart text change */
	add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );    // 2.1 + 
	function woo_archive_custom_cart_button_text() {
	    return __( 'BY NOW', 'woocommerce' );
	}

|| how to change product column
   your theme > inc > woocommerce > storefront-woocommerce-template-functions.php
   search storefront_loop_columns

|| How do I add WooCommerce product categories to a custom menu?
    Go to Appearance > Menus
    In the upper right corner, click on Screen Options and ensure the "Products" and "Product Categories" boxes are checked

|| Display My Account link in a template file
   <?php if ( is_user_logged_in() ) { ?>
      <a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
   <?php } 
   else { ?>
      <a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?</a>
   <?php } ?>

|| How to enable registration on "My Account" page
   Go to WooCommerce > Settings > Account and  Enable customer registration on the "My account" page.

|| 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 );
		
	?>

|| edit products page:

You need to add a folder to your theme named "woocommerce" and copy the contents from the woocommerce plugin folder under "templates", 
copy archive-product.php and paste your theme woocommerce folder. The loop folder contains the files you want to use. 
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>