Magento multi site setup

In this post, we will guide you how to setup multiple websites in Magento

As you know, Magento support multiple websites stores and store views. That means you can manage separate websites using same admin panel. Each website has its own settings, themes, products, customers …

In this post, we will tell you how to create and setup multiple website on Magento 1.

Step 1: Create a website in Magento admin

Go to System -> Manage Stores -> Create Website

Setup multiple websites in magento - Metagento

Please remember new website code, store code because you will need it when editing index.php file.

Step 2: Create a new Root Category

( optional – if your new website has different products )

Go to Catalog -> Manage Categories -> Add Root Category

Step 3: Create a new Store

Go to System -> Manage Stores -> Create Store, select the website and the root category that you’ve just created.

Setup multiple websites in magento - Metagento

Step 4: Create a new Store View

Go to System -> Manage Stores -> Create Store View, select the store that you’ve just created.

Setup multiple websites in magento - Metagento

Step 5: Set new website Base URL

Go to System -> Configuration -> General -> Web -> Change “Current Configuration Scope” to the new website.

Edit Base URL in “Unsecure” & “Secure” tab using your new website domain.

Setup multiple websites in magento

Step 6: Edit index.php file in Magento root directory

Use your Cpanel File Manager or other FTP Clients as FilleZilla, WinSCP. Move to document root of Magento installation, then edit index.php file. You should create a backup of this file before editing.

Add this code:

BEFORE:

Step 7: Flush Magento Storage Cache in System -> Cache Management.

It’s done, that’s how to setup multiple websites in Magento 1.

In the next tutorial, we will guide you to do this in Magento 2.

If you have any question, please leave a comment.

Magento 2 Manage Indexer using command line

Indexing is how Magento transforms data ( products, categories … ), to improve the performance of your storefront.
Magento stores lots of data (including catalog data, prices, users, stores … ) in many database tables. To optimize storefront performance, Magento accumulates data into special tables using indexers.

For example, you change the price of an item from $4.99 to $3.99. Magento must reindex the price change to display it on your storefront.

Let’s see how to manage, refresh indexers in Magento 2 using command line via SSH

1. Magento 2 indexers

In default, there are 10 indexers:

  • Design Config Grid ( name: design_config_grid )
  • Customer Grid ( name : customer_grid )
  • Category products ( name: catalog_category_product )
  • Product categories ( name: catalog_product_category)
  • Product price ( name: catalog_product_price)
  • Product entity attribute value ( name: catalog_product_attribute)
  • Catalog search ( name: catalogsearch_fulltext)
  • Stock ( name: cataloginventory_stock)
  • Catalog rule product ( name: catalogrule_rule)
  • Catalog product rule ( name: catalogrule_product)

We can get indexer info using command:

2. Indexer status

An indexer status can be one of following:

  • valid: data is synchronized, no reindex required
  • invalid: the original data was changed, the index should be updated
  • working: indexing is in progress

We can get indexer status using command:

3. Indexing modes

Re-indexing can be performed in two modes:

  • Update on Save: index tables are updated immediately after the dictionary data ( product, category, store…) is changed.
  • Update by Schedule: index tables are updated by cron job according to the configured schedule.

We can check indexer’s mode using command:

To change indexer mode, we use command

“realtime” is equal to  “Update on Save” and “schedule” is equal to “Update by Schedule”.

4. Re-index

Besides using “System -> Index Management” in Magento backend, we also can re-index using command:

We will get the result like:

5. Reset indexer when it’s locked.

During re-index process, you may get the message like:

So we need to reset that indexer status to be able to re-index ( in this case, it’s “cataloginventory_stock” )

We can reset indexer using command:

That’s how we can manage Magento 2 indexers. Please leave a comment or contact us if you have any question.

Thank you!

Manage cache Magento 2 using command line

Manage cache Magento 2 using command line – In Magento 2 there are 2 ways to manage cache, going to “System -> Cache Management” in backend or using command line.

You can run commands in following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

1. View the cache status

magento cache:status

You can get a result like this:

1 means “Enabled”  and 0 means “Disabled”

2. Enable or Disable cache types

This command enables or disables all cache types or only the ones you specify

You can get each cache type code and its description here.

 

Above commands will enable/disable all cache types. You will get the cache types status after running the command.

3. Clean and Flush cache types.

What’s different between “Clean” and “Flush”

  • Cleaning a cache type deletes all items from enabled Magento cache types only. In other words, this option does not affect other processes or applications because it cleans only the cache that Magento uses.Disabled cache types are not cleaned.
  • Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage.Flush cache types if you’ve already tried cleaning the cache and you’re still having issues that you cannot isolate.

Commands:

Please note:

