trunglv/mage2-dev

A few tools to understand Magento2

Installs: 768

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 1

Forks: 0

Open Issues: 0

Type:magento2-module

dev-main 2024-08-03 06:19 UTC

This package is auto-updated.

Last update: 2024-09-03 06:35:54 UTC


README

Packagist

Installation

1. Clone and copy a source code into a folder app/code/Betagento
2. Install from Composer
composer require trunglv/mage2-dev:dev-main [Recommend]

Debug tools

-1. Dependency Injection checking

** !!! Need to run setup:di:compile first to load DI configs (for preferences) and create kinds of Interceptor and Factory classes. **

php bin/magento beta_dev:check_di -t "Magento\Quote\Model\QuoteManagement"
----------------------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
| checkoutSession            | Magento\Checkout\Model\Session                      | Check possible interfaces. A class that relies on another class should interact with it through an interface!  | Magento\Framework\Session\SessionManagerInterface                         |
|                            |                                                     | Magento\Framework\Session\SessionManagerInterface                                                              |  ---> Magento\Framework\Session\Generic\Interceptor                       |
|                            |                                                     | Magento\Framework\ObjectManager\ResetAfterRequestInterface                                                     | Magento\Framework\ObjectManager\ResetAfterRequestInterface                |
|                            |                                                     |                                                                                                                |  ---> Magento\Framework\ObjectManager\ResetAfterRequestInterface          |
+----------------------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
+----------------------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
| customerSession            | Magento\Customer\Model\Session                      | Check possible interfaces. A class that relies on another class should interact with it through an interface!  | Magento\Framework\Session\SessionManagerInterface                         |
|                            |                                                     | Magento\Framework\Session\SessionManagerInterface                                                              |  ---> Magento\Framework\Session\Generic\Interceptor                       |
|                            |                                                     | Magento\Framework\ObjectManager\ResetAfterRequestInterface                                                     | Magento\Framework\ObjectManager\ResetAfterRequestInterface                |
|                            |                                                     |                                                                                                                |  ---> Magento\Framework\ObjectManager\ResetAfterRequestInterface          |
+----------------------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+

0. List all plugins by their listener type [before, around, after]

Example:

bin/magento beta_dev:show_plugins_by_listener_type -t around
------Plugins for Scope graphql------ 

+------------------------------------------------------------------+-----------------------------------------------------------------------+-----------------+--------------------------------------------------------------------------------------------------------------------+
| class                                                            | code                                                                  | original_method | instance                                                                                                           |
+------------------------------------------------------------------+-----------------------------------------------------------------------+-----------------+--------------------------------------------------------------------------------------------------------------------+
| Magento\Framework\GraphQl\Query\ResolverInterface                | cacheResolverResult                                                   | resolve         | Magento\GraphQlResolverCache\Model\Plugin\Resolver\Cache                                                           |
| Magento\Framework\Mail\Template\TransportBuilder                 | graphQlEmulateEmail                                                   | getTransport    | Magento\StoreGraphQl\Plugin\LocalizeEmail                                                                          |
| Magento\Framework\App\FrontControllerInterface                   | front-controller-builtin-cache                                        | dispatch        | Magento\PageCache\Model\App\FrontController\BuiltinPlugin                                                          |
| Magento\InventoryIndexer\Model\ResourceModel\GetStockItemData    | inventory_catalog_get_legacy_stock_item_data_from_stock_registry      | execute         | Magento\InventoryCatalog\Plugin\InventoryIndexer\Model\ResourceModel\GetLegacyStockStatusDataFromStockRegistry     |
| Magento\InventoryIndexer\Model\ResourceModel\GetStockItemsData   | inventory_catalog_get_bulk_legacy_stock_item_data_from_stock_registry | execute         | Magento\InventoryCatalog\Plugin\InventoryIndexer\Model\ResourceModel\GetBulkLegacyStockStatusDataFromStockRegistry |
| Magento\InventoryConfiguration\Model\GetLegacyStockItem          | inventory_catalog_get_legacy_stock_item_from_stock_registry           | execute         | \Magento\InventoryCatalog\Plugin\InventoryConfiguration\Model\GetLegacyStockItemFromStockRegistry                  |
| Magento\ConfigurableProduct\Model\Product\Type\Configurable      | used_products_cache_graphql                                           | getUsedProducts | Magento\ConfigurableProduct\Model\Plugin\Frontend\UsedProductsCache                                                |
| Magento\InventorySales\Model\AreProductsSalable                  | are_products_salable                                                  | execute         | Magento\InventoryIndexer\Plugin\InventorySales\AreProductsSalable                                                  |
| Magento\ReCaptchaValidationApi\Api\ValidatorInterface            | graphql_recaptcha_validation_override                                 | isValid         | Magento\ReCaptchaWebapiGraphQl\Plugin\ValidationOverrider                                                          |
| Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters | add_swatch_data_to_filters                                            | getData         | Magento\SwatchesGraphQl\Plugin\Filters\DataProviderPlugin                                                          |
+------------------------------------------------------------------+-----------------------------------------------------------------------+-----------------+--------------------------------------------------------------------------------------------------------------------+

1. List all plugins for a class

Example:

bin/magento beta_dev:show_plugins -t "Magento\InventorySales\Model\AreProductsSalableForRequestedQty"

Examples of results:

bin/magento beta_dev:show_plugins -t 'Magento\Quote\Api\CartManagementInterface'
 ------Plugins for Scope global------ 

Plugins for type Magento\Quote\Api\CartManagementInterface

