Skip to content

Commit 7a57c97

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-50937' into PR
2 parents d349299 + f36d7a4 commit 7a57c97

File tree

8 files changed

+74
-31
lines changed

8 files changed

+74
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function getAssociatedProducts($product)
202202
$collection = $this->getAssociatedProductCollection(
203203
$product
204204
)->addAttributeToSelect(
205-
'*'
205+
['name', 'price']
206206
)->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter(
207207
$this->getStoreFilter($product)
208208
)->addAttributeToFilter(

dev/tests/api-functional/testsuite/Magento/GroupedProduct/Api/ProductLinkManagementTest.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,21 @@ public function testGetLinkedItemsByType()
4141
[
4242
'sku' => 'grouped-product',
4343
'link_type' => 'associated',
44-
'linked_product_sku' => 'simple-1',
44+
'linked_product_sku' => 'simple',
4545
'linked_product_type' => 'simple',
4646
'position' => 1,
47+
'extension_attributes' => ['qty' => 1]
4748
],
4849
[
4950
'sku' => 'grouped-product',
5051
'link_type' => 'associated',
5152
'linked_product_sku' => 'virtual-product',
5253
'linked_product_type' => 'virtual',
5354
'position' => 2,
55+
'extension_attributes' => ['qty' => 2]
5456
],
5557
];
5658

57-
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
58-
array_walk(
59-
$expected,
60-
function (&$item) {
61-
$item['extension_attributes'] = ['qty' => 1.0000];
62-
}
63-
);
64-
} else {
65-
array_walk(
66-
$expected,
67-
function (&$item) {
68-
$item['extension_attributes'] = ['qty' => 1.0000];
69-
}
70-
);
71-
}
7259
$this->assertEquals($expected, $actual);
7360
}
7461
}

dev/tests/api-functional/testsuite/Magento/GroupedProduct/Api/ProductLinkRepositoryTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ class ProductLinkRepositoryTest extends \Magento\TestFramework\TestCase\WebapiAb
1515
const RESOURCE_PATH = '/V1/products/';
1616

1717
/**
18-
* @var \Magento\Framework\ObjectManager
18+
* @var \Magento\Framework\ObjectManagerInterface
1919
*/
2020
protected $objectManager;
2121

2222
protected function setUp()
2323
{
2424
$this->objectManager = Bootstrap::getObjectManager();
2525
}
26+
2627
/**
27-
* @magentoApiDataFixture Magento/Catalog/_files/products_new.php
28+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
2829
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
2930
*/
3031
public function testSave()
@@ -35,7 +36,7 @@ public function testSave()
3536
'sku' => $productSku,
3637
'link_type' => $linkType,
3738
'linked_product_type' => 'simple',
38-
'linked_product_sku' => 'simple',
39+
'linked_product_sku' => 'simple-1',
3940
'position' => 3,
4041
'extension_attributes' => [
4142
'qty' => (float) 300.0000,

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/TestCase/CreateGroupedProductEntityTest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
<data name="product/data/name" xsi:type="string">GroupedProduct %isolation%</data>
1414
<data name="product/data/sku" xsi:type="string">GroupedProduct_sku%isolation%</data>
1515
<data name="product/data/category" xsi:type="string">category_%isolation%</data>
16-
<data name="product/data/associated/products" xsi:type="string">catalogProductSimple::simple_big_qty,downloadableProduct::one_dollar_product_with_no_separated_link,catalogProductVirtual::required_fields_with_category</data>
16+
<data name="product/data/associated/products" xsi:type="string">catalogProductSimple::simple_big_qty,downloadableProduct::one_dollar_product_with_no_separated_link,catalogProductVirtual::default</data>
1717
<data name="product/data/associated/dataset" xsi:type="string">simple_downloadable_virtual</data>
1818
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
1919
<constraint name="Magento\Catalog\Test\Constraint\AssertProductVisibleInCategory" />
2020
<constraint name="Magento\Catalog\Test\Constraint\AssertProductPage" />
21+
<constraint name="Magento\GroupedProduct\Test\Constraint\AssertGroupedProductsDefaultQty" />
2122
</variation>
2223
<variation name="CreateGroupedProductEntityTestVariation2" summary="Create with required products and description">
2324
<data name="product/data/url_key" xsi:type="string">test-grouped-product-%isolation%</data>

dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77

88
class GroupedTest extends \PHPUnit_Framework_TestCase
99
{
10+
/**
11+
* @var \Magento\Framework\ObjectManagerInterface
12+
*/
13+
protected $objectManager;
14+
1015
/**
1116
* @var \Magento\Catalog\Model\Product\Type
1217
*/
1318
protected $_productType;
1419

1520
protected function setUp()
1621
{
17-
$this->_productType = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
18-
'Magento\Catalog\Model\Product\Type'
19-
);
22+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
23+
24+
$this->_productType = $this->objectManager->get('Magento\Catalog\Model\Product\Type');
2025
}
2126

2227
public function testFactory()
@@ -26,4 +31,53 @@ public function testFactory()
2631
$type = $this->_productType->factory($product);
2732
$this->assertInstanceOf('\Magento\GroupedProduct\Model\Product\Type\Grouped', $type);
2833
}
34+
35+
/**
36+
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
37+
* @magentoAppArea frontend
38+
*/
39+
public function testGetAssociatedProducts()
40+
{
41+
$productRepository = $this->objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
42+
43+
/** @var \Magento\Catalog\Model\Product $product */
44+
$product = $productRepository->get('grouped-product');
45+
$type = $product->getTypeInstance();
46+
$this->assertInstanceOf('\Magento\GroupedProduct\Model\Product\Type\Grouped', $type);
47+
48+
$associatedProducts = $type->getAssociatedProducts($product);
49+
$this->assertCount(2, $associatedProducts);
50+
51+
$this->assertProductInfo($associatedProducts[0]);
52+
$this->assertProductInfo($associatedProducts[1]);
53+
}
54+
55+
/**
56+
* @param \Magento\Catalog\Model\Product $product
57+
*/
58+
private function assertProductInfo($product)
59+
{
60+
$data = [
61+
1 => [
62+
'sku' => 'simple',
63+
'name' => 'Simple Product',
64+
'price' => '10',
65+
'qty' => '1',
66+
'position' => '1'
67+
],
68+
21 => [
69+
'sku' => 'virtual-product',
70+
'name' => 'Virtual Product',
71+
'price' => '10',
72+
'qty' => '2',
73+
'position' => '2'
74+
]
75+
];
76+
$productId = $product->getId();
77+
$this->assertEquals($data[$productId]['sku'], $product->getSku());
78+
$this->assertEquals($data[$productId]['name'], $product->getName());
79+
$this->assertEquals($data[$productId]['price'], $product->getPrice());
80+
$this->assertEquals($data[$productId]['qty'], $product->getQty());
81+
$this->assertEquals($data[$productId]['position'], $product->getPosition());
82+
}
2983
}

