MAGENTO TUTORIAL FOR BEGINNERS PDF

adminComment(0)

Hi Magento blog readers, the Magento Tutorial for beginners step by step is really necessary in Most importantly, you can download this pdf ebook for free. best possible assistance. To learn about recent additions or changes to existing topics, see the Change Log in the appendix of this guide. PDF User Guide. This tutorial will teach you the basics of Magento using which you can create websites with topics with screenshots explaining the Magento admin screens.


Magento Tutorial For Beginners Pdf

Author:JOSETTE BELMORE
Language:English, Japanese, German
Country:Solomon Islands
Genre:Children & Youth
Pages:198
Published (Last):04.12.2015
ISBN:665-3-14500-132-4
ePub File Size:19.78 MB
PDF File Size:15.70 MB
Distribution:Free* [*Register to download]
Downloads:35874
Uploaded by: LUCILA

Are you a starter Developer or newbies in Magento? Magento knowledge is extremely tremendous. That will become a mess and you are confused and don't . With Magento 2 Development Cookbook, we will cover the most important topics that will help you become a good Magento 2 developer. We will start with the. of this chapter will guide you through the basics of what Magento has to offer and Magento's basic operation in order to better understand the code. Let's start.

You already know email plays a very important role in modern website system. However, you probably know much less about email in Magento. Magento Events. Event is an important part of marketing aspect in eCommerce website.

Learn about Magento Events in this lesson.

Other books: PDF FOR NOKIA 500

Overriding core files in Magento. In this lesson, we will learn how to override core files in Magento. In reality, when developing a project, we rarely use a framework without changing it. However, these changes are not recommended because of its effect on the whole project. Entity Attribute Value in Magento.

Magento Product Types. Our Magento tutorial will examine a new issue: Magento Product Types and how to add a custom product type. Magento Custom Attributes.

In this lesson, we will learn about Custom Magento attributes. It lasts for two hours and is divided into two parts. The second lesson of Checkout Totals is Invoice and refund.

Shipping Method. Magento Payment Method. As you all know, one of the most important issues in e-commerce is payment method. Fortunately, Magento developed a full payment system, which ensures that your customers feel comfortable when shopping on your site. Learn about Magento Payment Method in this lesson. Magento Paypal Setup. Rule Conditions. In this lesson of Magento Tutorial for beginners, we will examine types of rule conditions and how to create a module to use these rule conditions.

Magento Indexer. URL Rewrite in Magento. When the redirect goes into effect, any existing links that point to the previous URL are automatically redirected to the new address.

In this lesson, you will understand URL rewrite in Magento. API in Magento. Here comes the final lesson of Magento Tutorial for beginners step by step. The Magento API provides you with the ability to manage your eCommerce stores by providing calls for working with resources such as customers, categories, products, and sales orders.

To understand the step by step guide of Magento Certificate Guide, take this for free. You can also find a list of lessons in our Magento Tutorial blog post. If you read the entire 31 tutorials then congratulations!

I am sure that you could basically create your own Magento website with primary features. If you intend to learn more, the Magento website building process still has much advance knowledge for you to discover. The in-depth, thorough and up-to-date guide about Omnichannel from Magestore. Hope these resources of Magento tutorial for beginners step by step would help you raise the confident to get started. Happy building and selling!

How can i validate customer new password in admin?

Have you ever considered creating an ebook or guest authoring on other blogs? I know my subscribers would appreciate your work. We are working on some new ideas which include Ebook on Magento. It is a great read. I particularly find your thoughts about module development interesting. Keep up these insightful posts.

References

Thanks for your publishing. It is not working of tutorial! Your email address will not be published. Save my name, email, and website in this browser for the next time I comment. Magento Tutorial for beginners. Comments one of the best resource to learn magento basics. Keep it as long as possible online. To run a test with these rules, we can run the following command: This command gives empty output, which means that this file is valid. This test gives us the following output: When we specify the ruleset of Magento 2, we have the following command: This command gives us the following output: These tools have defined their default rulesets for common usage.

