Skip to content

Commit 2b78994

Browse files
author
Volodymyr Kublytskyi
authored
Merge pull request #1735 from magento-partners/prs-2.2-develop-2017-11-17
[EngCom] Partners Pull Requests
2 parents b05a957 + 4c41ba9 commit 2b78994

File tree

6 files changed

+120
-13
lines changed

6 files changed

+120
-13
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,25 +369,55 @@ protected function getAttributeValues($entityIds, $storeId)
369369
}
370370
$values = [];
371371

372-
foreach ($entityIds as $entityId) {
373-
$values[$entityId] = [];
372+
$linkIds = $this->getLinkIds($entityIds);
373+
foreach ($linkIds as $linkId) {
374+
$values[$linkId] = [];
374375
}
376+
375377
$attributes = $this->getAttributes();
376378
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
379+
$linkField = $this->getCategoryMetadata()->getLinkField();
377380
foreach ($attributesType as $type) {
378381
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
379-
if (isset($row[$this->getCategoryMetadata()->getLinkField()]) && isset($row['attribute_id'])) {
382+
if (isset($row[$linkField]) && isset($row['attribute_id'])) {
380383
$attributeId = $row['attribute_id'];
381384
if (isset($attributes[$attributeId])) {
382385
$attributeCode = $attributes[$attributeId]['attribute_code'];
383-
$values[$row[$this->getCategoryMetadata()->getLinkField()]][$attributeCode] = $row['value'];
386+
$values[$row[$linkField]][$attributeCode] = $row['value'];
384387
}
385388
}
386389
}
387390
}
391+
388392
return $values;
389393
}
390394

