Skip to content

Commit

Permalink
MAGETWO-84238: #10765 Export data from grid not adding custom rendere…
Browse files Browse the repository at this point in the history
…d data magento2 #12373

 - Merge Pull Request #12373 from Zefiryn/magento2:10765-2.1
 - Merged commits:
   1. 5f3ef1b
   2. 74e1d85
  • Loading branch information
ishakhsuvarov committed Nov 21, 2017
2 parents 409eef5 + 74e1d85 commit d7632e4
Show file tree
Hide file tree
Showing 19 changed files with 288 additions and 37 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
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ protected function _createTemporaryFlatTable($storeId)

$columnComment = isset($fieldProp['comment']) ? $fieldProp['comment'] : $fieldName;

if ($fieldName == 'created_at') {
$columnDefinition['nullable'] = true;
$columnDefinition['default'] = null;
}

$table->addColumn($fieldName, $fieldProp['type'], $columnLength, $columnDefinition, $columnComment);
}

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 @@ -191,6 +191,7 @@ public function getProduct()
public function saveValues()
{
foreach ($this->getValues() as $value) {
$this->isDeleted(false);
$this->setData(
$value
)->setData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ define(
emailValidationResult = customer.isLoggedIn();

if (!quote.shippingMethod()) {
this.errorValidationMessage('Please specify a shipping method.');
this.errorValidationMessage($t('Please specify a shipping method.'));

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Api/CustomerRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
public function get($email, $websiteId = null);

/**
* Get customer by customer ID.
* Get customer by Customer ID.
*
* @param int $customerId
* @return \Magento\Customer\Api\Data\CustomerInterface
Expand Down Expand Up @@ -69,7 +69,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
public function delete(\Magento\Customer\Api\Data\CustomerInterface $customer);

/**
* Delete customer by ID.
* Delete customer by Customer ID.
*
* @param int $customerId
* @return bool true on success
Expand Down
9 changes: 7 additions & 2 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,13 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
default:
throw new InputException(
__(
'Invalid value of "%value" provided for the %fieldName field.',
['value' => $template, 'fieldName' => 'email type']
'Invalid value of "%value" provided for the %fieldName field. Possible values are %template1 or %template2.',
[
'value' => $template,
'fieldName' => 'template',
'template1' => AccountManagement::EMAIL_REMINDER,
'template2' => AccountManagement::EMAIL_RESET
]
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,10 +1192,6 @@ public function testInitiatePasswordResetEmailReset()
$this->assertTrue($this->accountManagement->initiatePasswordReset($email, $template));
}

/**
* @expectedException \Magento\Framework\Exception\InputException
* @expectedExceptionMessage Invalid value of "" provided for the email type field
*/
public function testInitiatePasswordResetNoTemplate()
{
$storeId = 1;
Expand All @@ -1211,6 +1207,10 @@ public function testInitiatePasswordResetNoTemplate()

$this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash);

$this->setExpectedException(
\Magento\Framework\Exception\InputException::class,
'Invalid value of "" provided for the template field. Possible values are email_reminder or email_reset.'
);
$this->accountManagement->initiatePasswordReset($email, $template);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Customer\Ui\Component\DataProvider\Document;
use Magento\Framework\Api\AttributeValue;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Phrase;
use Magento\Sales\Model\Order\Invoice;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -45,6 +47,11 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
*/
private $storeManager;

/**
* @var ScopeConfigInterface|MockObject
*/
private $scopeConfig;

/**
* @var Document
*/
Expand All @@ -60,11 +67,14 @@ protected function setUp()

$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);

$this->scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);

$this->document = new Document(
$this->attributeValueFactory,
$this->groupRepository,
$this->customerMetadata,
$this->storeManager
$this->storeManager,
$this->scopeConfig
);
}

Expand Down Expand Up @@ -157,6 +167,41 @@ public function testGetWebsiteAttribute()
static::assertEquals('Main Website', $attribute->getValue());
}

/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetConfirmationAttribute()
{
$websiteId = 1;
$this->document->setData('original_website_id', $websiteId);

$this->scopeConfig->expects(static::once())
->method('getValue')
->with()
->willReturn(true);

$this->document->setData('confirmation', null);
$attribute = $this->document->getCustomAttribute('confirmation');

$value = $attribute->getValue();
static::assertInstanceOf(Phrase::class, $value);
static::assertEquals('Confirmed', (string)$value);
}

/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetAccountLockValue()
{
$this->document->setData('lock_expires', null);

$attribute = $this->document->getCustomAttribute('lock_expires');

$value = $attribute->getValue();
static::assertInstanceOf(Phrase::class, $value);
static::assertEquals('Unlocked', (string)$value);
}

/**
* Create mock for attribute value factory
* @return void
Expand Down
Loading

0 comments on commit d7632e4

Please sign in to comment.