+--------------------+-----------------+--------------------+--------------------------------------------------+---------------+
| code               | original_method | plugin_method_type | instance                                         | method_exists |
+--------------------+-----------------+--------------------+--------------------------------------------------+---------------+
| order_cancellation | placeOrder      | around             | PayPal\Braintree\Plugin\OrderCancellation        | method is ok  |
| order_update       | placeOrder      | before             | Magento\PaymentServicesPaypal\Plugin\OrderUpdate | method is ok  |
+--------------------+-----------------+--------------------+--------------------------------------------------+---------------+
Plugins for type Magento\Quote\Model\QuoteManagement

+----------------------------------+-----------------+--------------------+------------------------------------------------------------+---------------+
| code                             | original_method | plugin_method_type | instance                                                   | method_exists |
+----------------------------------+-----------------+--------------------+------------------------------------------------------------+---------------+
| update_bundle_quote_item_options | submit          | before             | Magento\Bundle\Plugin\Quote\UpdateBundleQuoteItemOptions   | method is ok  |
| validate_purchase_order_number   | submit          | before             | Magento\OfflinePayments\Plugin\ValidatePurchaseOrderNumber | method is ok  |
| coupon_uses_increment_plugin     | submit          | around             | Magento\SalesRule\Plugin\CouponUsagesIncrement             | method is ok  |
+----------------------------------+-----------------+--------------------+------------------------------------------------------------+---------------+

 ----- END Plugins for Scope ------global
-- No specific scoped plugins injected for Magento\Quote\Api\CartManagementInterfaces in frontend --
-- No specific scoped plugins injected for Magento\Quote\Api\CartManagementInterfaces in adminhtml --
-- No specific scoped plugins injected for Magento\Quote\Api\CartManagementInterfaces in webapi_rest --
-- No specific scoped plugins injected for Magento\Quote\Api\CartManagementInterfaces in graphql --

When you find plugins for an interface 'Magento\Quote\Api\CartManagementInterface', it will show plugins that are injected into the interface itself and a preference concrete class 'Magento\Quote\Model\QuoteManagement'.

2. List all observers for an event

bin/magento beta_dev:show_observers -e catalog_product_get_final_price 
Usage:
  beta_dev:show_observers [options]

Options:
  -e, --event=EVENT              Event code : --e catalog_product_get_final_price
  -s, --scope_code[=SCOPE_CODE]  Scope : -s global|frontend|adminhtml|crontab|webapi_rest|webapi_soap|graphql

image

3. Show all controller actions per a scope

bin/magento beta_dev:show_controller_action  -f checkout -a frontend
Description:
  Show all controller actions per a scope

Usage:
  beta_dev:show_controller_action [options]

Options:
  -f, --frontname=FRONTNAME  Frontname : --m catalog
  -a, --area=AREA            Area Code: --a frontend|adminhtml 

Example Result:

image

4. Reflection for Api Services

Description:
  Refection for API Services

Usage:
  beta_dev:api_reflection [options]

Options:
  -a, --api=API                    API ID : -a : /V1/carts/:cartId/shipping-information 
  -m, --http_method[=HTTP_METHOD]  HTTP Method: -m POST 

Example :

bin/magento beta_dev:api_reflection --api "/V1/carts/:cartId/shipping-information" -m POST
General information

image

Input Data Reflection

image

Output Data Reflection

image

Deploy static files ( Javascript, Css, Html, Js-translation, requirejs-config.js )

Before running CLI commands below - Pls ensure you have deleted the folder var/view_proccessed ( Some static files are cached in that folder)

bin/magento   beta_dev:deploy_static -h
Description:
  Deploy a static file.
  ---> Deploy static files from a/an module/extension.
  E.g. bin/magento beta_dev:deploy_static -f js/view/shipping-address/address-renderer/default.js -t Magento/luna -m Magento_Checkout
  ---> Deploy Css files base on a theme base Magento-Luna architecure.
  E.g. bin/magento beta_dev:deploy_static -f css/styles-l.css -t Magento/luna
  E.g. bin/magento beta_dev:deploy_static -f css/styles-m.css -t Magento/luna
  ---> Deploy JS Translation Json File base on a theme base Magento-Luna architecure.
  E.g. bin/magento   beta_dev:deploy_static -t Magento/blank -f js-translation.json

Usage:
  beta_dev:deploy_static [options]

Options:
  -f, --file_path=FILE_PATH        File Path/ Directory Path: for specific file -f js/view/shipping-address/address-renderer/default.js OR for a specific folder -f js
  -t, --theme_path=THEME_PATH      Theme path: -t Magento/luna
  -a, --area=AREA                  Area Code: -a frontend|adminhtml
  -m, --module_name[=MODULE_NAME]  Module name: -m Magento_Checkout
  -l, --locale_code[=LOCALE_CODE]  Locale code: -l da_DK 

1. Build/Deploy CSS/Javascript Files COME FROM an/a extension/module

bin/magento beta_dev:deploy_static -m Magento_Checkout -f js/view/shipping-address/address-renderer/default.js -t Magento/luna

-- Able to deploy Adminhtml themes and fully deploy for a directory

bin/magento beta_dev:deploy_static -t Magento/backend -a adminhtml -m Magento_Catalog -f js

2. Deploy a js-translation.json

Example:

bin/magento   beta_dev:deploy_static-t Magento/luna -f js-translation.json

3. Deploy css/styles-m.css, css/styles-l.css

bin/magento   beta_dev:deploy_static-t Magento/luna -f css/styles-l.css
bin/magento   beta_dev:deploy_static -t Magento/luna -f css/styles-m.css

RequireJS Config

Deploy a requirejs-config.js

Example:

bin/magento  beta_dev:deploy_requirejs -t Magento/luna

I love coding

@Trung,lv - skype: beta.trunglv@outlook.com - email : luuvantrung@gmail.com