|
7 | 7 | 'underscore', |
8 | 8 | 'uiRegistry', |
9 | 9 | 'Magento_Ui/js/dynamic-rows/dynamic-rows', |
10 | | - 'jquery' |
11 | | -], function (_, registry, dynamicRows, $) { |
| 10 | + 'jquery', |
| 11 | + 'mageUtils' |
| 12 | +], function (_, registry, dynamicRows, $, utils) { |
12 | 13 | 'use strict'; |
13 | 14 |
|
14 | 15 | return dynamicRows.extend({ |
@@ -64,6 +65,28 @@ define([ |
64 | 65 | return this; |
65 | 66 | }, |
66 | 67 |
|
| 68 | + /** |
| 69 | + * Get product type from URL |
| 70 | + * |
| 71 | + * @returns {String|null} |
| 72 | + */ |
| 73 | + getProductTypeFromUrl: function () { |
| 74 | + var urlParams = utils.getUrlParameters(window.location.href), |
| 75 | + urlPath = window.location.pathname; |
| 76 | + |
| 77 | + if (urlPath.indexOf('/type/configurable') !== -1) { |
| 78 | + return 'configurable'; |
| 79 | + } |
| 80 | + |
| 81 | + // Check for type in URL parameters |
| 82 | + if (urlParams.type) { |
| 83 | + return urlParams.type; |
| 84 | + } |
| 85 | + |
| 86 | + // For existing products, try to get from source |
| 87 | + return this.source.get('data.product.type_id') || null; |
| 88 | + }, |
| 89 | + |
67 | 90 | /** |
68 | 91 | * Change visibility |
69 | 92 | * |
@@ -204,15 +227,23 @@ define([ |
204 | 227 | elemsCount, |
205 | 228 | tmpData, |
206 | 229 | path, |
207 | | - attributeCodes = this.source.get('data.attribute_codes'); |
| 230 | + attributeCodes = this.source.get('data.attribute_codes'), |
| 231 | + productType = this.getProductTypeFromUrl(); |
208 | 232 |
|
209 | 233 | this.isEmpty(data.length === 0); |
210 | | - this.isShowAddProductButton( |
211 | | - (!attributeCodes || data.length > 0 ? data.length : attributeCodes.length) > 0 |
212 | | - ); |
| 234 | + |
| 235 | + if (productType === 'configurable') { |
| 236 | + this.isShowAddProductButton( |
| 237 | + attributeCodes || attributeCodes.length > 0 |
| 238 | + ); |
| 239 | + } else { |
| 240 | + this.isShowAddProductButton( |
| 241 | + (!attributeCodes || data.length > 0 ? data.length : attributeCodes.length) > 0 |
| 242 | + ); |
| 243 | + } |
213 | 244 |
|
214 | 245 | tmpData = data.slice(this.pageSize * (this.currentPage() - 1), |
215 | | - this.pageSize * (this.currentPage() - 1) + parseInt(this.pageSize, 10)); |
| 246 | + this.pageSize * (this.currentPage() - 1) + parseInt(this.pageSize, 10)); |
216 | 247 |
|
217 | 248 | this.source.set(this.dataScope + '.' + this.index, []); |
218 | 249 |
|
|
0 commit comments