Skip to content

Commit

Permalink
Merge pull request #251 from magento-performance/MAGETWO-56740
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Volodymyr Klymenko authored Aug 18, 2016
2 parents 37692c8 + 8c926d0 commit 6e64d1c
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ public function __construct(
public function build($productId)
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');

return [$this->resource->getConnection()->select()
->from(['parent' => 'catalog_product_entity'], '')
->from(['parent' => $productTable], '')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => 'catalog_product_entity'],
['child' => $productTable],
"child.entity_id = link.child_id",
['entity_id']
)->joinInner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ public function build($productId)
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
$productTable = $this->resource->getTableName('catalog_product_entity');

$priceSelect = $this->resource->getConnection()->select()
->from(['parent' => 'catalog_product_entity'], '')
->from(['parent' => $productTable], '')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => 'catalog_product_entity'],
['child' => $productTable],
"child.entity_id = link.child_id",
['entity_id']
)->joinInner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ public function build($productId)
$specialPriceToDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_to_date');
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
$currentDate = $this->dateTime->formatDate($timestamp, false);
$productTable = $this->resource->getTableName('catalog_product_entity');

$specialPrice = $this->resource->getConnection()->select()
->from(['parent' => 'catalog_product_entity'], '')
->from(['parent' => $productTable], '')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => 'catalog_product_entity'],
['child' => $productTable],
"child.entity_id = link.child_id",
['entity_id']
)->joinInner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ public function __construct(
public function build($productId)
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');

$priceSelect = $this->resource->getConnection()->select()
->from(['parent' => 'catalog_product_entity'], '')
->from(['parent' => $productTable], '')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => 'catalog_product_entity'],
['child' => $productTable],
"child.entity_id = link.child_id",
['entity_id']
)->joinInner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ public function build($productId)
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
$currentDate = $this->dateTime->formatDate($timestamp, false);
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');

