Skip to content

Commit

Permalink
Merge pull request #419 from magento-tango/MAGETWO-50128
Browse files Browse the repository at this point in the history
[Tango] Configurable Product, Product Attributes, Bug Fixes
  • Loading branch information
magicbunneh committed Mar 19, 2016
2 parents 25f34d6 + 509fd9d commit 432b39b
Show file tree
Hide file tree
Showing 175 changed files with 10,195 additions and 926 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function modifyMeta(array $meta)
'buttons' => [
[
'text' => __('Cancel'),
'class' => 'action-secondary',
'actions' => ['closeModal'],
],
[
Expand Down Expand Up @@ -456,8 +455,13 @@ protected function getOptionInfo()
'dataType' => Form\Element\DataType\Text::NAME,
'formElement' => Form\Element\Select::NAME,
'componentType' => Form\Field::NAME,
'component' => 'Magento_Bundle/js/components/bundle-input-type',
'parentContainer' => 'product_bundle_container',
'selections' => 'bundle_selections',
'targetIndex' => 'is_default',
'dataScope' => 'type',
'label' => __('Input Type'),
'sortOrder' => 20,
'options' => [
[
'label' => __('Drop-down'),
Expand All @@ -476,7 +480,12 @@ protected function getOptionInfo()
'value' => 'multi'
]
],
'sortOrder' => 20,
'typeMap' => [
'select' => 'radio',
'radio' => 'radio',
'checkbox' => 'checkbox',
'multi' => 'checkbox'
]
],
],
],
Expand Down Expand Up @@ -533,15 +542,22 @@ protected function getBundleSelections()
'arguments' => [
'data' => [
'config' => [
'component' => 'Magento_Bundle/js/components/bundle-checkbox',
'formElement' => Form\Element\Checkbox::NAME,
'componentType' => Form\Field::NAME,
'component' => 'Magento_Bundle/js/components/bundle-checkbox',
'parentContainer' => 'product_bundle_container',
'parentSelections' => 'bundle_selections',
'changer' => 'option_info.type',
'dataType' => Form\Element\DataType\Boolean::NAME,
'formElement' => Form\Element\Checkbox::NAME,
'label' => __('Default'),
'dataScope' => 'is_default',
'prefer' => 'radio',
'value' => '1',
'value' => '0',
'sortOrder' => 50,
'valueMap' => [
'false' => '0',
'true' => '1'
]
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ define([
return Checkbox.extend({
defaults: {
clearing: false,
parentContainer: 'product_bundle_container',
parentSelections: 'bundle_selections',
changer: 'option_info.type'
parentContainer: '',
parentSelections: '',
changer: ''
},

/**
Expand All @@ -32,7 +32,7 @@ define([
*/
initConfig: function () {
this._super();
this.imports.changeType = this.getParentName(this.parentContainer) + '.' + this.changer + ':value';
this.imports.changeType = this.retrieveParentName(this.parentContainer) + '.' + this.changer + ':value';

return this;
},
Expand All @@ -41,59 +41,52 @@ define([
* @inheritdoc
*/
onUpdate: function () {
if (this.prefer === 'radio' && !this.clearing) {
if (this.prefer === 'radio' && this.checked() && !this.clearing) {
this.clearValues();
} else if (this.prefer === 'radio') {
this.clearing = false;
}

this._super();
},

/**
* Getter for parent name. Split string by provided parent name.
*
* @param {String} parent - parent name.
* @returns {String}
*/
getParentName: function (parent) {
return this.name.split(parent)[0] + parent;
},

/**
* Checkbox to radio type changer.
*
* @param {String} type - type to change.
*/
changeType: function (type) {
if (type === 'select') {
type = 'radio';
} else if (type === 'multi') {
type = 'checkbox';
}
var typeMap = registry.get(this.retrieveParentName(this.parentContainer) + '.' + this.changer).typeMap;

this.prefer = type;
this.clear();
this.elementTmpl(this.templates[type]);
this.clearing = false;
this.prefer = typeMap[type];
this.elementTmpl(this.templates[typeMap[type]]);
},

/**
* Clears values in components like this.
*/
clearValues: function () {
var records = registry.get(this.getParentName(this.parentSelections)),
var records = registry.get(this.retrieveParentName(this.parentSelections)),
index = this.index,
uid = this.uid;

this.clearing = true;
records.elems.each(function (record) {
record.elems.filter(function (comp) {
return comp.index === index && comp.uid !== uid;
}).each(function (comp) {
comp.clearing = true;
comp.clear();
comp.clearing = false;
});
});
},

/**
* Retrieve name for the most global parent with provided index.
*
* @param {String} parent - parent name.
* @returns {String}
*/
retrieveParentName: function (parent) {
return this.name.replace(new RegExp('^(.+?\\.)?' + parent + '\\..+'), '$1' + parent);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'Magento_Ui/js/form/element/select',
'uiRegistry'
], function (Select, registry) {
'use strict';

return Select.extend({
defaults: {
previousType: '',
parentContainer: '',
selections: '',
targetIndex: '',
typeMap: {}
},

/**
* @inheritdoc
*/
onUpdate: function () {
var type = this.typeMap[this.value()];

if (type !== this.previousType) {
this.previousType = type;

if (type === 'radio') {
this.clearValues();
}
}

this._super();
},

/**
* Clears values in components like this.
*/
clearValues: function () {
var records = registry.get(this.retrieveParentName(this.parentContainer) + '.' + this.selections),
checkedFound = false;

records.elems.each(function (record) {
record.elems.filter(function (comp) {
return comp.index === this.targetIndex;
}, this).each(function (comp) {
if (comp.checked()) {
if (checkedFound) {
comp.clearing = true;
comp.clear();
comp.clearing = false;
}

checkedFound = true;
}
});
}, this);
},

/**
* Retrieve name for the most global parent with provided index.
*
* @param {String} parent - parent name.
* @returns {String}
*/
retrieveParentName: function (parent) {
return this.name.replace(new RegExp('^(.+?\\.)?' + parent + '\\..+'), '$1' + parent);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Button;

/**
* Class Cancel
*/
class Cancel extends Generic
{
/**
* Get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Cancel'),
'data_attribute' => [
'mage-init' => [
'Magento_Ui/js/form/button-adapter' => [
'actions' => [
[
'targetName' => 'product_form.product_form.add_attribute_modal'
. '.create_new_attribute_modal',
'actionName' => 'toggleModal'
]
]
]
]
],
'on_click' => ''
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Button;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\UiComponent\Context;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Class Generic
*/
class Generic implements ButtonProviderInterface
{
/**
* Url Builder
*
* @var Context
*/
protected $context;

/**
* Registry
*
* @var Registry
*/
protected $registry;

/**
* Generic constructor
*
* @param Context $context
* @param Registry $registry
*/
public function __construct(
Context $context,
Registry $registry
) {
$this->context = $context;
$this->registry = $registry;
}

/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->context->getUrl($route, $params);
}

/**
* {@inheritdoc}
*/
public function getButtonData()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Button;

class Save extends Generic
{
/**
* Get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save Attribute'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
]
];
}
}
Loading

0 comments on commit 432b39b

Please sign in to comment.