Skip to content

Commit bbfc599

Browse files
authored
Merge pull request magento#4411 from magento-tsg/2.2-develop-pr103
[TSG] Fixes for 2.2 (pr103) (2.2-develop)
2 parents d104f69 + bbb9629 commit bbfc599

File tree

14 files changed

+207
-113
lines changed

14 files changed

+207
-113
lines changed

app/code/Magento/CatalogRule/view/adminhtml/templates/promo/fieldset.phtml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
9-
/**@var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $block */
7+
/** @var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $block */
108
?>
119
<?php $_element = $block->getElement() ?>
1210
<?php $_jsObjectName = $block->getFieldSetId() != null ? $block->getFieldSetId() : $_element->getHtmlId() ?>
1311
<div class="rule-tree">
14-
<fieldset id="<?= /* @escapeNotVerified */ $_jsObjectName ?>" <?= /* @escapeNotVerified */ $_element->serialize(['class']) ?> class="fieldset">
15-
<legend class="legend"><span><?= /* @escapeNotVerified */ $_element->getLegend() ?></span></legend>
12+
<fieldset id="<?= $block->escapeHtmlAttr($_jsObjectName) ?>"
13+
<?= /* @noEscape */ $_element->serialize(['class']) ?> class="fieldset">
14+
<legend class="legend"><span><?= $block->escapeHtml($_element->getLegend()) ?></span></legend>
1615
<br>
17-
<?php if ($_element->getComment()): ?>
16+
<?php if ($_element->getComment()) : ?>
1817
<div class="messages">
1918
<div class="message message-notice"><?= $block->escapeHtml($_element->getComment()) ?></div>
2019
</div>
@@ -30,9 +29,10 @@ require([
3029
"prototype"
3130
], function(VarienRulesForm){
3231

33-
window.<?= /* @escapeNotVerified */ $_jsObjectName ?> = new VarienRulesForm('<?= /* @escapeNotVerified */ $_jsObjectName ?>', '<?= /* @escapeNotVerified */ $block->getNewChildUrl() ?>');
34-
<?php if ($_element->getReadonly()): ?>
35-
<?= $_element->getHtmlId() ?>.setReadonly(true);
32+
window.<?= /* @noEscape */ $_jsObjectName ?> = new VarienRulesForm('<?= /* @noEscape */ $_jsObjectName ?>',
33+
'<?= /* @noEscape */ $block->getNewChildUrl() ?>');
34+
<?php if ($_element->getReadonly()) : ?>
35+
<?= /* @noEscape */ $_element->getHtmlId() ?>.setReadonly(true);
3636
<?php endif; ?>
3737

3838
});

app/code/Magento/CatalogRule/view/adminhtml/templates/promo/form.phtml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
96
?>
107
<div class="entry-edit rule-tree">
118
<?= $block->getFormHtml() ?>
129
</div>
13-

app/code/Magento/GoogleAdwords/view/frontend/templates/code.phtml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
86
?>
97
<?php
108
/** @var $block \Magento\GoogleAdwords\Block\Code */
119
?>
1210
<!-- Google Code for Sale Conversion Page -->
1311
<script>
1412
/* <![CDATA[ */
15-
var google_conversion_id = <?= /* @escapeNotVerified */ $block->getHelper()->getConversionId() ?>;
16-
var google_conversion_language = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionLanguage() ?>";
17-
var google_conversion_format = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionFormat() ?>";
18-
var google_conversion_color = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionColor() ?>";
19-
var google_conversion_label = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionLabel() ?>";
20-
var google_conversion_value = <?= /* @escapeNotVerified */ $block->getHelper()->getConversionValue() ?>;
13+
var google_conversion_id = <?= $block->escapeJs($block->getHelper()->getConversionId()) ?>;
14+
var google_conversion_language = "<?= $block->escapeJs($block->getHelper()->getConversionLanguage()) ?>";
15+
var google_conversion_format = "<?= $block->escapeJs($block->getHelper()->getConversionFormat()) ?>";
16+
var google_conversion_color = "<?= $block->escapeJs($block->getHelper()->getConversionColor()) ?>";
17+
var google_conversion_label = "<?= $block->escapeJs($block->getHelper()->getConversionLabel()) ?>";
18+
var google_conversion_value = <?= $block->escapeJs($block->getHelper()->getConversionValue()) ?>;
2119
/* ]]> */
2220
</script>
23-
<script src="<?= /* @escapeNotVerified */ $block->getHelper()->getConversionJsSrc() ?>"></script>
21+
<script src="<?= $block->escapeHtmlAttr($block->getHelper()->getConversionJsSrc()) ?>"></script>
2422
<noscript>
2523
<div style="display:inline;">
2624
<img height="1" width="1" style="border-style:none;" alt=""
27-
src="<?= /* @escapeNotVerified */ $block->getHelper()->getConversionImgSrc() ?>"/>
25+
src="<?= $block->escapeHtmlAttr($block->getHelper()->getConversionImgSrc()) ?>"/>
2826
</div>
2927
</noscript>
3028
<!-- END Google Code for Sale Conversion Page -->

