Magento2 call cms static block

 Buy cheap and genuine Windows 7 product key  |
 Windows 7 Product Key for Windows 32bit/64bit Updated 2016y  |
 Windows 7 Ultimate ISO download  |
 Windows 7 Product Key Generator 32 bit and 64 bit Full  |
 Legit Windows 7 Product Key Online Store, PayPal Support  |
 Windows 7 Ultimate with Service Pack 1 Product Key,Windows 7 Key Sale  |
 Windows 7 Key  |
 Get Free Windows 7 Product Key  |
windows-10-education-key
windows-10-enterprise-key
office-2010-key
windows-7-key-sale
windows-10-home-key
windows-10-activation-key
windows-10-pro-key
office-2016-key
windows-10-key
office-2013-key
windows-10-iso
windows-7-key
windows-10-product-key

If you want to call cms block in .phtml template file then add below code to your phtml file –

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('a2bizz_block_identifier')->toHtml();?>

If you want to call cms block in .xml file, then add below code to the layout file –

<referenceContainer name="content">
  <block class="Magento\Cms\Block\Block" name="a2bizz_block_identifier">
   <arguments>
     <argument name="a2bizz_block_id" xsi:type="string">a2bizz_block_identifier</argument>
   </arguments>
 </block>
</referenceContainer>

If you want to call cms block in CMS Page

{{block class="Magento\\Cms\\Block\\Block" block_id="a2bizz_block_identifier"}}

Magento2: create custom module

Today we will learn to create custom module in magento2-

For installation and initial learning please visit our previous blogs of magento2.

The overall development we are doing on Ubuntu 14.4, local environment the base directory structure of my local is –
/var/www/html/magento2/app/code/A2bizz/Blog

You can download full code from GIT below given URL –
https://github.com/bloga2bizz/Magento2-Sample-Frontend-Module

customModule

Step 1.Initialization of your custom module –

First of all we will have to initialize our custom module to the list of modules with magento configuration, for which we will have to first create a /var/www/html/magento2/app/code/A2bizz/Blog/registration.php file and write below code –

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'A2bizz_Blog',
__DIR__
);

?>

if you hit your magento2 URL i.e. http://localhost/magento2/, now you will get below issue –

Cannot read contents from file "/var/www/html/magento2/app/code/A2bizz/Blog/etc/module.xml"

Now create module.xml on file /var/www/html/magento2/app/code/A2bizz/Blog/etc/module.xml and write below code –

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="A2bizz_Blog" setup_version="2.0.0" />
</config>

Now we have initialised our custom module, To check that please check /var/www/html/magento2/app/etc/config.php where your created module will be listed down, if not then upgrade custom module.

Step 2. creating controller & routing –

Now Further create controller file /var/www/html/magento2/app/code/A2bizz/Blog/Controller/Index/Index.php

<?php

namespace A2bizz\Blog\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{    
	protected $resultPageFactory;

	public function __construct(
		\Magento\Framework\App\Action\Context $context,
		\Magento\Framework\View\Result\PageFactory $resultPageFactory
	)
	{
		$this->resultPageFactory = $resultPageFactory;
		parent::__construct($context);
	}
    
    public function execute()
    {
        return $this->resultPageFactory->create();
    }

}

and a routes.xml file on path /var/www/html/magento2/app/code/A2bizz/Blog/etc/frontend/routes.xml,which will provide the path execution to your custom module –

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="blog" frontName="blog">
            <module name="A2bizz_Blog" />
        </route>
    </router>
</config>

here, in this xml we initializing the calling path for our custom module. In this way we have successfully hit out the controller for our custom module. Here in our example hit – http://127.0.0.1/magento2/blog

if the hitting above URL is showing blank white page, it means controller is hitted in a proper manner and now asking for the page layout.

Step 3. designing layout (view) for our custom module –

Now Further create layout files for your custom module /var/www/html/magento2/app/code/A2bizz/Blog/view/frontend/layout/blog_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="A2bizz\Blog\Block\Blog" name="blog" template="A2bizz_Blog::blog.phtml" />
        </referenceContainer>
    </body>
</page>