These plugins will run a test when saving a file. For more details visit the following URL: If it is configured, there is a color indicator that says how clean your code is. More information can be found at https: Chapter 2. Working with Products In this chapter, we will cover the following recipes: Convincing the visitors to download something from the shop is the main target of every shop owner.

Products need to be set in such a way that a visitor can quickly find what he is looking for. With good product content, a shop looks reliable, due to which a visitor is more likely to download something. In this chapter, we will explain what you can do to display products in your shop, and we will see some extra things, such as a video and add to cart links, to raise conversion from a prospective downloader to an actual downloader.

The goal of this chapter is to make your shop more user-friendly with just a little development. Configuring the catalog defaults One of the first things is to configure some default catalog settings to the preferred values. We will cover all the configuration values that are possible in a Magento 2 installation. We will go through the available configurations and change some values to the recommended settings. Getting ready Open your frontend and log into the backend in a separate browser tab.

We will modify some configuration values to the recommended settings. When changing a configuration value, we can check what happens in the frontend. How to do it In the next steps, we will take a look at the catalog settings: In the backend, navigate to Stores Settings Configuration.

Open the Catalog menu, as we can see in the following screenshot: Open the Product Fields Auto-Generation section. In this section, we can configure the behavior of the generation of SKU and metadata. Open the Storefront section and set the following values: List mode: Otherwise, the last row of products will not be complete.

Products per page on List allowed values: No Note When you have a large number of products, it is not recommended to set the Allow all products per page option to Yes. When you have products and you want to show all the products on a single page, you will generate an enormous HTML output that can cause memory issues.

Product listing Sort by: No Use Flat Catalog Product: Yes 4. Enable the product reviews for guests. This allows everyone to write a review about a product.

When this is enabled, a review form will appear on the product review page. Open the Product Alerts section to configure product alert e-mails that will be sent when the price or stock changes. We will configure a stock alert with the following settings: Allow alert when product price changes: No Allow alert when product comes back in stock: Yes Note The previous configurations will send stock alert e-mails a stock alert is triggered when a product becomes available in stock to the subscribed e-mail addresses.

We can set the values for Product Alerts Run settings in the next section. We will configure a daily task at Daily Start time: Leave the Product Image Placeholders options as they are.

If we want, we can set a default image that will be shown when a product has no image or the image is not found. The best way is to set the placeholder images in the theme. Show for current: Website Note This will show the recent products you viewed over all stores and store views in the website.

Default recently viewed count: When Price Scope is set to Global, we can only configure one global price for a product, which will be the same in all store views.

In the Layered Navigation section, we will modify some settings to customize the left navigation for the category pages: Display product count: Yes Price navigation step calculation: Automatic this will equalize price ranges By making these settings, the price steps will always have the same increment. This means that the navigation will be shown with a maximum of three levels.

Configure the Catalog Search section as follows: Minimal Query Length: With this setting, you can disable the layered navigation if the results count is higher than the configured value. How it works All these settings are saved in the configuration table of Magento. The frontend files for the catalog pages will pick up these settings and render the output based on these settings. When you add extra functionality to the category page, you can easily extend the configuration with extra parameters.

More information about extending the configurations is given in the Extending the system configuration recipe of Chapter 6, Magento Backend. Working with attribute sets Magento has a flexible system to work with products.

When you sell, for example, a board game or a computer, the specifications of each product are different. For a board game, information such as age and duration is relevant. For a computer, a lot of technical specifications are relevant, such as the CPU power, disc size, and so on. To cover this, Magento 2 comes with a system called product templates, which can be compared with attribute sets in Magento 1.

A product template is a specification of product attributes that you can assign to products. We will create a newproduct attribute and a new product template such as an attribute set that we can use in new products. How to do it In the following steps, we will create an extra product attribute that we can use in a product template: Populate the form with the following instructions: Default label: Date this is the type of the attribute 3.

Magento Tutorial for beginners