app/code/Magento/GoogleAnalytics/view/frontend/templates/ga.phtml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
96
?>
107
<?php /** @var $block \Magento\GoogleAnalytics\Block\Ga */ ?>
118
<?php $accountId = $block->getConfig(\Magento\GoogleAnalytics\Helper\Data::XML_PATH_ACCOUNT) ?>
@@ -16,9 +13,9 @@
1613
"Magento_GoogleAnalytics/js/google-analytics": {
1714
"isCookieRestrictionModeEnabled": <?= (int)$block->isCookieRestrictionModeEnabled() ?>,
1815
"currentWebsite": <?= (int)$block->getCurrentWebsiteId() ?>,
19-
"cookieName": "<?= /* @escapeNotVerified */ \Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE ?>",
20-
"ordersTrackingData": <?= /* @escapeNotVerified */ json_encode($block->getOrdersTrackingData()) ?>,
21-
"pageTrackingData": <?= /* @escapeNotVerified */ json_encode($block->getPageTrackingData($accountId)) ?>
16+
"cookieName": "<?= /* @noEscape */ \Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE ?>",
17+
"ordersTrackingData": <?= /* @noEscape */ json_encode($block->getOrdersTrackingData()) ?>,
18+
"pageTrackingData": <?= /* @noEscape */ json_encode($block->getPageTrackingData($accountId)) ?>
2219
}
2320
}
2421
}

app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function getAssociatedProducts($product)
208208
$collection = $this->getAssociatedProductCollection(
209209
$product
210210
)->addAttributeToSelect(
211-
['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
211+
['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id', 'image']
212212
)->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter(
213213
$this->getStoreFilter($product)
214214
)->addAttributeToFilter(

app/code/Magento/GroupedProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GroupedTest.php

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedProductType;
2222
use Magento\GroupedProduct\Ui\DataProvider\Product\Form\Modifier\Grouped;
2323
use Magento\Store\Api\Data\StoreInterface;
24+
use Magento\Catalog\Model\Product;
25+
use Magento\GroupedProduct\Model\Product\Link\CollectionProvider\Grouped as GroupedProducts;
26+
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory;
2427

2528
/**
2629
* Class GroupedTest
@@ -82,23 +85,38 @@ class GroupedTest extends AbstractModifierTest
8285
*/
8386
protected $storeMock;
8487

88+
/**
89+
* @var GroupedProducts|\PHPUnit_Framework_MockObject_MockObject
90+
*/
91+
private $groupedProductsMock;
92+
93+
/**
94+
* @var ProductLinkInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
95+
*/
96+
private $productLinkFactoryMock;
97+
98+
/**
99+
* @inheritdoc
100+
*/
85101
protected function setUp()
86102
{
87103
$this->objectManager = new ObjectManager($this);
88104
$this->locatorMock = $this->getMockBuilder(LocatorInterface::class)
89105
->getMockForAbstractClass();
90-
$this->productMock = $this->getMockBuilder(ProductInterface::class)
106+
$this->productMock = $this->getMockBuilder(Product::class)
91107
->setMethods(['getId', 'getTypeId'])
92-
->getMockForAbstractClass();
108+
->disableOriginalConstructor()
109+
->getMock();
93110
$this->productMock->expects($this->any())
94111
->method('getId')
95112
->willReturn(self::PRODUCT_ID);
96113
$this->productMock->expects($this->any())
97114
->method('getTypeId')
98115
->willReturn(GroupedProductType::TYPE_CODE);
99-
$this->linkedProductMock = $this->getMockBuilder(ProductInterface::class)
116+
$this->linkedProductMock = $this->getMockBuilder(Product::class)
100117
->setMethods(['getId', 'getName', 'getPrice'])
101-
->getMockForAbstractClass();
118+
->disableOriginalConstructor()
119+
->getMock();
102120
$this->linkedProductMock->expects($this->any())
103121
->method('getId')
104122
->willReturn(self::LINKED_PRODUCT_ID);
@@ -135,7 +153,7 @@ protected function setUp()
135153
$this->linkRepositoryMock->expects($this->any())
136154
->method('getList')
137155
->with($this->productMock)
138-
->willReturn([$this->linkMock]);
156+
->willReturn([$this->linkedProductMock]);
139157
$this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
140158
->setMethods(['get'])
141159
->getMockForAbstractClass();
@@ -155,7 +173,7 @@ protected function setUp()
155173
}
156174

157175
/**
158-
* {@inheritdoc}
176+
* @inheritdoc
159177
*/
160178
protected function createModel()
161179
{
@@ -169,6 +187,16 @@ protected function createModel()
169187
->setMethods(['init', 'getUrl'])
170188
->disableOriginalConstructor()
171189
->getMock();
190+
191+
$this->groupedProductsMock = $this->getMockBuilder(GroupedProducts::class)
192+
->setMethods(['getLinkedProducts'])
193+
->disableOriginalConstructor()
194+
->getMock();
195+
$this->productLinkFactoryMock = $this->getMockBuilder(ProductLinkInterfaceFactory::class)
196+
->setMethods(['create'])
197+
->disableOriginalConstructor()
198+
->getMockForAbstractClass();
199+
172200
$this->imageHelperMock->expects($this->any())
173201
->method('init')
174202
->willReturn($this->imageHelperMock);
@@ -189,16 +217,23 @@ protected function createModel()
189217
'localeCurrency' => $this->currencyMock,
190218
'imageHelper' => $this->imageHelperMock,
191219
'attributeSetRepository' => $this->attributeSetRepositoryMock,
220+
'groupedProducts' => $this->groupedProductsMock,
221+
'productLinkFactory' => $this->productLinkFactoryMock,
192222
]);
193223
}
194224

