Skip to content

Commit

Permalink
Merge pull request #2109 from magento-tango/2.1.13-PR-0.5
Browse files Browse the repository at this point in the history
Fixed issues:

  - MAGETWO-60246 [Backport] - [Github]Magento 2.1.1 Problem with change currency #6746 - for 2.1.x
  - MAGETWO-70329 [GITHUB] The rich snippets are giving a warning for the element price #7173
  - MAGETWO-85781 Configurable product Final Price ignores Catalog Rule
  - MAGETWO-83204 "Hide from Product Page" option does not work for child of configurable product
  - MAGETWO-83094 Products Ordered Report exported CSV is empty
  - MAGETWO-71701 [Backport] - Catalog top nav, CSS class not set to active when using Varnish - for 2.1
  - MAGETWO-71229 Warning message is cached and shown a few times on the shopping cart
  • Loading branch information
igrybkov authored Feb 21, 2018
2 parents 6164f8e + 8980fec commit ce3efb6
Show file tree
Hide file tree
Showing 32 changed files with 1,014 additions and 310 deletions.
27 changes: 12 additions & 15 deletions app/code/Magento/Backend/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,33 +189,30 @@ public function getUrl($routePath = null, $routeParams = null)
}

$cacheSecretKey = false;
if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) {
if (isset($routeParams['_cache_secret_key'])) {
unset($routeParams['_cache_secret_key']);
$cacheSecretKey = true;
}
$result = parent::getUrl($routePath, $routeParams);
if (!$this->useSecretKey()) {
return $result;
}

$this->_setRoutePath($routePath);
$routeName = $this->_getRouteName('*');
$controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME);
$actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME);
if ($cacheSecretKey) {
$secret = [self::SECRET_KEY_PARAM_NAME => "\${$routeName}/{$controllerName}/{$actionName}\$"];
} else {
$secret = [
self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($routeName, $controllerName, $actionName),
];
}
if (is_array($routeParams)) {
$routeParams = array_merge($secret, $routeParams);
} else {
$routeParams = $secret;
}
if (is_array($this->_getRouteParams())) {
$routeParams = array_merge($this->_getRouteParams(), $routeParams);
if (!isset($routeParams[self::SECRET_KEY_PARAM_NAME])) {
if (!is_array($routeParams)) {
$routeParams = [];
}

$secretKey = $cacheSecretKey
? "\${$routeName}/{$controllerName}/{$actionName}\$"
: $this->getSecretKey($routeName, $controllerName, $actionName);
$routeParams[self::SECRET_KEY_PARAM_NAME] = $secretKey;
}

return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams);
}

Expand Down
7 changes: 1 addition & 6 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,12 +1058,7 @@ protected function _afterLoad()
*/
public function cleanCache()
{
if ($this->getId()) {
$this->_cacheManager->clean(
self::CACHE_TAG . '_' . $this->getId()
);
}
return $this;
return $this->cleanModelCache();
}