Click on Save and Continue Edit and the attribute will be saved. You will see that the Attribute Code field is prepopulated with a code that is generated from the label. Additionally, we can set the following values: Values required: No Scope: Store View with this setting, we create the possibility to specify separate values for each store view Default value: Leave this field empty Unique value: In the Manage Labels tab, we can set the label that will be displayed on the product detail page.

If left empty, the attribute label will be used. In the Storefront Properties tab, we can set the following properties: Use in search: No Comparable on Storefront: No Use for Promo Rule Conditions: No Visible on Catalog Pages on Storefront: No Used in Product Listing: No Used for Sorting in Product Listing: Click on Save Attribute; this will save the attribute.

The next step is to create an Attribute Set to which will assign a product to. In the backend, navigate to Stores Attributes Attribute Set. Click on the Add Attribute Set button and fill in the form, as follows: Clicking on Save will open the overview page.

The overview will look as follows: Save the Attribute Set. Navigate to Product Catalog and create a new product by clicking on the New Product button. Select the right Attribute Set in the form, as shown in the following screenshot: When selecting the product template, you will see that the Game specific data tab appears in the product tab, as shown in the following screenshot: How it works Product attributes and Attribute Sets are used when you work with multiple families of products.

In the sample data of our shop, there are more attribute sets available for bags, clothing, and more. With Attribute Sets, you can make groups of attributes for every product family. When creating a product attribute, you have to choose the type of the attribute, which can be one of the following: Working with product types In Magento 2, it is still possible to work with different types of products. The standard product is a simple product, which is used to sell basic products, but there are more types available, such as products, where you can choose a size and other options, or download products, virtual products such as a license , and product combinations.

Getting ready In this recipe, we will create a configurable product, for example, you want to download a pair of shoes where you can choose their size and color. Open the Magento backend and navigate to Products Catalog. How to do it In the following steps, we will create a product where we can specify a size on the product detail page: Navigate to Products Catalog, click on the arrow near the Add Product button, and choose Configurable Product as shown in the following screenshot: Choose a name, SKU, and price for the product.

The next step is to decide the attribute on which we want to configure our product. Scroll down through the New Products page, and click on the Create Configurations button.

In the grid, select the Size attribute and click on Next. Select the sizes for your products and click on Next. On the next screen, you can add images, prices, and quantities for the products, or you can do this later. When you click on Next, you will get an overview. When you click on Generate Products, the products will be displayed as shown in the following screenshot: Click on the Save button and a popup will show up to create a specific attribute set for this configuration.

Select the Add configurable attributes to the new set based on current option and select a Size for the name. Click on Confirm to save the products in the database.

On the Product Edit page, select the category where you want to add the product, click on Save, and search for the product in the right category in the frontend. The product detail page will look as follows: How it works… A configurable product is a product where you can select one or more options on the product detail page.

Each combination of selections leads to a simple product in the database. The customer chooses the options, and when adding the configurable product to the cart, a simple product is also added in the background.

This is the reason why we have generated simple products to be shown as options in our configurable product. The configurable product is a parent wrapper that is used to display in the frontend. The simple products are hidden in the frontend by the Visibility attribute. When a product is sold, the SKU of the selected child product will be used to process the order. The following overview gives a short description of what is possible with the different product types. A simple product A simple product is just a product that you can sell in your web shop.

A configurable product In this recipe, we created a configurable product. This product has child products that you can configure on the product page for example, to configure the size. The child products are simple products. A bundle product A bundled product is like a configurable product, but with this one, you can optionally specify more options.

Note Every option of a bundle represents another product in the shop. When you add a bundle product to the cart, the products of the chosen configuration will also be added to the cart in the background. A grouped product A grouped product is a product that represents a set in which you can specify the number of child products. In a grouped product, you assign simple products. When adding a grouped product to the cart, the child products will be added as separate products with the configured quantity.

A virtual product A virtual product is like a simple product but it is not physical. A good example of a virtual product is a software license. A downloadable product A downloadable product is a product that is not physical.

