magento2 插件开发流程

3.69K 浏览M2插件和模版分享区

magento2 插件开发流程

image 1-BNI8TI8EfDwIFkFt.png
基本结构如上图。

自定义的插件放在app/code下面。

默认是没有code这个目录的,手动创建一个就行。

以插件Iggo_Sport为例

1,在app/etc/config.php里注册插件名

<?php return array ( &#39;modules&#39; => array ( &#39;Iggo_Sport&#39; => 1, &#39;Magento_Store&#39; => 1, ... ));

2,下载示例插件
iggo_sport.zip

3,命令行执行:

sudo rm var/generation var/cache var/di -rf sudo php bin/magento setup:upgrade sudo php bin/magento setup:di:compile

4,测试

image //bbs.mallol.cn/assets/images/1-GaAVItGXDssKodSA.png
说明:

根据插件结构可以看出来,magento2跟1区别很大。

前后台的layout和template都写在插件里,不是独立放在app/design的。

然后代码都变了,都用的命名空间namespace

附录:

一些很好用的magento命令

Available commands: help Displays help for a command list Lists commands admin admin:user:create Creates an administrator admin:user:unlock Unlock Admin Account cache cache:clean Cleans cache type(s) cache:disable Disables cache type(s) cache:enable Enables cache type(s) cache:flush Flushes cache storage used by cache type(s) cache:status Checks cache status catalog catalog:images:resize Creates resized product images catalog:product:attributes:cleanup Removes unused product attributes. cron cron:run Runs jobs by schedule customer customer:hash:upgrade Upgrade customer&#39;s hash according to the latest algorithm deploy deploy:mode:set Set application mode. deploy:mode:show Displays current application mode. dev dev:source-theme:deploy Collects and publishes source files for theme. dev:tests:run Runs tests dev:urn-catalog:generate Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml. dev:xml:convert Converts XML file using XSL style sheets i18n i18n:collect-phrases Discovers phrases in the codebase i18n:pack Saves language package i18n:uninstall Uninstalls language packages indexer indexer:info Shows allowed Indexers indexer:reindex Reindexes Data indexer:reset Resets indexer status to invalid indexer:set-mode Sets index mode type indexer:show-mode Shows Index Mode indexer:status Shows status of Indexer info info:adminuri Displays the Magento Admin URI info:backups:list Prints list of available backup files info:currency:list Displays the list of available currencies info:dependencies:show-framework Shows number of dependencies on Magento framework info:dependencies:show-modules Shows number of dependencies between modules info:dependencies:show-modules-circular Shows number of circular dependencies between modules info:language:list Displays the list of available language locales info:timezone:list Displays the list of available timezones maintenance maintenance:allow-ips Sets maintenance mode exempt IPs maintenance:disable Disables maintenance mode maintenance:enable Enables maintenance mode maintenance:status Displays maintenance mode status module module:disable Disables specified modules module:enable Enables specified modules module:status Displays status of modules module:uninstall Uninstalls modules installed by composer sampledata sampledata:deploy Deploy sample data modules sampledata:remove Remove all sample data packages from composer.json sampledata:reset Reset all sample data modules for re-installation setup setup:backup Takes backup of Magento Application code base, media and database setup:config:set Creates or modifies the deployment configuration setup:cron:run Runs cron job scheduled for setup application setup:db-data:upgrade Installs and upgrades data in the DB setup:db-schema:upgrade Installs and upgrades the DB schema setup:db:status Checks if DB schema or data requires upgrade setup:di:compile Generates DI configuration and all missing classes that can be auto-generated setup:install Installs the Magento application setup:performance:generate-fixtures Generates fixtures setup:rollback Rolls back Magento Application codebase, media and database setup:static-content:deploy Deploys static view files setup:store-config:set Installs the store configuration setup:uninstall Uninstalls the Magento application setup:upgrade Upgrades the Magento application, DB data, and schema theme theme:uninstall Uninstalls theme
最后于 6月前 被admin编辑 ,原因:
0