225+
/**
226+
* Assert array has key
227+
*
228+
* @return void
229+
*/
195230
public function testModifyMeta()
196231
{
197232
$this->assertArrayHasKey(Grouped::GROUP_GROUPED, $this->getModel()->modifyMeta([]));
198233
}
199234

200235
/**
201-
* {@inheritdoc}
236+
* @inheritdoc
202237
*/
203238
public function testModifyData()
204239
{
@@ -226,6 +261,42 @@ public function testModifyData()
226261
],
227262
],
228263
];
229-
$this->assertSame($expectedData, $this->getModel()->modifyData([]));
264+
$model = $this->getModel();
265+
$linkedProductMock = $this->getMockBuilder(Product::class)
266+
->setMethods(['getId', 'getName', 'getPrice', 'getSku', 'getImage', 'getPosition', 'getQty'])
267+
->disableOriginalConstructor()
268+
->getMock();
269+
$linkedProductMock->expects($this->once())
270+
->method('getId')
271+
->willReturn(self::LINKED_PRODUCT_ID);
272+
$linkedProductMock->expects($this->once())
273+
->method('getName')
274+
->willReturn(self::LINKED_PRODUCT_NAME);
275+
$linkedProductMock->expects($this->once())
276+
->method('getPrice')
277+
->willReturn(self::LINKED_PRODUCT_PRICE);
278+
$linkedProductMock->expects($this->once())
279+
->method('getSku')
280+
->willReturn(self::LINKED_PRODUCT_SKU);
281+
$linkedProductMock->expects($this->once())
282+
->method('getImage')
283+
->willReturn('');
284+
$linkedProductMock->expects($this->exactly(2))
285+
->method('getPosition')
286+
->willReturn(self::LINKED_PRODUCT_POSITION);
287+
$linkedProductMock->expects($this->once())
288+
->method('getQty')
289+
->willReturn(self::LINKED_PRODUCT_QTY);
290+
$this->groupedProductsMock->expects($this->once())
291+
->method('getLinkedProducts')
292+
->willReturn([$linkedProductMock]);
293+
$linkMock = $this->getMockBuilder(ProductLinkInterface::class)
294+
->getMockForAbstractClass();
295+
296+
$this->productLinkFactoryMock->expects($this->once())
297+
->method('create')
298+
->willReturn($linkMock);
299+
300+
$this->assertSame($expectedData, $model->modifyData([]));
230301
}
231302
}

app/code/Magento/GroupedProduct/Ui/DataProvider/Product/Form/Modifier/Grouped.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
use Magento\Eav\Api\AttributeSetRepositoryInterface;
2222
use Magento\Catalog\Model\Product\Attribute\Source\Status;
2323
use Magento\Framework\Locale\CurrencyInterface;
24+
use Magento\GroupedProduct\Model\Product\Link\CollectionProvider\Grouped as GroupedProducts;
25+
use Magento\Framework\App\ObjectManager;
26+
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory;
2427