dev/tests/integration/testsuite/Magento/GroupedProduct/Model/ResourceModel/Product/Type/Grouped/AssociatedProductsCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testGetColumnValues()
3030
$resultData = $collection->getColumnValues('sku');
3131
$this->assertNotEmpty($resultData);
3232

33-
$expected = ['virtual-product', 'simple-1'];
33+
$expected = ['virtual-product', 'simple'];
3434
sort($expected);
3535
sort($resultData);
3636
$this->assertEquals($expected, $resultData);

dev/tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped.php

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

7-
require realpath(__DIR__ . '/../../') . '/Catalog/_files/product_simple_duplicated.php';
7+
require realpath(__DIR__ . '/../../') . '/Catalog/_files/product_associated.php';
88
require realpath(__DIR__ . '/../../') . '/Catalog/_files/product_virtual_in_stock.php';
99

1010
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
1111
$productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
1212

13-
$productId = $productRepository->get('simple-1')->getId();
14-
1513
/** @var $product \Magento\Catalog\Model\Product */
1614
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product');
1715
$product->isObjectNew(true);
@@ -37,9 +35,10 @@
3735

3836
$newLinks = [];
3937
$productLinkFactory = $objectManager->get('Magento\Catalog\Api\Data\ProductLinkInterfaceFactory');
38+
4039
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
4140
$productLink = $productLinkFactory->create();
42-
$linkedProduct = $productRepository->getById($productId);
41+
$linkedProduct = $productRepository->getById(1);
4342
$productLink->setSku($product->getSku())
4443
->setLinkType('associated')
4544
->setLinkedProductSku($linkedProduct->getSku())
@@ -48,6 +47,7 @@
4847
->getExtensionAttributes()
4948
->setQty(1);
5049
$newLinks[] = $productLink;
50+
5151
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
5252
$productLink = $productLinkFactory->create();
5353
$linkedProduct = $productRepository->getById(21);
@@ -57,7 +57,7 @@
5757
->setLinkedProductType($linkedProduct->getTypeId())
5858
->setPosition(2)
5959
->getExtensionAttributes()
60-
->setQty(1);
60+
->setQty(2);
6161
$newLinks[] = $productLink;
6262
$product->setProductLinks($newLinks);
6363
$product->save();

dev/tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped_rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$registry->register('isSecureArea', true);
1919
try {
2020
/** @var $simpleProduct \Magento\Catalog\Model\Product */
21-
$simpleProduct = $productRepository->get('simple-1', false, null, true);
21+
$simpleProduct = $productRepository->get('simple', false, null, true);
2222
$simpleProduct->delete();
2323
} catch (NoSuchEntityException $e) {
2424
//already deleted

0 commit comments

Comments
 (0)