Skip to content

Commit

Permalink
Merge pull request #375 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Bugfixes

- MAGETWO-52925 Simple child product without a special price still shown as "was (original price)" #4442 #5097
- MAGETWO-55327 [FT] Filter not applied on current page in test.
- MAGETWO-56584 [FT] Custom options are not created for product in test
- MAGETWO-57535 L2 Plan fails on mainline develop branch- Build B2B-DEV-TPFX3,3 #186
- MAGETWO-56341 Maximum error count when importing because issue URL key for specified store already exists
- MAGETWO-56077 [GitHub] Unable to add more than 1 product to a cart from Wishlist #5282
- MAGETWO-55975 [FT] Cannot set date of birth in customer form
- MAGETWO-56753 [FT] Cannot click on action-select button in customers grid block
- MAGETWO-55782 [FT] Threre is no "schedule update" section in "New Category" form
- MAGETWO-57205 Attribute for Send Welcome Email From shows wrong store ID
  • Loading branch information
slavvka authored Sep 13, 2016
2 parents e6363a8 + 43fb688 commit 38a8c8f
Show file tree
Hide file tree
Showing 29 changed files with 554 additions and 144 deletions.
40 changes: 39 additions & 1 deletion app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp)

$select = $this->_connection->select()->from(
$entityTable,
$this->getNewSkuFieldsForSelect()
array_merge($this->getNewSkuFieldsForSelect(), $this->getOldSkuFieldsForSelect())
)->where(
'sku IN (?)',
array_keys($entityRowsIn)
Expand All @@ -1330,10 +1330,45 @@ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp)
$this->skuProcessor->setNewSkuData($sku, $key, $value);
}
}

$this->updateOldSku($newProducts);
}

return $this;
}

/**
* Return additional data, needed to select.
* @return array
*/
private function getOldSkuFieldsForSelect()
{
return ['type_id', 'attribute_set_id'];
}

/**
* Adds newly created products to _oldSku
* @param array $newProducts
* @return void
*/
private function updateOldSku(array $newProducts)
{
$oldSkus = [];
foreach ($newProducts as $info) {
$typeId = $info['type_id'];
$sku = $info['sku'];
$oldSkus[$sku] = [
'type_id' => $typeId,
'attr_set_id' => $info['attribute_set_id'],
$this->getProductIdentifierField() => $info[$this->getProductIdentifierField()],
'supported_type' => isset($this->_productTypeModels[$typeId]),
$this->getProductEntityLinkField() => $info[$this->getProductEntityLinkField()],
];
}

$this->_oldSku = array_replace($this->_oldSku, $oldSkus);
}

/**
* Get new SKU fields for select
*
Expand Down Expand Up @@ -1718,6 +1753,7 @@ protected function _saveProducts()
['adapter' => $this, 'bunch' => $bunch]
);
}

return $this;
}

Expand Down Expand Up @@ -2452,6 +2488,7 @@ protected function _saveValidatedBunches()
{
$source = $this->_getSource();
$source->rewind();

while ($source->valid()) {
try {
$rowData = $source->current();
Expand All @@ -2465,6 +2502,7 @@ protected function _saveValidatedBunches()
$rowData = $this->_customFieldsMapping($rowData);

$this->validateRow($rowData, $source->key());

$source->next();
}
$this->checkUrlKeyDuplicates();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Pricing\Render;

use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\View\Element\Template\Context;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
/**
* @var ConfigurableOptionsProviderInterface
*/
private $configurableOptionsProvider;

/**
* @param Context $context
* @param SaleableInterface $saleableItem
* @param PriceInterface $price
* @param RendererPool $rendererPool
* @param ConfigurableOptionsProviderInterface $configurableOptionsProvider
* @param array $data
*/
public function __construct(
Context $context,
SaleableInterface $saleableItem,
PriceInterface $price,
RendererPool $rendererPool,
ConfigurableOptionsProviderInterface $configurableOptionsProvider,
array $data = []
) {
$this->configurableOptionsProvider = $configurableOptionsProvider;
parent::__construct($context, $saleableItem, $price, $rendererPool, $data);
}

