Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - #27390: magento/magento2: fixes PHPDocs for module Magento_reports (by @andrewbess)
 - #27353: Add xml declaration for catalog_widget_product_list.xml file (by @Usik2203)
 - #27375: Updating link to Adobe CLA in contributing.md (by @filmaj)
 - #26538: Refactor datetime class (by @Tjitse-E)
 - #27334: MFTF: Customer Subscribes To Newsletter Subscription On StoreFront (by @DmitryTsymbal)
 - #27319: Cleanup ObjectManager usage - Magento_Catalog ViewModel,Plugin (by @Bartlomiejsz)
 - #27000: MFTF FIX: Remove Customer by e-mail does not filter by e-mail (by @lbajsarowicz)
 - #25664: #25540: Products are not displaying infront end after updating product via importing CSV. (by @p-bystritsky)
 - #27307: magento/magento2: Fixes for the schema cache.xsd (by @andrewbess)
 - #27276: Add "Admin" prefix to Test and ActionGroup (by @lbajsarowicz)
 - #22011: #22010: Updates AbstractExtensibleObject and AbstractExtensibleModel annotations (by @atwixfirster)


Fixed GitHub Issues:
 - #25540: Products are not displaying infront end after updating product via importing CSV. (reported by @Sathishkumar8731) has been fixed in #25664 by @p-bystritsky in 2.4-develop branch
   Related commits:
     1. f96d993
     2. 1dd81a4
     3. 6ad372a
     4. a070cf3
     5. 143bd5b

 - #22010: 22010 -Updates AbstractExtensibleObject and AbstractExtensibleModel annotations (reported by @atwixfirster) has been fixed in #22011 by @atwixfirster in 2.4-develop branch
   Related commits:
     1. 1a2b1ce
     2. 1a66568
     3. 764cdf9
     4. 987d713
     5. 70c5e12
     6. 852bf03
  • Loading branch information
