Skip to content

Commit

Permalink
Merge pull request #539 from magento-dragons/DRAGONS-PR-BUGS-2.2
Browse files Browse the repository at this point in the history
[Dragons] Bug fixes for 2.2
  • Loading branch information
Yaroslav Onischenko authored Oct 27, 2016
2 parents d555891 + 508bc67 commit 76315a6
Show file tree
Hide file tree
Showing 53 changed files with 2,097 additions and 500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,12 @@ protected function getBundleOptions()
'arguments' => [
'data' => [
'config' => [
'componentType' => 'dynamicRows',
'componentType' => Container::NAME,
'component' => 'Magento_Bundle/js/components/bundle-dynamic-rows',
'template' => 'ui/dynamic-rows/templates/collapsible',
'label' => '',
'additionalClasses' => 'admin__field-wide',
'collapsibleHeader' => true,
'columnsHeader' => false,
'deleteProperty' => false,
'addButton' => false,
'dataScope' => 'data.bundle_options',
'bundleSelectionsName' => 'product_bundle_container.bundle_selections'
],
],
],
Expand Down Expand Up @@ -318,14 +315,11 @@ protected function getBundleOptions()
'arguments' => [
'data' => [
'config' => [
'componentType' => DynamicRows::NAME,
'label' => '',
'componentType' => Container::NAME,
'component' => 'Magento_Bundle/js/components/bundle-dynamic-rows-grid',
'sortOrder' => 50,
'additionalClasses' => 'admin__field-wide',
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows-grid',
'template' => 'ui/dynamic-rows/templates/default',
'columnsHeader' => false,
'columnsHeaderAfterRender' => true,
'provider' => 'product_form.product_form_data_source',
'dataProvider' => '${ $.dataScope }' . '.bundle_button_proxy',
'identificationDRProperty' => 'product_id',
Expand All @@ -343,8 +337,7 @@ protected function getBundleOptions()
'selection_qty' => '',
],
'links' => ['insertData' => '${ $.provider }:${ $.dataProvider }'],
'source' => 'product',
'addButton' => false,
'source' => 'product'
],
],
],
Expand Down Expand Up @@ -561,7 +554,7 @@ protected function getBundleSelections()
'componentType' => Container::NAME,
'isTemplate' => true,
'component' => 'Magento_Ui/js/dynamic-rows/record',
'is_collection' => true,
'is_collection' => true
],
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'underscore',
'Magento_Ui/js/dynamic-rows/dynamic-rows-grid'
], function (_, dynamicRowsGrid) {
'use strict';

return dynamicRowsGrid.extend({
defaults: {
label: '',
columnsHeader: false,
columnsHeaderAfterRender: true,
addButton: false
},

/**
* Initialize elements from grid
*
* @param {Array} data
*
* @returns {Object} Chainable.
*/
initElements: function (data) {
var newData = this.getNewData(data),
recordIndex;

this.parsePagesData(data);

if (newData.length) {
if (this.insertData().length) {
recordIndex = data.length - newData.length - 1;

_.each(newData, function (newRecord) {
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
}, this);
}
}

return this;
},

/**
* Mapping value from grid
*
* @param {Array} data
*/
mappingValue: function (data) {
if (_.isEmpty(data)) {
return;
}

this._super();
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'underscore',
'mageUtils',
'uiRegistry',
'Magento_Ui/js/dynamic-rows/dynamic-rows'
], function (_, utils, registry, dynamicRows) {
'use strict';

return dynamicRows.extend({
defaults: {
label: '',
collapsibleHeader: true,
columnsHeader: false,
deleteProperty: false,
addButton: false
},

/**
* Set new data to dataSource,
* delete element
*
* @param {Array} data - record data
*/
_updateData: function (data) {
var elems = _.clone(this.elems()),
path,
dataArr,
optionBaseData;

dataArr = this.recordData.splice(this.startIndex, this.recordData().length - this.startIndex);
dataArr.splice(0, this.pageSize);
elems = _.sortBy(this.elems(), function (elem) {
return ~~elem.index;
});

data.concat(dataArr).forEach(function (rec, idx) {
if (elems[idx]) {
elems[idx].recordId = rec[this.identificationProperty];
}

if (!rec.position) {
rec.position = this.maxPosition;
this.setMaxPosition();
}

path = this.dataScope + '.' + this.index + '.' + (this.startIndex + idx);
optionBaseData = _.pick(rec, function (value) {
return !_.isObject(value);
});
this.source.set(path, optionBaseData);
this.source.set(path + '.bundle_button_proxy', []);
this.source.set(path + '.bundle_selections', []);
this.removeBundleItemsFromOption(idx);
_.each(rec['bundle_selections'], function (obj, index) {
this.source.set(path + '.bundle_button_proxy' + '.' + index, rec['bundle_button_proxy'][index]);
this.source.set(path + '.bundle_selections' + '.' + index, obj);
}, this);
}, this);

this.elems(elems);
},

/**
* Removes nested dynamic-rows-grid rendered records from option
*
* @param {Number|String} index - element index
*/
removeBundleItemsFromOption: function (index) {
var bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName),
bundleSelectionsLength = (bundleSelections.elems() || []).length,
i;

if (bundleSelectionsLength) {
for (i = 0; i < bundleSelectionsLength; i++) {
bundleSelections.elems()[0].destroy();
}
}
},

/**
* {@inheritdoc}
*/
processingAddChild: function (ctx, index, prop) {
var recordIds = _.map(this.recordData(), function (rec) {
return parseInt(rec['record_id'], 10);
}),
maxRecordId = _.max(recordIds);

prop = maxRecordId > -1 ? maxRecordId + 1 : prop;
this._super(ctx, index, prop);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,25 @@ protected function _prepareRelationIndexSelect($parentIds = null)
)->joinLeft(
['e' => $this->getTable('catalog_product_entity')],
'e.' . $linkField .' = l.parent_id',
['e.entity_id as parent_id']
[]
)->join(
['cs' => $this->getTable('store')],
'',
[]
)->join(
['i' => $idxTable],
'l.child_id = i.entity_id AND cs.store_id = i.store_id',
['attribute_id', 'store_id', 'value']
[]
)->group(
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value']
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value', 'l.child_id']
)->columns(
[
'parent_id' => 'e.entity_id',
'attribute_id' => 'i.attribute_id',
'store_id' => 'i.store_id',
'value' => 'i.value',
'source_id' => 'l.child_id'
]
);
if ($parentIds !== null) {
$select->where('e.entity_id IN(?)', $parentIds);
Expand All @@ -222,7 +230,7 @@ protected function _prepareRelationIndexSelect($parentIds = null)
'select' => $select,
'entity_field' => new \Zend_Db_Expr('l.parent_id'),
'website_field' => new \Zend_Db_Expr('cs.website_id'),
'store_field' => new \Zend_Db_Expr('cs.store_id')
'store_field' => new \Zend_Db_Expr('cs.store_id'),
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
'pdd.attribute_id',
'cs.store_id',
'value' => $productValueExpression,
'source_id' => 'cpe.entity_id',
]
);

Expand Down Expand Up @@ -116,7 +117,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
'select' => $select,
'entity_field' => new \Zend_Db_Expr('cpe.entity_id'),
'website_field' => new \Zend_Db_Expr('cs.website_id'),
'store_field' => new \Zend_Db_Expr('cs.store_id')
'store_field' => new \Zend_Db_Expr('cs.store_id'),
]
);

Expand Down
Loading

0 comments on commit 76315a6

Please sign in to comment.