395+
/**
396+
* Translate entity ids into link ids
397+
*
398+
* Used for rows with no EAV attributes set.
399+
*
400+
* @param array $entityIds
401+
* @return array
402+
*/
403+
private function getLinkIds(array $entityIds)
404+
{
405+
$linkField = $this->getCategoryMetadata()->getLinkField();
406+
if ($linkField === 'entity_id') {
407+
return $entityIds;
408+
}
409+
410+
$select = $this->connection->select()->from(
411+
['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))],
412+
[$linkField]
413+
)->where(
414+
'e.entity_id IN (?)',
415+
$entityIds
416+
);
417+
418+
return $this->connection->fetchCol($select);
419+
}
420+
391421
/**
392422
* Return attribute values for given entities and store of specific attribute type
393423
*

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Full.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ protected function populateFlatTables(array $stores)
6464
}
6565
/** @TODO Do something with chunks */
6666
$categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500);
67+
6768
foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
6869
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
70+
$linkField = $this->categoryMetadata->getLinkField();
71+
6972
$data = [];
7073
foreach ($categories[$store->getRootCategoryId()] as $category) {
71-
if (!isset($attributesData[$category[$this->categoryMetadata->getLinkField()]])) {
74+
if (!isset($attributesData[$category[$linkField]])) {
7275
continue;
7376
}
7477
$category['store_id'] = $store->getId();
7578
$data[] = $this->prepareValuesToInsert(
76-
array_merge($category, $attributesData[$category[$this->categoryMetadata->getLinkField()]])
79+
array_merge($category, $attributesData[$category[$linkField]])
7780
);
7881
}
82+
7983
$this->connection->insertMultiple(
8084
$this->addTemporaryTableSuffix($this->getMainStoreTable($store->getId())),
8185
$data

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Rows.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,24 @@ public function reindex(array $entityIds = [], $useTempTable = false)
6969
$categoriesIdsChunk = $this->filterIdsByStore($categoriesIdsChunk, $store);
7070

7171
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
72+
$linkField = $this->categoryMetadata->getLinkField();
7273
$data = [];
7374
foreach ($categoriesIdsChunk as $categoryId) {
74-
if (!isset($attributesData[$categoryId])) {
75-
continue;
76-
}
77-
7875
try {
7976
$category = $this->categoryRepository->get($categoryId);
8077
} catch (NoSuchEntityException $e) {
8178
continue;
8279
}
8380

81+
$categoryData = $category->getData();
82+
if (!isset($attributesData[$categoryData[$linkField]])) {
83+
continue;
84+
}
85+
8486
$data[] = $this->prepareValuesToInsert(
8587
array_merge(
86-
$category->getData(),
87-
$attributesData[$categoryId],
88+
$categoryData,
89+
$attributesData[$categoryData[$linkField]],
8890
['store_id' => $store->getId()]
8991
)
9092
);

app/code/Magento/Catalog/Model/Product/Option/Value.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public function getProduct()
190190
public function saveValues()
191191
{
192192
foreach ($this->getValues() as $value) {
193+
$this->isDeleted(false);
193194
$this->setData(
194195
$value
195196
)->setData(

app/code/Magento/Customer/Controller/Ajax/Login.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
1414
use Magento\Framework\App\Config\ScopeConfigInterface;
1515
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Stdlib\CookieManagerInterface;
17+
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1618

1719
/**
1820
* Login controller
@@ -58,6 +60,16 @@ class Login extends \Magento\Framework\App\Action\Action
5860
*/
5961
protected $scopeConfig;
6062

63+
/**
64+
* @var CookieManagerInterface
65+
*/
66+
private $cookieManager;
67+
68+
/**
69+
* @var CookieMetadataFactory
70+
*/
71+
private $cookieMetadataFactory;
72+
6173
/**
6274
* Initialize Login controller
6375
*
@@ -67,21 +79,31 @@ class Login extends \Magento\Framework\App\Action\Action
6779
* @param AccountManagementInterface $customerAccountManagement
6880
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
6981
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
82+
* @param CookieManagerInterface $cookieManager
83+
* @param CookieMetadataFactory $cookieMetadataFactory
7084
*/
7185
public function __construct(
7286
\Magento\Framework\App\Action\Context $context,
7387
\Magento\Customer\Model\Session $customerSession,
7488
\Magento\Framework\Json\Helper\Data $helper,
7589
AccountManagementInterface $customerAccountManagement,
7690
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
77-
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory
91+
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
92+
CookieManagerInterface $cookieManager = null,
93+
CookieMetadataFactory $cookieMetadataFactory = null
7894
) {
7995
parent::__construct($context);
8096
$this->customerSession = $customerSession;
8197
$this->helper = $helper;
8298
$this->customerAccountManagement = $customerAccountManagement;
8399
$this->resultJsonFactory = $resultJsonFactory;
84100
$this->resultRawFactory = $resultRawFactory;
101+
$this->cookieManager = $cookieManager ?: ObjectManager::getInstance()->get(
102+
CookieManagerInterface::class
103+
);
104+
$this->cookieMetadataFactory = $cookieMetadataFactory ?: ObjectManager::getInstance()->get(
105+
CookieMetadataFactory::class
106+
);
85107
}
86108

87109
/**
@@ -169,6 +191,11 @@ public function execute()
169191
$this->customerSession->setCustomerDataAsLoggedIn($customer);
170192
$this->customerSession->regenerateId();
171193
$redirectRoute = $this->getAccountRedirect()->getRedirectCookie();
194+
if ($this->cookieManager->getCookie('mage-cache-sessid')) {
195+
$metadata = $this->cookieMetadataFactory->createCookieMetadata();
196+
$metadata->setPath('/');
197+
$this->cookieManager->deleteCookie('mage-cache-sessid', $metadata);
198+
}
172199
if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectRoute) {
173200
$response['redirectUrl'] = $this->_redirect->success($redirectRoute);
174201
$this->getAccountRedirect()->clearRedirectCookie();

app/code/Magento/Customer/Test/Unit/Controller/Ajax/LoginTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ class LoginTest extends \PHPUnit\Framework\TestCase
7373
*/
7474
protected $redirectMock;
7575

76+
/**
77+
* @var \Magento\Framework\Stdlib\CookieManagerInterface| \PHPUnit_Framework_MockObject_MockObject
78+
*/
79+
private $cookieManager;
80+
81+
/**
82+
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory| \PHPUnit_Framework_MockObject_MockObject
83+
*/
84+
private $cookieMetadataFactory;
85+
86+
/**
87+
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadata| \PHPUnit_Framework_MockObject_MockObject
88+
*/
89+
private $cookieMetadata;
90+
7691
protected function setUp()
7792
{
7893
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
@@ -100,6 +115,16 @@ protected function setUp()
100115
->setMethods(['create'])
101116
->getMock();
102117

118+
$this->cookieManager = $this->getMockBuilder(\Magento\Framework\Stdlib\CookieManagerInterface::class)
119+
->setMethods(['getCookie', 'deleteCookie'])
120+
->getMockForAbstractClass();
121+
$this->cookieMetadataFactory = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
$this->cookieMetadata = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
125+
->disableOriginalConstructor()
126+
->getMock();
127+
103128
$this->resultRaw = $this->getMockBuilder(\Magento\Framework\Controller\Result\Raw::class)
104129
->disableOriginalConstructor()
105130
->getMock();
@@ -128,6 +153,8 @@ protected function setUp()
128153
'resultJsonFactory' => $this->resultJsonFactory,
129154
'objectManager' => $this->objectManager,
130155
'customerAccountManagement' => $this->customerAccountManagementMock,
156+
'cookieManager' => $this->cookieManager,
157+
'cookieMetadataFactory' => $this->cookieMetadataFactory
131158
]
132159
);
133160
}
@@ -179,6 +206,22 @@ public function testLogin()
179206
$this->object->setAccountRedirect($redirectMock);
180207
$redirectMock->expects($this->once())->method('getRedirectCookie')->willReturn('some_url1');
181208

209+
$this->cookieManager->expects($this->once())
210+
->method('getCookie')
211+
->with('mage-cache-sessid')
212+
->willReturn(true);
213+
$this->cookieMetadataFactory->expects($this->once())
214+
->method('createCookieMetadata')
215+
->willReturn($this->cookieMetadata);
216+
$this->cookieMetadata->expects($this->once())
217+
->method('setPath')
218+
->with('/')
219+
->willReturnSelf();
220+
$this->cookieManager->expects($this->once())
221+
->method('deleteCookie')
222+
->with('mage-cache-sessid', $this->cookieMetadata)
223+
->willReturnSelf();
224+
182225
$scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
183226
$this->object->setScopeConfig($scopeConfigMock);
184227
$scopeConfigMock->expects($this->once())->method('getValue')

0 commit comments

Comments
 (0)