Unit 1 Flashcards
Which two tasks are supported by Magento CLI? Customer password reset, Clearing cache, Codebase deployment from developer machine to staging server, Administrator account creation
- Administrator account creation
- Clearing cache
A custom module must make changes to the schema following each setup:upgrade run. This must be done after all other module’s schema updates have been applied. How is this accomplished?
With the declarative squema this is not an issue (Since magento 2.3) Recurring class which implements installSchemaInterface
Which three scopes can be used to set different System Configuration values in Magento?: Language, Area, Store View, Store, Website
- WebSite
- Store
- StoreView
A Magento industry partner shipping provider has tasked you to build their integration module called MyCompany_ShippingProvider. Where do you define the class that provides options for the select field that enables or disables the provider in the file etc/adminhtml/system.xml?
Mycompany
separator-top Shipping Provider MyCompany MyCompany_ShippingProvider::shippingprovider_config Options Module Enable Magento\Config\Model\Config\Source\Yesno
In the field inside the section defined for the tab
You added a new constructor argument to an existing action controller class. When you reload the page you get a PHP error that the wrong argument is passed to the class. How do you fix this?
Clean generated (Clean page cache)
You need to find all orders in the processing state. You have written the code: $orderRepository->getList($searchCriteriaBuilder->addFilter(‘state’, ‘processing’)); When you run the code, you get the following exception: Uncaught TypeError: Argument 1 passed to OrderRepository::getList() must be an instance of SearchCriteriaInterface.How do you resolve the exception?
- Add filters to the searchCriteriaBuilder outside the getList method
- Once added the filters, create a variable $searchCriteria which values is $searchCriteriaBuilder->create(). This create method returns an object of type SearchCriteriaInterface
- Pass the $searchCriteria object as parameter for the getList method
- Declare $orders = $this->orderRepository->getList($searchCriteria)->getItems() -> With the getItems method you will have an array of orders
or simply chain the create method in the parameter
$searchCriteraBuilder->addFilter(‘state’,’processing’)->create()
“You are working on a new entity called vendor. You implemented the model, resource model and
collection. You want to ensure that standard model events will be fired for your model, so an
observer can be created for the events vendor_save_after, vendor_save_commit_after and others.
How do you do that?”
In the properties of the model class you have to declare $_eventPrefix=”vendor”.
Note: In the model you can declare $_evenObject this property holds a name to display in the event and $_cacheTag, which holds an identifier within the cache
“You are setting up a brand new Magento installation for a merchant who is migrating from Magento 1 to Magento 2. Keeping in mind upgradability and the need to customize, which one do you choose?
A. Create a new Magento instance using composer create-project
B. Clone the magento/magento2 GitHub repository
C. Run php bin/magento setup:migrate command
D. Create a new Magento instance by using the bin/magento install command”
If the brand new installation is intended to preserver the old m1 installation, then
- You deploy the production site on a new server
- The asnwer is C, because this way the data will be translated and migrated to the new squema en m2
- When the migration results were satisfactory the migrate to live server
ANSWER IS A
"You are implementing a custom module MyModule, which provides an implementation of \Psr\Log\LoggerInterface called \MyCompany\MyModule\Logger. The LoggerInterface has the default preference declared in app/etc/di.xml. Keeping upgradability in mind, how do you make \MyCompany\MyModule\Logger the default implementation of the LoggerInterface globally?"
You have to override the current preference in module/etc/di.xml
"In a custom module you are adding a new field to the store configuration. The field will set the value for the configuration path mycompany/mymodule/myoption. How do you supply the default value for that configuration option?"
In etc/config.xml
in the node config/default/mycompany/mymodule/myoption
"configuration path"
“A module you are working on needs to send a newsletter to all subscribed customers at predefined intervals. Which two actions do you take to make sure the newsletter is sent?
A. Implement \MyCompany\MyModule\Cron\NewsLetterSender::execute and register it in
etc/crontab/di.xml
B. Implement \MyCompany\MyModule\Cron\NewsLetterSender::execute and register it in
etc/crontab/.xml
C. Make sure bin/magento cron:run is added to the system crontab
D. Register the plugin for \Magento\Customer\Model\Customer::authenticate in etc/crontab.xml”
Answer is B and C, assumign the B says etc/crontab.xml because once you implemented the logic in NewsLetterSender this is the file in which you have to register the cron and C because is the only other option valid
“Magento 2’s architecture uses code to bootstrap a custom module that resides in app/code. What two files are required to make a module usable? (Choose two.)
A. Helper/Data.php
B. etc/config.xml
C. etc/module.xml
D. registration.php”
C & D
“You are debugging a problem resulting from a recently deployed around plugin. The plugin is
intercepting the doSomething method. The aroundDoSomething plugin method is called
successfully, but the original doSomething method is no longer being executed as expected. What is causing this?”
It’s possible that a fail in the implementation of the plugin is preventing the doSomething method to execute, for example the plugin could be sending the wron parameters to the proceed callable
You need to add a new text attribute to all products in the Magento store. When this attribute is displayed on the product page, its values must be different depending on the selected language. Keeping simplicity in mind, how do you add this attribute?
I think that the most simple way to achieve this is using the admin panel to create a new extesion attribute, however this will have to be recreated in every enviroment in which the code is deployed so it can be more simple to use a data path and version it to the project’s repository
“You are implementing a before plugin in MyCompany_Magic. It will intercept the same method that MyCompany_Admission is already intercepting using a before plugin: Topmenu::getBlockHtml. Which two actions are required to ensure the new plugin will execute last? (Choose two.)
A. Include a sortOrder=”20” on the new plugin in MyCompany_Magic’s etc/di.xml file
B. Configure plugin sequencing for both plugins in MyCompany_Magic’s etc/plugin_sequence.xml file
C. Set a sortOrder=”10” for MyCompany_Admission’s plugin in MyCompany_Magic’s etc/di.xml
D. Add MyCompany_Admission as a dependency in MyCompany_Magic’s etc/module.xml file”
Answer is C&D
With C you ensure that this plugin is executed first
With D you ensure the Admission module is execute before Magic