Free AD0-E716 Exam Braindumps (page: 4)

Page 3 of 18

An Adobe Commerce developer is developing a custom module. As part of their implementation they have decided that all instances of their Custom\Module\Model\Example class should receive a new instance of Magento\Filesystem\Adapter\Local.
How would the developer achieve this using di. xml?




Answer(s): B

Explanation:

The developer can achieve this by adding the following configuration to their di.xml file:
XML
<config>
<component name="Custom\Module\Model\Example"
factory="Custom\Module\Model\ExampleFactory">
<arguments>
<argument name="filesystemAdapter" type="Magento\Filesystem\Adapter\Local" /> </arguments>
</component>
</config>
This configuration will ensure that all instances of the Custom\Module\Model\Example class will receive a new instance of the Magento\Filesystem\Adapter\Local class.



An Adobe Commerce developer has been tasked with applying a pricing adjustment to products on the website. The adjustments come from a database table. In this case, catalog price rules do not work. They created a plugin for getPrice on the price model, but the layered navigation is still displaying the old price.
How can this be resolved?

  1. Create an implementation for \Magento\Catalog\Hodel\Product\PriceModifierlnterf ace.
  2. Create an after plugin On \Magento\Catalog\Api\Data\BasePriceInterface:: getPrice.
  3. Create a plugin for\Magento\Catalog\Model\Indexer\Product\Price::executeRow.

Answer(s): C

Explanation:

The developer can resolve this issue by creating a plugin for the Magento\Catalog\Model\Indexer\Product\Price::executeRow() method. This method is responsible for updating the product price index.
The plugin can be used to add the pricing adjustment from the database to the product price index. Once the product price index is updated, the layered navigation will display the correct price. Here is an example of a plugin for the executeRow() method:
PHP
class MyPlugin
{
public function executeRow(
\Magento\Catalog\Model\Indexer\Product\Price $subject, \Magento\Catalog\Model\Product $product,
array $data
) {

$adjustment = $this->getAdjustment($product);

$product->setPrice($product->getPrice() + $adjustment); }

private function getAdjustment(Product $product)
{
$adjustment = $product->getData('adjustment');

if (!is_numeric($adjustment)) {
return 0;
}

return $adjustment;
}
}
This plugin will add the adjustment data from the product to the product price index. Once the product price index is updated, the layered navigation will display the correct price.



An Adobe Commerce developer is writing an integration test. They checked some Integration Tests for Magento core modules for reference and noticed that they use data fixtures initialized by adding annotations to test classes. For example:



The developer wants to add their own fixture to test a MyVendor_MyModule they created.
Which steps will make this possible?

  1. 1. Create a PHP file with the fixture data inside their own module in [module dir]/Test/integration/_fiies/my_fixture.php.
    2. Add the following annotation to the test method:

  2. 1. Create a PHP file With the fixture data in [magento root dir]/dev/tests/integration/testsuite/MyVendor/MyModule/_files/my_fixture.php.
    2. Add the following annotation to the test method:

  3. 1. Create a PHP file with the fixture data inside their own module in [module dir]/Test/integration/_f iies/my_f ixture.php.

    2. Add the following annotation to the test method:

Answer(s): B

Explanation:

To add a custom fixture to test a MyVendor_MyModule, the developer needs to do the following:
Create a PHP file with the fixture data in [magento root dir]/dev/tests/integration/testsuite/MyVendor/MyModule/_files/my_fixture.php.
Add the following annotation to the test method:

@magentoDataFixture(
'testsuite/MyVendor/MyModule/_files/my_fixture.php'
)

This will tell Magento to load the fixture data from the my_fixture.php file before the test method is executed.



An Adobe Commerce developer has created a before plugin for the save() function within the Magento\Framework\App\cache\Proxy class. The purpose of this plugin is to add a prefix on all cache identifiers that fulfill certain criteria.
Why is the plugin not executing as expected?

  1. Another around plugin defined for the same function does not call the callable.
  2. Cache identifiers are immutable and cannot be changed.
  3. The target ClaSS implements Magento\Framework\ObjectManager\NoninterceptableInterface.

Answer(s): C

Explanation:

According to the Plugins (Interceptors) guide for Magento 2 developers, plugins are class methods that modify the behavior of public class methods by intercepting them and running code before, after, or around them. However, some classes in Magento 2 implement the NoninterceptableInterface interface, which prevents plugins from being generated for them. The Magento\Framework\App\cache\Proxy class is one of them, as it extends from Magento\Framework\ObjectManager\NoninterceptableInterface. Therefore, the plugin is not executing as expected because the target class implements NoninterceptableInterface. Verified


Reference:

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html






Post your Comments and Discuss Adobe AD0-E716 exam with other Community members:

AD0-E716 Discussions & Posts