Skip to content

Commit 6a8d195

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-60205' into pull-second
2 parents 4bc9fcc + eee05a3 commit 6a8d195

File tree

15 files changed

+345
-32
lines changed

15 files changed

+345
-32
lines changed

app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php

+20-11
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,8 @@ protected function _toHtml()
2929
}
3030

3131
$result = parent::_toHtml();
32-
33-
try {
34-
/** @var MsrpPrice $msrpPriceType */
35-
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
36-
} catch (\InvalidArgumentException $e) {
37-
$this->_logger->critical($e);
38-
return $this->wrapResult($result);
39-
}
40-
4132
//Renders MSRP in case it is enabled
42-
$product = $this->getSaleableItem();
43-
if ($msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product)) {
33+
if ($this->isMsrpPriceApplicable()) {
4434
/** @var BasePriceBox $msrpBlock */
4535
$msrpBlock = $this->rendererPool->createPriceRender(
4636
MsrpPrice::PRICE_CODE,
@@ -56,6 +46,25 @@ protected function _toHtml()
5646
return $this->wrapResult($result);
5747
}
5848

49+
/**
50+
* Check is MSRP applicable for the current product.
51+
*
52+
* @return bool
53+
*/
54+
protected function isMsrpPriceApplicable()
55+
{
56+
try {
57+
/** @var MsrpPrice $msrpPriceType */
58+
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
59+
} catch (\InvalidArgumentException $e) {
60+
$this->_logger->critical($e);
61+
return false;
62+
}
63+
64+
$product = $this->getSaleableItem();
65+
return $msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product);
66+
}
67+
5968
/**
6069
* Wrap with standard required container
6170
*

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public function getJsonConfig()
193193
$config = [
194194
'attributes' => $attributesData['attributes'],
195195
'template' => str_replace('%s', '<%- data.price %>', $store->getCurrentCurrency()->getOutputFormat()),
196+
'currencyFormat' => $store->getCurrentCurrency()->getOutputFormat(),
196197
'optionPrices' => $this->getOptionPrices(),
197198
'prices' => [
198199
'oldPrice' => [
@@ -229,7 +230,17 @@ protected function getOptionPrices()
229230
{
230231
$prices = [];
231232
foreach ($this->getAllowProducts() as $product) {
233+
$tierPrices = [];
232234
$priceInfo = $product->getPriceInfo();
235+
$tierPriceModel = $priceInfo->getPrice('tier_price');
236+
$tierPricesList = $tierPriceModel->getTierPriceList();
237+
foreach ($tierPricesList as $tierPrice) {
238+
$tierPrices[] = [
239+
'qty' => $this->_registerJsPrice($tierPrice['price_qty']),
240+
'price' => $this->_registerJsPrice($tierPrice['price']->getValue()),
241+
'percentage' => $this->_registerJsPrice($tierPriceModel->getSavePercent($tierPrice['price'])),
242+
];
243+
}
233244

234245
$prices[$product->getId()] =
235246
[
@@ -247,8 +258,9 @@ protected function getOptionPrices()
247258
'amount' => $this->_registerJsPrice(
248259
$priceInfo->getPrice('final_price')->getAmount()->getValue()
249260
),
250-
]
251-
];
261+
],
262+
'tierPrices' => $tierPrices,
263+
];
252264
}
253265
return $prices;
254266
}
@@ -263,4 +275,14 @@ protected function _registerJsPrice($price)
263275
{
264276
return str_replace(',', '.', $price);
265277
}
278+
279+
/**
280+
* Should we generate "As low as" block or not
281+
*
282+
* @return bool
283+
*/
284+
public function showMinimalPrice()
285+
{
286+
return true;
287+
}
266288
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Pricing\Render;
7+
8+
/**
9+
* Responsible for displaying tier price box on configurable product page.
10+
*
11+
* @package Magento\ConfigurableProduct\Pricing\Render
12+
*/
13+
class TierPriceBox extends FinalPriceBox
14+
{
15+
/**
16+
* @inheritdoc
17+
*/
18+
public function toHtml()
19+
{
20+
// Hide tier price block in case of MSRP.
21+
if (!$this->isMsrpPriceApplicable()) {
22+
return parent::toHtml();
23+
}
24+
}
25+
}

app/code/Magento/ConfigurableProduct/view/base/layout/catalog_product_prices.xml

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<arguments>
1111
<argument name="configurable" xsi:type="array">
1212
<item name="prices" xsi:type="array">
13+
<item name="tier_price" xsi:type="array">
14+
<item name="render_class" xsi:type="string">Magento\ConfigurableProduct\Pricing\Render\TierPriceBox</item>
15+
<item name="render_template" xsi:type="string">Magento_ConfigurableProduct::product/price/tier_price.phtml</item>
16+
</item>
1317
<item name="final_price" xsi:type="array">
1418
<item name="render_class" xsi:type="string">Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox</item>
1519
<item name="render_template" xsi:type="string">Magento_ConfigurableProduct::product/price/final_price.phtml</item>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
?>
8+
<script type="text/x-magento-template" id="tier-prices-template">
9+
<ul class="prices-tier items">
10+
<% _.each(tierPrices, function(item, key) { %>
11+
<% var priceStr = '<span class="price-container price-tier_price">'
12+
+ '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
13+
+ ' data-price-type=""' + ' class="price-wrapper ">'
14+
+ '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
15+
+ '</span>'
16+
+ '</span>'; %>
17+
<li class="item">
18+
<%= $t('Buy %1 for %2 each and').replace('%1', item.qty).replace('%2', priceStr) %>
19+
<strong class="benefit">
20+
<%= $t('save') %><span class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
21+
</strong>
22+
</li>
23+
<% }); %>
24+
</ul>
25+
</script>
26+
<div data-role="tier-price-block"></div>

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ define([
77
'jquery',
88
'underscore',
99
'mage/template',
10+
'mage/translate',
1011
'priceUtils',
1112
'priceBox',
1213
'jquery/ui',
1314
'jquery/jquery.parsequery'
14-
], function ($, _, mageTemplate) {
15+
], function ($, _, mageTemplate, $t, priceUtils) {
1516
'use strict';
1617

1718
$.widget('mage.configurable', {
@@ -38,7 +39,10 @@ define([
3839
*
3940
* @type {String}
4041
*/
41-
gallerySwitchStrategy: 'replace'
42+
gallerySwitchStrategy: 'replace',
43+
tierPriceTemplateSelector: '#tier-prices-template',
44+
tierPriceBlockSelector: '[data-role="tier-price-block"]',
45+
tierPriceTemplate: ''
4246
},
4347

4448
/**
@@ -84,6 +88,7 @@ define([
8488
options.priceFormat = priceBoxOptions.priceFormat;
8589
}
8690
options.optionTemplate = mageTemplate(options.optionTemplate);
91+
options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
8792

8893
options.settings = options.spConfig.containerId ?
8994
$(options.spConfig.containerId).find(options.superSelector) :
@@ -259,6 +264,7 @@ define([
259264
}
260265
this._reloadPrice();
261266
this._displayRegularPriceBlock(this.simpleProduct);
267+
this._displayTierPriceBlock(this.simpleProduct);
262268
this._changeProductImage();
263269
},
264270

@@ -513,6 +519,31 @@ define([
513519
var galleryObject = element.data('gallery');
514520

515521
this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
522+
},
523+
524+
/**
525+
* Show or hide tier price block
526+
*
527+
* @param {*} optionId
528+
* @private
529+
*/
530+
_displayTierPriceBlock: function (optionId) {
531+
if (typeof optionId != 'undefined' &&
532+
this.options.spConfig.optionPrices[optionId].tierPrices != []
533+
) {
534+
var options = this.options.spConfig.optionPrices[optionId];
535+
if (this.options.tierPriceTemplate) {
536+
var tierPriceHtml = mageTemplate(this.options.tierPriceTemplate, {
537+
'tierPrices': options.tierPrices,
538+
'$t': $t,
539+
'currencyFormat': this.options.spConfig.currencyFormat,
540+
'priceUtils': priceUtils
541+
});
542+
$(this.options.tierPriceBlockSelector).html(tierPriceHtml).show();
543+
}
544+
} else {
545+
$(this.options.tierPriceBlockSelector).hide();
546+
}
516547
}
517548
});
518549

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
define([
77
'jquery',
88
'underscore',
9+
'mage/template',
910
'mage/smart-keyboard-handler',
11+
'mage/translate',
12+
'priceUtils',
1013
'jquery/ui',
1114
'jquery/jquery.parsequery',
1215
'mage/validation/validation'
13-
], function ($, _, keyboardHandler) {
16+
], function ($, _, mageTemplate, keyboardHandler, $t, priceUtils) {
1417
'use strict';
1518

1619
/**
@@ -254,7 +257,13 @@ define([
254257
gallerySwitchStrategy: 'replace',
255258

256259
// whether swatches are rendered in product list or on product page
257-
inProductList: false
260+
inProductList: false,
261+
262+
// tier prise selectors start
263+
tierPriceTemplateSelector: '#tier-prices-template',
264+
tierPriceBlockSelector: '[data-role="tier-price-block"]',
265+
tierPriceTemplate: ''
266+
// tier prise selectors end
258267
},
259268

260269
/**
@@ -279,6 +288,7 @@ define([
279288
} else {
280289
console.log('SwatchRenderer: No input data received');
281290
}
291+
this.options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
282292
},
283293

284294
/**
@@ -809,7 +819,8 @@ define([
809819
$product = $widget.element.parents($widget.options.selectorProduct),
810820
$productPrice = $product.find(this.options.selectorProductPrice),
811821
options = _.object(_.keys($widget.optionsMap), {}),
812-
result;
822+
result,
823+
tierPriceHtml;
813824

814825
$widget.element.find('.' + $widget.options.classes.attributeClass + '[option-selected]').each(function () {
815826
var attributeId = $(this).attr('attribute-id');
@@ -825,6 +836,23 @@ define([
825836
'prices': $widget._getPrices(result, $productPrice.priceBox('option').prices)
826837
}
827838
);
839+
840+
if (result.tierPrices.length) {
841+
if (this.options.tierPriceTemplate) {
842+
tierPriceHtml = mageTemplate(
843+
this.options.tierPriceTemplate,
844+
{
845+
'tierPrices': result.tierPrices,
846+
'$t': $t,
847+
'currencyFormat': this.options.jsonConfig.currencyFormat,
848+
'priceUtils': priceUtils
849+
}
850+
);
851+
$(this.options.tierPriceBlockSelector).html(tierPriceHtml).show();
852+
}
853+
} else {
854+
$(this.options.tierPriceBlockSelector).hide();
855+
}
828856
},
829857

830858
/**

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class AssertProductPage extends AbstractAssertForm
3131
*/
3232
protected $product;
3333

34+
/**
35+
* @var CatalogProductView
36+
*/
37+
protected $pageView;
38+
3439
/**
3540
* Assert that displayed product data on product page(front-end) equals passed from fixture:
3641
* 1. Product Name
@@ -53,6 +58,7 @@ public function processAssert(
5358
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
5459

5560
$this->product = $product;
61+
$this->pageView = $catalogProductView;
5662
$this->productView = $catalogProductView->getViewBlock();
5763

5864
$errors = $this->verify();

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple/CheckoutData.xml

+8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@
137137
</field>
138138
</dataset>
139139

140+
<dataset name="simple_order_tier_price_5">
141+
<field name="qty" xsi:type="string">5</field>
142+
<field name="cartItem" xsi:type="array">
143+
<item name="price" xsi:type="string">40</item>
144+
<item name="subtotal" xsi:type="string">40</item>
145+
</field>
146+
</dataset>
147+
140148
<dataset name="simple_order_10_dollar_product">
141149
<field name="qty" xsi:type="string">1</field>
142150
<field name="cartItem" xsi:type="array">

0 commit comments

Comments
 (0)