Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into MAGETWO-51859
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Korablov committed Apr 13, 2016
2 parents 1f2a854 + 072a1ae commit de3ce5c
Show file tree
Hide file tree
Showing 52 changed files with 1,484 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
-->
<button class="action-delete"
data-bind="
click: function(){ $parents[1].deleteRecord($parent.index, $parent.recordId); },
click: function(){ $parent.processingDeleteRecord($record().index, $record().recordId); },
attr: {
title: $parents[1].deleteButtonLabel
title: $parent.deleteButtonLabel
}
">
<span data-bind="text: $parents[1].deleteButtonLabel"></span>
<span data-bind="text: $parent.deleteButtonLabel"></span>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,44 @@
</label>

<div class="admin__field-control" data-role="grid-wrapper">
<div class="admin__control-table-pagination" visible="!!$data.recordData().length">
<div class="admin__data-grid-pager">
<button class="action-previous" type="button" data-bind="attr: {title: $t('Previous Page')}, click: previousPage, disable: isFirst()"></button>
<input class="admin__control-text" type="number" data-bind="attr: {id: ++ko.uid}, value: currentPage">
<label class="admin__control-support-text" data-bind="attr: {for: ko.uid}, text: 'of ' + pages()"></label>
<button class="action-next" type="button" data-bind="attr: {title: $t('Next Page')}, click: nextPage, disable: isLast()"></button>
</div>
</div>
<div class="admin__control-table-wrapper">
<table class="admin__dynamic-rows data-grid" data-role="grid">
<thead if="element.columnsHeader">
<tr>
<th if="dndConfig.enabled"
class="data-grid-draggable-row-cell"/>

<!-- ko foreach: {data: labels, as: 'item'} -->
<th class="data-grid-th"
text="item.label"
visible="item.visible"
disabled="item.disabled"
css="$parent.setClasses(item)">
<th repeat="foreach: labels, item: '$label'"
class="data-grid-th"
text="$label().label"
visible="$label().visible"
disable="$label().disabled"
css="setClasses($label())">
</th>
<!-- /ko -->
</tr>
</thead>

<tbody data-bind="foreach: elems">
<tr class="data-row"
css="'_odd-row': $index() % 2">
<td if="$parent.dndConfig.enabled"
<tr repeat="foreach: elems, item: '$record'"
class="data-row"
css="'_odd-row': $index % 2">
<td if="dndConfig.enabled"
class="data-grid-draggable-row-cell"
template="name: $parent.dndConfig.template, data: $parent.dnd"/>
template="name: dndConfig.template, data: dnd"/>

<!-- ko foreach: { data: elems, as: 'elem'} -->
<!-- ko fastForEach: { data: $record().elems, as: 'elem'} -->
<td if="elem.template"
visible="elem.visible"
disabled="elem.disabled"
css="$parents[1].setClasses(elem)"
disable="elem.disabled"
css="$parent.setClasses(elem)"
template="elem.template"
attr="'data-index': index"/>
<!-- /ko -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public function __construct(
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$this->attributeHelper->setProductIds($collection->getAllIds());
if ($this->getRequest()->getParam('filters')) {
$collection = $this->filter->getCollection($this->collectionFactory->create());
$this->attributeHelper->setProductIds($collection->getAllIds());
}

if (!$this->_validateProducts()) {
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php
/**
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Action\Attribute;

class EditTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save */
private $object;

/** @var \Magento\Catalog\Helper\Product\Edit\Action\Attribute|\PHPUnit_Framework_MockObject_MockObject */
private $attributeHelper;

/** @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */
private $resultRedirectFactory;

/** @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */
private $filter;

/** @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
private $context;

/** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */
private $collectionFactory;

/** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */
private $resultPage;

/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
private $request;

protected function setUp()
{
$this->attributeHelper = $this->getMockBuilder('Magento\Catalog\Helper\Product\Edit\Action\Attribute')
->setMethods(['getProductIds', 'setProductIds'])
->disableOriginalConstructor()->getMock();

$this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->filter = $this->getMockBuilder('Magento\Ui\Component\MassAction\Filter')
->setMethods(['getCollection'])->disableOriginalConstructor()->getMock();

$this->collectionFactory = $this->getMockBuilder(
'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'
)->setMethods(['create'])->disableOriginalConstructor()->getMock();

$this->resultPage = $this->getMockBuilder('Magento\Framework\View\Result\Page')
->setMethods(['getConfig'])->disableOriginalConstructor()->getMock();

$resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
->setMethods(['create'])->disableOriginalConstructor()->getMock();
$resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage);

$this->prepareContext();

$this->object = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
'Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Edit',
[
'context' => $this->context,
'attributeHelper' => $this->attributeHelper,
'filter' => $this->filter,
'resultPageFactory' => $resultPageFactory,
'collectionFactory' => $this->collectionFactory
]
);
}

