Unit 1 Flashcards

1
Q

Which two tasks are supported by Magento CLI? Customer password reset, Clearing cache, Codebase deployment from developer machine to staging server, Administrator account creation

A
  • Administrator account creation

- Clearing cache

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
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?
A
With the declarative squema this is not an issue (Since magento 2.3)
Recurring class which implements installSchemaInterface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which three scopes can be used to set different System Configuration values in Magento?: Language, Area, Store View, Store, Website

A
  • WebSite
  • Store
  • StoreView
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
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?
A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?

A

Clean generated (Clean page cache)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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?

A
  1. Add filters to the searchCriteriaBuilder outside the getList method
  2. Once added the filters, create a variable $searchCriteria which values is $searchCriteriaBuilder->create(). This create method returns an object of type SearchCriteriaInterface
  3. Pass the $searchCriteria object as parameter for the getList method
  4. 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()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

“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?”

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“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”

A

If the brand new installation is intended to preserver the old m1 installation, then

  1. You deploy the production site on a new server
  2. The asnwer is C, because this way the data will be translated and migrated to the new squema en m2
  3. When the migration results were satisfactory the migrate to live server

ANSWER IS A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
"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?"
A

You have to override the current preference in module/etc/di.xml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
"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?"
A

In etc/config.xml
in the node config/default/mycompany/mymodule/myoption

                     "configuration path"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

“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”

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

“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”

A

C & D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

“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?”

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

“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”

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

You are writing a customization for the customer module. You need to make sure the configuration files from your module are loaded after the customer module’s configuration. Where should the dependency be declared?

A

If the customization can’t run without the config files from the custome module’s then is a hard dependency and should be defined in the composer.json file of the customization module in the requiere section of the file.

17
Q
A custom module needs to log all calls of
\Magento\Customer\Api\AddressRepositoryInterface::save(). Which mechanism do you use?
A

I think that the best way to achieve this in with a plugin before

18
Q

A merchant gives you the module MyCompany_MyModule to install. How do you identify which REST endpoints are supported by the module?

A

I look into the etc/webapi.xml file, this file contains the endpoints declaration

19
Q

You have configured an event observer to watch the checkout_submit_all_after event. What is the required class definition for the event observer?

A

Create the file in vendor/module/Observer directory
It should implements Magento\Framework\Event\ObserverInterface
Also it should implement execute method
—————————————————————–
namespace MyCompany\MyModule\Observer;

use Magento\Framework\Event\ObserverInterface;

class MyObserver implements ObserverInterface
{
  public function \_\_construct()
  {
    // Observer initialization code...
    // You can use dependency injection to get any class this observer may need.
  }
  public function execute(\Magento\Framework\Event\Observer $observer)
  {
    //This way has access to the params send in dispatch
    $myEventData = $observer->getData('myEventData');
    // Observer execution code...
  }
}
20
Q

“You are tasked to install an extension to the merchant’s Magento instance. The extension is developed by the company called MyCompany and its codebase is available from all four locations listed below. Which two installations options do you choose from to prevent version conflicts during upgrade?

A. Clone the code from GitHub and put it into the vendor directory
B. Download the extension code from the developer’s website, and put it into app/code
C. Use Magento web setup wizard to pull the code from Magento’s composer repository
D. Use composer CLI to pull the code from MyCompany’s repository”

A

I think that the only viable option to avoid problems is D and C

21
Q

“In a code review of a merchant’s site you have discovered that there are multiple observers for the
checkout_submit_all_after event. After closer inspection, you notice one of these observers is
relying on the others being executed before it is called.
What risk does this pose, and how can it be mitigated?”

A

If the observers that needs other observers execution is named alphabetically superior then there should not be problems with that zz > aa

22
Q

What scopes are available for customer attributes?

A

Only global

23
Q

What is a valid use case for an around plugin?

A

The only valid use case is when the before and after plugins executions must be suppresed

24
Q

“You added a plugin declaration to MyCompany/MyModule/etc/di.xml:

What will be the effect of this declaration?”

A

If the double quotes duplicated are not a typo in the question, then this will throw an exception because that is an incorrect sintax

25
Q
"You have created a custom module which must perform an action immediately after an order is
placed, but only on the store front of the merchant site. You have selected the
checkout_submit_all_after as the target event which the module will observe.
In which file will the event observer be declared?
A

It should be declared in etc/frontend/events.xml

This way the scope of the event is delimited to the store front only

26
Q
"You are reviewing a Magento module and see a directory named Service.
What can you determine from this directory’s name?"
A

It’s not an standar magento directory so nothing can be inferred from its name, you have to check whats inside of it

27
Q

“You got a notification about error that occurred on a production environment. The merchant gave
you the error identifier.
How do you find the error message based on the identifier?”

A

The error is sent to a configured email for this porpouse

the subject should be the identifier

28
Q

“You have been asked to display details from the customer’s latest order on the customer’s
account dashboard (customer/account/). You create a new custom template to show the
information.
How do you obtain an order repository so you can fetch an order?”

A
I think you can make use of the dependency injection in a class like the block then create a method that fetch the order using the injected repository
Create viewmodel!!!!
29
Q
"The constructor function for \Magento\Catalog\Model\Category contains this excerpt: 
public funcion \_\_construct(
//..
\Magento\Store\Model\StoreManagerInterface $storeManager
//..
) { /* ... */}
With the automatic dependency injection that Magento provides, how is the
StoreManagerInterface resolved?"
A

If there is a preference defined in di.xml that class should be used

If there is not an object of type StoreManagerInterface passed to the constructor then Magento creates a concrete class based on the interface

TODO: Corroborate in code