Index

Api


Create your own api. Test is with the build in api tester in your magento 2 installation. http://<yourmagento2website>/swagger

WARNING. This api is public. Acl will be added soon.

Back to top

Block


Creates just a Block

Create a Simple Block for the Frontend or Adminhtml. It is also possible to insert the block based on a layout handle and a reference.

Example

Create a Notice Block

Input for the block form

  • classname: Notices
  • methodname: getCustomNotice
  • scope: Frontend
  • layout handle: default
  • reference type: Container
  • reference name: content
Back to top

Cache


Custom Cache snippet

Back to top

Category Attribute


Install Magento 2 category attributes programmatically.

Back to top

Company Attribute (Magento Commerce)


With this snippet you can create company attribute programmatically through a Magento 2 InstallSchema or UpdateSchema setup script and adds the fields to the admin form.

Magento 2 create company attribute programmatically

Back to top

Component


Create React Component

Back to top

Configuration Type


Back to top

Console Command


Console commands are listed and executed by bin/magento command line tool.

  • action_name: Console action name. Example: Backup, Import
  • short_description: Console action description. Example: Backups the Magento environment, Starts product import

Snippet generation

When you generate a module with an action_name (backup) and the module is named (MageGen/Module). The generated command used by bin/magento is:

bin/magento mage2gen_module:backup
Back to top

Controller


Controller is used to serve a request path. A request path look like this:

www.yourmagentoinstallation.com/frontname/section/action
  • frontname: Configured in the router.xml and must be unique.
  • section: Is a subfolder or folders to the action class.
  • action: An action class that will execute the reqeust.

This snippet will also create a layout.xml, Block and phtml for the action.

Back to top

Crongroup


With this snippet you can create a separate cron group. It will generate just a cron_groups.xml file which is automatically loaded by Magento.

Back to top

Cronjob


With this snippet you can create a class with a 'execute' method wich will be executed by the magento cron schedule according to the cron schedule you have configured.

The class will be created within the "Cron" folder of the module.

To build up the cron schedule manually use php bin/magento cron:run

You should find a log in the var/log/system.log after the cronjob has runned.

In the Magento 2 Adminpanel under Stores > Configuration > Advanched > System you change scheduler settings per cron group.

You can create your own groups if you wish. In that case be sure to add extra system settings.

Instead of the <schedule> tag in the crontab.xml you can set a system config path

Example

<config_path>crontab/default/jobs/catalog_product_alert/schedule/cron_expr</config_path>

This way a admin user can configure the cronschedule for this task.

Back to top

Customer Attribute


With this snippet you can create customer and customer address attribute programmatically thru a Magento 2 InstallData setup script. You can asign them to the forms where the should appear.

Warning. Not all template files are setup to load customer or customer address attributes dynamically.

Magento 2 create customer attribute programmatically

Back to top

Customer(Section) Data


Creates a Customer(Section) Data

Since private content is specific to individual users, it’s reasonable to handle it on the client (i.e., web browser).

Use our customer-data JS library to store private data in local storage, invalidate private data using customizable rules, and synchronize data with the backend.

Back to top

EAV Entity


Back to top

EAV Attribute (custom)


Install Magento 2 custom eav entity attributes programmatically.

Back to top

GraphQl Endpoint


Back to top

GraphQl Url Locator


Back to top

Helper


A Helper can be used to retrieve logic which can be used more then once. For example the module function isEnabled.

Back to top

Language


Magento 2 uses csv files for translations per language. This snippet will generate a translation csv file for selected language with one example translation.

  • language: Language for translation file.

Snippet generation

When you generate a module for the language English (United States), it will create a csv translation file in i18n/en_US.csv

Back to top

Model


Model is used to create a easie CRUD interface to the database

  • Model ame: The name of the model, the table name wil be <module_name>_<model_name>.
  • Field name: The name of the database table field.
  • Field type: The type of database field.
  • Adminhtml grid: Add this field to the adminhtml grid layout

Model ID field: The snippet will auto add the model id field to the database table, the field name is <model_name>_id.

Back to top

Observer / Event


With observers you can hook in on events fired by Magento or other third party modules. For creating an observer we need the event name and the scope:

  • Event name: Name of event you want to observe, example: catalog_product_save_after
  • Scope: For which scope the observer is active.
    • All: Observer is always active
    • Frontend: Observer is only active in the frontend of Magento.
    • Backend: Observer is only active in the admin panel of Magento.

