Skip to content

Commit 547c179

Browse files
merge magento/2.4-develop into magento-trigger/elastic_spike
2 parents b0d8481 + 8a16cba commit 547c179

File tree

38 files changed

+731
-367
lines changed

38 files changed

+731
-367
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ If you are a new GitHub user, we recommend that you create your own [free github
3131
This will allow you to collaborate with the Magento 2 development team, fork the Magento 2 project and send pull requests.
3232

3333
1. Search current [listed issues](https://github.com/magento/magento2/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution.
34-
2. Review the [Contributor License Agreement](https://magento.com/legaldocuments/mca) if this is your first time contributing.
34+
2. Review the [Contributor License Agreement](https://opensource.adobe.com/cla.html) if this is your first time contributing.
3535
3. Create and test your work.
3636
4. Fork the Magento 2 repository according to the [Fork A Repository instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#pull_request).
3737
5. Once your contribution is received the Magento 2 development team will review the contribution and collaborate with you as needed.

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/Plugin/Model/ResourceModel/Config.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Plugin\Model\ResourceModel;
79

8-
use Magento\Framework\App\ObjectManager;
10+
use Magento\Eav\Model\Cache\Type;
11+
use Magento\Eav\Model\Entity\Attribute;
12+
use Magento\Framework\App\Cache\StateInterface;
13+
use Magento\Framework\App\CacheInterface;
914
use Magento\Framework\Serialize\SerializerInterface;
1015

1116
/**
@@ -21,43 +26,43 @@ class Config
2126
/**#@-*/
2227

2328
/**#@-*/
24-
protected $cache;
29+
private $cache;
2530

2631
/**
27-
* @var bool|null
32+
* @var bool
2833
*/
29-
protected $isCacheEnabled = null;
34+
private $isCacheEnabled;
3035

3136
/**
3237
* @var SerializerInterface
3338
*/
3439
private $serializer;
3540

3641
/**
37-
* @param \Magento\Framework\App\CacheInterface $cache
38-
* @param \Magento\Framework\App\Cache\StateInterface $cacheState
42+
* @param CacheInterface $cache
43+
* @param StateInterface $cacheState
3944
* @param SerializerInterface $serializer
4045
*/
4146
public function __construct(
42-
\Magento\Framework\App\CacheInterface $cache,
43-
\Magento\Framework\App\Cache\StateInterface $cacheState,
44-
SerializerInterface $serializer = null
47+
CacheInterface $cache,
48+
StateInterface $cacheState,
49+
SerializerInterface $serializer
4550
) {
4651
$this->cache = $cache;
47-
$this->isCacheEnabled = $cacheState->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
48-
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
52+
$this->isCacheEnabled = $cacheState->isEnabled(Type::TYPE_IDENTIFIER);
53+
$this->serializer = $serializer;
4954
}
5055

5156
/**
5257
* Cache attribute used in listing.
5358
*
5459
* @param \Magento\Catalog\Model\ResourceModel\Config $config
55-
* @param \Closure $proceed
60+
* @param callable $proceed
5661
* @return array
5762
*/
5863
public function aroundGetAttributesUsedInListing(
5964
\Magento\Catalog\Model\ResourceModel\Config $config,
60-
\Closure $proceed
65+
callable $proceed
6166
) {
6267
$cacheId = self::PRODUCT_LISTING_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_' . $config->getStoreId();
6368
if ($this->isCacheEnabled && ($attributes = $this->cache->load($cacheId))) {
@@ -69,8 +74,8 @@ public function aroundGetAttributesUsedInListing(
6974
$this->serializer->serialize($attributes),
7075
$cacheId,
7176
[
72-
\Magento\Eav\Model\Cache\Type::CACHE_TAG,
73-
\Magento\Eav\Model\Entity\Attribute::CACHE_TAG
77+
Type::CACHE_TAG,
78+
Attribute::CACHE_TAG
7479
]
7580
);
7681
}
@@ -81,12 +86,12 @@ public function aroundGetAttributesUsedInListing(
8186
* Cache attributes used for sorting.
8287
*
8388
* @param \Magento\Catalog\Model\ResourceModel\Config $config
84-
* @param \Closure $proceed
89+
* @param callable $proceed
8590
* @return array
8691
*/
8792
public function aroundGetAttributesUsedForSortBy(
8893
\Magento\Catalog\Model\ResourceModel\Config $config,
89-
\Closure $proceed
94+
callable $proceed
9095
) {
9196
$cacheId = self::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_'
9297
. $config->getStoreId();
@@ -99,8 +104,8 @@ public function aroundGetAttributesUsedForSortBy(
99104
$this->serializer->serialize($attributes),
100105
$cacheId,
101106
[
102-
\Magento\Eav\Model\Cache\Type::CACHE_TAG,
103-
\Magento\Eav\Model\Entity\Attribute::CACHE_TAG
107+
Type::CACHE_TAG,
108+
Attribute::CACHE_TAG
104109
]
105110
);
106111
}

0 commit comments

Comments
 (0)