Skip to content

Commit

Permalink
Merge pull request #585 from magento-nord/develop
Browse files Browse the repository at this point in the history
[NORD] Bug fixes
  • Loading branch information
Onischenko, Yaroslav(yonischenko) committed May 11, 2016
2 parents 0611634 + a0fc088 commit 392644b
Show file tree
Hide file tree
Showing 31 changed files with 773 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product;

use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;

class AddAttribute extends Action
{
Expand All @@ -28,18 +29,11 @@ public function __construct(
}

/**
* Add "super" attribute from popup window
*
* @return void
* @inheritdoc
*/
public function execute()
{
$this->_view->loadLayout('popup');
$this->productBuilder->build($this->getRequest());
$attributeBlock = $this->_view->getLayout()->createBlock(
'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created'
);
$this->_addContent($attributeBlock);
$this->_view->renderLayout();
return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

namespace Magento\ConfigurableProduct\Test\Unit\Controller\Adminhtml\Product;

use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class AddAttributeTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
private $resultFactory;

/** @var \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute */
protected $controller;

Expand Down Expand Up @@ -45,35 +49,39 @@ protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->context = $this->getMockBuilder('\Magento\Backend\App\Action\Context')
$this->context = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class)
->disableOriginalConstructor()
->getMock();
$this->request = $this->getMock('Magento\Framework\App\RequestInterface');
$this->request = $this->getMock(\Magento\Framework\App\RequestInterface::class);
$this->resultFactory = $this->getMock(\Magento\Framework\Controller\ResultFactory::class, [], [], '', false);
$this->response = $this->getMock(
'\Magento\Framework\App\ResponseInterface',
\Magento\Framework\App\ResponseInterface::class,
[
'sendResponse',
'setBody'
]
);
$this->productBuilder = $this->getMockBuilder('\Magento\Catalog\Controller\Adminhtml\Product\Builder')
$this->productBuilder = $this->getMockBuilder(\Magento\Catalog\Controller\Adminhtml\Product\Builder::class)
->disableOriginalConstructor()
->setMethods(['build'])
->getMock();
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface');
$this->view = $this->getMock(\Magento\Framework\App\ViewInterface::class);

$this->context->expects($this->any())
->method('getRequest')
->will($this->returnValue($this->request));
$this->context->expects($this->any())
->method('getResponse')
->will($this->returnValue($this->response));
$this->context->expects($this->any())
->method('getResultFactory')
->will($this->returnValue($this->resultFactory));
$this->context->expects($this->any())
->method('getView')
->will($this->returnValue($this->view));

$this->controller = $this->objectManagerHelper->getObject(
'\Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute',
\Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute::class,
[
'context' => $this->context,
'productBuilder' => $this->productBuilder
Expand All @@ -83,25 +91,16 @@ protected function setUp()

public function testExecute()
{
$product = $this->getMockBuilder('\Magento\Catalog\Model\Product')
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->setMethods(['_wakeup', 'getId'])
->getMock();
$layout = $this->getMock('\Magento\Framework\View\LayoutInterface');
$block = $this->getMockBuilder(
'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created'
)
->disableOriginalConstructor()
->setMethods(['setIndex', 'toHtml'])
->getMock();

$this->view->expects($this->once())->method('loadLayout')->with('popup')->willReturnSelf();
$this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
$this->view->expects($this->any())->method('getLayout')->willReturn($layout);
$layout->expects($this->once())->method('createBlock')->willReturn($block);
$layout->expects($this->once())->method('setChild')->willReturnSelf();
$this->view->expects($this->any())->method('renderLayout')->willReturnSelf();
$resultLayout = $this->getMock(\Magento\Framework\View\Result\Layout::class, [], [], '', false);
$this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_LAYOUT)
->willReturn($resultLayout);

$this->controller->execute();
$this->assertInstanceOf(\Magento\Framework\View\Result\Layout::class, $this->controller->execute());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<container name="root">
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created" template="Magento_ConfigurableProduct::catalog/product/attribute/new/created.phtml" as="product.attribute.created" />
</container>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@
$('#create_new_attribute').modal('closeModal');

})(window.parent.jQuery);
</script>
<div class="a-center">
<?php echo $block->getCloseButtonHtml() ?>
</div>
</script>
14 changes: 12 additions & 2 deletions app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getAllOptions($withEmpty = true, $defaultValues = false)
}
$options = $defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId];
if ($withEmpty) {
array_unshift($options, ['label' => '', 'value' => '']);
$options = $this->addEmptyOption($options);
}

return $options;
Expand All @@ -89,11 +89,21 @@ public function getSpecificOptions($ids, $withEmpty = true)
->load()
->toOptionArray();
if ($withEmpty) {
array_unshift($options, ['label' => '', 'value' => '']);
$options = $this->addEmptyOption($options);
}
return $options;
}

/**
* @param array $options
* @return array
*/
private function addEmptyOption(array $options)
{
array_unshift($options, ['label' => $this->getAttribute()->getIsRequired() ? '' : ' ', 'value' => '']);
return $options;
}