2528
/**
2629
* Data provider for Grouped products
@@ -99,6 +102,16 @@ class Grouped extends AbstractModifier
99102
*/
100103
private static $codeQty = 'qty';
101104

105+
/**
106+
* @var GroupedProducts
107+
*/
108+
private $groupedProducts;
109+
110+
/**
111+
* @var ProductLinkInterfaceFactory
112+
*/
113+
private $productLinkFactory;
114+
102115
/**
103116
* @param LocatorInterface $locator
104117
* @param UrlInterface $urlBuilder
@@ -109,6 +122,9 @@ class Grouped extends AbstractModifier
109122
* @param AttributeSetRepositoryInterface $attributeSetRepository
110123
* @param CurrencyInterface $localeCurrency
111124
* @param array $uiComponentsConfig
125+
* @param GroupedProducts|null $groupedProducts
126+
* @param ProductLinkInterfaceFactory|null $productLinkFactory
127+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
112128
*/
113129
public function __construct(
114130
LocatorInterface $locator,
@@ -119,7 +135,9 @@ public function __construct(
119135
Status $status,
120136
AttributeSetRepositoryInterface $attributeSetRepository,
121137
CurrencyInterface $localeCurrency,
122-
array $uiComponentsConfig = []
138+
array $uiComponentsConfig = [],
139+
GroupedProducts $groupedProducts = null,
140+
ProductLinkInterfaceFactory $productLinkFactory = null
123141
) {
124142
$this->locator = $locator;
125143
$this->urlBuilder = $urlBuilder;
@@ -130,6 +148,9 @@ public function __construct(
130148
$this->status = $status;
131149
$this->localeCurrency = $localeCurrency;
132150
$this->uiComponentsConfig = array_replace_recursive($this->uiComponentsConfig, $uiComponentsConfig);
151+
$this->groupedProducts = $groupedProducts ?: ObjectManager::getInstance()->get(GroupedProducts::class);
152+
$this->productLinkFactory = $productLinkFactory ?: ObjectManager::getInstance()
153+
->get(ProductLinkInterfaceFactory::class);
133154
}
134155

135156
/**
@@ -143,18 +164,15 @@ public function modifyData(array $data)
143164
if ($modelId) {
144165
$storeId = $this->locator->getStore()->getId();
145166
$data[$product->getId()]['links'][self::LINK_TYPE] = [];
146-
$linkedItems = $this->productLinkRepository->getList($product);
167+
$linkedItems = $this->groupedProducts->getLinkedProducts($product);
147168
usort($linkedItems, function ($a, $b) {
148169
return $a->getPosition() <=> $b->getPosition();
149170
});
171+
$productLink = $this->productLinkFactory->create();
150172
foreach ($linkedItems as $index => $linkItem) {
151-
if ($linkItem->getLinkType() !== self::LINK_TYPE) {
152-
continue;
153-
}
154173
/** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */
155-
$linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId);
156174
$linkItem->setPosition($index);
157-
$data[$modelId]['links'][self::LINK_TYPE][] = $this->fillData($linkedProduct, $linkItem);
175+
$data[$modelId]['links'][self::LINK_TYPE][] = $this->fillData($linkItem, $productLink);
158176
}
159177
$data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId;
160178
}
@@ -167,6 +185,7 @@ public function modifyData(array $data)
167185
* @param ProductInterface $linkedProduct
168186
* @param ProductLinkInterface $linkItem
169187
* @return array
188+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
170189
*/
171190
protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem)
172191
{
@@ -176,12 +195,15 @@ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterfac
176195
return [
177196
'id' => $linkedProduct->getId(),
178197
'name' => $linkedProduct->getName(),
179-
'sku' => $linkItem->getLinkedProductSku(),
198+
'sku' => $linkedProduct->getSku(),
180199
'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())),
181-
'qty' => $linkItem->getExtensionAttributes()->getQty(),
182-
'position' => $linkItem->getPosition(),
183-
'positionCalculated' => $linkItem->getPosition(),
184-
'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(),
200+
'qty' => $linkedProduct->getQty(),
201+
'position' => $linkedProduct->getPosition(),
202+
'positionCalculated' => $linkedProduct->getPosition(),
203+
'thumbnail' => $this->imageHelper
204+
->init($linkedProduct, 'product_listing_thumbnail')
205+
->setImageFile($linkedProduct->getImage())
206+
->getUrl(),
185207
'type_id' => $linkedProduct->getTypeId(),
186208
'status' => $this->status->getOptionText($linkedProduct->getStatus()),
187209
'attribute_set' => $this->attributeSetRepository

0 commit comments

Comments
 (0)