Skip to content

Commit

Permalink
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGE…
Browse files Browse the repository at this point in the history
…TWO-83328
  • Loading branch information
slopukhov committed Nov 22, 2017
2 parents 7583730 + 9fc1138 commit 20540c2
Show file tree
Hide file tree
Showing 24 changed files with 1,137 additions and 481 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ public function setCollection($collection)
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
if ($this->getCurrentOrder() == 'position') {
$this->_collection->addAttributeToSort(
$this->getCurrentOrder(),
$this->getCurrentDirection()
)->addAttributeToSort('entity_id', $this->getCurrentDirection());
} else {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}
return $this;
}
Expand Down
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
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ public function isInStock()
* Get attribute text by its code
*
* @param string $attributeCode Code of the attribute
* @return string
* @return string|array|null
*/
public function getAttributeText($attributeCode)
{
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
19 changes: 13 additions & 6 deletions app/code/Magento/Directory/Model/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Magento\Directory\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\InputException;
use Magento\Directory\Model\Currency\Filter;

Expand Down Expand Up @@ -65,6 +66,11 @@ class Currency extends \Magento\Framework\Model\AbstractModel
*/
protected $_localeCurrency;

/**
* @var CurrencyConfig
*/
private $currencyConfig;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -76,6 +82,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param CurrencyConfig $currencyConfig
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -88,7 +95,8 @@ public function __construct(
\Magento\Framework\Locale\CurrencyInterface $localeCurrency,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
CurrencyConfig $currencyConfig = null
) {
parent::__construct(
$context,
Expand All @@ -102,6 +110,7 @@ public function __construct(
$this->_directoryHelper = $directoryHelper;
$this->_currencyFilterFactory = $currencyFilterFactory;
$this->_localeCurrency = $localeCurrency;
$this->currencyConfig = $currencyConfig ?: ObjectManager::getInstance()->get(CurrencyConfig::class);
}

/**
Expand Down Expand Up @@ -347,7 +356,7 @@ public function getOutputFormat()
*/
public function getConfigAllowCurrencies()
{
$allowedCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_ALLOW);
$allowedCurrencies = $this->currencyConfig->getConfigCurrencies(self::XML_PATH_CURRENCY_ALLOW);
$appBaseCurrencyCode = $this->_directoryHelper->getBaseCurrencyCode();
if (!in_array($appBaseCurrencyCode, $allowedCurrencies)) {
$allowedCurrencies[] = $appBaseCurrencyCode;
Expand All @@ -369,17 +378,15 @@ public function getConfigAllowCurrencies()
*/
public function getConfigDefaultCurrencies()
{
$defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_DEFAULT);
return $defaultCurrencies;
return $this->currencyConfig->getConfigCurrencies(self::XML_PATH_CURRENCY_DEFAULT);
}

/**
* @return array
*/
public function getConfigBaseCurrencies()
{
$defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_BASE);
return $defaultCurrencies;
return $this->currencyConfig->getConfigCurrencies(self::XML_PATH_CURRENCY_BASE);
}

/**
Expand Down
Loading

0 comments on commit 20540c2

Please sign in to comment.