and add /var/www/html/magento2/app/code/A2bizz/Blog/view/frontend/templates/blog.phtml

<?php
echo "Blog Template";
?>

Now hit your custom module URL again, will show you below error
Object DOMDocument should be created.

it means it is unable to find corresponding Block method for its layout.

Now create your Block method, in /var/www/html/magento2/app/code/A2bizz/Blog/Block/Blog.php

<?php
namespace A2bizz\Blog\Block;

class Blog extends \Magento\Framework\View\Element\Template
{
	public function _prepareLayout()
	{
	    return parent::_prepareLayout();
	}
}
?>

Now, Executing your URL http://localhost/magento2/blog, will show you complete module functionality.

Magento 2 Overriding Controller

This post walks through the process to override a controller in Magento 2.

There are a few steps to override a Magento 2 controller.

Step 1. Building a Magento 2 extension structure

Building directories as given following:

magento2 --- app --- code
                       |--- A2bizz --- Sample
                       | --- Controller
                       | --- etc
                              | --- module.xml
                              | --- di.xml

Creating module.xml to define a Magento2 extension:

<?xml version="1.0"?>
<!--
/**
 * Created by blog.a2bizz@gmail.com
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="A2bizz_Sample" setup_version="0.0.1"/>
</config>

Step 2. Setting preference in di.xml

Creating di.xml to refer the overriding class:

<?xml version="1.0"?>
<!--
/**
 * Created by blog.a2bizz@gmail.com
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Cms\Controller\Index\Index" type="A2bizz\Sample\Controller\Index\Index" /> 
</config>

A2bizz\Sample\Controller\Index\Index will be used to override Magento\Cms\Controller\Index\Index, which is the homepage in original Magento 2.

Step 3. Defining an overriding controller class

Under magento2/app/code/A2bizz/Sample/Controller, defining Index.php as following.

<?php
/**
 * Created by blog.a2bizz@gmail.com
 */
namespace A2bizz\Sample\Controller\Index;
class Index extends \Magento\Cms\Controller\Index\Index
{
    public function execute($coreRoute = null)
    {
        $this->messageManager->addSuccess('Message from new controller.');
        return parent::execute($coreRoute);
    }
} 

Index.php redefines function execute() to override the function in \Magento\Cms\Controller\Index\Index. The new execute() adds a message to homepage, but it may also implements a complex logic.

Magento2: Overriding Block

This post go through the process to extend a block in Magento2.

There are a few steps to override a Magento2 block as given below –

Step 1. Building a Magento 2 extension structure

Building directories as following:

magento2 --- app --- code
                       |--- A2bizz --- Sample
                                             | --- Block
                                             | --- etc
                                                    | --- module.xml
                                                    | --- di.xml

Creating module.xml to define a Magento2 extension:

<?xml version="1.0"?>
<!--
/**
 * Created by blog.a2bizz@gmail.com
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="A2bizz_Sample" setup_version="0.0.1"/>
</config>

Step 2. Setting preference in di.xml

Creating di.xml to refer the overriding block class:

<?xml version="1.0"?> 
<!-- /** * Created by blog.a2bizz@gmail.com */ --> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> 
<preference for="Magento\Theme\Block\Html\Title" type="A2bizz\Sample\Block\HelloTitle" /> 
</config> 

A2bizz\Sample\Block\HelloTitle will be used to override Magento\Theme\Block\Html\Title.

Step 3. Defining an overriding class

Under magento2/app/code/A2bizz/Sample/Block, defining HelloTitle.php as following.

<?php
/**
 * Created by blog.a2bizz@gmail.com
 */
namespace A2bizz\Sample\Block;
use Magento\Framework\View\Element\Template;
class HelloTitle extends \Magento\Theme\Block\Html\Title
{
    public function getPageTitle()
    {
        return 'A2bizz Custom';
    }
    protected function _toHtml()
    {
        $this->setModuleName($this->extractModuleName('Magento\Theme\Block\Html\Title'));
        return parent::_toHtml();
    }
}

HelloTitle.php redefines function getPageTitle() to override the function in \Magento\Theme\Block\Html\Title. The new getPageTitle() just return a text string, but it may also implements a complex logic.