private function prepareContext()
{
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->setMethods(['getParam', 'getParams', 'setParams'])
->disableOriginalConstructor()->getMock();

$objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
->setMethods(['isProductsHasSku'])
->disableOriginalConstructor()->getMock();
$product->expects($this->any())->method('isProductsHasSku')
->with([1, 2, 3])
->willReturn(true);
$objectManager->expects($this->any())->method('create')
->with('Magento\Catalog\Model\Product')
->willReturn($product);
$messageManager = $this->getMockBuilder('\Magento\Framework\Message\ManagerInterface')
->setMethods([])
->disableOriginalConstructor()->getMock();
$messageManager->expects($this->any())->method('addError')->willReturn(true);
$this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context')
->setMethods(['getRequest', 'getObjectManager', 'getMessageManager', 'getResultRedirectFactory'])
->disableOriginalConstructor()->getMock();
$this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
$this->context->expects($this->any())->method('getObjectManager')->willReturn($objectManager);
$this->context->expects($this->any())->method('getMessageManager')->willReturn($messageManager);
$this->context->expects($this->any())->method('getResultRedirectFactory')
->willReturn($this->resultRedirectFactory);
}

public function testExecutePageRequested()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(['placeholder' => true]);
$this->request->expects($this->any())->method('getParams')->willReturn(
[
'namespace' => 'product_listing',
'exclude' => true,
'filters' => ['placeholder' => true]
]
);

$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
$this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);

$collection = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Product\Collection')
->setMethods(['getAllIds'])
->disableOriginalConstructor()->getMock();
$collection->expects($this->any())->method('getAllIds')->willReturn([1, 2, 3]);
$this->filter->expects($this->any())->method('getCollection')->with($collection)->willReturn($collection);
$this->collectionFactory->expects($this->any())->method('create')->willReturn($collection);

$title = $this->getMockBuilder('Magento\Framework\View\Page\Title')
->setMethods(['prepend'])
->disableOriginalConstructor()->getMock();
$config = $this->getMockBuilder('Magento\Framework\View\Page\Config')
->setMethods(['getTitle'])
->disableOriginalConstructor()->getMock();
$config->expects($this->any())->method('getTitle')->willReturn($title);
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);

$this->assertSame($this->resultPage, $this->object->execute());
}

public function testExecutePageReload()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
$this->request->expects($this->any())->method('getParams')->willReturn([]);

$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
$this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);

$title = $this->getMockBuilder('Magento\Framework\View\Page\Title')
->setMethods(['prepend'])
->disableOriginalConstructor()->getMock();
$config = $this->getMockBuilder('Magento\Framework\View\Page\Config')
->setMethods(['getTitle'])
->disableOriginalConstructor()->getMock();
$config->expects($this->any())->method('getTitle')->willReturn($title);
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);

$this->assertSame($this->resultPage, $this->object->execute());
}

public function testExecutePageDirectAccess()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
$this->request->expects($this->any())->method('getParams')->willReturn([]);
$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null);

$resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
->setMethods(['setPath'])
->disableOriginalConstructor()
->getMock();
$resultRedirect->expects($this->any())->method('setPath')
->with('catalog/product/', ['_current' => true])
->willReturnSelf();
$this->resultRedirectFactory->expects($this->any())
->method('create')
->willReturn($resultRedirect);