magento-engcom-team authored Mar 25, 2020
2 parents 8ec21ff + 5bcca97 commit 8a16cba
Show file tree
Hide file tree
Showing 38 changed files with 731 additions and 367 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If you are a new GitHub user, we recommend that you create your own [free github
This will allow you to collaborate with the Magento 2 development team, fork the Magento 2 project and send pull requests.

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.
2. Review the [Contributor License Agreement](https://magento.com/legaldocuments/mca) if this is your first time contributing.
2. Review the [Contributor License Agreement](https://opensource.adobe.com/cla.html) if this is your first time contributing.
3. Create and test your work.
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).
5. Once your contribution is received the Magento 2 development team will review the contribution and collaborate with you as needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,31 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\BundleImportExport\Model\Import\Product\Type;

use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Bundle\Model\Product\Price as BundlePrice;
use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
use Magento\CatalogImportExport\Model\Import\Product;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class Bundle
* Import entity Bundle product type.
*
* @package Magento\BundleImportExport\Model\Import\Product\Type
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
{

/**
* Delimiter before product option value.
*/
const BEFORE_OPTION_VALUE_DELIMITER = ';';

/**
* Pair value separator.
*/
const PAIR_VALUE_SEPARATOR = '=';

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

/**
* Not fixed dynamic attribute.
*/
const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view';

/**
* Selection price type fixed.
*/
const SELECTION_PRICE_TYPE_FIXED = 0;

/**
* Selection price type percent.
*/
const SELECTION_PRICE_TYPE_PERCENT = 1;

/**
Expand Down Expand Up @@ -133,7 +120,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
protected $_optionTypeMapping = [
'dropdown' => 'select',
'radiobutton' => 'radio',
'checkbox' => 'checkbox',
'checkbox' => 'checkbox',
'multiselect' => 'multi',
];

Expand Down Expand Up @@ -543,7 +530,7 @@ protected function populateExistingSelections($existingOptions)
? $this->_bundleFieldMapping[$origKey]
: $origKey;
if (
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
) {
$this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key] =
$existingSelection[$origKey];
Expand Down Expand Up @@ -616,6 +603,7 @@ protected function populateInsertOptionValues(array $optionIds): array
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index']
&& $assoc['parent_id'] == $entityId) {
$option['parent_id'] = $entityId;
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
$optionValues = array_merge(
$optionValues,
$this->populateOptionValueTemplate($option, $optionId)
Expand Down Expand Up @@ -675,10 +663,7 @@ private function insertParentChildRelations()
$childIds = [];
foreach ($options as $option) {
foreach ($option['selections'] as $selection) {
if (!isset($selection['parent_product_id'])) {
if (!isset($this->_cachedSkuToProducts[$selection['sku']])) {
continue;
}
if (isset($this->_cachedSkuToProducts[$selection['sku']])) {
$childIds[] = $this->_cachedSkuToProducts[$selection['sku']];
}
}
Expand Down Expand Up @@ -717,6 +702,8 @@ protected function _initAttributes()
}
}
}

return $this;
}

/**
Expand All @@ -735,17 +722,19 @@ protected function deleteOptionsAndSelections($productIds)
$optionTable = $this->_resource->getTableName('catalog_product_bundle_option');
$optionValueTable = $this->_resource->getTableName('catalog_product_bundle_option_value');
$selectionTable = $this->_resource->getTableName('catalog_product_bundle_selection');
$valuesIds = $this->connection->fetchAssoc($this->connection->select()->from(
['bov' => $optionValueTable],
['value_id']
)->joinLeft(
['bo' => $optionTable],
'bo.option_id = bov.option_id',
['option_id']
)->where(
'parent_id IN (?)',
$productIds
));
$valuesIds = $this->connection->fetchAssoc(
$this->connection->select()->from(
['bov' => $optionValueTable],
['value_id']
)->joinLeft(
['bo' => $optionTable],
'bo.option_id = bov.option_id',
['option_id']
)->where(
'parent_id IN (?)',
$productIds
)
);
$this->connection->delete(
$optionValueTable,
$this->connection->quoteInto('value_id IN (?)', array_keys($valuesIds))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="UpdateBundleProductViaImportTest">
<annotations>
<features value="Import/Export"/>
<title value="Update Bundle product via import"/>
<description
value="Check that Bundle products are displaying on the storefront after updating product via importing CSV"/>
<severity value="MAJOR"/>
<group value="importExport"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<!-- Delete products created via import -->
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteBundleProduct">
<argument name="sku" value="Bundle"/>
</actionGroup>
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteSimpleProduct">
<argument name="sku" value="Simple"/>
</actionGroup>
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
</after>

<!-- Create Bundle product via import -->
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsCreate">
<argument name="behavior" value="Add/Update"/>
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
<argument name="importNoticeMessage" value="Created: 2, Updated: 0, Deleted: 0"/>
</actionGroup>
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterCreate"/>
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterCreate"/>

<!-- Check Bundle product is visible on the storefront-->
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterCreation">
<argument name="categoryName" value="New"/>
</actionGroup>
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
stepKey="assertBundleProductInStockAfterCreation">
<argument name="productName" value="Bundle"/>
</actionGroup>

<!-- Update Bundle product via import -->
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsUpdate">
<argument name="behavior" value="Add/Update"/>
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
<argument name="importNoticeMessage" value="Created: 0, Updated: 2, Deleted: 0"/>
</actionGroup>
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterUpdate"/>
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterUpdate"/>

<!-- Check Bundle product is still visible on the storefront-->
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterUpdate">
<argument name="categoryName" value="New"/>
</actionGroup>
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
stepKey="assertBundleProductInStockAfterUpdate">
<argument name="productName" value="Bundle"/>
</actionGroup>
</test>
</tests>
43 changes: 24 additions & 19 deletions app/code/Magento/Catalog/Plugin/Model/ResourceModel/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Plugin\Model\ResourceModel;

use Magento\Framework\App\ObjectManager;
use Magento\Eav\Model\Cache\Type;
use Magento\Eav\Model\Entity\Attribute;
use Magento\Framework\App\Cache\StateInterface;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\Serialize\SerializerInterface;

/**
Expand All @@ -21,43 +26,43 @@ class Config
/**#@-*/

/**#@-*/
protected $cache;
private $cache;

/**
* @var bool|null
* @var bool
*/
protected $isCacheEnabled = null;
private $isCacheEnabled;

/**
* @var SerializerInterface
*/
private $serializer;

/**
* @param \Magento\Framework\App\CacheInterface $cache
* @param \Magento\Framework\App\Cache\StateInterface $cacheState
* @param CacheInterface $cache
* @param StateInterface $cacheState
* @param SerializerInterface $serializer
*/
public function __construct(
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\App\Cache\StateInterface $cacheState,
SerializerInterface $serializer = null
CacheInterface $cache,
StateInterface $cacheState,
SerializerInterface $serializer
) {
$this->cache = $cache;
$this->isCacheEnabled = $cacheState->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
$this->isCacheEnabled = $cacheState->isEnabled(Type::TYPE_IDENTIFIER);
$this->serializer = $serializer;
}

/**
* Cache attribute used in listing.
*
* @param \Magento\Catalog\Model\ResourceModel\Config $config
* @param \Closure $proceed
* @param callable $proceed
* @return array
*/
public function aroundGetAttributesUsedInListing(
\Magento\Catalog\Model\ResourceModel\Config $config,
\Closure $proceed
callable $proceed
) {
$cacheId = self::PRODUCT_LISTING_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_' . $config->getStoreId();
if ($this->isCacheEnabled && ($attributes = $this->cache->load($cacheId))) {
Expand All @@ -69,8 +74,8 @@ public function aroundGetAttributesUsedInListing(
$this->serializer->serialize($attributes),
$cacheId,
[
\Magento\Eav\Model\Cache\Type::CACHE_TAG,
\Magento\Eav\Model\Entity\Attribute::CACHE_TAG
Type::CACHE_TAG,
Attribute::CACHE_TAG
]
);
}
Expand All @@ -81,12 +86,12 @@ public function aroundGetAttributesUsedInListing(
* Cache attributes used for sorting.
*
* @param \Magento\Catalog\Model\ResourceModel\Config $config
* @param \Closure $proceed
* @param callable $proceed
* @return array
*/
public function aroundGetAttributesUsedForSortBy(
\Magento\Catalog\Model\ResourceModel\Config $config,
\Closure $proceed
callable $proceed
) {
$cacheId = self::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_'
. $config->getStoreId();
Expand All @@ -99,8 +104,8 @@ public function aroundGetAttributesUsedForSortBy(
$this->serializer->serialize($attributes),
$cacheId,
[
\Magento\Eav\Model\Cache\Type::CACHE_TAG,
\Magento\Eav\Model\Entity\Attribute::CACHE_TAG
Type::CACHE_TAG,
Attribute::CACHE_TAG
]
);
}
Expand Down
Loading

0 comments on commit 8a16cba

Please sign in to comment.