Skip to content

Commit 6e64d1c

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #251 from magento-performance/MAGETWO-56740
Fixed - MAGETWO-56865 Configurable product not visible in category on frontend after creation - MAGETWO-56591 Configurable product not visible in category on frontend after creation
2 parents 37692c8 + 8c926d0 commit 6e64d1c

File tree

9 files changed

+121
-27
lines changed

9 files changed

+121
-27
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ public function __construct(
5656
public function build($productId)
5757
{
5858
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
59+
$productTable = $this->resource->getTableName('catalog_product_entity');
5960

6061
return [$this->resource->getConnection()->select()
61-
->from(['parent' => 'catalog_product_entity'], '')
62+
->from(['parent' => $productTable], '')
6263
->joinInner(
6364
['link' => $this->resource->getTableName('catalog_product_relation')],
6465
"link.parent_id = parent.$linkField",
6566
[]
6667
)->joinInner(
67-
['child' => 'catalog_product_entity'],
68+
['child' => $productTable],
6869
"child.entity_id = link.child_id",
6970
['entity_id']
7071
)->joinInner(

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ public function build($productId)
6565
{
6666
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
6767
$priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
68+
$productTable = $this->resource->getTableName('catalog_product_entity');
69+
6870
$priceSelect = $this->resource->getConnection()->select()
69-
->from(['parent' => 'catalog_product_entity'], '')
71+
->from(['parent' => $productTable], '')
7072
->joinInner(
7173
['link' => $this->resource->getTableName('catalog_product_relation')],
7274
"link.parent_id = parent.$linkField",
7375
[]
7476
)->joinInner(
75-
['child' => 'catalog_product_entity'],
77+
['child' => $productTable],
7678
"child.entity_id = link.child_id",
7779
['entity_id']
7880
)->joinInner(

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ public function build($productId)
8686
$specialPriceToDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_to_date');
8787
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
8888
$currentDate = $this->dateTime->formatDate($timestamp, false);
89+
$productTable = $this->resource->getTableName('catalog_product_entity');
8990

9091
$specialPrice = $this->resource->getConnection()->select()
91-
->from(['parent' => 'catalog_product_entity'], '')
92+
->from(['parent' => $productTable], '')
9293
->joinInner(
9394
['link' => $this->resource->getTableName('catalog_product_relation')],
9495
"link.parent_id = parent.$linkField",
9596
[]
9697
)->joinInner(
97-
['child' => 'catalog_product_entity'],
98+
['child' => $productTable],
9899
"child.entity_id = link.child_id",
99100
['entity_id']
100101
)->joinInner(

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ public function __construct(
6868
public function build($productId)
6969
{
7070
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
71+
$productTable = $this->resource->getTableName('catalog_product_entity');
72+
7173
$priceSelect = $this->resource->getConnection()->select()
72-
->from(['parent' => 'catalog_product_entity'], '')
74+
->from(['parent' => $productTable], '')
7375
->joinInner(
7476
['link' => $this->resource->getTableName('catalog_product_relation')],
7577
"link.parent_id = parent.$linkField",
7678
[]
7779
)->joinInner(
78-
['child' => 'catalog_product_entity'],
80+
['child' => $productTable],
7981
"child.entity_id = link.child_id",
8082
['entity_id']
8183
)->joinInner(

app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ public function build($productId)
7474
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
7575
$currentDate = $this->dateTime->formatDate($timestamp, false);
7676
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
77+
$productTable = $this->resource->getTableName('catalog_product_entity');
7778

7879
return [$this->resource->getConnection()->select()
79-
->from(['parent' => 'catalog_product_entity'], '')
80+
->from(['parent' => $productTable], '')
8081
->joinInner(
8182
['link' => $this->resource->getTableName('catalog_product_relation')],
8283
"link.parent_id = parent.$linkField",
8384
[]
8485
)->joinInner(
85-
['child' => 'catalog_product_entity'],
86+
['child' => $productTable],
8687
"child.entity_id = link.child_id",
8788
['entity_id']
8889
)->joinInner(

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/summary.phtml

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<!-- ko if: gridNew().length -->
1818
<!-- ko template: {name: getGridTemplate(), data: {
1919
grid: gridNew,
20+
paging: pagingNew,
2021
id: getGridId(),
2122
title: $t('New Product Review'),
2223
note: $t('Here are the products you\'re about to create.')
@@ -25,6 +26,7 @@
2526

2627
<!-- ko if: gridExisting().length -->
2728
<!-- ko template: {name: getGridTemplate(), data: {
29+
paging: pagingExisting,
2830
grid: gridExisting,
2931
id: getGridId(),
3032
title: $t('Associated Products'),
@@ -34,6 +36,7 @@
3436

3537
<!-- ko if: gridDeleted().length -->
3638
<!-- ko template: {name: getGridTemplate(), data: {
39+
paging: pagingDeleted,
3740
grid: gridDeleted,
3841
id: getGridId(),
3942
title: $t('Disassociated Products'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'Magento_Ui/js/grid/paging/sizes'
7+
], function (Sizes) {
8+
'use strict';
9+
10+
return Sizes.extend({
11+
defaults: {
12+
excludedOptions: ['100', '200']
13+
},
14+
15+
/**
16+
* @override
17+
*/
18+
initialize: function () {
19+
this._super();
20+
21+
this.excludedOptions.forEach(function (excludedOption) {
22+
delete this.options[excludedOption];
23+
}, this);
24+
this.updateArray();
25+
26+
return this;
27+
}
28+
});
29+
});

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/summary.js

+67-16
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ define([
88
'jquery',
99
'ko',
1010
'underscore',
11+
'Magento_Ui/js/grid/paging/paging',
1112
'mage/translate'
12-
], function (Component, $, ko, _) {
13+
], function (Component, $, ko, _, paging) {
1314
'use strict';
1415

1516
return Component.extend({
@@ -25,31 +26,70 @@ define([
2526
gridExisting: [],
2627
gridNew: [],
2728
gridDeleted: [],
29+
variationsExisting: [],
30+
variationsNew: [],
31+
variationsDeleted: [],
32+
pagingExisting: paging({
33+
name: 'configurableWizard.pagingExisting',
34+
sizesConfig: {
35+
component: 'Magento_ConfigurableProduct/js/variations/paging/sizes',
36+
name: 'configurableWizard.pagingExisting_sizes'
37+
}
38+
}),
39+
pagingNew: paging({
40+
name: 'configurableWizard.pagingNew',
41+
sizesConfig: {
42+
component: 'Magento_ConfigurableProduct/js/variations/paging/sizes',
43+
name: 'configurableWizard.pagingNew_sizes'
44+
}
45+
}),
46+
pagingDeleted: paging({
47+
name: 'configurableWizard.pagingDeleted',
48+
sizesConfig: {
49+
component: 'Magento_ConfigurableProduct/js/variations/paging/sizes',
50+
name: 'configurableWizard.pagingDeleted_sizes'
51+
}
52+
}),
2853
attributes: [],
2954
attributesName: [$.mage.__('Images'), $.mage.__('SKU'), $.mage.__('Quantity'), $.mage.__('Price')],
3055
sections: [],
3156
gridTemplate: 'Magento_ConfigurableProduct/variations/steps/summary-grid'
3257
},
3358
initObservable: function () {
59+
var pagingObservables = {
60+
currentNew: ko.getObservable(this.pagingNew, 'current'),
61+
currentExisting: ko.getObservable(this.pagingExisting, 'current'),
62+
currentDeleted: ko.getObservable(this.pagingDeleted, 'current'),
63+
pageSizeNew: ko.getObservable(this.pagingNew, 'pageSize'),
64+
pageSizeExisting: ko.getObservable(this.pagingExisting, 'pageSize'),
65+
pageSizeDeleted: ko.getObservable(this.pagingDeleted, 'pageSize')
66+
};
67+
3468
this._super().observe('gridExisting gridNew gridDeleted attributes sections');
3569
this.gridExisting.columns = ko.observableArray();
3670
this.gridNew.columns = ko.observableArray();
3771
this.gridDeleted.columns = ko.observableArray();
3872

73+
_.each(pagingObservables, function (observable) {
74+
observable.subscribe(function () {
75+
this.generateGrid();
76+
}, this);
77+
}, this);
78+
3979
return this;
4080
},
4181
nextLabelText: $.mage.__('Generate Products'),
4282
variations: [],
43-
generateGrid: function (variations, getSectionValue) {
83+
calculate: function (variations, getSectionValue) {
4484
var productSku = this.variationsComponent().getProductValue('sku'),
4585
productPrice = this.variationsComponent().getProductPrice(),
4686
productWeight = this.variationsComponent().getProductValue('weight'),
4787
variationsKeys = [],
4888
gridExisting = [],
4989
gridNew = [],
5090
gridDeleted = [];
51-
this.variations = [];
5291

92+
this.variations = [];
5393
_.each(variations, function (options) {
5494
var product, images, sku, quantity, price, variation,
5595
productId = this.variationsComponent().getProductIdByOptions(options);
@@ -101,14 +141,6 @@ define([
101141
variationsKeys.push(this.variationsComponent().getVariationKey(options));
102142
}, this);
103143

104-
this.gridExisting(gridExisting);
105-
this.gridExisting.columns(this.getColumnsName(this.wizard.data.attributes));
106-
107-
if (gridNew.length > 0) {
108-
this.gridNew(gridNew);
109-
this.gridNew.columns(this.getColumnsName(this.wizard.data.attributes));
110-
}
111-
112144
_.each(_.omit(this.variationsComponent().productAttributesMap, variationsKeys), function (productId) {
113145
gridDeleted.push(this.prepareRowForGrid(
114146
_.findWhere(this.variationsComponent().variations, {
@@ -117,13 +149,28 @@ define([
117149
));
118150
}.bind(this));
119151

120-
if (gridDeleted.length > 0) {
121-
this.gridDeleted(gridDeleted);
122-
this.gridDeleted.columns(this.getColumnsName(this.variationsComponent().productAttributes));
123-
}
152+
this.variationsExisting = gridExisting;
153+
this.variationsNew = gridNew;
154+
this.variationsDeleted = gridDeleted;
155+
156+
},
157+
generateGrid: function () {
158+
var pageExisting = this.pagingExisting.pageSize * this.pagingExisting.current,
159+
pageNew = this.pagingNew.pageSize * this.pagingNew.current,
160+
pageDeleted = this.pagingDeleted.pageSize * this.pagingDeleted.current;
161+
162+
this.pagingExisting.totalRecords = this.variationsExisting.length;
163+
this.gridExisting(this.variationsExisting.slice(pageExisting - this.pagingExisting.pageSize, pageExisting));
164+
165+
this.pagingNew.totalRecords = this.variationsNew.length;
166+
this.gridNew(this.variationsNew.slice(pageNew - this.pagingNew.pageSize, pageNew));
167+
168+
this.pagingDeleted.totalRecords = this.variationsDeleted.length;
169+
this.gridDeleted(this.variationsDeleted.slice(pageDeleted - this.pagingDeleted.pageSize, pageDeleted));
124170
},
125171
prepareRowForGrid: function (variation) {
126172
var row = [];
173+
127174
row.push(_.extend({
128175
images: []
129176
}, variation.images));
@@ -158,7 +205,11 @@ define([
158205
this.gridNew([]);
159206
this.gridExisting([]);
160207
this.gridDeleted([]);
161-
this.generateGrid(wizard.data.variations, wizard.data.sectionHelper);
208+
this.gridExisting.columns(this.getColumnsName(this.wizard.data.attributes));
209+
this.gridNew.columns(this.getColumnsName(this.wizard.data.attributes));
210+
this.gridDeleted.columns(this.getColumnsName(this.variationsComponent().productAttributes));
211+
this.calculate(wizard.data.variations, wizard.data.sectionHelper);
212+
this.generateGrid();
162213
},
163214
force: function () {
164215
this.variationsComponent().render(this.variations, this.attributes());

app/code/Magento/ConfigurableProduct/view/adminhtml/web/template/variations/steps/summary-grid.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
</div>
1414

1515
<div class="fieldset-wrapper-content in collapse" data-collapsed="true" data-bind="attr: {id: id}">
16+
<!-- ko template: {
17+
name: "ui/grid/paging/paging", data: paging
18+
} -->
19+
<!-- /ko -->
1620
<div class="note" data-bind="text: note"></div>
1721
<table class="data-grid data-grid-configurable">
1822
<thead>
@@ -23,7 +27,7 @@
2327

2428
<tbody>
2529
<tr repeat="foreach: grid, item: '$product'">
26-
<!-- ko fastForEach: { data: $product(), as: 'property' } -->
30+
<!-- ko foreach: { data: $product(), as: 'property' } -->
2731
<td if="property && property.preview" class="data-grid-thumbnail-cell">
2832
<div class="images-uploaded">
2933
<img data-bind="attr: {src: property.preview}"/>

0 commit comments

Comments
 (0)