$this->assertSame($resultRedirect, $this->object->execute());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ protected function getTextColumn($dataScope, $fit, Phrase $label, $sortOrder)
'componentType' => Field::NAME,
'formElement' => Input::NAME,
'elementTmpl' => 'ui/dynamic-rows/cells/text',
'component' => 'Magento_Ui/js/form/element/text',
'dataType' => Text::NAME,
'dataScope' => $dataScope,
'fit' => $fit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<?php
/* @var $block \Magento\Backend\Block\Widget\Form\Renderer\Fieldset\Element */
$element = $block->getElement();
$note = $element->getNote() ? '<div class="note">' . $element->getNote() . '</div>' : '';
$note = $element->getNote() ? '<div class="note admin__field-note">' . $element->getNote() . '</div>' : '';
$elementBeforeLabel = $element->getExtType() == 'checkbox' || $element->getExtType() == 'radio';
$addOn = $element->getBeforeElementHtml() || $element->getAfterElementHtml();
$fieldId = ($element->getHtmlId()) ? ' id="attribute-' . $element->getHtmlId() . '-container"' : '';
$entity = $element->getEntityAttribute();
$fieldClass = "field field-{$element->getId()} {$element->getCssClass()}";
$fieldClass = "admin__field field field-{$element->getId()} {$element->getCssClass()}";
$fieldClass .= ($elementBeforeLabel) ? ' choice' : '';
$fieldClass .= ($addOn) ? ' with-addon' : '';
$fieldClass .= ($element->getRequired()) ? ' required' : '';
Expand Down Expand Up @@ -51,7 +51,7 @@ $fieldAttributes = $fieldId . ' class="' . $fieldClass . '" '
<?php /* @escapeNotVerified */ echo $note ?>
<?php else: ?>
<?php echo $element->getLabelHtml('', $block->getScopeLabel()) ?>
<div class="control">
<div class="admin__field-control control">
<?php /* @escapeNotVerified */ echo($addOn) ? '<div class="addon">' . $block->getElementHtml() . '</div>' : $block->getElementHtml(); ?>
<?php /* @escapeNotVerified */ echo $note ?>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<button class="action-delete"
attr="{'data-action': 'remove_row'}"
data-bind="
click: function(){ $data.deleteRecord($parents); },
click: function(){ $data.processingDeleteRecord($parents); },
attr: {
title: $parents[1].deleteButtonLabel
title: $parent.deleteButtonLabel
}
">
<span data-bind="text: $parents[1].deleteButtonLabel"></span>
<span data-bind="text: $parent.deleteButtonLabel"></span>
</button>
31 changes: 23 additions & 8 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,18 @@ protected function getItemsPerPage()
$memoryUsagePercent = 0.8;
// Minimum Products limit
$minProductsLimit = 500;
// Maximal Products limit
$maxProductsLimit = 5000;

$this->_itemsPerPage = intval(
($memoryLimit * $memoryUsagePercent - memory_get_usage(true)) / $memoryPerProduct
);
if ($this->_itemsPerPage < $minProductsLimit) {
$this->_itemsPerPage = $minProductsLimit;
}
if ($this->_itemsPerPage > $maxProductsLimit) {
$this->_itemsPerPage = $maxProductsLimit;
}
}
return $this->_itemsPerPage;
}
Expand Down Expand Up @@ -850,8 +855,10 @@ protected function getExportData()
if ($storeId == Store::DEFAULT_STORE_ID && isset($stockItemRows[$productId])) {
$dataRow = array_merge($dataRow, $stockItemRows[$productId]);
}

$exportData = array_merge($exportData, $this->addMultirowData($dataRow, $multirawData));
$this->appendMultirowData($dataRow, $multirawData);
if ($dataRow) {
$exportData[] = $dataRow;
}
}
}
} catch (\Exception $e) {
Expand Down Expand Up @@ -1053,9 +1060,8 @@ protected function isValidAttributeValue($code, $value)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function addMultirowData($dataRow, $multiRawData)
private function appendMultirowData(&$dataRow, &$multiRawData)
{
$result = [];
$productId = $dataRow['product_id'];
$productLinkId = $dataRow['product_link_id'];
$storeId = $dataRow['store_id'];
Expand Down Expand Up @@ -1121,7 +1127,6 @@ protected function addMultirowData($dataRow, $multiRawData)
}
}
$dataRow = $this->rowCustomizer->addData($dataRow, $productId);

}

if (!empty($this->collectedMultiselectsData[$storeId][$productId])) {
Expand All @@ -1144,17 +1149,27 @@ protected function addMultirowData($dataRow, $multiRawData)
}

if (empty($dataRow)) {
return $result;
return null;
} elseif ($storeId != Store::DEFAULT_STORE_ID) {
$dataRow[self::COL_STORE] = $this->_storeIdToCode[$storeId];
if (isset($productData[Store::DEFAULT_STORE_ID][self::COL_VISIBILITY])) {
$dataRow[self::COL_VISIBILITY] = $productData[Store::DEFAULT_STORE_ID][self::COL_VISIBILITY];
}
}
$dataRow[self::COL_SKU] = $sku;
$result[] = $dataRow;
return $dataRow;
}

return $result;
/**
* @deprecated
* @param array $dataRow
* @param array $multiRawData
* @return array
*/
protected function addMultirowData($dataRow, $multiRawData)
{
$data = $this->appendMultirowData($dataRow, $multiRawData);
return $data ? [$data] : [];
}

/**
Expand Down
Loading

0 comments on commit de3ce5c

Please sign in to comment.