/**
Expand Down
15 changes: 0 additions & 15 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1391,21 +1391,6 @@ public function testGetOptionByIdForProductWithoutOptions()
$this->assertNull($this->model->getOptionById(100));
}

public function testCleanCache()
{
//Without an ID cleanCache won't clean anything because the entity is
//not identified and it will be called later exactly once.
$this->model->setId(null);
$this->cacheManagerMock
->expects($this->once())
->method('clean');
$this->model->cleanCache();

//Now that ID is set clean will be called.
$this->model->setId(1);
$this->model->cleanCache();
}

public function testGetCacheTags()
{
//If entity is identified getCacheTags has to return the same values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
<?php echo($block->getPriceDisplayLabel()) ? 'data-label="' . $block->getPriceDisplayLabel() . $block->getPriceDisplayInclExclTaxes() . '"' : '' ?>
data-price-amount="<?php /* @escapeNotVerified */ echo $block->getDisplayValue(); ?>"
data-price-type="<?php /* @escapeNotVerified */ echo $block->getPriceType(); ?>"
class="price-wrapper <?php /* @escapeNotVerified */ echo $block->getPriceWrapperCss(); ?>"
<?php echo $block->getSchema() ? ' itemprop="price"' : '' ?>>
<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>
class="price-wrapper <?php /* @escapeNotVerified */ echo $block->getPriceWrapperCss(); ?>">
<?php /* @noEscape */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>
</span>
<?php if ($block->getSchema()): ?>
<span class="_hidden" itemprop="price">
<?php /* @noEscape */ echo $block->getDisplayValue() ?>
</span>
<?php endif; ?>
<?php if ($block->hasAdjustmentsHtml()): ?>
<?php echo $block->getAdjustmentsHtml() ?>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ define([
* @param {Object} form
* @returns {Boolean}
*/
submitHandler: function (form) {
submitHandler: function (form, event) {
var jqForm = $(form).catalogAddToCart({
bindSubmit: bindSubmit
});

jqForm.catalogAddToCart('submitForm', jqForm);
jqForm.catalogAddToCart('submitForm', jqForm, event);

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
{
$attrCode = $this->getAttribute();
if ('category_ids' == $attrCode) {
return $this->validateAttribute($model->getAvailableInCategories());
return parent::validate($model);
}

$oldAttrValue = $model->getData($attrCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,41 @@ class ProductTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute|\PHPUnit_Framework_MockObject_MockObject */
protected $eavAttributeResource;

/** @var \Magento\Catalog\Model\ResourceModel\Category|\PHPUnit_Framework_MockObject_MockObject */
private $category;

/** @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */
private $connection;

/** @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */
private $dbSelect;

protected function setUp()
{
$this->config = $this->getMock('Magento\Eav\Model\Config', ['getAttribute'], [], '', false);
$this->productModel = $this->getMock(
'Magento\Catalog\Model\Product',
[
'__wakeup',
'getAvailableInCategories',
'hasData',
'getData',
'getId',
'getStoreId',
'getResource',
'addAttributeToSelect',
],
[],
'',
false
);
$this->productResource = $this->getMock(
'Magento\Catalog\Model\ResourceModel\Product',
['loadAllAttributes',
'getAttributesByCode',
'getAttribute'
],
[],
'',
false
);
$this->eavAttributeResource = $this->getMock(
'\Magento\Catalog\Model\ResourceModel\Eav\Attribute',
[
'__wakeup',
'isAllowedForRuleCondition',
'getDataUsingMethod',
'getAttributeCode',
'getFrontendLabel',
'isScopeGlobal',
'getBackendType',
'getFrontendInput'
],
[],
'',
false
);
$this->config = $this->getMockBuilder(\Magento\Eav\Model\Config::class)
->disableOriginalConstructor()
->setMethods(['getAttribute'])
->getMock();
$this->productModel = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->getMock();
$this->category = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Category::class)
->disableOriginalConstructor()
->getMock();
$this->productResource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product::class)
->setMethods(['loadAllAttributes', 'getAttributesByCode', 'getAttribute', 'getConnection', 'getTable'])
->disableOriginalConstructor()
->getMock();
$this->connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->dbSelect = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->setMethods(['from', 'where'])
->getMock();
$this->eavAttributeResource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
->disableOriginalConstructor()
->getMock();

$this->productResource->expects($this->any())->method('loadAllAttributes')
->will($this->returnSelf());
Expand All @@ -89,11 +79,12 @@ protected function setUp()

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->product = $this->objectManagerHelper->getObject(
'Magento\CatalogRule\Model\Rule\Condition\Product',
\Magento\CatalogRule\Model\Rule\Condition\Product::class,
[
'config' => $this->config,
'product' => $this->productModel,
'productResource' => $this->productResource
'productResource' => $this->productResource,
'category' => $this->category
]
);
}
Expand All @@ -103,12 +94,27 @@ protected function setUp()
*/
public function testValidateMeetsCategory()
{
$categoryIdList = [1, 2, 3];

$this->productResource->expects($this->atLeastOnce())
->method('getConnection')
->willReturn($this->connection);
$this->connection->expects($this->atLeastOnce())
->method('select')
->willReturn($this->dbSelect);
$this->dbSelect->expects($this->atLeastOnce())
->method('from')
->willReturnSelf();
$this->dbSelect->expects($this->atLeastOnce())
->method('where')
->willReturnSelf();
$this->connection->expects($this->once())
->method('fetchCol')
->willReturn($categoryIdList);
$this->product->setData('attribute', 'category_ids');
$this->product->setData('value_parsed', '1');
$this->product->setData('operator', '>=');
$this->product->setData('operator', '{}');

$this->productModel->expects($this->once())->method('getAvailableInCategories')
->will($this->returnValue('2'));
$this->assertTrue($this->product->validate($this->productModel));
}

Expand Down
14 changes: 9 additions & 5 deletions app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public function getCurrencyRate()
{
$rate = $this->_getData('currency_rate');
if ($rate === null) {
$rate = $this->_storeManager->getStore($this->getStoreId())
->getCurrentCurrencyRate();
$rate = $this->_storeManager->getStore()->getCurrentCurrencyRate();
}
if (!$rate) {
$rate = 1;
Expand All @@ -175,6 +174,11 @@ public function getCurrencyRate()
*/
protected function _renderRangeLabel($fromPrice, $toPrice)
{
$fromPrice *= $this->getCurrencyRate();
if ($toPrice) {
$toPrice *= $this->getCurrencyRate();
}

$formattedFromPrice = $this->priceCurrency->format($fromPrice);
if ($toPrice === '') {
return __('%1 and above', $formattedFromPrice);
Expand Down Expand Up @@ -212,7 +216,7 @@ protected function _getItemsData()
if (strpos($key, '_') === false) {
continue;
}
$data[] = $this->prepareData($key, $count, $data);
$data[] = $this->prepareData($key, $count);
}
}

Expand Down Expand Up @@ -262,8 +266,8 @@ private function prepareData($key, $count)
$to = $this->getTo($to);
}
$label = $this->_renderRangeLabel(
empty($from) ? 0 : $from * $this->getCurrencyRate(),
empty($to) ? $to : $to * $this->getCurrencyRate()
empty($from) ? 0 : $from,
$to
);
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();

Expand Down
Loading

0 comments on commit ce3efb6

Please sign in to comment.