Skip to content

Commit

Permalink
Merge remote-tracking branch 'magento2/develop' into PR-11082016
Browse files Browse the repository at this point in the history
  • Loading branch information
viktym committed Nov 28, 2016
2 parents d6df71e + d491a45 commit eeb13d7
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 32 deletions.
31 changes: 20 additions & 11 deletions app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@ protected function _toHtml()
}

$result = parent::_toHtml();

try {
/** @var MsrpPrice $msrpPriceType */
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
} catch (\InvalidArgumentException $e) {
$this->_logger->critical($e);
return $this->wrapResult($result);
}

//Renders MSRP in case it is enabled
$product = $this->getSaleableItem();
if ($msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product)) {
if ($this->isMsrpPriceApplicable()) {
/** @var BasePriceBox $msrpBlock */
$msrpBlock = $this->rendererPool->createPriceRender(
MsrpPrice::PRICE_CODE,
Expand All @@ -56,6 +46,25 @@ protected function _toHtml()
return $this->wrapResult($result);
}

/**
* Check is MSRP applicable for the current product.
*
* @return bool
*/
protected function isMsrpPriceApplicable()
{
try {
/** @var MsrpPrice $msrpPriceType */
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
} catch (\InvalidArgumentException $e) {
$this->_logger->critical($e);
return false;
}

$product = $this->getSaleableItem();
return $msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product);
}

/**
* Wrap with standard required container
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function getJsonConfig()
$config = [
'attributes' => $attributesData['attributes'],
'template' => str_replace('%s', '<%- data.price %>', $store->getCurrentCurrency()->getOutputFormat()),
'currencyFormat' => $store->getCurrentCurrency()->getOutputFormat(),
'optionPrices' => $this->getOptionPrices(),
'prices' => [
'oldPrice' => [
Expand Down Expand Up @@ -229,7 +230,17 @@ protected function getOptionPrices()
{
$prices = [];
foreach ($this->getAllowProducts() as $product) {
$tierPrices = [];
$priceInfo = $product->getPriceInfo();
$tierPriceModel = $priceInfo->getPrice('tier_price');
$tierPricesList = $tierPriceModel->getTierPriceList();
foreach ($tierPricesList as $tierPrice) {
$tierPrices[] = [
'qty' => $this->_registerJsPrice($tierPrice['price_qty']),
'price' => $this->_registerJsPrice($tierPrice['price']->getValue()),
'percentage' => $this->_registerJsPrice($tierPriceModel->getSavePercent($tierPrice['price'])),
];
}

$prices[$product->getId()] =
[
Expand All @@ -247,8 +258,9 @@ protected function getOptionPrices()
'amount' => $this->_registerJsPrice(
$priceInfo->getPrice('final_price')->getAmount()->getValue()
),
]
];
],
'tierPrices' => $tierPrices,
];
}
return $prices;
}
Expand All @@ -263,4 +275,14 @@ protected function _registerJsPrice($price)
{
return str_replace(',', '.', $price);
}

/**
* Should we generate "As low as" block or not
*
* @return bool
*/
public function showMinimalPrice()
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Pricing\Render;

/**
* Responsible for displaying tier price box on configurable product page.
*
* @package Magento\ConfigurableProduct\Pricing\Render
*/
class TierPriceBox extends FinalPriceBox
{
/**
* @inheritdoc
*/
public function toHtml()
{
// Hide tier price block in case of MSRP.
if (!$this->isMsrpPriceApplicable()) {
return parent::toHtml();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<arguments>
<argument name="configurable" xsi:type="array">
<item name="prices" xsi:type="array">
<item name="tier_price" xsi:type="array">
<item name="render_class" xsi:type="string">Magento\ConfigurableProduct\Pricing\Render\TierPriceBox</item>
<item name="render_template" xsi:type="string">Magento_ConfigurableProduct::product/price/tier_price.phtml</item>
</item>
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

?>
<script type="text/x-magento-template" id="tier-prices-template">
<ul class="prices-tier items">
<% _.each(tierPrices, function(item, key) { %>
<% var priceStr = '<span class="price-container price-tier_price">'
+ '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
+ ' data-price-type=""' + ' class="price-wrapper ">'
+ '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
+ '</span>'
+ '</span>'; %>
<li class="item">
<%= $t('Buy %1 for %2 each and').replace('%1', item.qty).replace('%2', priceStr) %>
<strong class="benefit">
<%= $t('save') %><span class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
</strong>
</li>
<% }); %>
</ul>
</script>
<div data-role="tier-price-block"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ define([
'jquery',
'underscore',
'mage/template',
'mage/translate',
'priceUtils',
'priceBox',
'jquery/ui',
'jquery/jquery.parsequery'
], function ($, _, mageTemplate) {
], function ($, _, mageTemplate, $t, priceUtils) {
'use strict';

$.widget('mage.configurable', {
Expand All @@ -38,7 +39,10 @@ define([
*
* @type {String}
*/
gallerySwitchStrategy: 'replace'
gallerySwitchStrategy: 'replace',
tierPriceTemplateSelector: '#tier-prices-template',
tierPriceBlockSelector: '[data-role="tier-price-block"]',
tierPriceTemplate: ''
},

/**
Expand Down Expand Up @@ -84,6 +88,7 @@ define([
options.priceFormat = priceBoxOptions.priceFormat;
}
options.optionTemplate = mageTemplate(options.optionTemplate);
options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();

options.settings = options.spConfig.containerId ?
$(options.spConfig.containerId).find(options.superSelector) :
Expand Down Expand Up @@ -259,6 +264,7 @@ define([
}
this._reloadPrice();
this._displayRegularPriceBlock(this.simpleProduct);
this._displayTierPriceBlock(this.simpleProduct);
this._changeProductImage();
},

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

this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
},

/**
* Show or hide tier price block
*
* @param {*} optionId
* @private
*/
_displayTierPriceBlock: function (optionId) {
if (typeof optionId != 'undefined' &&
this.options.spConfig.optionPrices[optionId].tierPrices != []
) {
var options = this.options.spConfig.optionPrices[optionId];
if (this.options.tierPriceTemplate) {
var tierPriceHtml = mageTemplate(this.options.tierPriceTemplate, {
'tierPrices': options.tierPrices,
'$t': $t,
'currencyFormat': this.options.spConfig.currencyFormat,
'priceUtils': priceUtils
});
$(this.options.tierPriceBlockSelector).html(tierPriceHtml).show();
}
} else {
$(this.options.tierPriceBlockSelector).hide();
}
}
});

Expand Down
34 changes: 31 additions & 3 deletions app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
define([
'jquery',
'underscore',
'mage/template',
'mage/smart-keyboard-handler',
'mage/translate',
'priceUtils',
'jquery/ui',
'jquery/jquery.parsequery',
'mage/validation/validation'
], function ($, _, keyboardHandler) {
], function ($, _, mageTemplate, keyboardHandler, $t, priceUtils) {
'use strict';

/**
Expand Down Expand Up @@ -254,7 +257,13 @@ define([
gallerySwitchStrategy: 'replace',

// whether swatches are rendered in product list or on product page
inProductList: false
inProductList: false,

// tier prise selectors start
tierPriceTemplateSelector: '#tier-prices-template',
tierPriceBlockSelector: '[data-role="tier-price-block"]',
tierPriceTemplate: ''
// tier prise selectors end
},

/**
Expand All @@ -279,6 +288,7 @@ define([
} else {
console.log('SwatchRenderer: No input data received');
}
this.options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
},

/**
Expand Down Expand Up @@ -809,7 +819,8 @@ define([
$product = $widget.element.parents($widget.options.selectorProduct),
$productPrice = $product.find(this.options.selectorProductPrice),
options = _.object(_.keys($widget.optionsMap), {}),
result;
result,
tierPriceHtml;

$widget.element.find('.' + $widget.options.classes.attributeClass + '[option-selected]').each(function () {
var attributeId = $(this).attr('attribute-id');
Expand All @@ -825,6 +836,23 @@ define([
'prices': $widget._getPrices(result, $productPrice.priceBox('option').prices)
}
);

if (result.tierPrices.length) {
if (this.options.tierPriceTemplate) {
tierPriceHtml = mageTemplate(
this.options.tierPriceTemplate,
{
'tierPrices': result.tierPrices,
'$t': $t,
'currencyFormat': this.options.jsonConfig.currencyFormat,
'priceUtils': priceUtils
}
);
$(this.options.tierPriceBlockSelector).html(tierPriceHtml).show();
}
} else {
$(this.options.tierPriceBlockSelector).hide();
}
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class AssertProductPage extends AbstractAssertForm
*/
protected $product;

/**
* @var CatalogProductView
*/
protected $pageView;

/**
* Assert that displayed product data on product page(front-end) equals passed from fixture:
* 1. Product Name
Expand All @@ -53,6 +58,7 @@ public function processAssert(
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');

$this->product = $product;
$this->pageView = $catalogProductView;
$this->productView = $catalogProductView->getViewBlock();

$errors = $this->verify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
</field>
</dataset>

<dataset name="simple_order_tier_price_5">
<field name="qty" xsi:type="string">5</field>
<field name="cartItem" xsi:type="array">
<item name="price" xsi:type="string">40</item>
<item name="subtotal" xsi:type="string">40</item>
</field>
</dataset>

<dataset name="simple_order_10_dollar_product">
<field name="qty" xsi:type="string">1</field>
<field name="cartItem" xsi:type="array">
Expand Down
Loading

0 comments on commit eeb13d7

Please sign in to comment.