Skip to content
Snippets Groups Projects
Commit e7a90e5e authored by Oleksandr Ivashchenko's avatar Oleksandr Ivashchenko
Browse files

MAGETWO-17177: mass price update doesn't affect discount price

 - Created plugin instead of old indexer functionality
parent 0efd237c
Branches
No related merge requests found
<?php
/**
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
*/
namespace Magento\CatalogRule\Plugin\Model\Product;
use Magento\Catalog\Model\Product\Action as ProductAction;
use Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor;
class Action
{
/**
* @var ProductRuleProcessor
*/
protected $productRuleProcessor;
/**
* @param ProductRuleProcessor $productRuleProcessor
*/
public function __construct(ProductRuleProcessor $productRuleProcessor)
{
$this->productRuleProcessor = $productRuleProcessor;
}
/**
* @param ProductAction $object
* @param ProductAction $result
* @return ProductAction
*
* @SuppressWarnings(PHPMD.UnusedFormatParameter)
*/
public function afterUpdateAttributes(ProductAction $object, ProductAction $result)
{
$data = $result->getAttributesData();
if (!empty($data['price'])) {
$this->productRuleProcessor->reindexList($result->getProductIds());
}
return $result;
}
}
...@@ -31,4 +31,7 @@ ...@@ -31,4 +31,7 @@
<type name="Magento\Catalog\Model\Resource\Eav\Attribute"> <type name="Magento\Catalog\Model\Resource\Eav\Attribute">
<plugin name="change_product_attribute" type="Magento\CatalogRule\Plugin\Indexer\Product\Attribute"/> <plugin name="change_product_attribute" type="Magento\CatalogRule\Plugin\Indexer\Product\Attribute"/>
</type> </type>
<type name="Magento\Catalog\Model\Product\Action">
<plugin name="price_plugin" type="Magento\CatalogRule\Plugin\Model\Product\Action"/>
</type>
</config> </config>
<?php
/**
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
*/
namespace Magento\CatalogRule\Plugin\Model\Product;
class ActionTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\CatalogRule\Plugin\Model\Product\Action */
protected $action;
/** @var \Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor|\PHPUnit_Framework_MockObject_MockObject */
protected $productRuleProcessor;
protected function setUp()
{
$this->productRuleProcessor = $this->getMockBuilder(
'Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor'
)->disableOriginalConstructor()
->setMethods(['reindexList'])
->getMock();
$this->action = new Action($this->productRuleProcessor);
}
public function testAfterUpdateAttributes()
{
$subject = $this->getMockBuilder('Magento\Catalog\Model\Product\Action')
->disableOriginalConstructor()
->setMethods([])
->getMock();
$result = $this->getMockBuilder('Magento\Catalog\Model\Product\Action')
->disableOriginalConstructor()
->setMethods(['getAttributesData', 'getProductIds'])
->getMock();
$result->expects($this->once())
->method('getAttributesData')
->willReturn([]);
$result->expects($this->never())
->method('getProductIds');
$this->productRuleProcessor->expects($this->never())
->method('reindexList');
$this->action->afterUpdateAttributes($subject, $result);
}
public function testAfterUpdateAttributesWithPrice()
{
$productIds = [1, 2, 3];
$subject = $this->getMockBuilder('Magento\Catalog\Model\Product\Action')
->disableOriginalConstructor()
->setMethods([])
->getMock();
$result = $this->getMockBuilder('Magento\Catalog\Model\Product\Action')
->disableOriginalConstructor()
->setMethods(['getAttributesData', 'getProductIds'])
->getMock();
$result->expects($this->once())
->method('getAttributesData')
->willReturn(['price' => 100]);
$result->expects($this->once())
->method('getProductIds')
->willReturn($productIds);
$this->productRuleProcessor->expects($this->once())
->method('reindexList')
->with($productIds);
$this->action->afterUpdateAttributes($subject, $result);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment