Skip to content

Commit caa360b

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-prs
- merged with '2.4-develop-express-lane-prs' branch
2 parents 8b43f03 + 8c8397f commit caa360b

File tree

50 files changed

+1364
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1364
-319
lines changed

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,31 @@
66
* Copyright © Magento, Inc. All rights reserved.
77
* See COPYING.txt for license details.
88
*/
9+
910
namespace Magento\BundleImportExport\Model\Import\Product\Type;
1011

11-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
12-
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
13-
use Magento\Framework\App\ObjectManager;
1412
use Magento\Bundle\Model\Product\Price as BundlePrice;
1513
use Magento\Catalog\Model\Product\Type\AbstractType;
14+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
1615
use Magento\CatalogImportExport\Model\Import\Product;
16+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
17+
use Magento\Framework\App\ObjectManager;
1718
use Magento\Framework\App\ResourceConnection;
1819
use Magento\Framework\EntityManager\MetadataPool;
1920
use Magento\Store\Model\StoreManagerInterface;
2021

2122
/**
22-
* Class Bundle
23+
* Import entity Bundle product type.
2324
*
24-
* @package Magento\BundleImportExport\Model\Import\Product\Type
2525
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2626
*/
2727
class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
2828
{
29-
3029
/**
3130
* Delimiter before product option value.
3231
*/
3332
const BEFORE_OPTION_VALUE_DELIMITER = ';';
3433

35-
/**
36-
* Pair value separator.
37-
*/
3834
const PAIR_VALUE_SEPARATOR = '=';
3935

4036
/**
@@ -47,19 +43,10 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
4743
*/
4844
const VALUE_FIXED = 'fixed';
4945

50-
/**
51-
* Not fixed dynamic attribute.
52-
*/
5346
const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view';
5447

55-
/**
56-
* Selection price type fixed.
57-
*/
5848
const SELECTION_PRICE_TYPE_FIXED = 0;
5949

60-
/**
61-
* Selection price type percent.
62-
*/
6350
const SELECTION_PRICE_TYPE_PERCENT = 1;
6451

6552
/**
@@ -133,7 +120,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
133120
protected $_optionTypeMapping = [
134121
'dropdown' => 'select',
135122
'radiobutton' => 'radio',
136-
'checkbox' => 'checkbox',
123+
'checkbox' => 'checkbox',
137124
'multiselect' => 'multi',
138125
];
139126

@@ -543,7 +530,7 @@ protected function populateExistingSelections($existingOptions)
543530
? $this->_bundleFieldMapping[$origKey]
544531
: $origKey;
545532
if (
546-
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
533+
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
547534
) {
548535
$this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key] =
549536
$existingSelection[$origKey];
@@ -616,6 +603,7 @@ protected function populateInsertOptionValues(array $optionIds): array
616603
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index']
617604
&& $assoc['parent_id'] == $entityId) {
618605
$option['parent_id'] = $entityId;
606+
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
619607
$optionValues = array_merge(
620608
$optionValues,
621609
$this->populateOptionValueTemplate($option, $optionId)
@@ -675,10 +663,7 @@ private function insertParentChildRelations()
675663
$childIds = [];
676664
foreach ($options as $option) {
677665
foreach ($option['selections'] as $selection) {
678-
if (!isset($selection['parent_product_id'])) {
679-
if (!isset($this->_cachedSkuToProducts[$selection['sku']])) {
680-
continue;
681-
}
666+
if (isset($this->_cachedSkuToProducts[$selection['sku']])) {
682667
$childIds[] = $this->_cachedSkuToProducts[$selection['sku']];
683668
}
684669
}
@@ -717,6 +702,8 @@ protected function _initAttributes()
717702
}
718703
}
719704
}
705+
706+
return $this;
720707
}
721708

722709
/**
@@ -735,17 +722,19 @@ protected function deleteOptionsAndSelections($productIds)
735722
$optionTable = $this->_resource->getTableName('catalog_product_bundle_option');
736723
$optionValueTable = $this->_resource->getTableName('catalog_product_bundle_option_value');
737724
$selectionTable = $this->_resource->getTableName('catalog_product_bundle_selection');
738-
$valuesIds = $this->connection->fetchAssoc($this->connection->select()->from(
739-
['bov' => $optionValueTable],
740-
['value_id']
741-
)->joinLeft(
742-
['bo' => $optionTable],
743-
'bo.option_id = bov.option_id',
744-
['option_id']
745-
)->where(
746-
'parent_id IN (?)',
747-
$productIds
748-
));
725+
$valuesIds = $this->connection->fetchAssoc(
726+
$this->connection->select()->from(
727+
['bov' => $optionValueTable],
728+
['value_id']
729+
)->joinLeft(
730+
['bo' => $optionTable],
731+
'bo.option_id = bov.option_id',
732+
['option_id']
733+
)->where(
734+
'parent_id IN (?)',
735+
$productIds
736+
)
737+
);
749738
$this->connection->delete(
750739
$optionValueTable,
751740
$this->connection->quoteInto('value_id IN (?)', array_keys($valuesIds))
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="UpdateBundleProductViaImportTest">
12+
<annotations>
13+
<features value="Import/Export"/>
14+
<title value="Update Bundle product via import"/>
15+
<description
16+
value="Check that Bundle products are displaying on the storefront after updating product via importing CSV"/>
17+
<severity value="MAJOR"/>
18+
<group value="importExport"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
22+
</before>
23+
<after>
24+
<!-- Delete products created via import -->
25+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteBundleProduct">
26+
<argument name="sku" value="Bundle"/>
27+
</actionGroup>
28+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteSimpleProduct">
29+
<argument name="sku" value="Simple"/>
30+
</actionGroup>
31+
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
32+
</after>
33+
34+
<!-- Create Bundle product via import -->
35+
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsCreate">
36+
<argument name="behavior" value="Add/Update"/>
37+
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
38+
<argument name="importNoticeMessage" value="Created: 2, Updated: 0, Deleted: 0"/>
39+
</actionGroup>
40+
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterCreate"/>
41+
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterCreate"/>
42+
43+
<!-- Check Bundle product is visible on the storefront-->
44+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterCreation">
45+
<argument name="categoryName" value="New"/>
46+
</actionGroup>
47+
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
48+
stepKey="assertBundleProductInStockAfterCreation">
49+
<argument name="productName" value="Bundle"/>
50+
</actionGroup>
51+
52+
<!-- Update Bundle product via import -->
53+
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsUpdate">
54+
<argument name="behavior" value="Add/Update"/>
55+
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
56+
<argument name="importNoticeMessage" value="Created: 0, Updated: 2, Deleted: 0"/>
57+
</actionGroup>
58+
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterUpdate"/>
59+
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterUpdate"/>
60+
61+
<!-- Check Bundle product is still visible on the storefront-->
62+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterUpdate">
63+
<argument name="categoryName" value="New"/>
64+
</actionGroup>
65+
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
66+
stepKey="assertBundleProductInStockAfterUpdate">
67+
<argument name="productName" value="Bundle"/>
68+
</actionGroup>
69+
</test>
70+
</tests>

app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
1616
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1717

18+
/**
19+
* Update catalog_product_index_price table after delete or save customer group
20+
*/
1821
class CustomerGroup
1922
{
2023
/**
@@ -80,7 +83,7 @@ public function aroundSave(
8083
\Closure $proceed,
8184
GroupInterface $group
8285
) {
83-
$isGroupNew = !$group->getId();
86+
$isGroupNew = $group->getId() === null;
8487
$group = $proceed($group);
8588
if ($isGroupNew) {
8689
foreach ($this->getAffectedDimensions((string)$group->getId()) as $dimensions) {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Plugin;
7+
8+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration;
9+
use Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup;
10+
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
11+
use Magento\Customer\Api\GroupRepositoryInterface;
12+
use Magento\Customer\Model\Data\Group;
13+
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
14+
use Magento\Framework\Indexer\DimensionFactory;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
18+
/**
19+
* Test for CustomerGroup plugin
20+
*/
21+
class CustomerGroupTest extends \PHPUnit\Framework\TestCase
22+
{
23+
/**
24+
* @var ObjectManager
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var CustomerGroup
30+
*/
31+
private $model;
32+
33+
/**
34+
* @var DimensionFactory|MockObject
35+
*/
36+
private $dimensionFactory;
37+
38+
/**
39+
* @var TableMaintainer|MockObject
40+
*/
41+
private $tableMaintainerMock;
42+
43+
/**
44+
* @var DimensionModeConfiguration|MockObject
45+
*/
46+
private $dimensionModeConfiguration;
47+
48+
/**
49+
* @var \Callable
50+
*/
51+
private $proceedMock;
52+
53+
protected function setUp()
54+
{
55+
$this->objectManager = new ObjectManager($this);
56+
57+
$this->dimensionFactory = $this->createPartialMock(
58+
DimensionFactory::class,
59+
['create']
60+
);
61+
62+
$this->dimensionModeConfiguration = $this->createPartialMock(
63+
DimensionModeConfiguration::class,
64+
['getDimensionConfiguration']
65+
);
66+
67+
$this->tableMaintainerMock = $this->createPartialMock(
68+
TableMaintainer::class,
69+
['createTablesForDimensions']
70+
);
71+
72+
$this->model = $this->objectManager->getObject(
73+
CustomerGroup::class,
74+
[
75+
'dimensionFactory' => $this->dimensionFactory,
76+
'dimensionModeConfiguration' => $this->dimensionModeConfiguration,
77+
'tableMaintainer' => $this->tableMaintainerMock,
78+
]
79+
);
80+
}
81+
82+
/**
83+
* Check of call count createTablesForDimensions() method
84+
*
85+
* @param $customerGroupId
86+
* @param $callTimes
87+
*
88+
* @dataProvider aroundSaveDataProvider
89+
*/
90+
public function testAroundSave($customerGroupId, $callTimes)
91+
{
92+
$subjectMock = $this->createMock(GroupRepositoryInterface::class);
93+
$customerGroupMock = $this->createPartialMock(
94+
Group::class,
95+
['getId']
96+
);
97+
$customerGroupMock->method('getId')->willReturn($customerGroupId);
98+
$this->tableMaintainerMock->expects(
99+
$this->exactly($callTimes)
100+
)->method('createTablesForDimensions');
101+
$this->proceedMock = function ($customerGroupMock) {
102+
return $customerGroupMock;
103+
};
104+
$this->dimensionModeConfiguration->method('getDimensionConfiguration')->willReturn(
105+
[CustomerGroupDimensionProvider::DIMENSION_NAME]
106+
);
107+
$this->model->aroundSave($subjectMock, $this->proceedMock, $customerGroupMock);
108+
}
109+
110+
/**
111+
* Data provider for testAroundSave
112+
*
113+
* @return array
114+
*/
115+
public function aroundSaveDataProvider()
116+
{
117+
return [
118+
'customer_group_id = 0' => [
119+
'customer_group_id' => '0',
120+
'create_tables_call_times' => 0
121+
],
122+
'customer_group_id = 1' => [
123+
'customer_group_id' => '1',
124+
'create_tables_call_times' => 0
125+
],
126+
'customer_group_id = null' => [
127+
'customer_group_id' => null,
128+
'create_tables_call_times' => 1
129+
],
130+
];
131+
}
132+
}

0 commit comments

Comments
 (0)