Skip to content

Commit

Permalink
Merge pull request #1459 from magento-thunder/bugfixes-delivery
Browse files Browse the repository at this point in the history
Bug
- MAGETWO-49796 Catalog top nav, CSS class not set to active when using Varnish
- MAGETWO-71890 Magento fails with deploymentConfig present on new install
  • Loading branch information
VladimirZaets authored Sep 6, 2017
2 parents 9223ab3 + e6362d1 commit 7978fcf
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 3 deletions.
58 changes: 58 additions & 0 deletions app/code/Magento/Deploy/Console/CommandList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Deploy\Console;

use Magento\Framework\ObjectManagerInterface;

/**
* Provides list of commands to be available for uninstalled application
*/
class CommandList implements \Magento\Framework\Console\CommandListInterface
{
/**
* Object Manager
*
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @param ObjectManagerInterface $objectManager Object Manager
*/
public function __construct(ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}

/**
* Gets list of command classes
*
* @return string[]
*/
private function getCommandsClasses()
{
return [
\Magento\Deploy\Console\Command\App\ConfigImportCommand::class,
];
}

/**
* @inheritdoc
*/
public function getCommands()
{
$commands = [];
foreach ($this->getCommandsClasses() as $class) {
if (class_exists($class)) {
$commands[] = $this->objectManager->get($class);
} else {
throw new \Exception('Class ' . $class . ' does not exist');
}
}

return $commands;
}
}
58 changes: 58 additions & 0 deletions app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Deploy\Test\Unit\Console;

use Magento\Deploy\Console\Command\App\ConfigImportCommand;
use Magento\Deploy\Console\CommandList;
use Magento\Framework\ObjectManagerInterface;
use PHPUnit\Framework\TestCase;

/**
* @inheritdoc
*/
class CommandListTest extends TestCase
{
/**
* @var CommandList
*/
private $model;

/**
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $objectManagerMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
->getMockForAbstractClass();

$this->model = new CommandList(
$this->objectManagerMock
);
}

public function testGetCommands()
{
$configImportCommand = $this->getMockBuilder(ConfigImportCommand::class)
->disableOriginalConstructor()
->getMock();

$this->objectManagerMock->expects($this->once())
->method('get')
->willReturnMap([
[ConfigImportCommand::class, $configImportCommand],
]);

$this->assertSame(
[$configImportCommand],
$this->model->getCommands()
);
}
}
8 changes: 8 additions & 0 deletions app/code/Magento/Deploy/cli_commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
if (PHP_SAPI == 'cli') {
\Magento\Framework\Console\CommandLocator::register(\Magento\Deploy\Console\CommandList::class);
}
1 change: 1 addition & 0 deletions app/code/Magento/Deploy/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"autoload": {
"files": [
"cli_commands.php",
"registration.php"
],
"psr-4": {
Expand Down
106 changes: 106 additions & 0 deletions lib/web/mage/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ define([
}

this._assignControls()._listen();
this._setActiveMenu();
},

/**
Expand Down Expand Up @@ -108,6 +109,111 @@ define([
}
},

/**
* Tries to figure out the active category for current page and add appropriate classes:
* - 'active' class for active category
* - 'has-active' class for all parents of active category
*
* First, checks whether current URL is URL of category page,
* otherwise tries to retrieve category URL in case of current URL is product view page URL
* which has category tree path in it.
*
* @return void
* @private
*/
_setActiveMenu: function () {
var currentUrl = window.location.href.split('?')[0];

if (!this._setActiveMenuForCategory(currentUrl)) {
this._setActiveMenuForProduct(currentUrl);
}
},

/**
* Looks for category with provided URL and adds 'active' CSS class to it if it was not set before.
* If menu item has parent categories, sets 'has-active' class to all af them.
*
* @param {String} url - possible category URL
* @returns {Boolean} - true if active category was founded by provided URL, otherwise return false
* @private
*/
_setActiveMenuForCategory: function (url) {
var activeCategoryLink = this.element.find('a[href="' + url + '"]'),
classes,
classNav;

if (!activeCategoryLink || !activeCategoryLink.hasClass('ui-corner-all')) {

//category was not found by provided URL
return false;
} else if (!activeCategoryLink.parent().hasClass('active')) {
activeCategoryLink.parent().addClass('active');
classes = activeCategoryLink.parent().attr('class');
classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi);

if (classNav) {
this._setActiveParent(classNav[0]);
}
}

return true;
},

/**
* Sets 'has-active' CSS class to all parent categories which have part of provided class in childClassName
*
* @example
* childClassName - 'nav-1-2-3'
* CSS class 'has-active' will be added to categories have 'nav-1-2' and 'nav-1' classes
*
* @param {String} childClassName - Class name of active category <li> element
* @return void
* @private
*/
_setActiveParent: function (childClassName) {
var parentElement,
parentClass = childClassName.substr(0, childClassName.lastIndexOf('-'));

if (parentClass.lastIndexOf('-') !== -1) {
parentElement = this.element.find('.' + parentClass);

if (parentElement) {
parentElement.addClass('has-active');
}
this._setActiveParent(parentClass);
}
},

/**
* Tries to retrieve category URL from current URL and mark this category as active
* @see _setActiveMenuForCategory(url)
*
* @example
* currentUrl - http://magento.com/category1/category12/product.html,
* category URLs has extensions .phtml - http://magento.com/category1.phtml
* method sets active category which has URL http://magento.com/category1/category12.phtml
*
* @param {String} currentUrl - current page URL without parameters
* @return void
* @private
*/
_setActiveMenuForProduct: function (currentUrl) {
var categoryUrlExtension,
lastUrlSection,
possibleCategoryUrl,
//retrieve first category URL to know what extension is used for category URLs
firstCategoryUrl = this.element.find('> li a').attr('href');

if (firstCategoryUrl) {
lastUrlSection = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('/'));
categoryUrlExtension = lastUrlSection.lastIndexOf('.') !== -1 ?
lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : '';

possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension;
this._setActiveMenuForCategory(possibleCategoryUrl);
}
},

/**
* Add class for expanded option.
*/
Expand Down
7 changes: 7 additions & 0 deletions setup/src/Magento/Setup/Console/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Setup\Console\Command;

use Magento\Deploy\Console\Command\App\ConfigImportCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Setup\Model\InstallerFactory;
Expand Down Expand Up @@ -123,6 +125,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$consoleLogger = new ConsoleLogger($output);
$installer = $this->installerFactory->create($consoleLogger);
$installer->install($input->getOptions());

$importConfigCommand = $this->getApplication()->find(ConfigImportCommand::COMMAND_NAME);
$arrayInput = new ArrayInput([]);
$arrayInput->setInteractive($input->isInteractive());
$importConfigCommand->run($arrayInput, $output);
}

/**
Expand Down
Loading

0 comments on commit 7978fcf

Please sign in to comment.