/**
* Define if the special price should be shown
*
* @return bool
*/
public function hasSpecialPrice()
{
$product = $this->getSaleableItem();
foreach ($this->configurableOptionsProvider->getProducts($product) as $subProduct) {
$regularPrice = $subProduct->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getValue();
$finalPrice = $subProduct->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();
if ($finalPrice < $regularPrice) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render;

use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
use Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox;

class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;

/**
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
*/
private $saleableItem;

/**
* @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $price;

/**
* @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject
*/
private $rendererPool;

/**
* @var ConfigurableOptionsProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $configurableOptionsProvider;

/**
* @var FinalPriceBox
*/
private $model;

protected function setUp()
{
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
->disableOriginalConstructor()
->getMock();

$this->saleableItem = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->getMock();

$this->price = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();

$this->rendererPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class)
->disableOriginalConstructor()
->getMock();

$this->configurableOptionsProvider = $this->getMockBuilder(ConfigurableOptionsProviderInterface::class)
->getMockForAbstractClass();

$this->model = new FinalPriceBox(
$this->context,
$this->saleableItem,
$this->price,
$this->rendererPool,
$this->configurableOptionsProvider
);
}

/**
* @param float $regularPrice
* @param float $finalPrice
* @param bool $expected
* @dataProvider hasSpecialPriceDataProvider
*/
public function testHasSpecialPrice(
$regularPrice,
$finalPrice,
$expected
) {
$priceMockOne = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();

$priceMockOne->expects($this->once())
->method('getValue')
->willReturn($regularPrice);

$priceMockTwo = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->getMockForAbstractClass();

$priceMockTwo->expects($this->once())
->method('getValue')
->willReturn($finalPrice);

$priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
->disableOriginalConstructor()
->getMock();

$priceInfoMock->expects($this->exactly(2))
->method('getPrice')
->willReturnMap([
[RegularPrice::PRICE_CODE, $priceMockOne],
[FinalPrice::PRICE_CODE, $priceMockTwo],
]);

$productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
->setMethods(['getPriceInfo'])
->getMockForAbstractClass();

$productMock->expects($this->exactly(2))
->method('getPriceInfo')
->willReturn($priceInfoMock);

$this->configurableOptionsProvider->expects($this->once())
->method('getProducts')
->with($this->saleableItem)
->willReturn([$productMock]);

$this->assertEquals($expected, $this->model->hasSpecialPrice());
}

/**
* @return array
*/
public function hasSpecialPriceDataProvider()
{
return [
[10., 20., false],
[10., 10., false],
[20., 10., true],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<referenceBlock name="render.product.prices">
<arguments>
<argument name="configurable" xsi:type="array">
<item name="prices" xsi:type="array">
<item name="final_price" xsi:type="array">
<item name="render_class" xsi:type="string">Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox</item>
<item name="render_template" xsi:type="string">Magento_ConfigurableProduct::product/price/final_price.phtml</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

?>

<?php
/** @var \Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox$block */

/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');

/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php if ($block->hasSpecialPrice()): ?>
<span class="special-price">
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('Special Price'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
</span>
<span class="old-price sly-old-price no-display">
<?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]); ?>
</span>
<?php else: ?>
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
<?php endif; ?>

<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?php /* @escapeNotVerified */ echo $block->getSaleableItem()->getProductUrl(); ?>" class="minimal-price-link">
<?php /* @escapeNotVerified */ echo $block->renderAmountMinimal(); ?>
</a>
<?php else:?>
<span class="minimal-price-link">
<?php /* @escapeNotVerified */ echo $block->renderAmountMinimal(); ?>
</span>
<?php endif?>
<?php endif; ?>
Loading

0 comments on commit 38a8c8f

Please sign in to comment.