magento cache:flush is equivalent “Flush Storage Cache” in System -> Cache Management

magento cache:clean is equivalent “Flush Magento Cache” in System-> Cache Management

That’s how we can manage cache Magento 2 using command line. 

Magento 2 get Base URL

Magento 2 get Base URL – As you know, in Magento 1 we can easily get base url using function:

In this tutorial, let’s find out how to get base url in Magento 2

In Magento 2, we can get base url using an instance of StoreManagerInterface 

1. Create an instance of StoreManagerInterface in __construct function.

Then we can get base url using function

We also can get url for media, static, js directory:

2. In another way, we can create an instance of StoreManagerInterface using ObjectManager:

That’s how to get base url in Magento 2. See you in the next tutorial.

Magento 2 Add a menu item in backend

In this blog post we will see how to add a menu item in backend for your Magento 2 module.

1. Create file VendorName/ModuleName/etc/menu.xml

The admin menu in Magento 2 has 3 parts:

  • The main admin menu title which shows up in left sidebar
  • Submenu title
  • Actual menu

2. Create file VendorName/ModuleName/etc/acl.xml

3. Create Admin Routes with file: VendorName/ModuleName/etc/adminhtml/routes.xml

with content:

4. Create a backend controller to handle menu item url

VendorName/ModuleName/Controller/Adminhtml/World/Index.php

Finally, when you click on the new menu item, you will see “Hello World” in a page.

If something is wroing, you will be redirected to dashboard automatically.

That’s how to add a menu item in backend Magento 2, see you in other posts.

Magento 2 – Create system configuration – system.xml

In this blog post we will see how to create System Configuration for your module in Magento 2

System configuration in Magento 2 is very similar to Magento 1

System configuration is divided into different parts; tab, section, group and field which is described in magento1 blog. This same concepts are used in Magento2 as well.

1. Create VendorName/ModuleName/etc/adminhtml/system.xml file

with content

2. Set default values for these configuration item

Create file: VendorName/ModuleName/etc/config.xml

3. Create ACL file

Create file: VendorName/ModuleName/etc/acl.xml

Now when you open Magento admin, you see the “Test” tab and sections.
You might get an error 404 Not Found first time, just logout and login again to fix this.

That’s how to create store configuration in Magento 2. See you in other tutorials.

 

Magento 2 Fix Issue “No Region Found within the Locale…”

In Magento 2 sometimes, an error displays: No region found within the locale “de” (or other locale code). In this topic we will give you a solution for this issue.

How to get bug “No Region Found within the Locale…”

You have to setup language for your browser. Example with google chrome: Setting → Language → Choose your language → Done No Region Found within the Locale Magento 2 No Region Found within the Locale Magento 2

Then please refresh your browser you can get the bug if your extension use \Magento\Framework\CurrencyInterface

How to fix it?

We should use try catch function when define CurrencyInterface

Refresh your browser and this issue has gone.

That is the shortest process for you to  Fix Issue “No Region Found within the Locale…” in Magento 2 . With this guide, you can manage the Issue “No Region Found within the Locale…” in Magento 2 easily.

Thank you for reading this post and see you in other posts

Magento 2 Compile error: “No tokens were provided”

Magento 2 Compile error: “No tokens were provided”

In Magento 2, when you run “setup:di:compile” you may get error message:

“No tokens were provided”

That error message is caused by an empty file. You can find it using command:

It usually comes from an additional extension, just delete the empty file and run compilation again using:

I hope this will help. If you have any question, leave a comment or contact us.

Thanks.

Magento 2 Render WYSIWYG content

Render WYSIWYG Magento 2 – In this tutorial, we’re going to tell you how to render WYSIWYG Magento 2.

Some cases, you save your data using WYSIWYG editor then you want to render it in frontend.

With Magento 1, you can do it in this way:

However, in Magento 2, there is no BlockTemplateProcessor. We need to use this method instead:

Hope this could help.

Magento 2 Send Email Programmatically

Magento 2 send email programmatically – In this post, let’s find out how to send email programmatically in Magento 2. It will be useful for you in your custom module or new feature. What we need to do:

  • Create your email template in a html file.
  • Declare your email template.
  • Create a function to send your email.

We’re doing step by step:

Create new html file

/app/code/VendorName/ModuleName/view/frontend/email/modulename/test.html

with simple content:

Declare your email template, create xml file

/app/code/VendorName/ModuleName/etc/email_templates.xml

with content:

Finally, create a function to send your email.

In this tutorial, we’re using a controller action. Create file:

/app/code/VendorName/ModuleName/Controller/Index/Sendemail.php

with content:

You also can create this function in helper, model …

If you have any question, just leave a comment or contact us.

Thanks.