-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-8051…
…4-PR-11155
- Loading branch information
Showing
6 changed files
with
238 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/code/Magento/CatalogInventory/Model/Plugin/ReindexUpdatedProducts.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogInventory\Model\Plugin; | ||
|
||
use Magento\Catalog\Model\Product\Action as ProductAction; | ||
|
||
/** | ||
* Plugin for Magento\Catalog\Model\Product\Action | ||
*/ | ||
class ReindexUpdatedProducts | ||
{ | ||
/** | ||
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor | ||
*/ | ||
private $indexerProcessor; | ||
|
||
/** | ||
* @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor | ||
*/ | ||
public function __construct(\Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor) | ||
{ | ||
$this->indexerProcessor = $indexerProcessor; | ||
} | ||
|
||
/** | ||
* Reindex on product attribute mass change | ||
* | ||
* @param ProductAction $subject | ||
* @param ProductAction $action | ||
* @param array $productIds | ||
* @return ProductAction | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterUpdateAttributes( | ||
ProductAction $subject, | ||
ProductAction $action, | ||
$productIds | ||
) { | ||
$this->indexerProcessor->reindexList(array_unique($productIds)); | ||
return $action; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped_with_simple.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\Product\Type; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\GroupedProduct\Model\Product\Type\Grouped; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = Bootstrap::getObjectManager() | ||
->get(ProductRepositoryInterface::class); | ||
|
||
$productLinkFactory = Bootstrap::getObjectManager() | ||
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class); | ||
$productIds = ['11', '22']; | ||
|
||
foreach ($productIds as $productId) { | ||
/** @var $product Product */ | ||
$product = Bootstrap::getObjectManager()->create(Product::class); | ||
$product->setTypeId(Type::TYPE_SIMPLE) | ||
->setId($productId) | ||
->setWebsiteIds([1]) | ||
->setAttributeSetId(4) | ||
->setName('Simple ' . $productId) | ||
->setSku('simple_' . $productId) | ||
->setPrice(100) | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]); | ||
|
||
$linkedProducts[] = $productRepository->save($product); | ||
} | ||
|
||
/** @var $product Product */ | ||
$product = Bootstrap::getObjectManager()->create(Product::class); | ||
|
||
$product->setTypeId(Grouped::TYPE_CODE) | ||
->setId(1) | ||
->setWebsiteIds([1]) | ||
->setAttributeSetId(4) | ||
->setName('Grouped Product') | ||
->setSku('grouped') | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]); | ||
|
||
foreach ($linkedProducts as $linkedProduct) { | ||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */ | ||
$productLink = $productLinkFactory->create(); | ||
$productLink->setSku($product->getSku()) | ||
->setLinkType('associated') | ||
->setLinkedProductSku($linkedProduct->getSku()) | ||
->setLinkedProductType($linkedProduct->getTypeId()) | ||
->getExtensionAttributes() | ||
->setQty(1); | ||
$newLinks[] = $productLink; | ||
} | ||
|
||
$product->setProductLinks($newLinks); | ||
|
||
$productRepository->save($product); |
34 changes: 34 additions & 0 deletions
34
...egration/testsuite/Magento/GroupedProduct/_files/product_grouped_with_simple_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
|
||
/** @var \Magento\Framework\Registry $registry */ | ||
$registry = $objectManager->get(\Magento\Framework\Registry::class); | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
|
||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ | ||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() | ||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
|
||
$skuList = ['simple_11', 'simple_22', 'grouped']; | ||
foreach ($skuList as $sku) { | ||
try { | ||
$product = $productRepository->get($sku, false, null, true); | ||
|
||
$stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class); | ||
$stockStatus->load($product->getEntityId(), 'product_id'); | ||
$stockStatus->delete(); | ||
|
||
$productRepository->delete($product); | ||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) { | ||
//Product already removed | ||
} | ||
} | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |