Skip to content

Instantly share code, notes, and snippets.

@shebin512
Last active May 19, 2018 08:56
Show Gist options
  • Save shebin512/361b52543355ab8275badc766ef0531b to your computer and use it in GitHub Desktop.
Save shebin512/361b52543355ab8275badc766ef0531b to your computer and use it in GitHub Desktop.
Magento 2

Magento 2 Gists


Module creation via n98-magerun2.phar

emb-shebshe@emb-ban-297 /var/www/html/bfl-magento/htdocs $ n98-magerun2.phar dev:module:create --help
Usage:
 dev:module:create [-m|--minimal] [--add-blocks] [--add-helpers] [--add-models] [--add-setup] [--add-all] [-e|--enable] [--modman] [--add-readme] [--add-composer] [--author-name [AUTHOR-NAME]] [--author-email [AUTHOR-EMAIL]] [--description [DESCRIPTION]] [--] <vendorNamespace> <moduleName>

Arguments:
 vendorNamespace       Namespace (your company prefix)
 moduleName            Name of your module.

Options:
 --minimal (-m)        Create only module file
 --add-blocks          Adds blocks
 --add-helpers         Adds helpers
 --add-models          Adds models
 --add-setup           Adds SQL setup
 --add-all             Adds blocks, helpers and models
 --enable (-e)         Enable module after creation
 --modman              Create all files in folder with a modman file.
 --add-readme          Adds a readme.md file to generated module
 --add-composer        Adds a composer.json file to generated module
 --author-name         Author for readme.md or composer.json
 --author-email        Author for readme.md or composer.json
 --description         Description for readme.md or composer.json
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --root-dir            Force magento root dir. No auto detection
 --skip-config         Do not load any custom config.
 --skip-root-check     Do not check if n98-magerun runs as root
 --skip-core-commands  Do not include Magento 2 core commands


n98-magerun2.phar dev:module:create -m --add-composer \ 
--author-name "Your_Name" \
--author-email '[email protected]' \ 
--add-readme \ 
-- <vendorNamespace> <moduleName>

magento install / updage schema.

Adding index (making coulmn values unique)


You can use Index Type as \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE To add unique key use code,

<?php
// ..
->addIndex(
    $installer->getIdxName(
        'YOUR_TABLE_NAME',
        ['YOUR_UNIQUE_FIELD_NAME'],
        \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
    ),
    ['YOUR_UNIQUE_FIELD_NAME'],
    ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
)

You can add multiple column combination as UNIQUE with,

<?php
// ..
->addIndex(
    $installer->getIdxName(
        'catalog_product_entity_datetime',
        ['entity_id', 'attribute_id', 'store_id'],
        \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
    ),
    ['entity_id', 'attribute_id', 'store_id'],
    ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
)

Refer vendor\magento\module-catalog\Setup\InstallSchema.php ref: https://magento.stackexchange.com/a/160712/4794


Adding CMS block to CMS page

{{block class="Magento\Cms\Block\Block" block_id="Demo_Test"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment