Skip to content

Commit

Permalink
Merge pull request #1495 from magento-borg/MAGETWO-72469
Browse files Browse the repository at this point in the history
Merge 2.2-develop into develop
  • Loading branch information
slavvka authored Sep 15, 2017
2 parents 75155ae + 84172ef commit e649b4c
Show file tree
Hide file tree
Showing 236 changed files with 9,986 additions and 2,158 deletions.
6 changes: 3 additions & 3 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@

date_default_timezone_set('UTC');

/* Adjustment of precision value for several versions of PHP */
ini_set('precision', 15);
ini_set('serialize_precision', 15);
/* For data consistency between displaying (printing) and serialization a float number */
ini_set('precision', 14);
ini_set('serialize_precision', 14);
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@

use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;

class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\AbstractPlugin
class Import
{
/**
* @var \Magento\Framework\Indexer\IndexerRegistry
*/
private $indexerRegistry;

/**
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
*/
public function __construct(\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry)
{
$this->indexerRegistry = $indexerRegistry;
}

/**
* After import handler
*
Expand All @@ -18,9 +31,7 @@ class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\Abstrac
*/
public function afterSaveAdvancedPricing(AdvancedPricing $subject)
{
if (!$this->getPriceIndexer()->isScheduled()) {
$this->invalidateIndexer();
}
$this->invalidateIndexer();
}

/**
Expand All @@ -32,18 +43,19 @@ public function afterSaveAdvancedPricing(AdvancedPricing $subject)
*/
public function afterDeleteAdvancedPricing(AdvancedPricing $subject)
{
if (!$this->getPriceIndexer()->isScheduled()) {
$this->invalidateIndexer();
}
$this->invalidateIndexer();
}

/**
* Get price indexer
* Invalidate indexer
*
* @return \Magento\Framework\Indexer\IndexerInterface
* @return void
*/
protected function getPriceIndexer()
private function invalidateIndexer()
{
return $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID);
$priceIndexer = $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID);
if (!$priceIndexer->isScheduled()) {
$priceIndexer->invalidate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ class ImportTest extends \PHPUnit\Framework\TestCase
/**
* @var \Magento\Framework\Indexer\IndexerInterface |\PHPUnit_Framework_MockObject_MockObject
*/
protected $indexer;
private $indexer;

/**
* @var Import |\PHPUnit_Framework_MockObject_MockObject
*/
protected $import;
private $import;

/**
* @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing|\PHPUnit_Framework_MockObject_MockObject
*/
protected $advancedPricing;
private $advancedPricing;

/**
* @var \Magento\Framework\Indexer\IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject
*/
private $indexerRegistry;

protected function setUp()
{
Expand All @@ -33,29 +38,58 @@ protected function setUp()
'',
false
);
$this->import = $this->createPartialMock(
\Magento\AdvancedPricingImportExport\Model\Indexer\Product\Price\Plugin\Import::class,
['getPriceIndexer', 'invalidateIndexer']
$this->indexerRegistry = $this->createMock(
\Magento\Framework\Indexer\IndexerRegistry::class
);
$this->import = new \Magento\AdvancedPricingImportExport\Model\Indexer\Product\Price\Plugin\Import(
$this->indexerRegistry
);
$this->advancedPricing = $this->createMock(
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class
);
$this->import->expects($this->any())->method('getPriceIndexer')->willReturn($this->indexer);
$this->indexerRegistry->expects($this->any())
->method('get')
->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)
->willReturn($this->indexer);
}

public function testAfterSaveAdvancedPricing()
public function testAfterSaveReindexIsOnSave()
{
$this->indexer->expects($this->once())->method('isScheduled')->willReturn(false);
$this->import->expects($this->once())->method('invalidateIndexer');
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(false);
$this->indexer->expects($this->once())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}

public function testAfterSaveReindexIsOnSchedule()
{
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(true);
$this->indexer->expects($this->never())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}

public function testAfterDeleteAdvancedPricing()
public function testAfterDeleteReindexIsOnSave()
{
$this->indexer->expects($this->once())->method('isScheduled')->willReturn(false);
$this->import->expects($this->once())->method('invalidateIndexer');
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(false);
$this->indexer->expects($this->once())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}

