Skip to content

Commit

Permalink
Merge pull request #720 from magento-dragons/BugFestW2
Browse files Browse the repository at this point in the history
[DRAGONS] Bug Fixes
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Oct 13, 2015
2 parents 50d3dc1 + b1e5ae4 commit e5dedb8
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function prepareSortableFieldsByCategory($category)
}
$availableOrders = $this->getAvailableOrders();
if (!$this->getSortBy()) {
$categorySortBy = $category->getDefaultSortBy();
$categorySortBy = $this->getDefaultSortBy() ?: $category->getDefaultSortBy();
if ($categorySortBy) {
if (!$availableOrders) {
$availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray();
Expand Down
15 changes: 8 additions & 7 deletions app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Block\Product\ProductList;

use Magento\Catalog\Helper\Product\ProductList;
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;

/**
Expand Down Expand Up @@ -63,7 +64,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
*
* @var string
*/
protected $_direction = \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION;
protected $_direction = ProductList::DEFAULT_SORT_DIRECTION;

/**
* Default View mode
Expand Down Expand Up @@ -102,7 +103,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
protected $_toolbarModel;

/**
* @var \Magento\Catalog\Helper\Product\ProductList
* @var ProductList
*/
protected $_productListHelper;

Expand All @@ -122,7 +123,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
* @param \Magento\Catalog\Model\Config $catalogConfig
* @param ToolbarModel $toolbarModel
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
* @param \Magento\Catalog\Helper\Product\ProductList $productListHelper
* @param ProductList $productListHelper
* @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
* @param array $data
*/
Expand All @@ -132,7 +133,7 @@ public function __construct(
\Magento\Catalog\Model\Config $catalogConfig,
ToolbarModel $toolbarModel,
\Magento\Framework\Url\EncoderInterface $urlEncoder,
\Magento\Catalog\Helper\Product\ProductList $productListHelper,
ProductList $productListHelper,
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
array $data = []
) {
Expand Down Expand Up @@ -355,7 +356,7 @@ public function removeOrderFromAvailableOrders($order)
}

/**
* Compare defined order field vith current order field
* Compare defined order field with current order field
*
* @param string $order
* @return bool
Expand All @@ -375,7 +376,7 @@ public function getPagerUrl($params = [])
{
$urlParams = [];
$urlParams['_current'] = true;
$urlParams['_escape'] = true;
$urlParams['_escape'] = false;
$urlParams['_use_rewrite'] = true;
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams);
Expand Down Expand Up @@ -678,7 +679,7 @@ public function getWidgetOptionsJson(array $customOptions = [])
'order' => ToolbarModel::ORDER_PARAM_NAME,
'limit' => ToolbarModel::LIMIT_PARAM_NAME,
'modeDefault' => $defaultMode,
'directionDefault' => \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION,
'directionDefault' => $this->_direction ?: ProductList::DEFAULT_SORT_DIRECTION,
'orderDefault' => $this->_productListHelper->getDefaultSortField(),
'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode),
'url' => $this->getPagerUrl(),
Expand Down
33 changes: 22 additions & 11 deletions app/code/Magento/Catalog/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,31 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);

$attributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'Images');

// update General Group
$categorySetup->updateAttributeGroup(
$attributeGroup = $categorySetup->getAttributeGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'attribute_group_name',
'Images and Videos'
'Images',
'attribute_group_name'
);
if (isset($attributeGroup['attribute_group_name']) && $attributeGroup['attribute_group_name'] == 'Images') {
// update General Group
$categorySetup->updateAttributeGroup(
$entityTypeId,
$attributeSetId,
$attributeGroup['attribute_group_id'],
'attribute_group_name',
'Images and Videos'
);
}
}

if ($context->getVersion()
&& version_compare($context->getVersion(), '2.0.1') < 0
) {
$select = $setup->getConnection()->select()
->from(
$setup->getTable('catalog_product_entity_group_price'),
[
'value_id',
'entity_id',
'all_groups',
'customer_group_id',
Expand All @@ -69,11 +79,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'website_id'
]
);
$setup->getConnection()->insertFromSelect(
$select = $setup->getConnection()->insertFromSelect(
$select,
$setup->getTable('catalog_product_entity_group_price'),
$setup->getTable('catalog_product_entity_tier_price'),
[
'value_id',
'entity_id',
'all_groups',
'customer_group_id',
Expand All @@ -82,6 +91,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'website_id'
]
);
$setup->getConnection()->query($select);

$categorySetupManager = $this->categorySetupFactory->create();
$categorySetupManager->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'group_price');
}
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ protected function addForeignKeys(SchemaSetupInterface $setup)
*/
private function addSupportVideoMediaAttributes(SchemaSetupInterface $setup)
{
if ($setup->tableExists(Media::GALLERY_VALUE_TO_ENTITY_TABLE)) {
return;
};

/** Add support video media attribute */
$this->createValueToEntityTable($setup);
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ define([
parameters;
for (var i = 0; i < urlParams.length; i++) {
parameters = urlParams[i].split('=');
paramData[parameters[0]] = parameters[1] !== undefined ? parameters[1] : '';
paramData[parameters[0]] = parameters[1] !== undefined
? window.decodeURIComponent(parameters[1].replace(/\+/g, '%20'))
: '';
}
paramData[paramName] = paramValue;
if (paramValue == defaultValue) {
Expand All @@ -81,4 +83,4 @@ define([
});

return $.mage.productListToolbarForm;
});
});
3 changes: 2 additions & 1 deletion app/code/Magento/CatalogSearch/Block/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ public function setListOrders()
/* @var $category \Magento\Catalog\Model\Category */
$availableOrders = $category->getAvailableSortByOptions();
unset($availableOrders['position']);
$availableOrders['relevance'] = __('Relevance');

$this->getListBlock()->setAvailableOrders(
$availableOrders
)->setDefaultDirection(
'desc'
)->setSortBy(
)->setDefaultSortBy(
'relevance'
);

Expand Down
13 changes: 8 additions & 5 deletions app/code/Magento/Store/App/Request/PathInfoProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
*/
namespace Magento\Store\App\Request;

use Magento\Framework\Exception\NoSuchEntityException;

class PathInfoProcessor implements \Magento\Framework\App\Request\PathInfoProcessorInterface
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $_storeManager;
private $storeManager;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
{
$this->_storeManager = $storeManager;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -33,14 +35,15 @@ public function process(\Magento\Framework\App\RequestInterface $request, $pathI
$storeCode = $pathParts[0];

try {
$store = $this->_storeManager->getStore($storeCode);
} catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException
/** @var \Magento\Store\Api\Data\StoreInterface $store */
$store = $this->storeManager->getStore($storeCode);
} catch (NoSuchEntityException $e) {
return $pathInfo;
}

if ($store->isUseStoreInUrl()) {
if (!$request->isDirectAccessFrontendName($storeCode)) {
$this->_storeManager->setCurrentStore($storeCode);
$this->storeManager->setCurrentStore($storeCode);
$pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
return $pathInfo;
} elseif (!empty($storeCode)) {
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Store/Controller/Store/SwitchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context as ActionContext;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Api\StoreCookieManagerInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Model\Store;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function execute()
$store = $this->storeRepository->getActiveStoreByCode($storeCode);
} catch (StoreIsInactiveException $e) {
$error = __('Requested store is inactive');
} catch (\InvalidArgumentException $e) {
} catch (NoSuchEntityException $e) {
$error = __('Requested store is not found');
}

Expand Down
5 changes: 2 additions & 3 deletions app/code/Magento/Store/Model/StoreRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public function get($code)
$store = $this->storeFactory->create();
$store->load($code, 'code');
if ($store->getId() === null) {
// TODO: MAGETWO-39826 Need to replace on NoSuchEntityException
throw new \InvalidArgumentException();
throw new NoSuchEntityException(__('Requested store is not found'));
}
$this->entities[$code] = $store;
$this->entitiesById[$store->getId()] = $store;
Expand Down Expand Up @@ -89,7 +88,7 @@ public function getById($id)
$store = $this->storeFactory->create();
$store->load($id);
if ($store->getId() === null) {
throw new NoSuchEntityException();
throw new NoSuchEntityException(__('Requested store is not found'));
}
$this->entitiesById[$id] = $store;
$this->entities[$store->getCode()] = $store;
Expand Down
14 changes: 2 additions & 12 deletions app/code/Magento/Store/Model/StoreResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,9 @@ protected function getRequestedStoreByCode($storeCode)
try {
$store = $this->storeRepository->getActiveStoreByCode($storeCode);
} catch (StoreIsInactiveException $e) {
$error = __('Requested store is inactive');
} catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException
$error = __('Requested store is not found');
throw new NoSuchEntityException(__('Requested store is inactive'));
}

if (isset($error, $e)) {
throw new NoSuchEntityException($error, $e);
}
return $store;
}

Expand All @@ -160,14 +155,9 @@ protected function getDefaultStoreById($id)
try {
$store = $this->storeRepository->getActiveStoreById($id);
} catch (StoreIsInactiveException $e) {
$error = __('Default store is inactive');
} catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException
$error = __('Default store is not found');
throw new NoSuchEntityException(__('Default store is inactive'));
}

if (isset($error, $e)) {
throw new NoSuchEntityException($error, $e);
}
return $store;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Store\Test\Unit\App\Request;

use Magento\Framework\Exception\NoSuchEntityException;

class PathInfoProcessorTest extends \PHPUnit_Framework_TestCase
{
/**
Expand Down Expand Up @@ -112,8 +114,7 @@ public function testProcessIfStoreCodeIsNotExist()
{
$store = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
$this->_storeManagerMock->expects($this->once())->method('getStore')->with('storeCode')
// TODO: MAGETWO-39826 Need to replace on NoSuchEntityException
->willThrowException(new \InvalidArgumentException());
->willThrowException(new NoSuchEntityException());
$store->expects($this->never())->method('isUseStoreInUrl');
$this->_requestMock->expects($this->never())->method('isDirectAccessFrontendName');

Expand Down
Loading

0 comments on commit e5dedb8

Please sign in to comment.