Skip to content

Commit 92cc98e

Browse files
committed
MAGETWO-85588: [forwarded from 2.2] #12378: Regions list in Directory module for India #1015
- Merge Pull Request magento-engcom/magento2ce#1015 from p-bystritsky/magento2:ISSUE-12378-DEV - Merged commits: 1. ac1eb6d
2 parents c1a4d89 + ac1eb6d commit 92cc98e

File tree

285 files changed

+6186
-1275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+6186
-1275
lines changed

app/code/Magento/Backend/Block/Widget/Tabs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function addTab($tabId, $tab)
164164
*/
165165
protected function _addTabByName($tab, $tabId)
166166
{
167-
if (strpos($tab, '\Block\\')) {
167+
if (strpos($tab, '\Block\\') !== false) {
168168
$this->_tabs[$tabId] = $this->getLayout()->createBlock($tab, $this->getNameInLayout() . '_tab_' . $tabId);
169169
} elseif ($this->getChildBlock($tab)) {
170170
$this->_tabs[$tabId] = $this->getChildBlock($tab);

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public function getExtendedElement($switchAttributeCode)
142142
[
143143
'name' => "product[{$switchAttributeCode}]",
144144
'values' => $this->getOptions(),
145-
'value' => $switchAttributeCode,
146145
'class' => 'required-entry next-toinput',
147146
'no_span' => true,
148147
'disabled' => $this->isDisabledField(),

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ protected function parseOption($values)
217217
$option = [];
218218
foreach ($values as $keyValue) {
219219
$keyValue = trim($keyValue);
220-
if ($pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR)) {
220+
$pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR);
221+
if ($pos !== false) {
221222
$key = substr($keyValue, 0, $pos);
222223
$value = substr($keyValue, $pos + 1);
223224
if ($key == 'type') {

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,21 @@ public function prepareSortableFieldsByCategory($category)
265265
public function getIdentities()
266266
{
267267
$identities = [];
268-
foreach ($this->_getProductCollection() as $item) {
269-
$identities = array_merge($identities, $item->getIdentities());
270-
}
268+
271269
$category = $this->getLayer()->getCurrentCategory();
272270
if ($category) {
273271
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
274272
}
273+
274+
//Check if category page shows only static block (No products)
275+
if ($category->getData('display_mode') == Category::DM_PAGE) {
276+
return $identities;
277+
}
278+
279+
foreach ($this->_getProductCollection() as $item) {
280+
$identities = array_merge($identities, $item->getIdentities());
281+
}
282+
275283
return $identities;
276284
}
277285

app/code/Magento/Catalog/Block/Product/View/Attributes.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ public function getAdditionalData(array $excludeAttr = [])
8383
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
8484
$value = $attribute->getFrontend()->getValue($product);
8585

86-
if (!$product->hasData($attribute->getAttributeCode())) {
87-
$value = __('N/A');
88-
} elseif ((string)$value == '') {
89-
$value = __('No');
86+
if ($value instanceof Phrase) {
87+
$value = (string)$value;
9088
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
9189
$value = $this->priceCurrency->convertAndFormat($value);
9290
}
9391

94-
if ($value instanceof Phrase || (is_string($value) && strlen($value))) {
92+
if (is_string($value) && strlen($value)) {
9593
$data[$attribute->getAttributeCode()] = [
9694
'label' => __($attribute->getStoreLabel()),
9795
'value' => $value,

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,55 @@ protected function getAttributeValues($entityIds, $storeId)
369369
}
370370
$values = [];
371371

372+
$linkIds = $this->getLinkIds($entityIds);
373+
foreach ($linkIds as $linkId) {
374+
$values[$linkId] = [];
375+
}
376+
372377
$attributes = $this->getAttributes();
373378
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
379+
$linkField = $this->getCategoryMetadata()->getLinkField();
374380
foreach ($attributesType as $type) {
375381
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
376-
if (isset($row['entity_id']) && isset($row['attribute_id'])) {
382+
if (isset($row[$linkField]) && isset($row['attribute_id'])) {
377383
$attributeId = $row['attribute_id'];
378384
if (isset($attributes[$attributeId])) {
379385
$attributeCode = $attributes[$attributeId]['attribute_code'];
380-
$values[$row['entity_id']][$attributeCode] = $row['value'];
386+
$values[$row[$linkField]][$attributeCode] = $row['value'];
381387
}
382388
}
383389
}
384390
}
391+
385392
return $values;
386393
}
387394

395+
/**
396+
* Translate entity ids into link ids
397+
*
398+
* Used for rows with no EAV attributes set.
399+
*
400+
* @param array $entityIds
401+
* @return array
402+
*/
403+
private function getLinkIds(array $entityIds)
404+
{
405+
$linkField = $this->getCategoryMetadata()->getLinkField();
406+
if ($linkField === 'entity_id') {
407+
return $entityIds;
408+
}
409+
410+
$select = $this->connection->select()->from(
411+
['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))],
412+
[$linkField]
413+
)->where(
414+
'e.entity_id IN (?)',
415+
$entityIds
416+
);
417+
418+
return $this->connection->fetchCol($select);
419+
}
420+
388421
/**
389422
* Return attribute values for given entities and store of specific attribute type
390423
*

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Full.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ protected function populateFlatTables(array $stores)
6464
}
6565
/** @TODO Do something with chunks */
6666
$categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500);
67+
6768
foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
6869
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
70+
$linkField = $this->categoryMetadata->getLinkField();
71+
6972
$data = [];
7073
foreach ($categories[$store->getRootCategoryId()] as $category) {
71-
if (!isset($attributesData[$category[$this->categoryMetadata->getLinkField()]])) {
74+
if (!isset($attributesData[$category[$linkField]])) {
7275
continue;
7376
}
7477
$category['store_id'] = $store->getId();
7578
$data[] = $this->prepareValuesToInsert(
76-
array_merge($category, $attributesData[$category[$this->categoryMetadata->getLinkField()]])
79+
array_merge($category, $attributesData[$category[$linkField]])
7780
);
7881
}
82+
7983
$this->connection->insertMultiple(
8084
$this->addTemporaryTableSuffix($this->getMainStoreTable($store->getId())),
8185
$data

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Rows.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,22 @@ private function reindexStore(Store $store, array $entityIds, $useTempTable)
164164
*/
165165
private function buildIndexData(Store $store, $categoriesIdsChunk, $attributesData)
166166
{
167+
$linkField = $this->categoryMetadata->getLinkField();
168+
167169
$data = [];
168170
foreach ($categoriesIdsChunk as $categoryId) {
169171
try {
172+
$category = $this->categoryRepository->get($categoryId);
173+
$categoryData = $category->getData();
174+
$linkId = $categoryData[$linkField];
175+
170176
$categoryAttributesData = [];
171-
if (isset($attributesData[$categoryId]) && is_array($attributesData[$categoryId])) {
172-
$categoryAttributesData = $attributesData[$categoryId];
177+
if (isset($attributesData[$linkId]) && is_array($attributesData[$linkId])) {
178+
$categoryAttributesData = $attributesData[$linkId];
173179
}
174180
$categoryIndexData = $this->buildCategoryIndexData(
175181
$store,
176-
$categoryId,
182+
$categoryData,
177183
$categoryAttributesData
178184
);
179185
$data[] = $categoryIndexData;
@@ -186,18 +192,16 @@ private function buildIndexData(Store $store, $categoriesIdsChunk, $attributesDa
186192

187193
/**
188194
* @param Store $store
189-
* @param int $categoryId
195+
* @param array $categoryData
190196
* @param array $categoryAttributesData
191197
* @return array
192198
* @throws NoSuchEntityException
193199
*/
194-
private function buildCategoryIndexData(Store $store, $categoryId, array $categoryAttributesData)
200+
private function buildCategoryIndexData(Store $store, array $categoryData, array $categoryAttributesData)
195201
{
196-
$category = $this->categoryRepository->get($categoryId);
197-
$categoryAttributesData = [];
198202
$data = $this->prepareValuesToInsert(
199203
array_merge(
200-
$category->getData(),
204+
$categoryData,
201205
$categoryAttributesData,
202206
['store_id' => $store->getId()]
203207
)

app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ protected function _createTemporaryFlatTable($storeId)
179179

180180
$columnComment = isset($fieldProp['comment']) ? $fieldProp['comment'] : $fieldName;
181181

182+
if ($fieldName == 'created_at') {
183+
$columnDefinition['nullable'] = true;
184+
$columnDefinition['default'] = null;
185+
}
186+
182187
$table->addColumn($fieldName, $fieldProp['type'], $columnLength, $columnDefinition, $columnComment);
183188
}
184189

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@ protected function initializeProductData(array $productData, $createNew)
340340
foreach ($productData as $key => $value) {
341341
$product->setData($key, $value);
342342
}
343-
$this->assignProductToWebsites($product);
343+
$this->assignProductToWebsites($product, $createNew);
344344

345345
return $product;
346346
}
347347

348348
/**
349349
* @param \Magento\Catalog\Model\Product $product
350+
* @param bool $createNew
350351
* @return void
351352
*/
352-
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
353+
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product, $createNew)
353354
{
354355
$websiteIds = $product->getWebsiteIds();
355356

@@ -362,7 +363,7 @@ private function assignProductToWebsites(\Magento\Catalog\Model\Product $product
362363
);
363364
}
364365

365-
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
366+
if ($createNew && $this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
366367
$websiteIds = array_keys($this->storeManager->getWebsites());
367368
}
368369

0 commit comments

Comments
 (0)