/**
* Get a text for option value
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testGetSpecificOptions($optionIds, $withEmpty)

$attribute = $this->getMock(
'Magento\Eav\Model\Entity\Attribute\AbstractAttribute',
['getId', 'getStoreId', '__wakeup'],
['getId', 'getStoreId', 'getIsRequired', '__wakeup'],
[],
'',
false
Expand All @@ -131,6 +131,9 @@ public function testGetSpecificOptions($optionIds, $withEmpty)
$attribute->expects($this->once())
->method('getStoreId')
->willReturn($storeId);
$attribute->expects($this->any())
->method('getIsRequired')
->willReturn(false);

$this->model->setAttribute($attribute);

Expand Down Expand Up @@ -160,7 +163,7 @@ public function testGetSpecificOptions($optionIds, $withEmpty)
->willReturn($options);

if ($withEmpty) {
array_unshift($options, ['label' => '', 'value' => '']);
array_unshift($options, ['label' => ' ', 'value' => '']);
}

$this->assertEquals($options, $this->model->getSpecificOptions($optionIds, $withEmpty));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ define([
$.unique(errorsMessage).join(', ');
};

if (data.error && data.error.code === 400) {
if (data.error && [400, 402, 403].indexOf(data.error.code) !== -1) {
this._onRequestError(createErrorMessage());

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ define([
var url = this.options.saveRemoteVideoUrl,
self = this;

this._getPreviewImage().attr('src', sourceUrl).hide();
this._blockActionButtons(true, true);
$.ajax({
url: url,
Expand Down Expand Up @@ -628,7 +629,7 @@ define([
* @private
*/
_create: function () {
var imgs = this.element.closest(this.options.videoSelector).data('images') || [],
var imgs = _.values(this.element.closest(this.options.videoSelector).data('images')) || [],
widget,
uploader,
tmp,
Expand Down Expand Up @@ -697,7 +698,7 @@ define([
roles.prop('disabled', false);
file = widget.element.find('#file_name').val();
widget._onGetVideoInformationEditClick();
modalTitleElement = widget.element.closest('.mage-new-video-dialog .modal-title');
modalTitleElement = modal.find('.modal-title');

if (!file) {
widget._blockActionButtons(true);
Expand Down
14 changes: 7 additions & 7 deletions app/code/Magento/Review/Model/ResourceModel/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function processRatingCodes(\Magento\Framework\Model\AbstractModel $ob
->where('rating_id = :rating_id');
$old = $connection->fetchPairs($select, [':rating_id' => $ratingId]);
$new = array_filter(array_map('trim', $object->getRatingCodes()));
$this->deleteRatingData($ratingId, $table, array_diff_assoc($old, $new));
$this->deleteRatingData($ratingId, $table, array_keys(array_diff_assoc($old, $new)));

$insert = [];
foreach (array_diff_assoc($new, $old) as $storeId => $title) {
Expand All @@ -210,10 +210,10 @@ protected function processRatingStores(\Magento\Framework\Model\AbstractModel $o
->where('rating_id = :rating_id');
$old = $connection->fetchCol($select, [':rating_id' => $ratingId]);
$new = $object->getStores();
$this->deleteRatingData($ratingId, $table, array_diff_assoc($old, $new));
$this->deleteRatingData($ratingId, $table, array_diff($old, $new));

$insert = [];
foreach (array_keys(array_diff_assoc($new, $old)) as $storeId) {
foreach (array_diff($new, $old) as $storeId) {
$insert[] = ['rating_id' => $ratingId, 'store_id' => (int)$storeId];
}
$this->insertRatingData($table, $insert);
Expand All @@ -223,18 +223,18 @@ protected function processRatingStores(\Magento\Framework\Model\AbstractModel $o
/**
* @param int $ratingId
* @param string $table
* @param array $data
* @param array $storeIds
* @return void
*/
protected function deleteRatingData($ratingId, $table, array $data)
protected function deleteRatingData($ratingId, $table, array $storeIds)
{
if (empty($data)) {
if (empty($storeIds)) {
return;
}
$connection = $this->getConnection();
$connection->beginTransaction();
try {
$where = ['rating_id = ?' => $ratingId, 'store_id IN(?)' => array_keys($data)];
$where = ['rating_id = ?' => $ratingId, 'store_id IN(?)' => $storeIds];
$connection->delete($table, $where);
$connection->commit();
} catch (\Exception $e) {
Expand Down
50 changes: 50 additions & 0 deletions app/code/Magento/Swatches/Plugin/Catalog/CacheInvalidate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Swatches\Plugin\Catalog;

use \Magento\Framework\App\Cache\Type\Block;
use \Magento\Framework\App\Cache\Type\Collection;

class CacheInvalidate
{
/**
* @var \Magento\Framework\App\Cache\TypeListInterface
*/
private $typeList;

/**
* @var \Magento\Swatches\Helper\Data
*/
private $swatchHelper;

/**
* @param \Magento\Framework\App\Cache\TypeListInterface $typeList
* @param \Magento\Swatches\Helper\Data $swatchHelper
*/
public function __construct(
\Magento\Framework\App\Cache\TypeListInterface $typeList,
\Magento\Swatches\Helper\Data $swatchHelper
) {
$this->typeList = $typeList;
$this->swatchHelper = $swatchHelper;
}

/**
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
* @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
*/
public function afterSave(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject,
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
) {
if ($this->swatchHelper->isSwatchAttribute($subject)) {
$this->typeList->invalidate(Block::TYPE_IDENTIFIER);
$this->typeList->invalidate(Collection::TYPE_IDENTIFIER);
}
return $result;
}
}
Loading

0 comments on commit 392644b

Please sign in to comment.