Skip to content

Commit

Permalink
Merge pull request #35 from gelanivishal/2.1-develop-PR-port-15980
Browse files Browse the repository at this point in the history
[Backport] Use correct error message for duplicate error key in product import
  • Loading branch information
gelanivishal authored Jun 25, 2018
2 parents 746ffce + 4e23358 commit 6e9661d
Show file tree
Hide file tree
Showing 40 changed files with 409 additions and 152 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/Model/Product/Option/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\Catalog\Model\Product\Option;

use Magento\Catalog\Pricing\Price\BasePrice;
use Magento\Framework\Model\AbstractModel;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Option;
Expand Down Expand Up @@ -225,7 +226,7 @@ public function saveValues()
public function getPrice($flag = false)
{
if ($flag && $this->getPriceType() == self::TYPE_PERCENT) {
$basePrice = $this->getOption()->getProduct()->getFinalPrice();
$basePrice = $this->getOption()->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
return $price;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,30 @@ private function getMockedOption()
private function getMockedProduct()
{
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->setMethods(['getFinalPrice', '__wakeup'])
->setMethods(['getPriceInfo', '__wakeup'])
->disableOriginalConstructor();
$mock = $mockBuilder->getMock();

$mock->expects($this->any())
->method('getFinalPrice')
->will($this->returnValue(10));
$priceInfoMock = $this->getMockForAbstractClass(
\Magento\Framework\Pricing\PriceInfoInterface::class,
[],
'',
false,
false,
true,
['getPrice']
);

$priceMock = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Price\PriceInterface::class);

$priceInfoMock->expects($this->any())->method('getPrice')->willReturn($priceMock);

$mock->expects($this->any())->method('getPriceInfo')->willReturn($priceInfoMock);

$priceMock->expects($this->any())->method('getValue')->willReturn(10);

return $mock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,12 @@ protected function checkUrlKeyDuplicates()
);
foreach ($urlKeyDuplicates as $entityData) {
$rowNum = $this->rowNumbers[$entityData['store_id']][$entityData['request_path']];
$this->addRowError(ValidatorInterface::ERROR_DUPLICATE_URL_KEY, $rowNum);
$message = sprintf(
$this->retrieveMessageTemplate(ValidatorInterface::ERROR_DUPLICATE_URL_KEY),
$entityData['request_path'],
$entityData['sku']
);
$this->addRowError(ValidatorInterface::ERROR_DUPLICATE_URL_KEY, $rowNum, 'url_key', $message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ define([
var element;

_.each(this.disabledAttributes, function (attribute) {
registry.get('index = ' + attribute).disabled(false);
registry.get('code = ' + attribute, 'index = ' + attribute).disabled(false);
});
this.disabledAttributes = [];

_.each(attributes, function (attribute) {
element = registry.get('index = ' + attribute.code);
element = registry.get('code = ' + attribute.code, 'index = ' + attribute.code);
if (!_.isUndefined(element)) {
element.disabled(true);
this.disabledAttributes.push(attribute.code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Exception\InputException;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\ScopeInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -61,6 +63,16 @@ class AddressRepository implements \Magento\Customer\Api\AddressRepositoryInterf
*/
protected $extensionAttributesJoinProcessor;

/**
* @var \Magento\Directory\Model\AllowedCountries
*/
private $allowedCountriesReader;

/**
* @var \Magento\Customer\Model\Config\Share
*/
private $shareConfig;

/**
* @param \Magento\Customer\Model\AddressFactory $addressFactory
* @param \Magento\Customer\Model\AddressRegistry $addressRegistry
Expand All @@ -70,6 +82,10 @@ class AddressRepository implements \Magento\Customer\Api\AddressRepositoryInterf
* @param \Magento\Customer\Api\Data\AddressSearchResultsInterfaceFactory $addressSearchResultsFactory
* @param \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressCollectionFactory
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
* @param \Magento\Directory\Model\AllowedCountries|null $allowedCountriesReader
* @param \Magento\Customer\Model\Config\Share|null $shareConfig
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Customer\Model\AddressFactory $addressFactory,
Expand All @@ -79,7 +95,9 @@ public function __construct(
\Magento\Directory\Helper\Data $directoryData,
\Magento\Customer\Api\Data\AddressSearchResultsInterfaceFactory $addressSearchResultsFactory,
\Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressCollectionFactory,
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
\Magento\Directory\Model\AllowedCountries $allowedCountriesReader = null,
\Magento\Customer\Model\Config\Share $shareConfig = null
) {
$this->addressFactory = $addressFactory;
$this->addressRegistry = $addressRegistry;
Expand All @@ -89,6 +107,10 @@ public function __construct(
$this->addressSearchResultsFactory = $addressSearchResultsFactory;
$this->addressCollectionFactory = $addressCollectionFactory;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
$this->allowedCountriesReader = $allowedCountriesReader
?: ObjectManager::getInstance()->get(\Magento\Directory\Model\AllowedCountries::class);
$this->shareConfig = $shareConfig
?: ObjectManager::getInstance()->get(\Magento\Customer\Model\Config\Share::class);
}

/**
Expand Down Expand Up @@ -290,7 +312,7 @@ private function _validate(CustomerAddressModel $customerAddressModel)
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'countryId']));
} else {
//Checking if such country exists.
if (!in_array($countryId, $this->directoryData->getCountryCollection()->getAllIds(), true)) {
if (!in_array($countryId, $this->getWebsiteAllowedCountries($customerAddressModel), true)) {
$exception->addError(
__(
'Invalid value of "%value" provided for the %fieldName field.',
Expand Down Expand Up @@ -334,4 +356,23 @@ private function _validate(CustomerAddressModel $customerAddressModel)

return $exception;
}

/**
* Return allowed counties per website.
*
* @param \Magento\Customer\Model\Address $customerAddressModel
* @return array
*/
private function getWebsiteAllowedCountries(\Magento\Customer\Model\Address $customerAddressModel)
{
$websiteId = null;

if (!$this->shareConfig->isGlobalScope()) {
$websiteId = $customerAddressModel->getCustomer()
? $customerAddressModel->getCustomer()->getWebsiteId()
: null;
}

return $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $websiteId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
namespace Magento\Customer\Test\Unit\Model\ResourceModel;

use Magento\Customer\Api\Data\AddressInterface as AddressData;
use Magento\Directory\Model\ResourceModel\Country\Collection as Countries;
use Magento\Framework\Exception\InputException;
use Magento\Store\Model\ScopeInterface;

/**
* Unit test for Magento\Customer\Model\ResourceModel\AddressRepository
Expand Down Expand Up @@ -71,6 +71,16 @@ class AddressRepositoryTest extends \PHPUnit_Framework_TestCase
*/
protected $repository;

/**
* @var \Magento\Directory\Model\AllowedCountries|\PHPUnit_Framework_MockObject_MockObject
*/
private $allowedCountriesReaderMock;

/**
* @var \Magento\Customer\Model\Config\Share|\PHPUnit_Framework_MockObject_MockObject
*/
private $shareConfigMock;

protected function setUp()
{
$this->addressFactory = $this->getMock(
Expand Down Expand Up @@ -137,6 +147,26 @@ protected function setUp()
false
);

$this->allowedCountriesReaderMock = $this->getMock(
\Magento\Directory\Model\AllowedCountries::class,
['getAllowedCountries'],
[],
'',
false
);
$this->shareConfigMock = $this->getMock(
\Magento\Customer\Model\Config\Share::class,
['isGlobalScope'],
[],
'',
false
);
$this->shareConfigMock->method('isGlobalScope')->willReturn(false);
$this->allowedCountriesReaderMock
->method('getAllowedCountries')
->with(ScopeInterface::SCOPE_WEBSITE, null)
->willReturn(['1', '2']);

$this->repository = new \Magento\Customer\Model\ResourceModel\AddressRepository(
$this->addressFactory,
$this->addressRegistry,
Expand All @@ -145,7 +175,9 @@ protected function setUp()
$this->directoryData,
$this->addressSearchResultsFactory,
$this->addressCollectionFactory,
$this->extensionAttributesJoinProcessor
$this->extensionAttributesJoinProcessor,
$this->allowedCountriesReaderMock,
$this->shareConfigMock
);
}

Expand Down Expand Up @@ -315,15 +347,6 @@ public function testSaveWithInvalidRegion()
->method('getRegion')
->willReturn('');

/** @var \PHPUnit_Framework_MockObject_MockObject $countryCollection */
$countryCollection = $this->getMockBuilder(Countries::class)
->disableOriginalConstructor()
->getMock();
$countryCollection->expects($this->once())->method('getAllIds')->willReturn(['1', '2']);
$this->directoryData->expects($this->once())
->method('getCountryCollection')
->willReturn($countryCollection);

$this->repository->save($customerAddress);
}

Expand Down Expand Up @@ -408,15 +431,6 @@ public function testSaveWithInvalidRegionId()
->method('getRegion')
->willReturn('');

/** @var \PHPUnit_Framework_MockObject_MockObject $countryCollection */
$countryCollection = $this->getMockBuilder(Countries::class)
->disableOriginalConstructor()
->getMock();
$countryCollection->expects($this->once())->method('getAllIds')->willReturn(['1', '2']);
$this->directoryData->expects($this->once())
->method('getCountryCollection')
->willReturn($countryCollection);

$this->repository->save($customerAddress);
}

Expand Down Expand Up @@ -714,15 +728,6 @@ private function prepareAddressData($countryId, $regionId)
$countryModel->expects($this->any())->method('getRegionCollection')->willReturn($regionCollection);
$regionCollection->expects($this->any())->method('getAllIds')->willReturn(['3', '4']);

/** @var \PHPUnit_Framework_MockObject_MockObject $countryCollection */
$countryCollection = $this->getMockBuilder(Countries::class)
->disableOriginalConstructor()
->getMock();
$countryCollection->expects($this->once())->method('getAllIds')->willReturn(['1', '2']);
$this->directoryData->expects($this->once())
->method('getCountryCollection')
->willReturn($countryCollection);

return $customerAddress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="field email required">
<label class="label" for="email"><span><?php echo $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="login[username]" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()) :?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" data-validate="{required:true, 'validate-email':true}">
<input name="login[username]" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()) :?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
</div>
</div>
<div class="field password required">
Expand All @@ -51,12 +51,3 @@
</div>
</div>

<script type="text/x-magento-init">
{
".field.email": {
"Magento_Customer/js/trim-username": {
"formSelector": "form.form-login"
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<div class="field required">
<label for="email_address" class="label"><span><?php echo $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
<input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
</div>
</div>
<div class="field password required" data-mage-init='{"passwordStrengthIndicator": {}}'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define(

/** Show login popup window */
showModal: function () {
$(this.modalWindow).modal('openModal');
$(this.modalWindow).modal('openModal').trigger('contentUpdated');
}
}
}
Expand Down
65 changes: 0 additions & 65 deletions app/code/Magento/Customer/view/frontend/web/js/trim-username.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
id="email"
type="email"
class="input-text"
data-mage-init='{"mage/trim-input":{}}'
data-bind="attr: {autocomplete: autocomplete}"
data-validate="{required:true, 'validate-email':true}">
</div>
Expand Down
Loading

0 comments on commit 6e9661d

Please sign in to comment.