Some events:

  • sales_order_place_before
  • sales_order_place_after
  • checkout_cart_product_add_after
  • checkout_cart_update_items_before
  • checkout_cart_save_before
  • catalog_product_get_final_price
Back to top

PageBuilder Content Type


Page Builder comes with several content types (controls) you can use to build your storefront pages. In this tutorial, you will add a new content type: a Quote control, which you can use to show customer testimonials or other types of quotations within your storefront.

https://devdocs.magento.com/page-builder/docs/create-custom-content-type/overview.html

Back to top

Payment Method


Creates a payment method

Generated Payment methods can be found in Magento Adminpanel > Stores > Settings > Configuration > Sales > Payment Methods

It allows you to add extra payment methods to Magento. For example if you need to have a payment method which can only be used in the backend or if you need a payment that directly creates an invoice.

Back to top

Plugin


Creates a Plugin

Plugins are designed to overwrite core Magento methods or methods from other 3rd party modules.

You can choose to change it before, after, or around the original method is called.

Example

Change the product name to show pipes before and after the name.

Input for the plugin form

  • classname: MagentoCatalogModelProduct
  • methodname: getName
  • plugintype: After
public function afterGetName(
        Magento\Catalog\Model\Product $subject,
        $result
){
        return '|'.$result.'|';
}
Back to top

Preference / Rewrite


Create the old school Magento 1 Rewrite, but it is not recommended.

Back to top

Product Attribute


Install Magento 2 product attributes programmatically.

The attribute is automatically added to all the attribute sets.

Back to top

Product Type


Creates a Product Type

Magento supports a number of product types, each with its own behavior and attributes.

This powerful concept allows Magento to support a wide range of industries and merchant needs by mixing and matching product experiences in their catalog.

Even more powerful, however, is the ability for developers to easily add new product types.

In general, when a product class has distinct behavior or attributes, it should be represented by its own product type.

This allows the product type to have complex and custom logic and presentation,

with no impact on other product types — ensuring that native product types can continue to function as intended.

Back to top

Router


Custom routers

Create an implementation of RouterInterface to create a custom router, and define the match() function in this class to use your own route matching logic.

If you need route configuration data, use the Route Config class.

Back to top

Sales Attribute


Install Magento 2 sales order attributes programmatically.

Back to top

Shipping Method


Creates a basic Magento 2 shipping method.

Generated Shipping methods can be found in Magento Adminpanel > Stores > Settings > Configuration > Sales > Shipping Methods

It allows you to write your own price logic to calculate the shipping cost. It is written in /Model/Carries/Generatedshippingmethod.php

Example:

if you want to calculate the shipping cost based on the shipping cost per product in the customers basket.

$items = $request->getAllItems();
$cost = 0;

foreach($items as $item){
        $cost += $item->getProduct()->getShippingCost();
}
Back to top

System / Config / Setting


System config is used in Magento for storing settings to use in your module.

For example an option to enable and disable your module.

Snippet Instructions:

  1. Fill in the Tab (can be found in Magento Adminpanel > Stores > Settings > Configuration)
  2. Check the box to add your config to an existing Tab
  3. Fill in the Section
  4. Fill in the Group
  5. Fill in the Field
  6. Select the Field type
  7. Check the box to make your config available in the Graphql StoreConfig endpoint

Available Field Types:

  • Text
  • Textarea
  • Select
  • Multiselect
  • Encrypted (Obscure)

For Select and Multiselect you will need to define a source model. By default this will be this will be the core Magento yes/no.

Retrieve config value:

To retrieve the value you can use the xml path yourmodulename/general/enabled

$this->_scopeConfig->getValue('yourmodulename/general/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

(Depends on \Magento\Framework\App\Config\ScopeConfigInterface)

More information:

https://github.com/magento/magento2/blob/2.3-develop/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php#L29

Retrieve config in GraphQl:

Query a store’s configuation

The following call returns all details of a store’s configuration. .. json:

{
          storeConfig {
                        yourmodulename_general_enabled
          }
}

More information

https://devdocs.magento.com/guides/v2.3/graphql/reference/store-config.html#extend-configuration-data

Back to top

Unit Test


Unit tests are runned with magento dev:tests:run <test> and is used to test your code in development.

  • Test suite: A class with a collection of tests
  • Test name: The name of a test
Back to top

Viewmodel


A ViewModel can be used to retrieve customer specific logic with in a template file.

It is possible to set the viewModel argument with a layout update.

Back to top

Widget


Back to top