Skip to content

Commit

Permalink
MAGETWO-52925: Simple child product without a special price still sho…
Browse files Browse the repository at this point in the history
…wn as "was (original price)" #4442 #5097
  • Loading branch information
Sergey Semenov committed Aug 30, 2016
1 parent 3bcc1c9 commit 10fc55c
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 1 deletion.
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,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 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; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ define([
'<% } %>',
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
mediaGalleryInitial: null,
regularPriceSelector: '.old-price',
onlyMainImg: false
},

Expand Down Expand Up @@ -246,6 +247,7 @@ define([
this._resetChildren(element);
}
this._reloadPrice();
this._displayRegularPriceBlock(this.simpleProduct);
this._changeProductImage();
},

Expand Down Expand Up @@ -442,7 +444,7 @@ define([
},

/**
* Returns pracies for configured products
* Returns prices for configured products
*
* @param {*} config - Products configuration
* @returns {*}
Expand Down Expand Up @@ -485,6 +487,23 @@ define([
undefined :
_.first(config.allowedProducts);

},

/**
* Show or hide regular price block
*
* @param {*} optionId
* @private
*/
_displayRegularPriceBlock: function (optionId) {
if (typeof optionId != 'undefined'
&& this.options.spConfig.optionPrices[optionId].oldPrice.amount
!= this.options.spConfig.optionPrices[optionId].finalPrice.amount
) {
$(this.options.regularPriceSelector).show();
} else {
$(this.options.regularPriceSelector).hide();
}
}

});
Expand Down

0 comments on commit 10fc55c

Please sign in to comment.