HelloTitle.php also redefines function _toHtml(). Although HelloTitle overrides \Magento\Theme\Block\Html\Title, the template file of \Magento\Theme\Block\Html\Title is still supposed to be used. And the real path of a template file is determined by both the module name of a block and the template attribute of the block. Therefore, the module name of HelloTitle is still Magento_Theme, rather than A2bizz_Sample.

This line

$this->setModuleName($this->extractModuleName('Magento\Theme\Block\Html\Title'));

sets the correct nominal module name. This module name is necessary to render with the template originally defined for Magento\Theme\Block\Html\Title.

Magento2: indexer re-indexing manually using terminal

Indexing is how Magento2 transforms data such as products, categories, and so on, to improve the performance of your storefront. As data changes, the transformed data must be updated—or reindexed. Magento2 has a very sophisticated architecture that stores lots of merchant data (including catalog data, prices, users, stores, and so on) in many database tables. To optimize store front performance, Magento2 accumulates data into special tables using indexers.

In Magento2, there is none interface from admin, to re-index manually at a time as we did in magento1, for doing this we need to use terminal. Using Terminal we can did full indexing of magento2, whenever we need, to do this we just only need to open terminal and reach the root directory of magento2 installation and type below mentioned command.

magento indexer:reindex [indexer]

where [indexer] is a space-separated list of indexers. Omit [indexer] to reindex all indexers.

add custom role

The key features of WordPress that is often overlooked is that there are a number of different user roles available. These user roles can  help make insure that only the people have access to just the areas they need and also helps minimize the chances of any  accidents happening that could potentially bring down the site. in this article we will look at those user roles briefly and also go into how to create your own custom roles.

User roles have been an important part of the WordPress experience since version 2.0. Most people don’t even know they exist and assign administrator rights to everyone who has access to their site dashboard (obviously not a good thing for a whole bunch of reasons). Off the shelf, WordPress comes with six default user roles:

Administrator: someone who has access to all the administrative features and functions within a site.
Editor: someone who can publish and manage posts of all users, including their own.
Author: someone who can publish and manage their own posts.
Contributor: someone who can write and manage their own posts but can’t publish them.
Subscriber: someone who can only manage their profile.

Why Use Custom User Roles?

The most part the default user roles are all that are needed. But there are cases where you need a user role that doesn’t fit in with the parameters of the default roles. And in this article We’ll see how to create custom user roles without using a plugin.

Lets thought on why we want to use Custom User roles. Typically use Custom User roles to make sure that clients only have access to what they need.

But if you are responsible for making sure the site stays up 24/7, then We recommend restricting the access of the client through a custom user role. That way We can give the client everything they need to make their site effective, like add content, maybe add events whatever they need to do. What they can’t do is things that can bring the site down or mess-up some functionality. We restrict things like access to add or remove plugins, themes, update core, all the kinds of things We’d want to do as part of my ongoing maintenance.

But lets start with a quick review of the basics, shall we?

Basic WordPress Functions

In order to manage roles and capabilities effectively, there are five very straightforward functions:

add_role(): Enables you to add a custom role.
remove_role(): Enables you to remove a custom role.
add_cap(): Enables you to add a custom capability to a role.
remove_cap(): Enables you to remove a custom capability from a role.
get_role (): Gets information about a role as well as the capabilities associated with the role.

We are only going to use the add_role() function for this article as we are going to create a custom user role for our fictitious client.

Defining The User Role

So before we dive into the code we need to have a plan, because diving into code without a plan is never a good idea.

So we need to give the user role a name. We’ll keep it simple and call the user role ‘Customer’.

So what can the user role ‘Customer’ actually do? There are over 50 different capabilities available in a clean install of WordPress (the number increases once you start adding plugins, but we’ll go over that in another article). For our purposes we want the client to be able to do the following:

Create posts
Edit posts
Edit Others posts
Manage categories
Edit Pages

Equally important is what we don’t want them to be able to do:

Edit themes
Add or Remove Plugins
Update core

Writing the Code

We are going to put this code into the functions.php file for our active theme. So lets start by adding this to the file:

// Add a custom user role

$result = add_role( 'customer', __(
'Customer' ),
array( ) );

