Skip to content

Commit

Permalink
Merge pull request #512 from magento-nord/develop
Browse files Browse the repository at this point in the history
[NORD] Bug fixes
  • Loading branch information
Klymenko, Volodymyr(vklymenko) committed Apr 13, 2016
2 parents f4ae285 + 764431b commit 072a1ae
Show file tree
Hide file tree
Showing 27 changed files with 861 additions and 83 deletions.
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 @@ -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
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
7 changes: 2 additions & 5 deletions app/code/Magento/Checkout/Model/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ protected function _getProductRequest($requestInfo)
$request = new \Magento\Framework\DataObject($requestInfo);
}

if (!$request->hasQty()) {
$request->setQty(1);
}
!$request->hasFormKey() ?: $request->unsFormKey();

return $request;
Expand All @@ -350,7 +347,7 @@ public function addProduct($productInfo, $requestInfo = null)
//If product was not found in cart and there is set minimal qty for it
if ($minimumQty
&& $minimumQty > 0
&& $request->getQty() < $minimumQty
&& !$request->getQty()
&& !$this->getQuote()->hasProductId($productId)
) {
$request->setQty($minimumQty);
Expand Down Expand Up @@ -690,7 +687,7 @@ public function updateItem($itemId, $requestInfo = null, $updatingParams = null)
// If product was not found in cart and there is set minimal qty for it
if ($minimumQty
&& $minimumQty > 0
&& $request->getQty() < $minimumQty
&& !$request->getQty()
&& !$this->getQuote()->hasProductId($productId)
) {
$request->setQty($minimumQty);
Expand Down
12 changes: 12 additions & 0 deletions app/code/Magento/Cms/Model/Page/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public function __construct(
$this->collection = $pageCollectionFactory->create();
$this->dataPersistor = $dataPersistor;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
return $meta;
}

/**
Expand Down
22 changes: 12 additions & 10 deletions app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,20 @@ public function getOptionText($value)
*/
public function addValueSortToCollection($collection, $dir = \Magento\Framework\DB\Select::SQL_ASC)
{
$valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1';
$valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2';
$attribute = $this->getAttribute();
$valueTable1 = $attribute->getAttributeCode() . '_t1';
$valueTable2 = $attribute->getAttributeCode() . '_t2';
$linkField = $attribute->getEntity()->getLinkField();
$collection->getSelect()->joinLeft(
[$valueTable1 => $this->getAttribute()->getBackend()->getTable()],
"e.entity_id={$valueTable1}.entity_id" .
" AND {$valueTable1}.attribute_id='{$this->getAttribute()->getId()}'" .
[$valueTable1 => $attribute->getBackend()->getTable()],
"e.{$linkField}={$valueTable1}." . $linkField .
" AND {$valueTable1}.attribute_id='{$attribute->getId()}'" .
" AND {$valueTable1}.store_id=0",
[]
)->joinLeft(
[$valueTable2 => $this->getAttribute()->getBackend()->getTable()],
"e.entity_id={$valueTable2}.entity_id" .
" AND {$valueTable2}.attribute_id='{$this->getAttribute()->getId()}'" .
[$valueTable2 => $attribute->getBackend()->getTable()],
"e.{$linkField}={$valueTable2}." . $linkField .
" AND {$valueTable2}.attribute_id='{$attribute->getId()}'" .
" AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
[]
);
Expand All @@ -161,11 +163,11 @@ public function addValueSortToCollection($collection, $dir = \Magento\Framework\

$this->_attrOptionFactory->create()->addOptionValueToCollection(
$collection,
$this->getAttribute(),
$attribute,
$valueExpr
);

$collection->getSelect()->order("{$this->getAttribute()->getAttributeCode()} {$dir}");
$collection->getSelect()->order("{$attribute->getAttributeCode()} {$dir}");

return $this;
}
Expand Down
Loading

0 comments on commit 072a1ae

Please sign in to comment.