Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## 10.1 Demonstrate ability to customize My Account

Describe how to customize the “My Account” section.

*How do you add a menu item?*
- Create A theme or use an existing one
- Create a folder in the theme Magento_Customer
- Create a folder inside the theme Magento_Customer called layout
- Create a file inside the theme/Magento_Customer/layout/customer_account.xml
- Add similar xml
```xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page layout="2columns-left" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-address-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Russell Special</argument>
<argument name="path" xsi:type="string">special/link</argument>
<argument name="sortOrder" xsi:type="number">165</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
```

*How would you customize the “Order History” page?*
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## 10.2 Demonstrate ability to customize customer functionality

Describe how to add or modify customer attributes.

Describe how to extend the customer entity.

*How would you extend the customer entity using the extension attributes mechanism?*

Describe how to customize the customer address.

*How would you add another field into the customer address?*

Describe customer groups and their role in different business processes.

*What is the role of customer groups?*

*What functionality do they affect?*

Describe Magento functionality related to VAT.

*How do you customize VAT functionality?*
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,247 @@ menu.xml - `urn:magento:module:Magento_Backend:/etc/menu.xsd` - flat structure
- just set one of top level parents, e.g. 'Magento_Backend::system'

*How do menu items relate to ACL permissions?*

## Describe how to check for permissions in the permissions management tree structures.
*How would you add a new user with a given set of permissions?*

- System > Permissions > User Roles has all the differnet roles and associated permissions. Each role can be scoped to Website level and granular permissions based on resource options.
- System > Permissions > All Users to view and create new users and associate to a role. There are two tabs 1 is user info the other is User Role where you define the Role for this user. You can only select 1 role per user.

*How can you do that programmatically?*
- You can leverage \Magento\Authorization\Model\Acl\AclRetriever. That as a few methods that will help

```php
/**
* Get a list of available resources using user details
*
* @param string $userType
* @param int $userId
* @return string[]
* @throws AuthorizationException
* @throws LocalizedException
*/
public function getAllowedResourcesByUser($userType, $userId)
{
if ($userType == UserContextInterface::USER_TYPE_GUEST) {
return [self::PERMISSION_ANONYMOUS];
} elseif ($userType == UserContextInterface::USER_TYPE_CUSTOMER) {
return [self::PERMISSION_SELF];
}
try {
$role = $this->_getUserRole($userType, $userId);
if (!$role) {
throw new AuthorizationException(
__('We can\'t find the role for the user you wanted.')
);
}
$allowedResources = $this->getAllowedResourcesByRole($role->getId());
} catch (AuthorizationException $e) {
throw $e;
} catch (\Exception $e) {
$this->logger->critical($e);
throw new LocalizedException(
__(
'Something went wrong while compiling a list of allowed resources. '
. 'You can find out more in the exceptions log.'
)
);
}
return $allowedResources;
}

/**
* Get a list of available resource using user role id
*
* @param string $roleId
* @return string[]
*/
public function getAllowedResourcesByRole($roleId)
{
$allowedResources = [];
$rulesCollection = $this->rulesCollectionFactory->create();
$rulesCollection->getByRoles($roleId)->load();
$acl = $this->aclBuilder->getAcl();
/** @var \Magento\Authorization\Model\Rules $ruleItem */
foreach ($rulesCollection->getItems() as $ruleItem) {
$resourceId = $ruleItem->getResourceId();
if ($acl->has($resourceId) && $acl->isAllowed($roleId, $resourceId)) {
$allowedResources[] = $resourceId;
}
}
return $allowedResources;
}
```

However the actual code to set privilage permission may look like this in the core code
vendor/magento/magento2-base/setup/src/Magento/Setup/Fixtures/AdminUsersFixture.php

In particular this section:

```php
$adminUser = $this->userFactory->create();
$adminUser->setRoleId($role->getId())
->setEmail('admin' . $i . '@example.com')
->setFirstName('Firstname')
->setLastName('Lastname')
->setUserName('admin' . $i)
->setPassword('123123q')
->setIsActive(1);
$adminUser->save();
```

