Skip to content

Commit 70ecfa4

Browse files
committed
MAGETWO-84908: Duplicate array key #12520
- Merge Pull Request #12520 from lfluvisotto/magento2:2.3-develop-duplicate-array-key - Merged commits: 1. 24cfb4c
2 parents c1a4d89 + 24cfb4c commit 70ecfa4

File tree

84 files changed

+1892
-262
lines changed

Some content is hidden

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

84 files changed

+1892
-262
lines changed

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/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/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

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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Api;
7+
8+
/**
9+
* Command to load the block data by specified identifier
10+
* @api
11+
*/
12+
interface GetBlockByIdentifierInterface
13+
{
14+
/**
15+
* Load block data by given block identifier.
16+
*
17+
* @param string $identifier
18+
* @param int $storeId
19+
* @throws \Magento\Framework\Exception\NoSuchEntityException
20+
* @return \Magento\Cms\Api\Data\BlockInterface
21+
*/
22+
public function execute(string $identifier, int $storeId) : \Magento\Cms\Api\Data\BlockInterface;
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Api;
7+
8+
/**
9+
* Command to load the page data by specified identifier
10+
* @api
11+
*/
12+
interface GetPageByIdentifierInterface
13+
{
14+
/**
15+
* Load page data by given page identifier.
16+
*
17+
* @param string $identifier
18+
* @param int $storeId
19+
* @throws \Magento\Framework\Exception\NoSuchEntityException
20+
* @return \Magento\Cms\Api\Data\PageInterface
21+
*/
22+
public function execute(string $identifier, int $storeId) : \Magento\Cms\Api\Data\PageInterface;
23+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Model;
7+
8+
use Magento\Cms\Api\GetBlockByIdentifierInterface;
9+
use Magento\Cms\Api\Data\BlockInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
/**
13+
* Class GetBlockByIdentifier
14+
*/
15+
class GetBlockByIdentifier implements GetBlockByIdentifierInterface
16+
{
17+
/**
18+
* @var \Magento\Cms\Model\BlockFactory
19+
*/
20+
private $blockFactory;
21+
22+
/**
23+
* @var ResourceModel\Block
24+
*/
25+
private $blockResource;
26+
27+
/**
28+
* @param BlockFactory $blockFactory
29+
* @param ResourceModel\Block $blockResource
30+
*/
31+
public function __construct(
32+
\Magento\Cms\Model\BlockFactory $blockFactory,
33+
\Magento\Cms\Model\ResourceModel\Block $blockResource
34+
) {
35+
$this->blockFactory = $blockFactory;
36+
$this->blockResource = $blockResource;
37+
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
public function execute(string $identifier, int $storeId) : BlockInterface
43+
{
44+
$block = $this->blockFactory->create();
45+
$block->setStoreId($storeId);
46+
$this->blockResource->load($block, $identifier, BlockInterface::IDENTIFIER);
47+
48+
if (!$block->getId()) {
49+
throw new NoSuchEntityException(__('CMS Block with identifier "%1" does not exist.', $identifier));
50+
}
51+
52+
return $block;
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Model;
7+
8+
use Magento\Cms\Api\Data\PageInterface;
9+
use Magento\Cms\Api\GetPageByIdentifierInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
/**
13+
* Class GetPageByIdentifier
14+
*/
15+
class GetPageByIdentifier implements GetPageByIdentifierInterface
16+
{
17+
/**
18+
* @var \Magento\Cms\Model\PageFactory
19+
*/
20+
private $pageFactory;
21+
22+
/**
23+
* @var ResourceModel\Page
24+
*/
25+
private $pageResource;
26+
27+
/**
28+
* @param PageFactory $pageFactory
29+
* @param ResourceModel\Page $pageResource
30+
*/
31+
public function __construct(
32+
\Magento\Cms\Model\PageFactory $pageFactory,
33+
\Magento\Cms\Model\ResourceModel\Page $pageResource
34+
) {
35+
$this->pageFactory = $pageFactory;
36+
$this->pageResource = $pageResource;
37+
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
public function execute(string $identifier, int $storeId) : PageInterface
43+
{
44+
$page = $this->pageFactory->create();
45+
$page->setStoreId($storeId);
46+
$this->pageResource->load($page, $identifier, PageInterface::IDENTIFIER);
47+
48+
if (!$page->getId()) {
49+
throw new NoSuchEntityException(__('CMS Page with identifier "%1" does not exist.', $identifier));
50+
}
51+
52+
return $page;
53+
}
54+
}

0 commit comments

Comments
 (0)