Skip to content

Commit

Permalink
Merge pull request #74 from magento-folks/bugfix
Browse files Browse the repository at this point in the history
[Folks] Bugfix
  • Loading branch information
slavvka committed Jun 8, 2016
2 parents 7edfd0c + 097a63d commit 5e4ddd4
Show file tree
Hide file tree
Showing 22 changed files with 752 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
foreach ($useDefaults as $attributeCode => $useDefaultState) {
if ($useDefaultState) {
$product->setData($attributeCode, null);
// UI component sends value even if field is disabled, so 'Use Config Settings' must be reset to false
if ($product->hasData('use_config_' . $attributeCode)) {
$product->setData('use_config_' . $attributeCode, false);
}
}
}

Expand Down Expand Up @@ -215,7 +219,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra

return $product;
}

/**
* Initialize product before saving
*
Expand Down Expand Up @@ -310,7 +314,7 @@ public function mergeProductOptions($productOptions, $overwriteOptions)
if (!is_array($overwriteOptions)) {
return $productOptions;
}

foreach ($productOptions as $index => $option) {
$optionId = $option['option_id'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Model\Product\Attribute\Backend;

use Magento\Catalog\Model\Product\Attribute\Source\Boolean as BooleanSource;

/**
* Product attribute for enable/disable option
*
Expand All @@ -22,7 +24,7 @@ public function beforeSave($object)
{
$attributeCode = $this->getAttribute()->getName();
if ($object->getData('use_config_' . $attributeCode)) {
$object->setData($attributeCode, '');
$object->setData($attributeCode, BooleanSource::VALUE_USE_CONFIG);
}
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class Boolean extends \Magento\Eav\Model\Entity\Attribute\Source\Boolean
{
/**
* Value of 'Use Config' option
*/
const VALUE_USE_CONFIG = 2;

/**
* Retrieve all attribute options
*
Expand All @@ -22,9 +27,9 @@ public function getAllOptions()
{
if (!$this->_options) {
$this->_options = [
['label' => __('Yes'), 'value' => 1],
['label' => __('No'), 'value' => 0],
['label' => __('Use config'), 'value' => 2],
['label' => __('Yes'), 'value' => static::VALUE_YES],
['label' => __('No'), 'value' => static::VALUE_NO],
['label' => __('Use config'), 'value' => static::VALUE_USE_CONFIG],
];
}
return $this->_options;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Backend;

use Magento\Catalog\Model\Product\Attribute\Backend\Boolean as BooleanBackend;
use Magento\Catalog\Model\Product\Attribute\Source\Boolean as BooleanSource;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\DataObject;

class BooleanTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|AbstractAttribute
*/
private $attributeMock;

/**
* @var BooleanBackend
*/
private $model;

protected function setUp()
{
$this->attributeMock = $this->getMockForAbstractClass(
AbstractAttribute::class,
[],
'',
false,
true,
true,
['getName']
);
$this->model = new BooleanBackend();
$this->model->setAttribute($this->attributeMock);
}