When a customer downloads a downloadable product, a download link will be sent to the customer so that they can download their product, which is in the form of a PDF, MP3, ZIP file, or any other type of file. Adding social media buttons These days, an increasing number of people are sharing their minds through different social media, such as Facebook, Twitter, and many more.

Every social media platform has the option to share pages on their platform. The most famous examples of this are the share buttons, such as the Like button of Facebook, the Tweet button, the Google Plus button, and many more.

Getting ready In this recipe, we will add share buttons for the following platforms. You can take a look at the developer documentation of each platform as a preparatory step: Facebook https: Ensure that you have access to the code with your IDE. How to do it The following steps show you how to add social media buttons to the description of your product: Open the page of the product where you want to add the social media buttons.

We will start with the Like button of Facebook. Visit https: When clicking the Get Code button, you will see the code of the button. Place this code in the product description field. Save the product and open the Product Detail page of that product in the frontend. You will see a Like button in the description field of the product. We can also add buttons for sharing on other social media using the same principle.

For Twitter, we can get the code of a button at https: From here, copy the code and paste it after the code of the Facebook Like button. Similarly, for Google Plus, we can get a button at https: When reloading the frontend, we can see the buttons on the detail page of that product.

If we want to show it on every page, we will have to make a change in the code of the product detail template.

Magento Tutorial for beginners

In that recipe, all the steps are explained on how to do this. Add the code of the social media buttons at the end of the file. You generate the product URL with the following code: Use this code to generate the URL for the button. The code for the Facebook Like button code will look as follows: Save the file, clean the cache, and you will see the Like button on every page. How it works A social media button is mostly a piece of external HTML that will render in your website.

With this button, a page can be shared. To render these buttons, external static resources from the social media website will be loaded.

When you read the code of the buttons, you can see that additional JavaScript libraries are included in the code. When sharing a page, the social media crawls the page to look for a title, image, and description for the post. In the first case, the crawler will search for the Open Graph meta tags. These tags are generated by Magento on a product detail page, so a good title, image, and description will be displayed for the post.

In this recipe, we will focus on how to add a YouTube video in a product description. Getting ready Go to http: How to do it The next steps shows you how to embed a YouTube video on a product detail page.

On the YouTube video page, click on the Embed button. When you click this button, the following screen shows up: Copy the HTML code and paste it in the description of the product. Save the product. Go to the product in the frontend. You will see the video on the Product page. How it works The ability to use HTML tags in product descriptions gives a lot of flexibility for this field.

On a YouTube video page, we opened the embed options where we can configure the code that we will include in our site. We can specify options such as width, height, color and more.

When everything is configured, we can paste the Embed code in the HTML of the product description, and the video will be visible in the description of the product.

In this recipe, we will explore the possibilities of URL rewrites in Magento. Getting ready In the backend, navigate to Products Inventory Catalog and look for a simple product with visibility Catalog, Search. This recipe is based on the Endeavor Daytrip Backpack product from the sample data.

How to do it In the following steps, we will see the procedure for changing a URL of a product detail page. Find the appropriate product in the frontend. You can find by navigating to Gear Bags. In the backend, change the URL key attribute to download-now-endeavor-daytrip- backpack. Reload the product in the frontend.

The URL will change to the one we have just entered in the backend. The checkbox is located in the product edit page in the backend under the URL Key attribute. Empty the URL key attribute at the backend and save the product again.

You will see that Magento autogenerates the URL key attribute based on the name of the product. Clear the product URL Suffix field and save the configuration. Clear the cache by navigating to System Cache Management. Reload the product in the frontend, and you will see that the. In technical terms, this is also called routing. In the backend, you can see all the URL rewrites that are available in the installation.

On this page, you can see the complete list of the URLs that are available in the web shop. If we search for endeavor-daytrip-backpack, we will see a list of all the URLs, which looks like this. What we see is the following: When a product is enabled in multiple stores, it is normal that a product has more than one URL.