return [$this->resource->getConnection()->select()
->from(['parent' => 'catalog_product_entity'], '')
->from(['parent' => $productTable], '')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => 'catalog_product_entity'],
['child' => $productTable],
"child.entity_id = link.child_id",
['entity_id']
)->joinInner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<!-- ko if: gridNew().length -->
<!-- ko template: {name: getGridTemplate(), data: {
grid: gridNew,
paging: pagingNew,
id: getGridId(),
title: $t('New Product Review'),
note: $t('Here are the products you\'re about to create.')
Expand All @@ -25,6 +26,7 @@

<!-- ko if: gridExisting().length -->
<!-- ko template: {name: getGridTemplate(), data: {
paging: pagingExisting,
grid: gridExisting,
id: getGridId(),
title: $t('Associated Products'),
Expand All @@ -34,6 +36,7 @@

<!-- ko if: gridDeleted().length -->
<!-- ko template: {name: getGridTemplate(), data: {
paging: pagingDeleted,
grid: gridDeleted,
id: getGridId(),
title: $t('Disassociated Products'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'Magento_Ui/js/grid/paging/sizes'
], function (Sizes) {
'use strict';

return Sizes.extend({
defaults: {
excludedOptions: ['100', '200']
},

/**
* @override
*/
initialize: function () {
this._super();

this.excludedOptions.forEach(function (excludedOption) {
delete this.options[excludedOption];
}, this);
this.updateArray();

return this;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ define([
'jquery',
'ko',
'underscore',
'Magento_Ui/js/grid/paging/paging',
'mage/translate'
], function (Component, $, ko, _) {
], function (Component, $, ko, _, paging) {
'use strict';

return Component.extend({
Expand All @@ -25,31 +26,70 @@ define([
gridExisting: [],
gridNew: [],
gridDeleted: [],
variationsExisting: [],
variationsNew: [],
variationsDeleted: [],
pagingExisting: paging({
name: 'configurableWizard.pagingExisting',
sizesConfig: {
component: 'Magento_ConfigurableProduct/js/variations/paging/sizes',
name: 'configurableWizard.pagingExisting_sizes'
}
}),
pagingNew: paging({
name: 'configurableWizard.pagingNew',
sizesConfig: {
component: 'Magento_ConfigurableProduct/js/variations/paging/sizes',
name: 'configurableWizard.pagingNew_sizes'
}
}),
pagingDeleted: paging({
name: 'configurableWizard.pagingDeleted',
sizesConfig: {
component: 'Magento_ConfigurableProduct/js/variations/paging/sizes',
name: 'configurableWizard.pagingDeleted_sizes'
}
}),
attributes: [],
attributesName: [$.mage.__('Images'), $.mage.__('SKU'), $.mage.__('Quantity'), $.mage.__('Price')],
sections: [],
gridTemplate: 'Magento_ConfigurableProduct/variations/steps/summary-grid'
},
initObservable: function () {
var pagingObservables = {
currentNew: ko.getObservable(this.pagingNew, 'current'),
currentExisting: ko.getObservable(this.pagingExisting, 'current'),
currentDeleted: ko.getObservable(this.pagingDeleted, 'current'),
pageSizeNew: ko.getObservable(this.pagingNew, 'pageSize'),
pageSizeExisting: ko.getObservable(this.pagingExisting, 'pageSize'),
pageSizeDeleted: ko.getObservable(this.pagingDeleted, 'pageSize')
};

this._super().observe('gridExisting gridNew gridDeleted attributes sections');
this.gridExisting.columns = ko.observableArray();
this.gridNew.columns = ko.observableArray();
this.gridDeleted.columns = ko.observableArray();

_.each(pagingObservables, function (observable) {
observable.subscribe(function () {
this.generateGrid();
}, this);
}, this);

return this;
},
nextLabelText: $.mage.__('Generate Products'),
variations: [],
generateGrid: function (variations, getSectionValue) {
calculate: function (variations, getSectionValue) {
var productSku = this.variationsComponent().getProductValue('sku'),
productPrice = this.variationsComponent().getProductPrice(),
productWeight = this.variationsComponent().getProductValue('weight'),
variationsKeys = [],
gridExisting = [],
gridNew = [],
gridDeleted = [];
this.variations = [];

this.variations = [];
_.each(variations, function (options) {
var product, images, sku, quantity, price, variation,
productId = this.variationsComponent().getProductIdByOptions(options);
Expand Down Expand Up @@ -101,14 +141,6 @@ define([
variationsKeys.push(this.variationsComponent().getVariationKey(options));
}, this);

this.gridExisting(gridExisting);
this.gridExisting.columns(this.getColumnsName(this.wizard.data.attributes));

if (gridNew.length > 0) {
this.gridNew(gridNew);
this.gridNew.columns(this.getColumnsName(this.wizard.data.attributes));
}

_.each(_.omit(this.variationsComponent().productAttributesMap, variationsKeys), function (productId) {
gridDeleted.push(this.prepareRowForGrid(
_.findWhere(this.variationsComponent().variations, {
Expand All @@ -117,13 +149,28 @@ define([
));
}.bind(this));

if (gridDeleted.length > 0) {
this.gridDeleted(gridDeleted);
this.gridDeleted.columns(this.getColumnsName(this.variationsComponent().productAttributes));
}
this.variationsExisting = gridExisting;
this.variationsNew = gridNew;
this.variationsDeleted = gridDeleted;

},
generateGrid: function () {
var pageExisting = this.pagingExisting.pageSize * this.pagingExisting.current,
pageNew = this.pagingNew.pageSize * this.pagingNew.current,
pageDeleted = this.pagingDeleted.pageSize * this.pagingDeleted.current;

this.pagingExisting.totalRecords = this.variationsExisting.length;
this.gridExisting(this.variationsExisting.slice(pageExisting - this.pagingExisting.pageSize, pageExisting));

this.pagingNew.totalRecords = this.variationsNew.length;
this.gridNew(this.variationsNew.slice(pageNew - this.pagingNew.pageSize, pageNew));

this.pagingDeleted.totalRecords = this.variationsDeleted.length;
this.gridDeleted(this.variationsDeleted.slice(pageDeleted - this.pagingDeleted.pageSize, pageDeleted));
},
prepareRowForGrid: function (variation) {
var row = [];

row.push(_.extend({
images: []
}, variation.images));
Expand Down Expand Up @@ -158,7 +205,11 @@ define([
this.gridNew([]);
this.gridExisting([]);
this.gridDeleted([]);
this.generateGrid(wizard.data.variations, wizard.data.sectionHelper);
this.gridExisting.columns(this.getColumnsName(this.wizard.data.attributes));
this.gridNew.columns(this.getColumnsName(this.wizard.data.attributes));
this.gridDeleted.columns(this.getColumnsName(this.variationsComponent().productAttributes));
this.calculate(wizard.data.variations, wizard.data.sectionHelper);
this.generateGrid();
},
force: function () {
this.variationsComponent().render(this.variations, this.attributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</div>

<div class="fieldset-wrapper-content in collapse" data-collapsed="true" data-bind="attr: {id: id}">
<!-- ko template: {
name: "ui/grid/paging/paging", data: paging
} -->
<!-- /ko -->
<div class="note" data-bind="text: note"></div>
<table class="data-grid data-grid-configurable">
<thead>
Expand All @@ -23,7 +27,7 @@

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

0 comments on commit 6e64d1c

Please sign in to comment.