Skip to content

Commit ec8af46

Browse files
author
Oleksii Korshenko
authored
Merge pull request magento#1709 from magento-qwerty/QwertyPR20171107
Bug MAGETWO-70726 [GITHUB] [2.1] Store View Language switch leads to 404 on some cases magento#5416 MAGETWO-52974 Configurable product options not saved when editing - for mainline
2 parents 2275b89 + 1605e86 commit ec8af46

File tree

18 files changed

+551
-125
lines changed

18 files changed

+551
-125
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,37 @@
1212
class DbStorage extends BaseDbStorage
1313
{
1414
/**
15-
* @param array $data
16-
* @return \Magento\Framework\DB\Select
15+
* {@inheritDoc}
1716
*/
1817
protected function prepareSelect(array $data)
1918
{
19+
$metadata = [];
20+
if (array_key_exists(UrlRewrite::METADATA, $data)) {
21+
$metadata = $data[UrlRewrite::METADATA];
22+
unset($data[UrlRewrite::METADATA]);
23+
}
24+
2025
$select = $this->connection->select();
21-
$select->from(['url_rewrite' => $this->resource->getTableName('url_rewrite')])
22-
->joinLeft(
23-
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
24-
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'
25-
)
26-
->where('url_rewrite.entity_id IN (?)', $data['entity_id'])
27-
->where('url_rewrite.entity_type = ?', $data['entity_type'])
28-
->where('url_rewrite.store_id IN (?)', $data['store_id']);
29-
if (empty($data[UrlRewrite::METADATA]['category_id'])) {
26+
$select->from([
27+
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
28+
]);
29+
$select->joinLeft(
30+
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
31+
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'
32+
);
33+
34+
foreach ($data as $column => $value) {
35+
$select->where('url_rewrite.' . $column . ' IN (?)', $value);
36+
}
37+
if (empty($metadata['category_id'])) {
3038
$select->where('relation.category_id IS NULL');
3139
} else {
32-
$select->where('relation.category_id = ?', $data[UrlRewrite::METADATA]['category_id']);
40+
$select->where(
41+
'relation.category_id = ?',
42+
$metadata['category_id']
43+
);
3344
}
45+
3446
return $select;
3547
}
3648
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Storage;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\CatalogUrlRewrite\Model\Storage\DbStorage;
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
12+
use PHPUnit_Framework_MockObject_MockObject as Mock;
13+
use Magento\Framework\Api\DataObjectHelper;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
use Magento\Framework\DB\Select;
16+
use Magento\Framework\App\ResourceConnection;
17+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
18+
19+
class DbStorageTest extends TestCase
20+
{
21+
/**
22+
* @var DbStorage
23+
*/
24+
private $storage;
25+
26+
/**
27+
* @var UrlRewriteFactory|Mock
28+
*/
29+
private $urlRewriteFactory;
30+
31+
/**
32+
* @var DataObjectHelper|Mock
33+
*/
34+
private $dataObjectHelper;
35+
36+
/**
37+
* @var AdapterInterface|Mock
38+
*/
39+
private $connectionMock;
40+
41+
/**
42+
* @var Select|Mock
43+
*/
44+
private $select;
45+
46+
/**
47+
* @var ResourceConnection|Mock
48+
*/
49+
private $resource;
50+
51+
/**
52+
* @inheritDoc
53+
*
54+
* Preparing mocks and target object.
55+
*/
56+
protected function setUp()
57+
{
58+
parent::setUp();
59+
60+
$this->urlRewriteFactory = $this
61+
->getMockBuilder(UrlRewriteFactory::class)
62+
->setMethods(['create'])
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$this->dataObjectHelper = $this->createMock(DataObjectHelper::class);
66+
$this->connectionMock = $this->createMock(AdapterInterface::class);
67+
$this->select = $this->createPartialMock(
68+
Select::class,
69+
['from', 'where', 'deleteFromSelect', 'joinLeft']
70+
);
71+
$this->resource = $this->createMock(ResourceConnection::class);
72+
73+
$this->resource->expects($this->any())
74+
->method('getConnection')
75+
->will($this->returnValue($this->connectionMock));
76+
$this->connectionMock->expects($this->any())
77+
->method('select')
78+
->will($this->returnValue($this->select));
79+
80+
$this->storage = (new ObjectManager($this))->getObject(
81+
DbStorage::class,
82+
[
83+
'urlRewriteFactory' => $this->urlRewriteFactory,
84+
'dataObjectHelper' => $this->dataObjectHelper,
85+
'resource' => $this->resource,
86+
]
87+
);
88+
}
89+
90+
public function testPrepareSelect()
91+
{
92+
//Passing expected parameters, checking select built.
93+
$entityType = 'custom';
94+
$entityId= 42;
95+
$storeId = 0;
96+
$categoryId = 2;
97+
$redirectType = 301;
98+
//Expecting this methods to be called on select
99+
$this->select
100+
->expects($this->at(2))
101+
->method('where')
102+
->with('url_rewrite.entity_id IN (?)', $entityId)
103+
->willReturn($this->select);
104+
$this->select
105+
->expects($this->at(3))
106+
->method('where')
107+
->with('url_rewrite.entity_type IN (?)', $entityType)
108+
->willReturn($this->select);
109+
$this->select
110+
->expects($this->at(4))
111+
->method('where')
112+
->with('url_rewrite.store_id IN (?)', $storeId)
113+
->willReturn($this->select);
114+
$this->select
115+
->expects($this->at(5))
116+
->method('where')
117+
->with('url_rewrite.redirect_type IN (?)', $redirectType)
118+
->willReturn($this->select);
119+
$this->select
120+
->expects($this->at(6))
121+
->method('where')
122+
->with('relation.category_id = ?', $categoryId)
123+
->willReturn($this->select);
124+
//Preparing mocks to be used
125+
$this->select
126+
->expects($this->any())
127+
->method('from')
128+
->willReturn($this->select);
129+
$this->select
130+
->expects($this->any())
131+
->method('joinLeft')
132+
->willReturn($this->select);
133+
//Indirectly calling prepareSelect
134+
$this->storage->findOneByData([
135+
UrlRewrite::ENTITY_ID => $entityId,
136+
UrlRewrite::ENTITY_TYPE => $entityType,
137+
UrlRewrite::STORE_ID => $storeId,
138+
UrlRewrite::REDIRECT_TYPE => $redirectType,
139+
UrlRewrite::METADATA => ['category_id' => $categoryId]
140+
]);
141+
}
142+
}

app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ define([
134134
*/
135135
_create: function () {
136136
$(this.element).on('gallery:loaded', $.proxy(function () {
137-
this.fotoramaItem = $(this.element).find('.fotorama-item');
138137
this._initialize();
139138
}, this));
140139
},
@@ -154,6 +153,7 @@ define([
154153
this.defaultVideoData = this.options.videoData = this.videoDataPlaceholder;
155154
}
156155

156+
this.fotoramaItem = $(this.element).find('.fotorama-item');
157157
this.clearEvents();
158158

159159
if (this._checkForVideoExist()) {
@@ -164,6 +164,8 @@ define([
164164
this._initFotoramaVideo();
165165
this._attachFotoramaEvents();
166166
}
167+
168+
this.element.trigger('AddFotoramaVideoEvents:loaded');
167169
},
168170

169171
/**

app/code/Magento/Store/Block/Switcher.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ public function getStoreName()
223223
*/
224224
public function getTargetStorePostData(\Magento\Store\Model\Store $store, $data = [])
225225
{
226-
$data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME] = $store->getCode();
226+
$data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME]
227+
= $store->getCode();
228+
//We need to fromStore as true because it will enable proper URL
229+
//rewriting during store switching.
227230
return $this->_postDataHelper->getPostData(
228-
$store->getCurrentUrl(false),
231+
$store->getCurrentUrl(true),
229232
$data
230233
);
231234
}

app/code/Magento/Store/Model/Store.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,14 @@ public function isDefault()
11361136
public function getCurrentUrl($fromStore = true)
11371137
{
11381138
$sidQueryParam = $this->_sidResolver->getSessionIdQueryParam($this->_getSession());
1139-
$requestString = $this->_url->escape(ltrim($this->_request->getRequestString(), '/'));
1139+
/** @var string $requestString Request path without query parameters */
1140+
$requestString = $this->_url->escape(
1141+
preg_replace(
1142+
'/\?.*?$/',
1143+
'',
1144+
ltrim($this->_request->getRequestString(), '/')
1145+
)
1146+
);
11401147

11411148
$storeUrl = $this->getUrl('', ['_secure' => $this->_storeManager->getStore()->isCurrentlySecure()]);
11421149

app/code/Magento/Store/Test/Unit/Block/SwitcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testGetTargetStorePostData()
5353
$storeSwitchUrl = 'http://domain.com/stores/store/switch';
5454
$store->expects($this->atLeastOnce())
5555
->method('getCurrentUrl')
56-
->with(false)
56+
->with(true)
5757
->willReturn($storeSwitchUrl);
5858
$this->corePostDataHelper->expects($this->any())
5959
->method('getPostData')

app/code/Magento/Store/Test/Unit/Model/StoreTest.php

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,11 @@ public function testGetBaseUrlWrongType()
370370
* @param boolean $secure
371371
* @param string $url
372372
* @param string $expected
373+
* @param bool|string $fromStore
373374
*/
374-
public function testGetCurrentUrl($secure, $url, $expected)
375+
public function testGetCurrentUrl($secure, $url, $expected, $fromStore)
375376
{
376-
$defaultStore = $this->createPartialMock(\Magento\Store\Model\Store::class, [
377+
$defaultStore = $this->createPartialMock(Store::class, [
377378
'getId',
378379
'isCurrentlySecure',
379380
'__wakeup'
@@ -386,15 +387,31 @@ public function testGetCurrentUrl($secure, $url, $expected)
386387

387388
$config = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
388389

389-
$this->requestMock->expects($this->atLeastOnce())->method('getRequestString')->will($this->returnValue(''));
390+
$requestString = preg_replace(
391+
'/http(s?)\:\/\/[a-z0-9\-]+\//i',
392+
'',
393+
$url
394+
);
395+
$this->requestMock
396+
->expects($this->atLeastOnce())
397+
->method('getRequestString')
398+
->willReturn($requestString);
390399
$this->requestMock->expects($this->atLeastOnce())->method('getQueryValue')->will($this->returnValue([
391400
'SID' => 'sid'
392401
]));
393402

394403
$urlMock = $this->getMockForAbstractClass(\Magento\Framework\UrlInterface::class);
395-
$urlMock->expects($this->atLeastOnce())->method('setScope')->will($this->returnSelf());
396-
$urlMock->expects($this->any())->method('getUrl')
397-
->will($this->returnValue($url));
404+
$urlMock
405+
->expects($this->atLeastOnce())
406+
->method('setScope')
407+
->will($this->returnSelf());
408+
$urlMock->expects($this->any())
409+
->method('getUrl')
410+
->will($this->returnValue(str_replace($requestString, '', $url)));
411+
$urlMock
412+
->expects($this->atLeastOnce())
413+
->method('escape')
414+
->willReturnArgument(0);
398415

399416
$storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
400417
$storeManager->expects($this->any())
@@ -409,7 +426,7 @@ public function testGetCurrentUrl($secure, $url, $expected)
409426
$model->setStoreId(2);
410427
$model->setCode('scope_code');
411428

412-
$this->assertEquals($expected, $model->getCurrentUrl(false));
429+
$this->assertEquals($expected, $model->getCurrentUrl($fromStore));
413430
}
414431

415432
/**
@@ -418,9 +435,31 @@ public function testGetCurrentUrl($secure, $url, $expected)
418435
public function getCurrentUrlDataProvider()
419436
{
420437
return [
421-
[true, 'http://test/url', 'http://test/url?SID=sid&amp;___store=scope_code'],
422-
[true, 'http://test/url?SID=sid1&___store=scope', 'http://test/url?SID=sid&amp;___store=scope_code'],
423-
[false, 'https://test/url', 'https://test/url?SID=sid&amp;___store=scope_code']
438+
[
439+
true,
440+
'http://test/url',
441+
'http://test/url?SID=sid&amp;___store=scope_code',
442+
false
443+
],
444+
[
445+
true,
446+
'http://test/url?SID=sid1&___store=scope',
447+
'http://test/url?SID=sid&amp;___store=scope_code',
448+
false
449+
],
450+
[
451+
false,
452+
'https://test/url',
453+
'https://test/url?SID=sid&amp;___store=scope_code',
454+
false
455+
],
456+
[
457+
true,
458+
'http://test/u/u.2?__store=scope_code',
459+
'http://test/u/u.2?'
460+
. 'SID=sid&amp;___store=scope_code&amp;___from_store=old-store',
461+
'old-store'
462+
]
424463
];
425464
}
426465

app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ public function __construct(
119119
$configurableAttributeData,
120120
$data
121121
);
122+
123+
$this->addData(
124+
[
125+
'cache_lifetime' => isset($data['cache_lifetime']) ? $data['cache_lifetime'] : 3600
126+
]
127+
);
122128
}
123129

124130
/**

app/code/Magento/Swatches/view/frontend/layout/checkout_cart_configure_type_configurable.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
*/
77
-->
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9-
<head>
10-
<link src="Magento_Swatches::js/configurable-customer-data.js"/>
11-
</head>
9+
<body>
10+
<referenceBlock name="product.info.options.wrapper">
11+
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-">
12+
<arguments>
13+
<argument name="cache_lifetime" xsi:type="boolean">false</argument>
14+
</arguments>
15+
</block>
16+
</referenceBlock>
17+
</body>
1218
</page>

app/code/Magento/Swatches/view/frontend/layout/wishlist_index_configure_type_configurable.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
<body>
1313
<referenceBlock name="product.info.options.configurable" remove="true"/>
1414
<referenceBlock name="product.info.options.wrapper">
15-
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-" />
15+
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-">
16+
<arguments>
17+
<argument name="cache_lifetime" xsi:type="boolean">false</argument>
18+
</arguments>
19+
</block>
1620
</referenceBlock>
1721
</body>
1822
</page>

0 commit comments

Comments
 (0)