For example, a URL rewrite for the contact page. The following screenshot shows us how we can create an alias from the contact-us. In the Store option, you can configure the store for the URL rewrite. You also have the choice to redirect the page with a permanent or temporary redirect. Chapter 3. Theming In this chapter, we will cover: Making a good first impression to your customers is an important point to raise the conversion.

Almost every store owner wants a look and feel of their company in their shop. In this chapter, we will cover all the things you need to customize a Magento theme. Exploring the default Magento 2 themes When Magento 2 is installed, there are two themes available. You have the Luma theme that you can see in the sample data, and you have the Blank theme that is developed as a starting point to customize your theme.

Getting ready Log in to the backend and open the design configuration. We can find this in Stores Configuration Design. How to do it… The following instructions describe how we can configure the theme settings for a Magento 2 store: When you look at the theme settings on the configuration page, we see that the Magento Luma theme is selected in the Design Theme section.

Select the Magento Blank option in the dropdown, save the configuration, and reload the frontend. You should see something like the following screenshot: We have now configured the Magento Blank theme for the store. The Magento Blank theme is the default theme where the Magento Luma theme will extend from. Open the page Content Themes in the backend and you will see an overview of the available themes in Magento. When Magento 2 is installed without modules, the following themes are available: When clicking on Magento Luma, we will see the details of the theme like the following screenshot: We see that the Parent Theme is Magento Blank.

This means that this theme will extend the Magento Blank theme. In the backend, open the page Content Schedule.

When clicking the Add Design Change button, we can configure a design change with a from and to date. How it works… In Magento 2 the concept of themes is much easier than in Magento 1.

There are no packages any more, and no skins. When a theme has a parent theme, it will inherit everything from that parent theme except you can override it in your theme. This means that if your theme is empty, all the settings of the parent theme will be used. Like in Magento 1, you can override the theme settings in different ways such as the following: Before you start, disable the full-page cache because this will save you a lot of trouble.

You can do this in the backend on the page System Cache Management. Click on the Flush Magento Cache button after you have disabled the Full page caching. How to do it… The following procedure shows you which actions are required to create a custom theme: For our theme, we will create a vendor namespace. In that namespace, we will create a theme called cookbook. Note A theme is always written in small letters such as luma, cookbook, blank.

To register the theme, we have to create the file with the following content: At this point, we have to create a theme configuration file. It is also possible to add a preview image to the theme. In the theme folder, create a media folder in the theme folder and add an image of your choice that we want to use as a preview.

To set the preview image, we have to add the highlighted XML configuration to the theme.

Clear the cache and run the composer install to register the theme. You should see the theme in the list. When we click on the theme, we can see the details that we have configured in the theme. The last step is to configure the theme. Go to the page Stores Configuration Design and configure the theme like the following screenshot: Flush the cache and reload the frontend. Your shop will now have the look and feel of the Blank theme.

How it works… We have just created an empty theme that inherits everything from the Magento base theme. When we want to change stuff on the theme, we can do it in this theme without overriding the core. When copying a file, the directory structure needs to be the same as the structure of the parent theme.

Note Changing code in the Magento core will also work, but this is not recommended. When you want to upgrade your store, all the core files will be overwritten and then all your changes will be lost.

We created a theme. Magento will store this data in the theme table of the database. So when the caches are enabled and you change something in the config files, make sure you clean and flush the caches. You can also disable the caches when developing.

When this is enabled, containers will be shown around blocks of HTML with the reference to the file and class that is loaded. To enable this, navigate to Stores Configuration Advanced Developer and change the configuration scope dropdown to Main Website like the following screenshot: In the Debug section, you can enable the hints by setting the dropdown values to Yes for the following fields: When this is done, reload your frontend and you will see red borders around each block of HTML.

We can only change some styles to make a shop look different. The second way is to customize the HTML output, which is what we will cover in this recipe.

It is very common to want to change some stuff on the HTML structure to make your shop look unique. Getting ready Make sure you have the theme installed and configured like we have done in the previous recipe. How to do it… In the next steps, we will change the logo, change a template, and we will add extra blocks to the footer: First we will change the logo.