```php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Setup\Fixtures;

use Magento\Authorization\Model\Acl\Role\Group;
use Magento\Authorization\Model\RoleFactory;
use Magento\Authorization\Model\RulesFactory;
use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\Acl\RootResource;
use Magento\User\Model\ResourceModel\User\CollectionFactory as UserCollectionFactory;
use Magento\User\Model\UserFactory;

/**
* Generate admin users
*
* Support the following format:
* <!-- Number of admin users -->
* <admin_users>{int}</admin_users>
*/
class AdminUsersFixture extends Fixture
{
/**
* @var int
*/
protected $priority = 5;

/**
* @var UserFactory
*/
private $userFactory;

/**
* @var RoleFactory
*/
private $roleFactory;

/**
* @var UserCollectionFactory
*/
private $userCollectionFactory;

/**
* @var RulesFactory
*/
private $rulesFactory;

/**
* @var RootResource
*/
private $rootResource;

/**
* @param FixtureModel $fixtureModel
* @param UserFactory $userFactory
* @param UserCollectionFactory $userCollectionFactory
* @param RoleFactory $roleFactory
* @param RulesFactory $rulesFactory
* @param RootResource $rootResource
*/
public function __construct(
FixtureModel $fixtureModel,
UserFactory $userFactory,
UserCollectionFactory $userCollectionFactory,
RoleFactory $roleFactory,
RulesFactory $rulesFactory,
RootResource $rootResource
) {
parent::__construct($fixtureModel);
$this->userFactory = $userFactory;
$this->roleFactory = $roleFactory;
$this->userCollectionFactory = $userCollectionFactory;
$this->rulesFactory = $rulesFactory;
$this->rootResource = $rootResource;
}

/**
* {@inheritdoc}
*/
public function execute()
{
$adminUsersNumber = $this->fixtureModel->getValue('admin_users', 0);
$adminUsersStartIndex = $this->userCollectionFactory->create()->getSize();

if ($adminUsersStartIndex >= $adminUsersNumber) {
return;
}

$role = $this->createAdministratorRole();

for ($i = $adminUsersStartIndex; $i <= $adminUsersNumber; $i++) {
$adminUser = $this->userFactory->create();
$adminUser->setRoleId($role->getId())
->setEmail('admin' . $i . '@example.com')
->setFirstName('Firstname')
->setLastName('Lastname')
->setUserName('admin' . $i)
->setPassword('123123q')
->setIsActive(1);
$adminUser->save();
}
}

/**
* {@inheritdoc}
*/
public function getActionTitle()
{
return 'Generating admin users';
}

/**
* {@inheritdoc}
*/
public function introduceParamLabels()
{
return [
'admin_users' => 'Admin Users'
];
}

/**
* Create administrator role with all privileges.
*
* @return \Magento\Authorization\Model\Role
*/
private function createAdministratorRole()
{
$role = $this->roleFactory->create();
$role->setParentId(0)
->setTreeLevel(1)
->setSortOrder(1)
->setRoleType(Group::ROLE_TYPE)
->setUserId(0)
->setUserType(UserContextInterface::USER_TYPE_ADMIN)
->setRoleName('Example Administrator');
$role->save();

/** @var \Magento\Authorization\Model\Rules $rule */
$rule = $this->rulesFactory->create();
$rule->setRoleId($role->getId())
->setResourceId($this->rootResource->getId())
->setPrivilegies(null)
->setPermission('allow');
$rule->save();

return $role;
}
}

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 9.1 Demonstrate ability to customize sales operations

Describe how to modify order processing and integrate it with a third-party ERP system.

*Describe how to modify order processing flow. How would you add new states and statuses for an order?*

*How do you change the behavior of existing states and statuses?*

Described how to customize invoices.

*How would you customize invoice generation, capturing, and management?*

Describe refund functionality in Magento.

*Which refund types are available, and how are they used?*
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 10.1 Demonstrate ability to customize My Account