Skip to content

Commit

Permalink
Merge pull request #169 from magento-vanilla/PR
Browse files Browse the repository at this point in the history
[Vanilla] Bugs
  • Loading branch information
Kopylova,Olga(okopylova) committed Mar 19, 2015
2 parents d2d0db2 + fba2f6b commit c4bbc29
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 18 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/view/base/web/js/price-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* See COPYING.txt for license details.
*/
define([
'jquery',
'underscore'
], function (_) {
], function ($, _) {
'use strict';

var globalPriceFormat = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ $class = ($_option->getIsRequire()) ? ' required' : '';
<input type="text"
id="options_<?php echo $_option->getId() ?>_text"
class="input-text product-custom-option"
<?php if (!empty($_textValidate)) {
echo 'data-validate=' . json_encode($_textValidate);
} ?>
<?php if (!empty($_textValidate)) {?>
data-validate="<?php echo $block->escapeHtml(json_encode($_textValidate));?>"
<?php } ?>
name="options[<?php echo $_option->getId() ?>]"
value="<?php echo $block->escapeHtml($block->getDefaultValue()) ?>"/>
<?php elseif ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_AREA): ?>
Expand All @@ -49,9 +49,9 @@ $class = ($_option->getIsRequire()) ? ' required' : '';
?>
<textarea id="options_<?php echo $_option->getId() ?>_text"
class="product-custom-option"
<?php if (!empty($_textAreaValidate)) {
echo 'data-validate=' . json_encode($_textAreaValidate);
} ?>
<?php if (!empty($_textAreaValidate)) {?>
data-validate="<?php echo $block->escapeHtml(json_encode($_textAreaValidate));?>"
<?php } ?>
name="options[<?php echo $_option->getId() ?>]"
rows="5"
cols="25"><?php echo $block->escapeHtml($block->getDefaultValue()) ?></textarea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ define([

submitForm: function(form) {
var self = this;
if (form.has('input[type="file"]').length) {
if (form.has('input[type="file"]').length && form.find('input[type="file"]').val() !== '') {
self.element.off('submit');
form.submit();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected function _getCellInputElementId($rowId, $columnName)
*/
protected function _getCellInputElementName($columnName)
{
return $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
return $this->getElement()->getName() . '[<%- _id %>][' . $columnName . ']';
}

/**
Expand All @@ -203,7 +203,7 @@ public function renderCellTemplate($columnName)
return $column['renderer']->setInputName(
$inputName
)->setInputId(
$this->_getCellInputElementId('#{_id}', $columnName)
$this->_getCellInputElementId('<%- _id %>', $columnName)
)->setColumnName(
$columnName
)->setColumn(
Expand All @@ -212,15 +212,15 @@ public function renderCellTemplate($columnName)
}

return '<input type="text" id="' . $this->_getCellInputElementId(
'#{_id}',
'<%- _id %>',
$columnName
) .
'"' .
' name="' .
$inputName .
'" value="#{' .
'" value="<%- ' .
$columnName .
'}" ' .
' %>" ' .
($column['size'] ? 'size="' .
$column['size'] .
'"' : '') .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function renderCellTemplate($columnName)
)->setName(
$this->_getCellInputElementName($columnName)
)->setHtmlId(
$this->_getCellInputElementId('#{_id}', $columnName)
$this->_getCellInputElementId('<%- _id %>', $columnName)
)->setValues(
$options
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $_colspan = $block->isAddAfter() ? 2 : 1;
'prototype'
], function (mageTemplate) {
// create row creator
var arrayRow<?php echo $_htmlId ?> = {
window.arrayRow<?php echo $_htmlId ?> = {

// define row prototypeJS template
template: mageTemplate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@
</constraints>
</field>
<field name="region" source="eav" formElement="input" visible="false"/>
<field name="postcode" source="eav">

<field name="postcode" source="eav" formElement="post_code_fix" >
<constraints>
<validate name="required-entry"/>
</constraints>
</field>

<field name="telephone" source="eav" label="Phone Number">
<constraints>
<validate name="required-entry"/>
Expand Down
18 changes: 17 additions & 1 deletion app/code/Magento/Directory/Model/Resource/Country/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
namespace Magento\Directory\Model\Resource\Country;

/**
* Class Collection
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
{
/**
Expand Down Expand Up @@ -44,6 +48,11 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac
*/
protected $_localeResolver;

/**
* @var \Magento\Directory\Helper\Data
*/
protected $helperData;

/**
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
* @param \Psr\Log\LoggerInterface $logger
Expand All @@ -54,6 +63,7 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac
* @param \Magento\Directory\Model\Resource\CountryFactory $countryFactory
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Framework\App\Helper\AbstractHelper $helperData
* @param mixed $connection
* @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -68,6 +78,7 @@ public function __construct(
\Magento\Directory\Model\Resource\CountryFactory $countryFactory,
\Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Framework\App\Helper\AbstractHelper $helperData,
$connection = null,
\Magento\Framework\Model\Resource\Db\AbstractDb $resource = null
) {
Expand All @@ -77,6 +88,7 @@ public function __construct(
$this->_localeResolver = $localeResolver;
$this->_countryFactory = $countryFactory;
$this->_arrayUtils = $arrayUtils;
$this->helperData = $helperData;
}

/**
Expand Down Expand Up @@ -208,7 +220,11 @@ public function toOptionArray($emptyLabel = ' ')
}
$options = [];
foreach ($sort as $label => $value) {
$options[] = ['value' => $value, 'label' => $label];
$option = ['value' => $value, 'label' => $label];
if ($this->helperData->isRegionRequired($value)) {
$option['is_region_required'] = true;
}
$options[] = $option;
}

if (count($options) > 0 && $emptyLabel !== false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ protected function setUp()
'',
false
);
$helperDataMock = $this->getMock(
'Magento\Directory\Helper\Data',
[],
[],
'',
false
);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$arguments = [
'logger' => $logger,
Expand All @@ -57,6 +64,7 @@ protected function setUp()
'scopeConfig' => $scopeConfigMock,
'countryFactory' => $countryFactory,
'resource' => $resource,
'helperData' => $helperDataMock
];
$this->_model = $objectManager->getObject('Magento\Directory\Model\Resource\Country\Collection', $arguments);
}
Expand Down
12 changes: 11 additions & 1 deletion app/code/Magento/Directory/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Directory\Model\Resource\Country\Collection" shared="false" />
<type name="Magento\Directory\Model\Currency\Import\Config">
<arguments>
<argument name="servicesConfig" xsi:type="array">
Expand All @@ -17,4 +16,15 @@
</argument>
</arguments>
</type>

<virtualType name="DirectoryHelperDataProxy" type="Magento\Directory\Helper\Data\Proxy">
<arguments>
<argument name="instanceName" xsi:type="string">Magento\Directory\Helper\Data</argument>
</arguments>
</virtualType>
<type name="Magento\Directory\Model\Resource\Country\Collection" shared="false">
<arguments>
<argument name="helperData" xsi:type="object">DirectoryHelperDataProxy</argument>
</arguments>
</type>
</config>
9 changes: 9 additions & 0 deletions app/code/Magento/Ui/view/base/layout/ui_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,13 @@
</argument>
</arguments>
</block>

<block class="Magento\Ui\Component\Form\Element\Input" name="post_code">
<arguments>
<argument name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/post-code</item>
<item name="dependentFiled" xsi:type="string">country_id</item>
</argument>
</arguments>
</block>
</layout>
65 changes: 65 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/form/element/post-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'underscore',
'Magento_Ui/js/lib/registry/registry',
'./abstract'
], function (_, registry, Abstract) {
'use strict';

return Abstract.extend({
/**
* Extended list of Listeners
*
* @return {this}
*/
initListeners: function () {
this._super()
.update()
.provider.data.on('update:' + this.parentScope + '.country_id', this.update.bind(this));

return this;
},

/**
* Fix _postcode_ depend on _country_id_ change:
* - If country in list "Zip/Postal Code is Optional countries" then
* - field "postcode" should not be required
*
* @returns {this}
*/
update: function () {
var parentScope = this.getPart(this.getPart(this.name, -2), -2),
option,
postcode = this;

registry.get(parentScope + '.country_id.0', function (countryComponent) {
var value = countryComponent.value();

if (!value) { // empty value discard logic
return;
}

countryComponent
.options()
.some(function (el) {
option = el;

return el.value === value;
});

if (!option.is_region_required) {
postcode.error(false);
postcode.validation = _.omit(postcode.validation, 'required-entry');
} else {
postcode.validation['required-entry'] = true;
}
postcode.required(!!option.is_region_required);
});

return this;
}
});
});

0 comments on commit c4bbc29

Please sign in to comment.