Skip to content

Commit

Permalink
Merge pull request #5988 from magento-engcom/MC-36526
Browse files Browse the repository at this point in the history
MC-36526: Revert public PR:27340
  • Loading branch information
naydav authored Aug 12, 2020
2 parents be26941 + 61ff26f commit a360c06
Show file tree
Hide file tree
Showing 39 changed files with 568 additions and 151 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Block/Account/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public function getLinks()
*/
private function compare(SortLinkInterface $firstLink, SortLinkInterface $secondLink): int
{
return $firstLink->getSortOrder() <=> $secondLink->getSortOrder();
return $secondLink->getSortOrder() <=> $firstLink->getSortOrder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

class NavigationTest extends TestCase
{
/**
* Stub name top links
*/
private const STUB_TOP_LINKS_NAME_IN_LAYOUT = 'top.links';

/**
* @var ObjectManagerHelper
*/
Expand Down Expand Up @@ -67,7 +62,7 @@ protected function setUp(): void
*
* @return void
*/
public function testGetLinksWithCustomerAndWishList(): void
public function testGetLinksWithCustomerAndWishList()
{
$wishListLinkMock = $this->getMockBuilder(WishListLink::class)
->disableOriginalConstructor()
Expand All @@ -81,30 +76,30 @@ public function testGetLinksWithCustomerAndWishList(): void

$wishListLinkMock->expects($this->any())
->method('getSortOrder')
->willReturn(30);
->willReturn(100);

$customerAccountLinkMock->expects($this->any())
->method('getSortOrder')
->willReturn(0);
->willReturn(20);

$topLinksNameInLayout = self::STUB_TOP_LINKS_NAME_IN_LAYOUT;
$nameInLayout = 'top.links';

$blockChildren = [
'customerAccountLink' => $customerAccountLinkMock,
'wishListLink' => $wishListLinkMock
'wishListLink' => $wishListLinkMock,
'customerAccountLink' => $customerAccountLinkMock
];

$this->navigation->setNameInLayout($topLinksNameInLayout);
$this->navigation->setNameInLayout($nameInLayout);
$this->layoutMock->expects($this->any())
->method('getChildBlocks')
->with($topLinksNameInLayout)
->with($nameInLayout)
->willReturn($blockChildren);

/* Assertion */
$this->assertEquals(
[
0 => $customerAccountLinkMock,
1 => $wishListLinkMock
0 => $wishListLinkMock,
1 => $customerAccountLinkMock
],
$this->navigation->getLinks()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@
<arguments>
<argument name="label" xsi:type="string" translate="true">My Account</argument>
<argument name="path" xsi:type="string">customer/account</argument>
<argument name="sortOrder" xsi:type="number">1</argument>
<argument name="sortOrder" xsi:type="number">250</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\Delimiter" name="customer-account-navigation-delimiter-1" template="Magento_Customer::account/navigation-delimiter.phtml">
<arguments>
<argument name="sortOrder" xsi:type="number">40</argument>
<argument name="sortOrder" xsi:type="number">200</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-address-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Address Book</argument>
<argument name="path" xsi:type="string">customer/address</argument>
<argument name="sortOrder" xsi:type="number">50</argument>
<argument name="sortOrder" xsi:type="number">190</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-account-edit-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Account Information</argument>
<argument name="path" xsi:type="string">customer/account/edit</argument>
<argument name="sortOrder" xsi:type="number">60</argument>
<argument name="sortOrder" xsi:type="number">180</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\Delimiter" name="customer-account-navigation-delimiter-2" template="Magento_Customer::account/navigation-delimiter.phtml">
<arguments>
<argument name="sortOrder" xsi:type="number">90</argument>
<argument name="sortOrder" xsi:type="number">130</argument>
</arguments>
</block>
</block>
Expand Down
10 changes: 3 additions & 7 deletions app/code/Magento/Customer/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="top.links">
<block class="Magento\Customer\Block\Account\Link" name="my-account-link" template="Magento_Customer::account/link/my-account.phtml">
<block class="Magento\Customer\Block\Account\Link" name="my-account-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">My Account</argument>
<argument name="sortOrder" xsi:type="number">1</argument>
<argument name="sortOrder" xsi:type="number">110</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\RegisterLink" name="register-link">
Expand All @@ -20,11 +20,7 @@
</arguments>
</block>
<block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link"
template="Magento_Customer::account/link/authorization.phtml">
<arguments>
<argument name="sortOrder" xsi:type="number">30</argument>
</arguments>
</block>
template="Magento_Customer::account/link/authorization.phtml"/>
</referenceBlock>
<referenceContainer name="content">
<block class="Magento\Customer\Block\Account\AuthenticationPopup" name="authentication-popup" as="authentication-popup" template="Magento_Customer::account/authentication-popup.phtml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<arguments>
<argument name="path" xsi:type="string">downloadable/customer/products</argument>
<argument name="label" xsi:type="string" translate="true">My Downloadable Products</argument>
<argument name="sortOrder" xsi:type="number">20</argument>
<argument name="sortOrder" xsi:type="number">217</argument>
</arguments>
</block>
</referenceBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

/**
* Pop-up for Login as Customer button then Login as Customer is not allowed.
*
* @api
*/
class NotAllowedPopup extends Template
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SaveAssetLinks
private const TABLE_ASSET_KEYWORD = 'media_gallery_asset_keyword';
private const FIELD_ASSET_ID = 'asset_id';
private const FIELD_KEYWORD_ID = 'keyword_id';
private const TABLE_MEDIA_ASSET = 'media_gallery_asset';

/**
* @var ResourceConnection
Expand Down Expand Up @@ -73,6 +74,10 @@ public function execute(int $assetId, array $keywordIds): void

$this->deleteAssetKeywords($assetId, $obsoleteKeywordIds);
$this->insertAssetKeywords($assetId, $newKeywordIds);

if ($obsoleteKeywordIds || $newKeywordIds) {
$this->setAssetUpdatedAt($assetId);
}
}

/**
Expand Down Expand Up @@ -179,4 +184,28 @@ function (KeywordInterface $keyword): int {
$keywordsData
);
}

/**
* Updates modified date of media asset
*
* @param int $assetId
* @throws CouldNotSaveException
*/
private function setAssetUpdatedAt(int $assetId): void
{
try {
$connection = $this->resourceConnection->getConnection();
$connection->update(
$connection->getTableName(self::TABLE_MEDIA_ASSET),
['updated_at' => null],
['id =?' => $assetId]
);
} catch (\Exception $exception) {
$this->logger->critical($exception);
throw new CouldNotSaveException(
__('Could not update assets modified date'),
$exception
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testAssetKeywordsSave(int $assetId, array $keywordIds, array $va
$expectedCalls = (int) (count($keywordIds));

if ($expectedCalls) {
$this->resourceConnectionMock->expects($this->once())
$this->resourceConnectionMock->expects($this->exactly(2))
->method('getConnection')
->willReturn($this->connectionMock);
$this->resourceConnectionMock->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Columns;

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
Expand Down Expand Up @@ -63,13 +65,15 @@ public function prepareDataSource(array $dataSource)
* Replace category path ids with category names
*
* @param string $pathWithIds
* @return string
* @throws NoSuchEntityException
*/
private function getCategoryPathWithNames(string $pathWithIds): string
{
$categoryPathWithName = '';
$categoryIds = explode('/', $pathWithIds);
foreach ($categoryIds as $id) {
if ($id == 1) {
if ($id == Category::TREE_ROOT_ID) {
continue;
}
$categoryName = $this->categoryRepository->get($id)->getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters;

use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Filters\FilterModifier;
use Magento\Ui\Component\Filters\Type\Select;
use Magento\Ui\Api\BookmarkManagementInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;

/**
* Used in products filter
*/
class UsedInProducts extends Select
{
/**
* @var BookmarkManagementInterface
*/
private $bookmarkManagement;

/**
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* Constructor
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param FilterBuilder $filterBuilder
* @param FilterModifier $filterModifier
* @param OptionSourceInterface $optionsProvider
* @param BookmarkManagementInterface $bookmarkManagement
* @param ProductRepositoryInterface $productRepository
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
FilterBuilder $filterBuilder,
FilterModifier $filterModifier,
OptionSourceInterface $optionsProvider = null,
BookmarkManagementInterface $bookmarkManagement,
ProductRepositoryInterface $productRepository,
array $components = [],
array $data = []
) {
$this->uiComponentFactory = $uiComponentFactory;
$this->filterBuilder = $filterBuilder;
parent::__construct(
$context,
$uiComponentFactory,
$filterBuilder,
$filterModifier,
$optionsProvider,
$components,
$data
);
$this->bookmarkManagement = $bookmarkManagement;
$this->productRepository = $productRepository;
}

/**
* Prepare component configuration
*
* @return void
*/
public function prepare()
{
$options = [];
$productIds = [];
$bookmarks = $this->bookmarkManagement->loadByNamespace($this->context->getNameSpace())->getItems();
foreach ($bookmarks as $bookmark) {
if ($bookmark->getIdentifier() === 'current') {
$applied = $bookmark->getConfig()['current']['filters']['applied'];
if (isset($applied[$this->getName()])) {
$productIds = $applied[$this->getName()];
}
}
}

foreach ($productIds as $id) {
$product = $this->productRepository->getById($id);
$options[] = [
'value' => $id,
'label' => $product->getName(),
'is_active' => $product->getStatus(),
'path' => $product->getSku(),
'optgroup' => false

];
}

$this->wrappedComponent = $this->uiComponentFactory->create(
$this->getName(),
parent::COMPONENT,
[
'context' => $this->getContext(),
'options' => $options
]
);

$this->wrappedComponent->prepare();
$productsFilterJsConfig = array_replace_recursive(
$this->getJsConfig($this->wrappedComponent),
$this->getJsConfig($this)
);
$this->setData('js_config', $productsFilterJsConfig);

$this->setData(
'config',
array_replace_recursive(
(array)$this->wrappedComponent->getData('config'),
(array)$this->getData('config')
)
);

$this->applyFilter();

parent::prepare();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
name="product_id"
provider="${ $.parentName }"
sortOrder="110"
class="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters\UsedInProducts"
component="Magento_Catalog/js/components/product-ui-select"
template="ui/grid/filters/elements/ui-select">
<argument name="data" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
name="product_id"
provider="${ $.parentName }"
sortOrder="110"
class="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters\UsedInProducts"
component="Magento_Catalog/js/components/product-ui-select"
template="ui/grid/filters/elements/ui-select">
<argument name="data" xsi:type="array">
Expand Down
Loading

0 comments on commit a360c06

Please sign in to comment.