By adding that piece of code, you have technically created a new user role (you can check it in the drop down on the Add New User page and it should be there). The problem is this user role has no functionality assigned to it. So the next step is obviously to add the functionality we had previously identified in our requirements above. Just add the array code to what you have already entered into your functions.php file.

// Add a custom user role

$result = add_role( 'customer', __(

'Customer' ),

array(

'read' => true, // true allows this capability
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode

)

);

That will give us the functionality we want the client to have but we still need to restrict them from doing things that could potentially cripple the site. So lets add that now.

// Add a custom user role

$result = add_role( 'customer', __(

'Customer' ),

array(

'read' => true, // true allows this capability
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
'edit_themes' => false, // false denies this capability. User can’t edit your theme
'install_plugins' => false, // User cant add new plugins
'update_plugin' => false, // User can’t update any plugins
'update_core' => false // user cant perform core updates
)
);

User Role Is Set Up Properly?

WordPress Sidebar Making sure your new user role is working as intended requires you to set up a new user with the appropriate role, log out and log back in as the new user.

Depending on what capabilities you’ve allowed and what you have denied, the first thing you should notice is a change in what’s available in the dashboard. The image below shows you what you would see if you set up the client role as we did above.

Opencart2 : Create custom module in admin

Here is the way add custom helloworld module in admin.

  1. create admin/controller/custom/helloworld.php
    <?php
    class ControllerCustomHelloworld extends Controller {
    
     public function index() {
    
     $this->load->language('custom/helloworld');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->load->model('custom/helloworld');        
    
     $data['header'] = $this->load->controller('common/header');
     $data['column_left'] = $this->load->controller('common/column_left');
     $data['footer'] = $this->load->controller('common/footer');
     $this->response->setOutput($this->load->view('custom/helloworld.tpl', $data));
    
     }
    }
    ?>
  2. Create admin/model/custom/helloworld.php

    <?php
    class ModelCustomHelloworld extends Model {
    
    public function helloworldmodel(){
    
     }
    }
    ?>
  3. create admin/language/english/custom/helloworld.php

    <?php
    // Heading
    $_['heading_title']          = 'Hello world Admin module';
    
    ?>
  4. Create admin/view/template/custom/helloworld.tpl

    <?php echo $header; ?><?php echo $column_left; ?>
    <h1><?php echo "This is helloworld admin module in opencart 2.x.x.x "; ?></h1>         
    <?php echo $footer; ?>
  5. Go to system -> users -> user groups -> edit Administrator group. Select all to access permission and modify permission and save.custom-module

Fix ‘Namespace_Module_Helper_Data’ not found fatal error in Magento ?

Following are the steps to resolve”fatal error: Class ‘Namespace_Module_Helper_Data’ not found” error.

  1. Install the extension when compilation is disabled in Magento admin.
  2. To check whether compilation is enabled or disabled, go to
    Admin > system >Tools > compilation  check enabled / disabled
  3. If enabled, then disable it and install the extension. Once the extension is installed you can enable compilation again by using ‘Re-run Compilation.
  4. If you have already installed the extension & are facing the above error, Disable the extension from app/etc/modules/Namespace_Module.xml
  5. <active>true</active> 
    To
    <active>false</active>
  6. Clear cache from var/cache folder.
  7. Now you will have the access to Magento admin panel from where you can disable the compilation.
  8. Now enable the extension from Namespace_Module.xml
  9. <active>false</active>
    To
    <active>true</active>
  10. Clear cache from var/cache folder.

Move website from one domain to another domain in opencart

Here is the steps to migrate opencart website from one server to another server.

  1. Download ALL the files from old server.
  2. Take a backup of Database using PhpMyAdmin.
  3. Upload files to NEW SERVER.
  4. Install Database on NEW SERVER
  5. Update the configuration files i.e config.php and admin/config.php with new domain path.

Update config file with following details.

<pre>
// HTTP
 
define('HTTP_SERVER', 'http://yournewdomain.com/');
 
// HTTPS
 
define('HTTPS_SERVER', 'http://yournewdomain.com/');
 
// DIR
 
