Skip to content

Commit

Permalink
Merge branch 'merchant_beta' into MAGETWO-40559
Browse files Browse the repository at this point in the history
  • Loading branch information
irenelagno committed Aug 28, 2015
2 parents 1c5bd87 + 18b6326 commit a433299
Show file tree
Hide file tree
Showing 39 changed files with 402 additions and 2,250 deletions.
79 changes: 63 additions & 16 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@

class AttributeMerger
{
/**
* Map form element
*
* @var array
*/
protected $formElementMap = [
'checkbox' => 'Magento_Ui/js/form/element/select',
'select' => 'Magento_Ui/js/form/element/select',
'textarea' => 'Magento_Ui/js/form/element/textarea',
'multiline' => 'Magento_Ui/js/form/components/group',
'multiselect' => 'Magento_Ui/js/form/element/multiselect',
];

/**
* Map template
*
* @var array
*/
protected $templateMap = [
'image' => 'media',
];

/**
* Map input_validation and validation rule from js
*
* @var array
*/
protected $inputValidationMap = [
'alpha' => 'validate-alpha',
'numeric' => 'validate-number',
'alphanumeric' => 'validate-alphanum',
'url' => 'validate-url',
'email' => 'email2',
];

/**
* @var AddressHelper
*/
Expand Down Expand Up @@ -102,16 +137,22 @@ protected function getFieldConfig(
$dataScopePrefix
) {
// street attribute is unique in terms of configuration, so it has its own configuration builder
if ($attributeCode == 'street') {
return $this->getStreetFieldConfig($attributeCode, $attributeConfig, $providerName, $dataScopePrefix);
if (isset($attributeConfig['validation']['input_validation'])) {
$validationRule = $attributeConfig['validation']['input_validation'];
$attributeConfig['validation'][$this->inputValidationMap[$validationRule]] = true;
unset($attributeConfig['validation']['input_validation']);
}

$uiComponent = $attributeConfig['formElement'] == 'select'
? 'Magento_Ui/js/form/element/select'
if ($attributeConfig['formElement'] == 'multiline') {
return $this->getMultilineFieldConfig($attributeCode, $attributeConfig, $providerName, $dataScopePrefix);
}

$uiComponent = isset($this->formElementMap[$attributeConfig['formElement']])
? $this->formElementMap[$attributeConfig['formElement']]
: 'Magento_Ui/js/form/element/abstract';
$elementTemplate = $attributeConfig['formElement'] == 'select'
? 'ui/form/element/select'
: 'ui/form/element/input';
$elementTemplate = isset($this->templateMap[$attributeConfig['formElement']])
? 'ui/form/element/' . $this->templateMap[$attributeConfig['formElement']]
: 'ui/form/element/' . $attributeConfig['formElement'];

$element = [
'component' => isset($additionalConfig['component']) ? $additionalConfig['component'] : $uiComponent,
Expand Down Expand Up @@ -195,12 +236,13 @@ protected function isFieldVisible($attributeCode, array $attributeConfig, array
* @param string $dataScopePrefix
* @return array
*/
protected function getStreetFieldConfig($attributeCode, array $attributeConfig, $providerName, $dataScopePrefix)
protected function getMultilineFieldConfig($attributeCode, array $attributeConfig, $providerName, $dataScopePrefix)
{
$streetLines = [];
for ($lineIndex = 0; $lineIndex < $this->addressHelper->getStreetLines(); $lineIndex++) {
$lines = [];
unset($attributeConfig['validation']['required-entry']);
for ($lineIndex = 0; $lineIndex < (int)$attributeConfig['size']; $lineIndex++) {
$isFirstLine = $lineIndex === 0;
$streetLines[] = [
$lines[] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
// customScope is used to group elements within a single form e.g. they can be validated separately
Expand All @@ -210,23 +252,28 @@ protected function getStreetFieldConfig($attributeCode, array $attributeConfig,
],
'dataScope' => $lineIndex,
'provider' => $providerName,
'validation' => $isFirstLine ? ['required-entry' => true] : [],
'validation' => $isFirstLine
? array_merge(
['required-entry' => (bool)$attributeConfig['required']],
$attributeConfig['validation']
)
: $attributeConfig['validation'],
'additionalClasses' => $isFirstLine ? : 'additional'
];
}
return [
'component' => 'Magento_Ui/js/form/components/group',
'label' => __('Address'),
'required' => true,
'label' => $attributeConfig['label'],
'required' => (bool)$attributeConfig['required'],
'dataScope' => $dataScopePrefix . '.' . $attributeCode,
'provider' => $providerName,
'sortOrder' => $attributeConfig['sortOrder'],
'type' => 'group',
'config' => [
'template' => 'ui/group/group',
'additionalClasses' => 'street'
'additionalClasses' => $attributeCode
],
'children' => $streetLines,
'children' => $lines,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</form>
<!-- /ko -->
<!-- ko if: accountCreated -->
<p data-bind="text: $t('Your password will be sent to your email')"></p>
<p data-bind="text: $t('A letter with further instructions will be sent to your email.')"></p>
<!-- /ko -->
</div>

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a433299

Please sign in to comment.