If you look at the frontend of the webshop, you will see that the default Magento logo is used. Create a logo. In that folder, create a default. You should see that the logo is changed to the specified file. Next we will change the toolbar on the category pages.

In the frontend, navigate to a category page with products such as Women Tops. To change the output of a category page, we have to override the template. To know what template is used, we can enable the template hints. Clean the cache and reload the page.

In the template hints, you will see that the file we just copied is used instead of the default one. Also disable the full-page cache when developing. In this file, we can change what we want without overriding the core. At last, we will add an extra menu with links in the footer. For this, we need to edit the file: Paste the following highlighted code in that XML file: Clean the cache and reload the frontend.

You should now see an extra column in the footer with two links in it. To end this recipe, we will add a link to the menu we have just created but that menu item is only visible on the cart page.

In that file, add the following content: Clean the cache and go to the cart page. You will see that there is an extra link in the menu. How it works… With the template hints on, we see that a lot of HTML blocks are used to build the page. All these blocks are configured in the layout XML files.

Every block in the page is from a specific type. This type is the class that is used to generate the block. In the layout XML files, the type of the block is specified with the class attribute. For changing the logo file, we have changed a parameter of the block class that is used for the logo. With the XML configuration in the default. We can modify page arguments like we have done with the logo or we can add child blocks like we have done with the extra footer menu.

The extra footer menu is a new block that we have specified as a child of the footer block. In the footer menu block, we have specified the links that are also implemented as a block. We add the new block in the default. This means that the configuration is loaded on all pages.

If you want to add a configuration that is only for a specific page, you have to put that configuration in a different file. Adding extra files to the theme In the previous recipe, we learned how we can make structural changes to the HTML output. However an HTML output is not a completed website.

This is a common case when integrating an external JavaScript plugin. To do this, we have to work in the theme folder that we created in the recipe Creating a Magento 2 theme earlier in this chapter. How to do it… The following steps describe how we can add extra files to a theme: In that file add the following content: You will see that the background color is changed to light gray and that the cookbook.

This works the same way as with the CSS file. Create the file cookbook. Clean the cache and reload the source of the frontend. Magento builds a symbolic link from the pub folder to the web folder in the theme.

When we have static files such as CSS, JavaScript, images, web fonts, and more, we have to place these files in the web folder of the theme. The following code snippet shows you how this works. How to change a page title is explained in the recipe Changing a page title in this chapter. Tip If you want to explore which configurations are possible in a particular XML file, have a look at the XSD file that is declared at the top of the file and you will see which configurations you can use in your config file.

CSS is very static. Access to a command line is also useful to work with Grunt. How to do it… The following steps describe how we can change the layout, such as how Magento 2 does it: Reload the page. Normally you will see no layout changes because we have to clear the pre-generated file. Remove the following folders with pre-generated CSS: Reload the page and your page will look like the following screenshot.

The load time of the page is a bit longer because the CSS needs to be generated: Note If you get a page without styling, an error occurred when rendering the CSS file.

If this happens, flush the cache and remove the folders again, as described in step 3. Another thing that can happen is that the pub and var folders do not have enough file permissions. Add the following highlighted code in that file around line This will give the top menu a darker color: You will see that the top bar is now in a dark color. The goal is to avoid duplicate CSS code that is loaded in the browser.

First, we did some styling by changing some variables that are defined by Magento. The purpose of the theme. In this folder, the variables of the default Magento components are initialized. We copied the original file to our theme.

This means that the file of our theme is loaded instead of the default theme. This process is called the fallback mechanism. When a file is loaded, Magento will look for it in the following order: When there is a change in a LESS file, we have to clear two folders. In this folder, all the particular LESS files are merged in a large file.

For CSS files, Magento will start the generation of them. For other files such as images, Magento will create symlinks to the source file. Changing files in the pub folder is not a good idea because you have to do it in the app folder and regenerate the files in pub. Tip It is also possible to use the JavaScript compiler.

