Skip to content

Commit 17340d9

Browse files
committed
ACP2E-4243: Issue with Update bundle option price per website via Import
- address CR concerns
1 parent e52de40 commit 17340d9

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
*/
66
namespace Magento\BundleImportExport\Model\Export;
77

8+
use Magento\Bundle\Model\Option;
9+
use Magento\Bundle\Model\Selection;
810
use Magento\Catalog\Helper\Data as CatalogData;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Type;
913
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1014
use Magento\CatalogImportExport\Model\Export\RowCustomizerInterface;
1115
use Magento\CatalogImportExport\Model\Import\Product as ImportProductModel;
1216
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
1317
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\Exception\LocalizedException;
1419
use Magento\ImportExport\Model\Import as ImportModel;
1520
use Magento\Catalog\Model\Product\Type\AbstractType;
21+
use Magento\Store\Model\Store;
1622
use Magento\Store\Model\StoreManagerInterface;
1723

1824
/**
@@ -157,7 +163,7 @@ private function getBundleColumns()
157163
/**
158164
* Prepare data for export
159165
*
160-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
166+
* @param Collection $collection
161167
* @param int[] $productIds
162168
* @return $this
163169
*/
@@ -169,7 +175,7 @@ public function prepareData($collection, $productIds)
169175
['in' => $productIds]
170176
)->addAttributeToFilter(
171177
'type_id',
172-
['eq' => \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE]
178+
['eq' => Type::TYPE_BUNDLE]
173179
);
174180

175181
return $this->populateBundleData($productCollection);
@@ -220,7 +226,7 @@ public function getAdditionalRowsCount($additionalRowsCount, $productId)
220226
/**
221227
* Populate bundle product data
222228
*
223-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
229+
* @param Collection $collection
224230
* @return $this
225231
*/
226232
protected function populateBundleData($collection)
@@ -244,10 +250,10 @@ protected function populateBundleData($collection)
244250
/**
245251
* Retrieve formatted bundle options
246252
*
247-
* @param \Magento\Catalog\Model\Product $product
253+
* @param Product $product
248254
* @return string
249255
*/
250-
protected function getFormattedBundleOptionValues(\Magento\Catalog\Model\Product $product): string
256+
protected function getFormattedBundleOptionValues(Product $product): string
251257
{
252258
$optionCollections = $this->getProductOptionCollection($product);
253259
$bundleData = '';
@@ -303,12 +309,12 @@ protected function getFormattedBundleSelections($optionValues, SelectionCollecti
303309
/**
304310
* Retrieve option value of bundle product
305311
*
306-
* @param \Magento\Bundle\Model\Option $option
312+
* @param Option $option
307313
* @param string[] $optionTitles
308314
* @return string
309315
*/
310316
protected function getFormattedOptionValues(
311-
\Magento\Bundle\Model\Option $option,
317+
Option $option,
312318
array $optionTitles = []
313319
): string {
314320
$data = [
@@ -459,22 +465,22 @@ private function parseAdditionalAttributes($additionalAttributes)
459465
* - 'name=All store views name' for all store views
460466
* - 'name_specific_store=Specific store name' for store view with 'specific_store' store code
461467
*
462-
* @param \Magento\Catalog\Model\Product $product
468+
* @param Product $product
463469
* @return array
464470
*/
465-
private function getBundleOptionTitles(\Magento\Catalog\Model\Product $product): array
471+
private function getBundleOptionTitles(Product $product): array
466472
{
467473
$optionCollections = $this->getProductOptionCollection($product);
468474
$optionsTitles = [];
469-
/** @var \Magento\Bundle\Model\Option $option */
475+
/** @var Option $option */
470476
foreach ($optionCollections->getItems() as $option) {
471477
$optionsTitles[$option->getId()]['name'] = $option->getTitle();
472478
}
473479
$storeIds = $product->getStoreIds();
474480
if (count($storeIds) > 1) {
475481
foreach ($storeIds as $storeId) {
476482
$optionCollections = $this->getProductOptionCollection($product, (int)$storeId);
477-
/** @var \Magento\Bundle\Model\Option $option */
483+
/** @var Option $option */
478484
foreach ($optionCollections->getItems() as $option) {
479485
$optionTitle = $option->getTitle();
480486
if ($optionsTitles[$option->getId()]['name'] != $optionTitle) {
@@ -494,10 +500,10 @@ private function getBundleOptionTitles(\Magento\Catalog\Model\Product $product):
494500
* while for a specific website it is stored under
495501
* public the 'price_website_<website-code>' and 'price_type_website_<website-code>' keys.
496502
*
497-
* @param \Magento\Catalog\Model\Product $product
503+
* @param Product $product
498504
* @return array
499505
*/
500-
private function getBundleOptionSelections(\Magento\Catalog\Model\Product $product): array
506+
private function getBundleOptionSelections(Product $product): array
501507
{
502508
$selections = $this->getBundleOptionSelectionsData($product);
503509

@@ -527,19 +533,19 @@ private function getBundleOptionSelections(\Magento\Catalog\Model\Product $produ
527533
/**
528534
* Get bundle product options selections data.
529535
*
530-
* @param \Magento\Catalog\Model\Product $product
536+
* @param Product $product
531537
* @param int $storeId
532538
* @return array
533539
*/
534540
private function getBundleOptionSelectionsData(
535-
\Magento\Catalog\Model\Product $product,
536-
int $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID
541+
Product $product,
542+
int $storeId = Store::DEFAULT_STORE_ID
537543
): array {
538544
$data = [];
539545
foreach ($this->getProductOptionCollection($product, $storeId) as $option) {
540-
/** @var \Magento\Bundle\Model\Option $option*/
546+
/** @var Option $option*/
541547
foreach ($option->getSelections() as $selection) {
542-
/** @var \Magento\Bundle\Model\Selection $selection*/
548+
/** @var Selection $selection*/
543549
$data[$option->getOptionId()][$selection->getSelectionId()] = [
544550
'sku' => $selection->getSku(),
545551
'price' => $selection->getSelectionPriceValue(),
@@ -558,13 +564,13 @@ private function getBundleOptionSelectionsData(
558564
*
559565
* Set given store id to the product if it was defined (default store id will be set if was not).
560566
*
561-
* @param \Magento\Catalog\Model\Product $product $product
567+
* @param Product $product $product
562568
* @param int $storeId
563569
* @return \Magento\Bundle\Model\ResourceModel\Option\Collection
564570
*/
565571
private function getProductOptionCollection(
566-
\Magento\Catalog\Model\Product $product,
567-
int $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID
572+
Product $product,
573+
int $storeId = Store::DEFAULT_STORE_ID
568574
): \Magento\Bundle\Model\ResourceModel\Option\Collection {
569575
$productSku = $product->getSku();
570576
if (!isset($this->optionCollections[$productSku][$storeId])) {
@@ -591,7 +597,7 @@ private function getProductOptionCollection(
591597
*
592598
* @param int $websiteId
593599
* @return int
594-
* @throws \Magento\Framework\Exception\LocalizedException
600+
* @throws LocalizedException
595601
*/
596602
private function getWebsiteDefaultStoreId(int $websiteId): int
597603
{
@@ -605,7 +611,7 @@ private function getWebsiteDefaultStoreId(int $websiteId): int
605611
*
606612
* @param int $websiteId
607613
* @return string
608-
* @throws \Magento\Framework\Exception\LocalizedException
614+
* @throws LocalizedException
609615
*/
610616
private function getWebsiteCodeById(int $websiteId): string
611617
{

0 commit comments

Comments
 (0)