Skip to content

Commit 725bfb2

Browse files
committed
MAGETWO-85522: 10124: Wrong invoice entity_model in table eav_entity_type.[port] #997
- Merge Pull Request magento-engcom/magento2ce#997 from nmalevanec/magento2:10124 - Merged commits: 1. 5aef5cb
2 parents c1a4d89 + 5aef5cb commit 725bfb2

File tree

272 files changed

+5848
-1257
lines changed

Some content is hidden

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

272 files changed

+5848
-1257
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/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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Block\Product\View;
8+
9+
use \PHPUnit\Framework\TestCase;
10+
use \Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
11+
use \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
12+
use \Magento\Catalog\Model\Product;
13+
use \Magento\Framework\View\Element\Template\Context;
14+
use \Magento\Framework\Registry;
15+
use \Magento\Framework\Pricing\PriceCurrencyInterface;
16+
use \Magento\Catalog\Block\Product\View\Attributes as AttributesBlock;
17+
18+
/**
19+
* Test class for \Magento\Catalog\Block\Product\View\Attributes
20+
*
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
23+
class AttributesTest extends TestCase
24+
{
25+
/**
26+
* @var \Magento\Framework\Phrase
27+
*/
28+
private $phrase;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\AbstractAttribute
32+
*/
33+
private $attribute;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
37+
*/
38+
private $frontendAttribute;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product
42+
*/
43+
private $product;
44+
45+
/**
46+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Element\Template\Context
47+
*/
48+
private $context;
49+
50+
/**
51+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Registry
52+
*/
53+
private $registry;
54+
55+
/**
56+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\PriceCurrencyInterface
57+
*/
58+
private $priceCurrencyInterface;
59+
60+
/**
61+
* @var \Magento\Catalog\Block\Product\View\Attributes
62+
*/
63+
private $attributesBlock;
64+
65+
protected function setUp()
66+
{
67+
$this->attribute = $this
68+
->getMockBuilder(AbstractAttribute::class)
69+
->disableOriginalConstructor()
70+
->getMock();
71+
$this->attribute
72+
->expects($this->any())
73+
->method('getIsVisibleOnFront')
74+
->willReturn(true);
75+
$this->attribute
76+
->expects($this->any())
77+
->method('getAttributeCode')
78+
->willReturn('phrase');
79+
$this->frontendAttribute = $this
80+
->getMockBuilder(AbstractFrontend::class)
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$this->attribute
84+
->expects($this->any())
85+
->method('getFrontendInput')
86+
->willReturn('phrase');
87+
$this->attribute
88+
->expects($this->any())
89+
->method('getFrontend')
90+
->willReturn($this->frontendAttribute);
91+
$this->product = $this
92+
->getMockBuilder(Product::class)
93+
->disableOriginalConstructor()
94+
->getMock();
95+
$this->product
96+
->expects($this->any())
97+
->method('getAttributes')
98+
->willReturn([$this->attribute]);
99+
$this->product
100+
->expects($this->any())
101+
->method('hasData')
102+
->willReturn(true);
103+
$this->context = $this
104+
->getMockBuilder(Context::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
$this->registry = $this
108+
->getMockBuilder(Registry::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
$this->registry
112+
->expects($this->any())
113+
->method('registry')
114+
->willReturn($this->product);
115+
$this->priceCurrencyInterface = $this
116+
->getMockBuilder(PriceCurrencyInterface::class)
117+
->disableOriginalConstructor()
118+
->getMock();
119+
$this->attributesBlock = new AttributesBlock(
120+
$this->context,
121+
$this->registry,
122+
$this->priceCurrencyInterface
123+
);
124+
}
125+
126+
/**
127+
* @return void
128+
*/
129+
public function testGetAttributeNoValue()
130+
{
131+
$this->phrase = '';
132+
$this->frontendAttribute
133+
->expects($this->any())
134+
->method('getValue')
135+
->willReturn($this->phrase);
136+
$attributes = $this->attributesBlock->getAdditionalData();
137+
$this->assertTrue(empty($attributes['phrase']));
138+
}
139+
140+
/**
141+
* @return void
142+
*/
143+
public function testGetAttributeHasValue()
144+
{
145+
$this->phrase = __('Yes');
146+
$this->frontendAttribute
147+
->expects($this->any())
148+
->method('getValue')
149+
->willReturn($this->phrase);
150+
$attributes = $this->attributesBlock->getAdditionalData();
151+
$this->assertNotTrue(empty($attributes['phrase']));
152+
$this->assertNotTrue(empty($attributes['phrase']['value']));
153+
$this->assertEquals('Yes', $attributes['phrase']['value']);
154+
}
155+
}

0 commit comments

Comments
 (0)