In the backend, you can enable it on the page Stores Configuration Advanced Developer Front-end development workflow. With Grunt, we can configure a watcher for our theme. To use Grunt, we first have to install nodejs and grunt-cli. We can do this with the following commands on a Ubuntu server: Open your terminal and change to the Magento project root. In this directory, run the following commands: If you want to install this on other operating systems, you can find more information on the following URL: When running grunt watch, these files will automatically be generated after a file change.

Changing a page title Changing a page title helps you to improve the SEO of your website.

Documentation and Resources

How to do it… To change the page title of the contact page, have a look at the following steps: Go to the contact page in the frontend. You see that the page title is set to Contact Us. We will change this to Give us a message. You will see that the page title is changed to Give us a message!. When you look for the renderTitle function, you see the following code: For other types of pages, such as a product detail page where we can set the title in the backend, the pageConfig values will be overwritten after loading the layout XML configuration.

But for the contact page, this is not the case. Working with translations Magento has the ability to run a store in multiple languages. Every store view has a language, and Magento has a system to translate the interface into that particular language. Getting ready Open the backend and go to the store configuration at Stores Configuration General.

We will configure the French language for the default store view. How to do it… The following steps show how we can translate the interface of Magento in a specific language: First, we will configure the default language of the store view.

In the backend, go to Stores Configuration General and change the locale to the preferred value. In Magento, the following language packs are installed: When cleaning the cache and reloading the frontend, you will see that the interface texts are translated into French.

When you want to translate existing strings, we can do this by the Inline Translation tool and we can do it in the theme. Reload the frontend and you will see red frames around each interface text.

When hovering over a frame, an icon will appear. Click on it and a pop-up window will be shown with the translation form: The second way of translating the interface is to use a theme translation. For adding custom translations for a theme, we have to create the following file: When we want to translate the string Panier on the shopping cart page, we have to know the original string.

You can find the original string in the Inline Translation popup or in the templates: The original string for Panier is Shopping Cart. When we add the following line in the CSV file we have just created, the string will be translated to that value Shopping Cart, Votre panier.

Clean the cache and reload the shopping cart page. You will see that the title is changed from Panier to Votre panier. How it works… Magento has a powerful translate function. To make a string translatable through that function, we have to use the following syntax: First, Magento will look in the database table translation. This table is used to save the values translated with Inline Translation. If the string is not found in the translation table, Magento will look for it in the theme.

The last fallback is the translation files of the modules. If no matching string is found, the translate function will return the original string that is passed as an argument to the translate function. Adding widgets to the layout Magento has a set of predefined widgets that you can configure and show on the different pages.

With the Magento widget interface, we can configure different widgets on different pages. Getting ready We will add a block of products on the content area of the homepage. Go to the backend and navigate to Content Widgets. How to do it… In the following steps, we will configure a widget for the category pages: Click on the button Add Widget.

In the form, set the following values: Catalog Products List Design Theme: Packt cookbook 3. Click continue and the following screen shows up: Complete the Storefront Properties tab with the following values: Widget Instance Title: Widget-home-products This is the title of the widget in the backend.

All Store Views 5. Complete the Widget Options tab with the following values: Featured products Number of Products to Display: Choose a specific category like the following screenshot: Save the widget by clicking Save and Continue Edit.

The widget instance is now saved but nothing will show up in the frontend because there is no layout update set. We have to create a layout update before the widget will show up in the frontend. On the widget page, open the Frontend Properties and complete the Layout Updates section as follows: Clear the cache and reload the home page. You will see a list with products from the configured category. How it works… In the Main Content Area, a new block is added to the frontend.

Like any other block in the frontend, this block has a block class and a template similar to other blocks. The only difference is that this block is not generated by an XML file but by an XML layout instruction in the database.

