Skip to content

Commit 487c488

Browse files
committed
Merge branch 'MAGETWO-60937' into MPI-Bugfixes
2 parents 6f4d9ca + 2d52c7a commit 487c488

File tree

2 files changed

+72
-50
lines changed

2 files changed

+72
-50
lines changed

app/code/Magento/Bundle/Model/Product/SaveHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function execute($entity, $arguments = [])
6666
$options = $bundleProductOptions ?: [];
6767
foreach ($options as $option) {
6868
$this->optionRepository->save($entity, $option);
69-
$entity->setCopyFromView(false);
7069
}
70+
$entity->setCopyFromView(false);
7171
}
7272
return $entity;
7373
}

dev/tests/integration/testsuite/Magento/Bundle/Model/ProductTest.php

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,54 @@
1010
*/
1111
namespace Magento\Bundle\Model;
1212

13+
use Magento\Bundle\Model\Product\Price;
14+
use Magento\Bundle\Model\Product\Type as BundleType;
15+
use Magento\Catalog\Api\ProductRepositoryInterface;
16+
use Magento\Catalog\Model\Product;
17+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
18+
use Magento\Catalog\Model\Product\Type;
19+
use Magento\Catalog\Model\Product\Visibility;
20+
use Magento\Framework\ObjectManagerInterface;
21+
use Magento\Store\Api\StoreRepositoryInterface;
22+
use Magento\TestFramework\Entity;
23+
use Magento\TestFramework\Helper\Bootstrap;
24+
1325
class ProductTest extends \PHPUnit_Framework_TestCase
1426
{
1527
/**
16-
* @var \Magento\Catalog\Model\Product
28+
* @var Product
29+
*/
30+
private $model;
31+
32+
/**
33+
* @var ObjectManagerInterface
1734
*/
18-
protected $_model;
35+
private $objectManager;
1936

2037
protected function setUp()
2138
{
22-
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
23-
\Magento\Catalog\Model\Product::class
24-
);
25-
$this->_model->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
26-
}
39+
$this->objectManager = Bootstrap::getObjectManager();
2740

28-
public function testGetTypeId()
29-
{
30-
$this->assertEquals(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE, $this->_model->getTypeId());
41+
$this->model = $this->objectManager->create(Product::class);
42+
$this->model->setTypeId(Type::TYPE_BUNDLE);
3143
}
3244

3345
public function testGetSetTypeInstance()
3446
{
3547
// model getter
36-
$typeInstance = $this->_model->getTypeInstance();
37-
$this->assertInstanceOf(\Magento\Bundle\Model\Product\Type::class, $typeInstance);
38-
$this->assertSame($typeInstance, $this->_model->getTypeInstance());
48+
$typeInstance = $this->model->getTypeInstance();
49+
$this->assertInstanceOf(BundleType::class, $typeInstance);
50+
$this->assertSame($typeInstance, $this->model->getTypeInstance());
3951

4052
// singleton getter
41-
$otherProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
42-
\Magento\Catalog\Model\Product::class
43-
);
44-
$otherProduct->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
53+
$otherProduct = $this->objectManager->create(Product::class);
54+
$otherProduct->setTypeId(Type::TYPE_BUNDLE);
4555
$this->assertSame($typeInstance, $otherProduct->getTypeInstance());
4656

4757
// model setter
48-
$customTypeInstance = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
49-
\Magento\Bundle\Model\Product\Type::class
50-
);
51-
$this->_model->setTypeInstance($customTypeInstance);
52-
$this->assertSame($customTypeInstance, $this->_model->getTypeInstance());
58+
$customTypeInstance = $this->objectManager->create(BundleType::class);
59+
$this->model->setTypeInstance($customTypeInstance);
60+
$this->assertSame($customTypeInstance, $this->model->getTypeInstance());
5361
}
5462

5563
/**
@@ -59,41 +67,55 @@ public function testGetSetTypeInstance()
5967
*/
6068
public function testCRUD()
6169
{
62-
$this->_model->setTypeId(
63-
\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE
64-
)->setAttributeSetId(
65-
4
66-
)->setName(
67-
'Bundle Product'
68-
)->setSku(
69-
uniqid()
70-
)->setPrice(
71-
10
72-
)->setMetaTitle(
73-
'meta title'
74-
)->setMetaKeyword(
75-
'meta keyword'
76-
)->setMetaDescription(
77-
'meta description'
78-
)->setVisibility(
79-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
80-
)->setStatus(
81-
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
82-
);
83-
$crud = new \Magento\TestFramework\Entity($this->_model, ['sku' => uniqid()]);
70+
$this->model->setTypeId(Type::TYPE_BUNDLE)
71+
->setAttributeSetId(4)
72+
->setName('Bundle Product')
73+
->setSku(uniqid())
74+
->setPrice(10)
75+
->setMetaTitle('meta title')
76+
->setMetaKeyword('meta keyword')
77+
->setMetaDescription('meta description')
78+
->setVisibility(Visibility::VISIBILITY_BOTH)
79+
->setStatus(Status::STATUS_ENABLED);
80+
$crud = new Entity($this->model, ['sku' => uniqid()]);
8481
$crud->testCrud();
8582
}
8683

8784
public function testGetPriceModel()
8885
{
89-
$this->_model->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
90-
$type = $this->_model->getPriceModel();
91-
$this->assertInstanceOf(\Magento\Bundle\Model\Product\Price::class, $type);
92-
$this->assertSame($type, $this->_model->getPriceModel());
86+
$this->model->setTypeId(Type::TYPE_BUNDLE);
87+
$type = $this->model->getPriceModel();
88+
$this->assertInstanceOf(Price::class, $type);
89+
$this->assertSame($type, $this->model->getPriceModel());
9390
}
9491

9592
public function testIsComposite()
9693
{
97-
$this->assertTrue($this->_model->isComposite());
94+
$this->assertTrue($this->model->isComposite());
95+
}
96+
97+
/**
98+
* Checks a case when bundle product is should be available per multiple stores.
99+
*
100+
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options.php
101+
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
102+
*/
103+
public function testMultipleStores()
104+
{
105+
/** @var ProductRepositoryInterface $productRepository */
106+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
107+
$bundle = $productRepository->get('bundle-product');
108+
109+
/** @var StoreRepositoryInterface $storeRepository */
110+
$storeRepository = $this->objectManager->get(StoreRepositoryInterface::class);
111+
$store = $storeRepository->get('fixture_second_store');
112+
113+
self::assertNotEquals($store->getId(), $bundle->getStoreId());
114+
115+
$bundle->setStoreId($store->getId())
116+
->setCopyFromView(true);
117+
$updatedBundle = $productRepository->save($bundle);
118+
119+
self::assertEquals($store->getId(), $updatedBundle->getStoreId());
98120
}
99121
}

0 commit comments

Comments
 (0)