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 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 How to add link on my account navigation

How to add link on my account navigation in Magento 2 – In this tutorial, we’re going to add a new link to my account navigation in Magento 2.
You only need to create a layout file:

/app/code/YourVendor/YourModule/view/frontend/layout/customer_account.xml

with content:

In this file “mymodule/index/index” is url path of your link and “My Custom Link” is the label.

After flushing cache, your account navigation should look like this:

How to add link on my account navigation in Magento 2
How to add link on my account navigation in Magento 2

Upload images in Magento programmatically

In our custom Magento modules, sometimes we need to be able to upload, save some images to our server. As we know, in Magento we can upload images for product, store logo … So we also can create a form which can be used to upload images and save them to the server. Let’s find out how to upload images in Magento.

What we need:

  • a form with a file input.
  • a controller to get request and save the images.
  • Assuming that we save all images in “/media” directory.

 

1. Create a form with content:

It’s simple, right ? Now we will create a controller with an action to get request from this form and process.

 

2. Create upload action in your controller class like this:

 

You can get uploaded file name and path in $result which is an array. You also can look into “/media” directory and see if the image is saved. Hope this post could help you upload images in Magento.

In the next post, we will tell you how to create this feature work in Magento 2.

 

Create product attribute programmatically in Magento

Create product attribute programmatically in Magento – In Magento, product is an EAV Model so to add a custom product attribute we need to create an EAV attribute. Before starting, make sure that you already prepared your own module. If you haven’t, you can create a simple module following this post.

In this tutorial, you need to to:
– edit your config.xml file
– create file /app/code/local/YourVendor/YourVendor/Model/Mysql4/Setup.php
– create file /app/code/local/YourVendor/YourModule/sql/yourmodule_setup/mysql4-install-1.0.0.php

Edit your config.xml file, add this content:

Create file /app/code/local/YourVendor/YourVendor/Model/Mysql4/Setup.php

with content:

Create file /app/code/local/YourVendor/YourModule/sql/yourmodule_setup/mysql4-install-1.0.0.php

with content:

In this file:
“1.0.0” is your module version which is declared in /etc/config.xml file.

To create a new product attribute, we will use function addAttribute of model eav/entity_setup. You can find that function in file /app/code/core/Mage/Eav/Model/Entity/Setup.php and this is the function:

 

After editing the file, if you already installed your module on your server before, you need to re-install in to execute mysql4-install-1.0.0.php file. You also can upgrade your module to higher version as 1.1.0 by editing config.xml file and rename file ‘mysql-install-1.0.0.php‘ to ‘mysql4-upgrade-1.0.0-1.1.0.php

To re-install your module, go to your phpmyadmin, find table core_resouce and delete row which has code ‘yourmodule_setup‘.

Finally, flush cache storage.

When everything is done, you could see your new product attribute in ‘Backend->Catalog->Attribute->Manage Attributes‘ search ‘new_product_attribute‘ for Attribute Code.

Create product attribute programmatically in MagentoThat’s how to create product attribute programmatically in Magento. Hope it will be helpful.
If you have any question, leave a comment or contact us.

Create custom product type in Magento

Create custom product type in Magento – As you know, in Magento, there are 6 product types:
– Simple products
– Configurable products
– Grouped products
– Bundle products
– Virtual products
– Downloadable products

In this tutorial, we will show you how to create a custom product type in Magento. If you don’t have your own module, please create a simple one following this post.

To create a new product type, we need to do:
– Edit your config.xml file to declare your new product type
– Create a model for your product type
– Create a model for your product type price

Let’s do it step by step.

1. Edit your config.xml file.

Open file /app/code/local/YourVendor/YourModule/etc/config.xml and add content:

– ‘special‘ is your product type code.
‘yourmodule/catalog/product/type/special‘ is your product type model.
– ‘yourmodule/catalog/product/type/special‘ is your product type price model.

2. Create product type model.

Create new file /app/code/local/YourVendor/YourModule/Model/Catalog/Product/Type/Special.php with content:

3. Create product type price model

Create new file /app/code/local/YourVendor/YourModule/Model/Catalog/Product/Type/Sepecial/Price.php with content:

In those 2 classes, you can override some functions of Magento core product type. You can find parent classes at:
/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php
/app/code/core/Mage/Catalog/Model/Product/Type/Price.php
At last, refresh all cache types and try to create a new product to check if Magento recognized your new product type.

create custom product type in Magento
create custom product type in Magento

 

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