The widget interface will generate a layout XML that is stored in the database. The block class and template are similar to other blocks in the XML files. Customizing email templates Magento has a lot of functionality that sends emails on particular actions, such as a new order, customer information, newsletter, and many more. When customizing the look and feel of your website, it is nice that your email templates have the same look and feel.

In this recipe, we will learn how we can do this. We will customize the new account email and we will learn how we can edit the generic header and footer of the transactional emails.

Getting ready We will customize email templates. To test this, make sure your development environment can send emails. Like the previous recipes, we will build the code further on the things that we have done in the previous recipes. How to do it… The following steps show how we can customize the email templates without overriding the standard templates: The email templates are located in the view folder of each module. If we want to change the new account email, we have to copy the original file to your theme.

When opening the new file, you can modify the content of the email in any way you want. We can use the following variables to make the file dynamic: You can also give a path between the quotes.

After the dot, you can specify the attribute of the customer object. Save the file and create a new account in the frontend with your email address. You will receive an email of a new account. If you open it, you will see that the variables are replaced by the information of Magento.

When we look in the template, we see that an email header is included in the template. How it works… When an email is sent in Magento, the general email function is used. This function sends an email with the right template and email headers such as subject, sender. The email function needs a template and that template is configured in the configuration XML files and uses a file from the email folder.

When an email template is configured through the configuration XML, it is also possible to overwrite this email template in the backend. This can be managed on the page Marketing Email Templates. New in Magento 2 is the ability to work with a header and footer template that is used in all the transactional emails. In the older versions of Magento 1, this was not possible and when you wanted to change something in the email header, you had to edit all the email template files.

These two features make it a lot easier to develop the transactional emails in Magento 2. Email templates are now part of a module. Chapter 4.

Creating a Module In this chapter, we will cover the following recipes: Every concept in the e-commerce flow is stored in a module. The Magento application is a combination of all these modules. One of the advantages of a modular architecture is the extendibility. It is easy to add modules that add to or modify the native behavior of Magento.

In this chapter, we will create a module with the most important things you need to know when writing code in Magento. Creating the module files When creating a module, the first step is to create the files and folders to register the module.

At the end of this recipe, we will have a registered module but without functionality. In the next recipes, we will add extra features to that module. Getting ready Open the root folder of your Magento 2 website. Access to a command line is also recommended because Magento 2 has a built-in console tool with a lot of commands that we can use during the development. How to do it… In the following steps, we will create the required files to register a Magento module: We will create a HelloWorld module in the Packt namespace.

In your Magento root, create the following folders: In the etc folder of the module, create a file called module. To register the module, we have to create a registration. Open your terminal and go to the Magento directory. When everything is OK, you can see the name of the module in the output of the last command. Ensure that you have cleaned the Magento caches. How it works… Module development in Magento 2 is much easier than in Magento 1.

The concept of code pools is gone, everything is stored in a single folder code, translations, templates, CSS, and more. These things make it a lot easier to develop and maintain a Magento module.

To initialize, we have to create the folders and the module. In the module. When we created the module files, we executed the setup: By running this command, we will run the install or upgrade procedure of all the modules.

This tool was introduced in Magento 2 and is a replacement of third-party tools from Magento 1 such as n98magerun and wiz. It is easy to add your own commands in a module.

Creating a controller In your Magento root, create the following folders: We will add an extra page that we can use for several purposes. Ensure that you have this module in your Magento instance. Also, ensure that the full page cache is disabled when you are developing. You can disable this in the backend by navigating to System Cache Management.

How to do it… The following steps show how to add extra pages using controllers and controller actions: Create the following folders:We can do this with the following commands on a Ubuntu server: When you run the command, you will see the following output: He started looking at Magento 2 as soon as he heard that the source code is available in a dev version. Databases and Modules In this chapter, we will cover: In this lesson, we will learn how to override core files in Magento.

For example, a URL rewrite for the contact page. When we want to change stuff on the theme, we can do it in this theme without overriding the core.

MICKI from Akron
I do enjoy reading comics dimly. Also read my other posts. One of my hobbies is cooking.
>