public function testBeforeSave()
{
$this->attributeMock->expects($this->any())->method('getName')->willReturn('attribute_name');
$object = new DataObject([
'use_config_attribute_name' => true,
]);
$this->model->beforeSave($object);
$this->assertEquals(BooleanSource::VALUE_USE_CONFIG, $object->getData('attribute_name'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Source;

use Magento\Catalog\Model\Product\Attribute\Source\Boolean as BooleanSource;

class BooleanTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $attributeFactoryMock;

/**
* @var BooleanSource
*/
private $model;

protected function setUp()
{
$this->attributeFactoryMock = $this->getMock(
'Magento\Eav\Model\ResourceModel\Entity\AttributeFactory',
[],
[],
'',
false
);
$this->model = new BooleanSource($this->attributeFactoryMock);
}

public function testGetAllOptions()
{
$expectedResult = [
['label' => __('Yes'), 'value' => BooleanSource::VALUE_YES],
['label' => __('No'), 'value' => BooleanSource::VALUE_NO],
['label' => __('Use config'), 'value' => BooleanSource::VALUE_USE_CONFIG],
];
$this->assertEquals($expectedResult, $this->model->getAllOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected function setUp()
->getMockForAbstractClass();
$this->productMock = $this->getMockBuilder(ProductInterface::class)
->setMethods([
'getId',
'getStoreId',
'getResource',
'getData',
Expand Down
20 changes: 18 additions & 2 deletions app/code/Magento/Checkout/Block/Cart/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
class Sidebar extends AbstractCart
{
/**
* Xml pah to checkout sidebar count value
* Xml pah to checkout sidebar display value
*/
const XML_PATH_CHECKOUT_SIDEBAR_DISPLAY = 'checkout/sidebar/display';

/**
* Xml pah to checkout sidebar count value
*/
const XML_PATH_CHECKOUT_SIDEBAR_COUNT = 'checkout/sidebar/count';

/**
* @var \Magento\Catalog\Helper\Image
*/
Expand Down Expand Up @@ -63,7 +68,8 @@ public function getConfig()
'updateItemQtyUrl' => $this->getUpdateItemQtyUrl(),
'removeItemUrl' => $this->getRemoveItemUrl(),
'imageTemplate' => $this->getImageHtmlTemplate(),
'baseUrl' => $this->getBaseUrl()
'baseUrl' => $this->getBaseUrl(),
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount()
];
}

Expand Down Expand Up @@ -171,4 +177,14 @@ public function getBaseUrl()
{
return $this->_storeManager->getStore()->getBaseUrl();
}

/**
* Return max visible item count for minicart
*
* @return int
*/
private function getMiniCartMaxItemsCount()
{
return (int)$this->_scopeConfig->getValue('checkout/sidebar/count', ScopeInterface::SCOPE_STORE);
}
}
35 changes: 21 additions & 14 deletions app/code/Magento/Checkout/Block/Cart/ValidationMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Checkout\Block\Cart;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;

/**
Expand All @@ -18,6 +19,11 @@ class ValidationMessages extends \Magento\Framework\View\Element\Messages
/** @var \Magento\Framework\Locale\CurrencyInterface */
protected $currency;

/**
* @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
*/
private $minimumAmountErrorMessage;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Message\Factory $messageFactory
Expand Down Expand Up @@ -72,22 +78,23 @@ protected function _prepareLayout()
protected function validateMinimumAmount()
{
if (!$this->cartHelper->getQuote()->validateMinimumAmount()) {
$warning = $this->_scopeConfig->getValue(
'sales/minimum_order/description',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
$this->messageManager->addNotice($this->getMinimumAmountErrorMessage()->getMessage());
}
}

/**
* @return \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
* @deprecated
*/
private function getMinimumAmountErrorMessage()
{
if ($this->minimumAmountErrorMessage === null) {
$objectManager = ObjectManager::getInstance();
$this->minimumAmountErrorMessage = $objectManager->get(
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class
);
if (!$warning) {
$currencyCode = $this->_storeManager->getStore()->getCurrentCurrencyCode();
$minimumAmount = $this->currency->getCurrency($currencyCode)->toCurrency(
$this->_scopeConfig->getValue(
'sales/minimum_order/amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
$warning = __('Minimum order amount is %1', $minimumAmount);
}
$this->messageManager->addNotice($warning);
}
return $this->minimumAmountErrorMessage;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public function testGetConfig()
'updateItemQtyUrl' => $updateItemQtyUrl,
'removeItemUrl' => $removeItemUrl,
'imageTemplate' => $imageTemplate,
'baseUrl' => $baseUrl
'baseUrl' => $baseUrl,
'minicartMaxItemsVisible' => 3
];

$valueMap = [
Expand All @@ -159,6 +160,13 @@ public function testGetConfig()
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
$this->imageHelper->expects($this->once())->method('getFrame')->willReturn(false);

$this->scopeConfigMock->expects($this->once())
->method('getValue')
->with(
\Magento\Checkout\Block\Cart\Sidebar::XML_PATH_CHECKOUT_SIDEBAR_COUNT,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)->willReturn(3);

$this->assertEquals($expectedResult, $this->model->getConfig());
}

Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ define([
$.widget('mage.sidebar', {
options: {
isRecursive: true,
maxItemsVisible: 3
minicart: {
maxItemsVisible: 3
}
},
scrollHeight: 0,

Expand Down Expand Up @@ -240,7 +242,7 @@ define([
_calcHeight: function () {
var self = this,
height = 0,
counter = this.options.maxItemsVisible,
counter = this.options.minicart.maxItemsVisible,
target = $(this.options.minicart.list),
outerHeight;

Expand Down
Loading

0 comments on commit 5e4ddd4

Please sign in to comment.