Skip to content

Commit f2607a4

Browse files
committed
ACP2E-4243: Issue with Update bundle option price per website via Import
- address issue when child product is not assigned to all websites the bundle product is assigned to resulting in missing website price for that child product
1 parent de047a2 commit f2607a4

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ private function getProductOptionCollection(
579579
$optionCollection = $product->getTypeInstance()
580580
->getOptionsCollection($product)
581581
->setOrder('position', Collection::SORT_ORDER_ASC);
582+
// Ensure children products are not filtered by website.
583+
// We need to export all children products regardless of the website they are assigned to.
584+
$product->getTypeInstance()->setStoreFilter(Store::DEFAULT_STORE_ID, $product);
582585
$selectionCollection = $product->getTypeInstance()
583586
->getSelectionsCollection(
584587
$product->getTypeInstance()->getOptionsIds($product),

dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
1010
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
1111
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Helper\Data;
1213
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1314
use Magento\Store\Model\ScopeInterface;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Store\Test\Fixture\Group as GroupFixture;
17+
use Magento\Store\Test\Fixture\Store as StoreFixture;
18+
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
19+
use Magento\TestFramework\Fixture\AppArea;
1420
use Magento\TestFramework\Fixture\Config;
1521
use Magento\TestFramework\Fixture\DataFixture;
1622
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
@@ -36,6 +42,16 @@ class RowCustomizerTest extends \PHPUnit\Framework\TestCase
3642
* @var \Magento\Catalog\Api\ProductRepositoryInterface
3743
*/
3844
private $productRepository;
45+
46+
/**
47+
* @var StoreManagerInterface
48+
*/
49+
private $storeManager;
50+
51+
/**
52+
* @var int
53+
*/
54+
private $currentStoreId;
3955

4056
/**
4157
* @inheritdoc
@@ -49,6 +65,14 @@ protected function setUp(): void
4965
$this->productRepository = $this->objectManager->get(
5066
\Magento\Catalog\Api\ProductRepositoryInterface::class
5167
);
68+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
69+
$this->currentStoreId = $this->storeManager->getStore()->getId();
70+
}
71+
72+
protected function tearDown(): void
73+
{
74+
$this->storeManager->setCurrentStore($this->currentStoreId);
75+
parent::tearDown();
5276
}
5377

5478
/**
@@ -136,10 +160,15 @@ function ($input) {
136160
}
137161

138162
#[
163+
// export is performed in global scope
164+
AppArea('global'),
139165
DbIsolation(false),
140-
Config(\Magento\Catalog\Helper\Data::XML_PATH_PRICE_SCOPE, 1, ScopeInterface::SCOPE_STORE, 'default'),
166+
Config(Data::XML_PATH_PRICE_SCOPE, 1, ScopeInterface::SCOPE_STORE, 'default'),
167+
Config(Data::XML_PATH_PRICE_SCOPE, 1, ScopeInterface::SCOPE_STORE, 'bundle_test_store2'),
141168
DataFixture(ScopeFixture::class, as: 'global_scope'),
142-
DataFixture(ScopeFixture::class, ['code' => 'default'], as: 'default_store'),
169+
DataFixture(WebsiteFixture::class, as: 'website2'),
170+
DataFixture(GroupFixture::class, ['website_id' => '$website2.id$'], 'group2'),
171+
DataFixture(StoreFixture::class, ['store_group_id' => '$group2.id$', 'code' => 'bundle_test_store2'], 'store2'),
143172
DataFixture(ProductFixture::class, as: 'p1'),
144173
DataFixture(ProductFixture::class, as: 'p2'),
145174
DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$', 'price' => 10, 'price_type' => 0], 'link1'),
@@ -148,7 +177,7 @@ function ($input) {
148177
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link2$']], 'opt2'),
149178
DataFixture(
150179
BundleProductFixture::class,
151-
['price' => 50,'price_type' => 1, '_options' => ['$opt1$','$opt2$']],
180+
['price' => 50,'price_type' => 1, 'website_ids' => [1, '$website2.id$'], '_options' => ['$opt1$','$opt2$']],
152181
'bundle',
153182
'global_scope',
154183
),
@@ -161,30 +190,34 @@ public function testExportWhenPriceScopeIsWebsite(): void
161190
$sku2 = $fixtures->get('p2')->getSku();
162191
$opt1 = $fixtures->get('opt1')->getTitle();
163192
$opt2 = $fixtures->get('opt2')->getTitle();
164-
$store = $fixtures->get('default_store');
193+
$websiteCode = $fixtures->get('website2')->getCode();
194+
$store = $fixtures->get('store2');
165195

166196
$data['bundle_values'] = "name=$opt1,type=select,required=1,sku=$sku1,price=10.0000" .
167197
",default=0,default_qty=1.0000,price_type=fixed,can_change_qty=0" .
168198
"|name=$opt2,type=select,required=1,sku=$sku2,price=20.0000" .
169199
",default=0,default_qty=1.0000,price_type=percent,can_change_qty=0";
170200
$this->assertBundleValues($data, $bundleProduct);
171201

172-
// Update selection prices in default store
173-
$bundleProduct = $this->productRepository->get($bundleProduct->getSku(), false, $store->getId());
202+
// Update selection prices in second store
203+
$bundleProduct = $this->productRepository->get($bundleProduct->getSku(), true);
204+
$this->storeManager->setCurrentStore($store->getId());
205+
$bundleProduct->setStoreId($store->getId());
174206
$extension = $bundleProduct->getExtensionAttributes();
175207
$options = $extension->getBundleProductOptions();
176208
$options[0]->getProductLinks()[0]->setPrice(40);
177209
$options[0]->getProductLinks()[0]->setPriceType(1);
178210
$options[1]->getProductLinks()[0]->setPrice(50);
179211
$options[1]->getProductLinks()[0]->setPriceType(1);
180212
$this->productRepository->save($bundleProduct);
213+
$this->storeManager->setCurrentStore($this->currentStoreId);
181214

182215
$data['bundle_values'] = "name=$opt1,type=select,required=1,sku=$sku1,price=10.0000" .
183216
",default=0,default_qty=1.0000,price_type=fixed,can_change_qty=0" .
184-
",price_website_base=40.000000,price_type_website_base=percent" .
217+
",price_website_$websiteCode=40.000000,price_type_website_$websiteCode=percent" .
185218
"|name=$opt2,type=select,required=1,sku=$sku2,price=20.0000" .
186219
",default=0,default_qty=1.0000,price_type=percent,can_change_qty=0" .
187-
",price_website_base=50.000000,price_type_website_base=percent";
220+
",price_website_$websiteCode=50.000000,price_type_website_$websiteCode=percent";
188221
$this->assertBundleValues($data, $bundleProduct);
189222
}
190223

0 commit comments

Comments
 (0)