public function testAfterDeleteReindexIsOnSchedule()
{
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(true);
$this->indexer->expects($this->never())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ $numColumns = sizeof($block->getColumns());
<?php endif; ?>

<?php if (strpos($block->getRowClickCallback(), 'order.') !== false): ?>
deps.push('Magento_Sales/order/create/form')
deps.push('Magento_Sales/order/create/form');
deps.push('jquery');
<?php endif; ?>

deps.push('mage/adminhtml/grid');
Expand Down
23 changes: 16 additions & 7 deletions app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,28 @@ public function providerForGetterTierPriceList()
/**
* @dataProvider providerForTestGetSavePercent
*/
public function testGetSavePercent($baseAmount, $savePercent)
public function testGetSavePercent($baseAmount, $tierPrice, $savePercent)
{
$basePrice = 10.;
/** @var \Magento\Framework\Pricing\Amount\AmountInterface|\PHPUnit_Framework_MockObject_MockObject $amount */
$amount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
$amount->expects($this->once())->method('getBaseAmount')->willReturn($baseAmount);
$amount->expects($this->any())
->method('getValue')
->will($this->returnValue($tierPrice));

$priceAmount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
$priceAmount->expects($this->any())
->method('getValue')
->will($this->returnValue($baseAmount));

$price = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
$price->expects($this->any())
->method('getValue')
->will($this->returnValue($basePrice));
->method('getAmount')
->will($this->returnValue($priceAmount));

$this->priceInfo->expects($this->any())
->method('getPrice')
->will($this->returnValue($price));

$this->assertEquals($savePercent, $this->model->getSavePercent($amount));
}

Expand All @@ -202,8 +211,8 @@ public function testGetSavePercent($baseAmount, $savePercent)
public function providerForTestGetSavePercent()
{
return [
'no fraction' => [9.0000, 10],
'lower half' => [9.1234, 9],
'no fraction' => [9.0000, 8.1, 10],
'lower half' => [9.1234, 8.3, 9],
];
}
}
32 changes: 15 additions & 17 deletions app/code/Magento/Catalog/Controller/Adminhtml/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ abstract class Category extends \Magento\Backend\App\Action
const ADMIN_RESOURCE = 'Magento_Catalog::categories';

/**
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
*/
private $dateTimeFilter;
protected $dateFilter;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date|null $dateFilter
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter = null
) {
$this->dateFilter = $dateFilter;
parent::__construct($context);
}

/**
* Initialize requested category and put it into registry.
Expand Down Expand Up @@ -125,20 +137,6 @@ protected function ajaxRequestResponse($category, $resultPage)
return $resultJson;
}

/**
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
*
* @deprecated 101.0.0
*/
private function getDateTimeFilter()
{
if ($this->dateTimeFilter === null) {
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
}
return $this->dateTimeFilter;
}

/**
* Datetime data preprocessing
*
Expand All @@ -154,7 +152,7 @@ protected function dateTimePreprocessing($category, $postData)
foreach ($attributes as $attrKey => $attribute) {
if ($attribute->getBackend()->getType() == 'datetime') {
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
$dateFieldFilters[$attrKey] = $this->dateFilter;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
* @param StoreManagerInterface $storeManager
* @param \Magento\Eav\Model\Config $eavConfig
*/
Expand All @@ -69,10 +70,11 @@ public function __construct(
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
StoreManagerInterface $storeManager,
\Magento\Eav\Model\Config $eavConfig = null
) {
parent::__construct($context);
parent::__construct($context, $dateFilter);
$this->resultRawFactory = $resultRawFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->layoutFactory = $layoutFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks;
use Magento\Catalog\Model\Product\Link\Resolver as LinkResolver;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\AttributeFilter;

/**
* @api
Expand Down Expand Up @@ -84,6 +85,11 @@ class Helper
*/
private $linkTypeProvider;

/**
* @var AttributeFilter
*/
private $attributeFilter;

/**
* Constructor
*
Expand All @@ -97,6 +103,7 @@ class Helper
* @param \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory|null $productLinkFactory
* @param \Magento\Catalog\Api\ProductRepositoryInterface|null $productRepository
* @param \Magento\Catalog\Model\Product\LinkTypeProvider|null $linkTypeProvider
* @param AttributeFilter|null $attributeFilter
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -109,7 +116,8 @@ public function __construct(
\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory = null,
\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory $productLinkFactory = null,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository = null,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null,
AttributeFilter $attributeFilter = null
) {
$this->request = $request;
$this->storeManager = $storeManager;
Expand All @@ -125,6 +133,8 @@ public function __construct(
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$this->linkTypeProvider = $linkTypeProvider ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Model\Product\LinkTypeProvider::class);
$this->attributeFilter = $attributeFilter ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(AttributeFilter::class);
}

/**
Expand Down Expand Up @@ -187,6 +197,11 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
$productOptions = [];
}
$productData['tier_price'] = isset($productData['tier_price']) ? $productData['tier_price'] : [];

$useDefaults = (array)$this->request->getPost('use_default', []);

$productData = $this->attributeFilter->prepareProductAttributes($product, $productData, $useDefaults);

$product->addData($productData);

if ($wasLockedMedia) {
Expand All @@ -196,8 +211,6 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
/**
* Check "Use Default Value" checkboxes values
*/
$useDefaults = (array)$this->request->getPost('use_default', []);

foreach ($useDefaults as $attributeCode => $useDefaultState) {
if ($useDefaultState) {
$product->setData($attributeCode, null);
Expand Down
Loading

0 comments on commit e649b4c

Please sign in to comment.