Skip to content

Commit

Permalink
Merge pull request #1735 from magento-partners/prs-2.2-develop-2017-1…
Browse files Browse the repository at this point in the history
…1-17

[EngCom] Partners Pull Requests
  • Loading branch information
Volodymyr Kublytskyi authored Nov 20, 2017
2 parents b05a957 + 4c41ba9 commit 2b78994
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,25 +369,55 @@ protected function getAttributeValues($entityIds, $storeId)
}
$values = [];

foreach ($entityIds as $entityId) {
$values[$entityId] = [];
$linkIds = $this->getLinkIds($entityIds);
foreach ($linkIds as $linkId) {
$values[$linkId] = [];
}

$attributes = $this->getAttributes();
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
$linkField = $this->getCategoryMetadata()->getLinkField();
foreach ($attributesType as $type) {
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
if (isset($row[$this->getCategoryMetadata()->getLinkField()]) && isset($row['attribute_id'])) {
if (isset($row[$linkField]) && isset($row['attribute_id'])) {
$attributeId = $row['attribute_id'];
if (isset($attributes[$attributeId])) {
$attributeCode = $attributes[$attributeId]['attribute_code'];
$values[$row[$this->getCategoryMetadata()->getLinkField()]][$attributeCode] = $row['value'];
$values[$row[$linkField]][$attributeCode] = $row['value'];
}
}
}
}

return $values;
}

/**
* Translate entity ids into link ids
*
* Used for rows with no EAV attributes set.
*
* @param array $entityIds
* @return array
*/
private function getLinkIds(array $entityIds)
{
$linkField = $this->getCategoryMetadata()->getLinkField();
if ($linkField === 'entity_id') {
return $entityIds;
}

$select = $this->connection->select()->from(
['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))],
[$linkField]
)->where(
'e.entity_id IN (?)',
$entityIds
);

return $this->connection->fetchCol($select);
}

/**
* Return attribute values for given entities and store of specific attribute type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,22 @@ protected function populateFlatTables(array $stores)
}
/** @TODO Do something with chunks */
$categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500);

foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
$linkField = $this->categoryMetadata->getLinkField();

$data = [];
foreach ($categories[$store->getRootCategoryId()] as $category) {
if (!isset($attributesData[$category[$this->categoryMetadata->getLinkField()]])) {
if (!isset($attributesData[$category[$linkField]])) {
continue;
}
$category['store_id'] = $store->getId();
$data[] = $this->prepareValuesToInsert(
array_merge($category, $attributesData[$category[$this->categoryMetadata->getLinkField()]])
array_merge($category, $attributesData[$category[$linkField]])
);
}

$this->connection->insertMultiple(
$this->addTemporaryTableSuffix($this->getMainStoreTable($store->getId())),
$data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,24 @@ public function reindex(array $entityIds = [], $useTempTable = false)
$categoriesIdsChunk = $this->filterIdsByStore($categoriesIdsChunk, $store);

$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
$linkField = $this->categoryMetadata->getLinkField();
$data = [];
foreach ($categoriesIdsChunk as $categoryId) {
if (!isset($attributesData[$categoryId])) {
continue;
}

try {
$category = $this->categoryRepository->get($categoryId);
} catch (NoSuchEntityException $e) {
continue;
}

$categoryData = $category->getData();
if (!isset($attributesData[$categoryData[$linkField]])) {
continue;
}

$data[] = $this->prepareValuesToInsert(
array_merge(
$category->getData(),
$attributesData[$categoryId],
$categoryData,
$attributesData[$categoryData[$linkField]],
['store_id' => $store->getId()]
)
);
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/Model/Product/Option/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public function getProduct()
public function saveValues()
{
foreach ($this->getValues() as $value) {
$this->isDeleted(false);
$this->setData(
$value
)->setData(
Expand Down
29 changes: 28 additions & 1 deletion app/code/Magento/Customer/Controller/Ajax/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;

/**
* Login controller
Expand Down Expand Up @@ -58,6 +60,16 @@ class Login extends \Magento\Framework\App\Action\Action
*/
protected $scopeConfig;

/**
* @var CookieManagerInterface
*/
private $cookieManager;

/**
* @var CookieMetadataFactory
*/
private $cookieMetadataFactory;

/**
* Initialize Login controller
*
Expand All @@ -67,21 +79,31 @@ class Login extends \Magento\Framework\App\Action\Action
* @param AccountManagementInterface $customerAccountManagement
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param CookieManagerInterface $cookieManager
* @param CookieMetadataFactory $cookieMetadataFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\Json\Helper\Data $helper,
AccountManagementInterface $customerAccountManagement,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
CookieManagerInterface $cookieManager = null,
CookieMetadataFactory $cookieMetadataFactory = null
) {
parent::__construct($context);
$this->customerSession = $customerSession;
$this->helper = $helper;
$this->customerAccountManagement = $customerAccountManagement;
$this->resultJsonFactory = $resultJsonFactory;
$this->resultRawFactory = $resultRawFactory;
$this->cookieManager = $cookieManager ?: ObjectManager::getInstance()->get(
CookieManagerInterface::class
);
$this->cookieMetadataFactory = $cookieMetadataFactory ?: ObjectManager::getInstance()->get(
CookieMetadataFactory::class
);
}

/**
Expand Down Expand Up @@ -169,6 +191,11 @@ public function execute()
$this->customerSession->setCustomerDataAsLoggedIn($customer);
$this->customerSession->regenerateId();
$redirectRoute = $this->getAccountRedirect()->getRedirectCookie();
if ($this->cookieManager->getCookie('mage-cache-sessid')) {
$metadata = $this->cookieMetadataFactory->createCookieMetadata();
$metadata->setPath('/');
$this->cookieManager->deleteCookie('mage-cache-sessid', $metadata);
}
if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectRoute) {
$response['redirectUrl'] = $this->_redirect->success($redirectRoute);
$this->getAccountRedirect()->clearRedirectCookie();
Expand Down
43 changes: 43 additions & 0 deletions app/code/Magento/Customer/Test/Unit/Controller/Ajax/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class LoginTest extends \PHPUnit\Framework\TestCase
*/
protected $redirectMock;

/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface| \PHPUnit_Framework_MockObject_MockObject
*/
private $cookieManager;

/**
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory| \PHPUnit_Framework_MockObject_MockObject
*/
private $cookieMetadataFactory;

/**
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadata| \PHPUnit_Framework_MockObject_MockObject
*/
private $cookieMetadata;

protected function setUp()
{
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
Expand Down Expand Up @@ -100,6 +115,16 @@ protected function setUp()
->setMethods(['create'])
->getMock();

$this->cookieManager = $this->getMockBuilder(\Magento\Framework\Stdlib\CookieManagerInterface::class)
->setMethods(['getCookie', 'deleteCookie'])
->getMockForAbstractClass();
$this->cookieMetadataFactory = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
->disableOriginalConstructor()
->getMock();
$this->cookieMetadata = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
->disableOriginalConstructor()
->getMock();

$this->resultRaw = $this->getMockBuilder(\Magento\Framework\Controller\Result\Raw::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -128,6 +153,8 @@ protected function setUp()
'resultJsonFactory' => $this->resultJsonFactory,
'objectManager' => $this->objectManager,
'customerAccountManagement' => $this->customerAccountManagementMock,
'cookieManager' => $this->cookieManager,
'cookieMetadataFactory' => $this->cookieMetadataFactory
]
);
}
Expand Down Expand Up @@ -179,6 +206,22 @@ public function testLogin()
$this->object->setAccountRedirect($redirectMock);
$redirectMock->expects($this->once())->method('getRedirectCookie')->willReturn('some_url1');

$this->cookieManager->expects($this->once())
->method('getCookie')
->with('mage-cache-sessid')
->willReturn(true);
$this->cookieMetadataFactory->expects($this->once())
->method('createCookieMetadata')
->willReturn($this->cookieMetadata);
$this->cookieMetadata->expects($this->once())
->method('setPath')
->with('/')
->willReturnSelf();
$this->cookieManager->expects($this->once())
->method('deleteCookie')
->with('mage-cache-sessid', $this->cookieMetadata)
->willReturnSelf();

$scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->object->setScopeConfig($scopeConfigMock);
$scopeConfigMock->expects($this->once())->method('getValue')
Expand Down

0 comments on commit 2b78994

Please sign in to comment.