define('DIR_APPLICATION','/root-folder-newdomain/public_html/catalog/');
define('DIR_SYSTEM','/root-folder-newdomain/public_html/system/');
define('DIR_DATABASE','/root-folder-newdomain/public_html/system/database/');
define('DIR_LANGUAGE','/root-folder-newdomain/public_html/catalog/language/');
define('DIR_TEMPLATE','/root-folder-newdomain/public_html/catalog/view/theme/');
define('DIR_CONFIG','/root-folder-newdomain/public_html/system/config/');
define('DIR_IMAGE','/root-folder-newdomain/public_html/image/');
define('DIR_CACHE','/root-folder-newdomain/public_html/system/cache/');
define('DIR_DOWNLOAD','/root-folder-newdomain/public_html/download/');
define('DIR_LOGS','/root-folder-newdomain/public_html/system/logs/');

// DB
 
define('DB_DRIVER','mysql');
define('DB_HOSTNAME','localhost');
define('DB_USERNAME','your-new-database-username');
define('DB_PASSWORD','your-new-database-password');
define('DB_DATABASE','your-new-database');
define('DB_PREFIX','oc_');

</pre>


Save the changes and upload files on new server.

How to setup Robots.txt In OpenCart?

How to setup Roboto.txt file?

Robots.txt stands for robots dot txt.  Roboto.txt is a text file that helps search engines like Google, Bing to understand what information on a particular site needed to be indexed. It is a critical file to success for any e-commerce store.

Why we need this file ( Roboto.txt )?

Robots.txt file should be placed in the root directory of your website. It tell the search engines, which pages to skip and which to index. Webmasters use robots.txt files to help search engines index the content of their websites.  Robots.txt file is the simple and easy method of easing the process for spiders to provide more relevant search results.

Improve performance by the use of Roboto.txt file in Opencart.

There are two primary reasons of using roboto.txt file, which are mention below :

  1. Robots.txt will help prevent duplicate content issue, one of the primary thing for SEO success.
  2. Robots.txt also hide technical details about website  i.e. Error logs, SVN files, wanted directories etc. Since, these are prevented by Robots.txt you are left with clean URLs to be indexed in search engines.

 

Set Up Robots.txt in OpenCart

Robots.txt settings will only cover 1 domain at a time, so for multiple stores you have to create separate robots.txt files for each stores. Creating Robots.txt is super simple since it’s nothing but a text file . It is supposed to reside at root of your site

Example :  Ff your store domain is www.a2bizz.com you should put robots.txt file under the domain root where you also have app directory. So it sits and accessed like www.a2bizz.com/robots.txt.

Note : Search engines look for Robots.txt file directly under store root and not under a directory.

 

Roboto.txt for opencart :

Test version of roboto.txt is given below :

User-agent: *
    Disallow: /*&limit
    Disallow: /*?limit
    Disallow: /*?sort
    Disallow: /*&sort
    Disallow: /*?order
    Disallow: /*&order
    Disallow: /*?price
    Disallow: /*&price
    Disallow: /*?brand_tabletpc
    Disallow: /*&brand_tabletpc
    Disallow: /*?color_default
    Disallow: /*&color_default
    Disallow: /*?filter_tag
    Disallow: /*&filter_tag
    Disallow: /*?mode
    Disallow: /*&mode
    Disallow: /*?cat
    Disallow: /*&cat
    Disallow: /*?dir
    Disallow: /*&dir
    Disallow: /*?color
    Disallow: /*&color
    Disallow: /*?product_id
    Disallow: /*&product_id
    Disallow: /*?minprice
    Disallow: /*&minprice
    Disallow: /*?maxprice
    Disallow: /*&maxprice
    Disallow: /*?route=checkout/
    Disallow: /*?route=account/
    Disallow: /*?route=product/search
    Disallow: /*?page=1
    Disallow: /*&create=1
    Disallow: /?route=information/contact
    Disallow: /*?route=affiliate/
    Disallow: /*?keyword
    Disallow: /*?av
    Disallow: /admin/
    Disallow: /system/
    Disallow: /catalog/
 
    Sitemap: http://www.a2bizz.com/index.php?route=feed/google_sitemap