Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Model/Payment/Method/Bread.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ public function getTitle()
$title = parent::getTitle();
$showPerMonth = $this->helper->showPerMonthCalculation();

if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_WEBAPI_REST && $showPerMonth) {
$areaIsRestOrFrontend = $this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_WEBAPI_REST
|| $this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND;

if ($areaIsRestOrFrontend && $showPerMonth) {
$data = $this->quoteHelper->submitQuote(null);
if (isset($data['asLowAs']) && isset($data['asLowAs']['amount'])) {
$title .= ' ' . sprintf(__('as low as %s/month*'), $data['asLowAs']['amount']);
Expand Down
12 changes: 10 additions & 2 deletions Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ class ConfigProvider implements ConfigProviderInterface
*/
public $helperData;

/**
* @var \Bread\BreadCheckout\Model\Payment\Method\Bread
*/
public $breadMethod;

public function __construct(
\Bread\BreadCheckout\Helper\Quote $helper,
\Bread\BreadCheckout\Helper\Data $helperData
\Bread\BreadCheckout\Helper\Data $helperData,
\Bread\BreadCheckout\Model\Payment\Method\Bread $breadMethod
) {
$this->helper = $helper;
$this->helperData = $helperData;
$this->breadMethod = $breadMethod;
}

/**
Expand Down Expand Up @@ -68,7 +75,8 @@ public function getConfig()
'buttonLocation' => $this->helperData->getCheckoutLocation(),
'methodTooltip' => $this->helper->getMethodTooltip(),
'productTypeMessage' => $this->helperData->getProductTypeMessage(),
'cartValidation' => $this->helper->validateAllowedProductTypes()
'cartValidation' => $this->helper->validateAllowedProductTypes(),
'methodTitle' => $this->breadMethod->getTitle()
]
]
]
Expand Down
1 change: 1 addition & 0 deletions view/adminhtml/web/js/breadcheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define(

var breadConfig = {
buttonId: 'bread-checkout-btn',
allowSplitPayCheckout: false,
shippingOptions: [data.shippingOptions],
tax: data.tax,
customTotal: data.grandTotal,
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/layout/catalog_product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<referenceBlock name="product.info.options.wrapper">
<block template="Bread_BreadCheckout::breadcheckout/options.phtml" class="Bread\BreadCheckout\Block\Product\View" name="breadcheckout.checkout.options"/>
</referenceBlock>
<referenceBlock name="product.info.main">
<block template="Bread_BreadCheckout::breadcheckout/price.phtml" class="Bread\BreadCheckout\Block\Product\View" name="breadcheckout.prod.price" after="product.info.price"/>
</referenceBlock>
</body>
</page>
3 changes: 3 additions & 0 deletions view/frontend/layout/catalog_product_view_type_bundle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<block template="Bread_BreadCheckout::breadcheckout/view.phtml"
class="Bread\BreadCheckout\Block\Product\Bundle" as="breadcheckout.prod.view" name="breadcheckout.prod.view"/>
</referenceContainer>
<referenceBlock name="product.info.main">
<block template="Bread_BreadCheckout::breadcheckout/price.phtml" class="Bread\BreadCheckout\Block\Product\Bundle" name="breadcheckout.prod.price" before="customize.button"/>
</referenceBlock>

<referenceBlock name="product.info.options.wrapper">
<referenceBlock name="breadcheckout.checkout.options" remove="true"/>
Expand Down
1 change: 1 addition & 0 deletions view/frontend/layout/catalog_product_view_type_grouped.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<body>

<referenceBlock name="breadcheckout.prod.view" remove="true"/>
<referenceBlock name="breadcheckout.prod.price" remove="true"/>
<referenceBlock name="breadcheckout.checkout.options" remove="true"/>

<referenceContainer name="product.info.extrahint">
Expand Down
3 changes: 2 additions & 1 deletion view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var config = {
map: {
'*': {
buttonConfig: 'Bread_BreadCheckout/js/button-config',
bundleHelper: 'Bread_BreadCheckout/js/bundle-helper'
bundleHelper: 'Bread_BreadCheckout/js/bundle-helper',
splitPay: 'Bread_BreadCheckout/js/product/splitpay'
}
}
};
1 change: 1 addition & 0 deletions view/frontend/templates/breadcheckout/bundle.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ require([
document.defaultItems[0]["price"] = this.cache.currentElement.selectedPrice * 100;
document.selectedSku = this.cache.currentElement.selectedSku;
document.configureButton(document.defaultItems);
document.splitPayConfigureButton(document.defaultItems);
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion view/frontend/templates/breadcheckout/cartview.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<div class="button-prevent" id="button-prevent">
<span class="buy_error_tip override_tip" data-content="<?= /* @noEscape */ $block->productTypeErrorMessage() ?>">&nbsp;</span>
</div>
<div class="splitpay-clickable-button"></div>
</div>

<script type="text/javascript">
require(['jquery', 'jquery/validate', 'mage/validation', '!domReady'], function($) {
require(['jquery', 'splitPay', 'jquery/validate', 'mage/validation', '!domReady'], function($, splitPay) {

var validateProductTypes = Boolean(<?= /* @noEscape */ $block->validateAllowedProductTypes() ?>);
if (validateProductTypes === false) {
Expand All @@ -35,6 +36,7 @@

var breadConfig = {
buttonId: "bread-checkout-btn",
allowSplitPayCheckout: false,
asLowAs: <?= /* @noEscape */ $block->getAsLowAs(); ?>,
actAsLabel: false,
<?php if (!$block->isHealthcare()) : ?>
Expand Down Expand Up @@ -207,6 +209,7 @@

if (typeof bread !== 'undefined') {
bread.checkout(breadConfig);
splitPay.setupSplitPay(breadConfig, '.splitpay-clickable-button', false);
}
};

Expand Down
1 change: 1 addition & 0 deletions view/frontend/templates/breadcheckout/configurable.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
document.selectedSku = document.baseProductSku + "///" +
document.Skus[document.selectedSimpleProductId];
document.resetPriceAndSku(true);
document.splitPayResetPriceAndSku(true);
}
}
};
Expand Down
18 changes: 14 additions & 4 deletions view/frontend/templates/breadcheckout/grouped.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
<div class="button-prevent" id="button-prevent">
<span class="buy_error_tip override_tip" data-content="<?= /* @noEscape */ __('Please complete product configuration') ?>">&nbsp;</span>
</div>
<div class="button-prevent" id="button-prevent-updating">
<span class="buy_error_tip override_tip" data-content="<?= /* @noEscape */ __('Please wait') ?>">&nbsp;</span>
</div>
<div class="splitpay-clickable-button"></div>
</div>

<script>
require([
'jquery',
'splitPay',
'jquery/validate',
'mage/validation'
], function($) {
], function($, splitPay) {
document.configureButton = function (items) {
var buttonOnProduct = <?= /* @noEscape */ $block->getIsButtonOnProduct(); ?>;
var buttonCss = '<?= /* @noEscape */ $block->getButtonDesign(); ?>';
Expand All @@ -29,6 +34,7 @@

var breadConfig = {
buttonId: "bread-checkout-btn",
allowSplitPayCheckout: false,
<?php if (!$block->isHealthcare()) : ?>
items: items,
<?php else : ?>
Expand Down Expand Up @@ -216,6 +222,8 @@

if (typeof bread !== 'undefined') {
bread.checkout(breadConfig);
splitPay.setupSplitPay(breadConfig, '.splitpay-clickable-button', false);
$('#button-prevent-updating').hide();
}
}).fail(function(error) {
document.logBreadIssue('error', {},
Expand All @@ -230,7 +238,8 @@
* Overlay element onto bread button to prevent
* it from being clicked until options are selected
*/
$('.button-prevent').show();
$('#button-prevent').show();
$('#button-prevent-updating').hide();

$('#product_addtocart_form').on('change', function() {
document.updateButton(this);
Expand All @@ -243,7 +252,8 @@

document.updateButton = function(form) {
if ($(form).valid()) {
$('.button-prevent').hide();
$('#button-prevent').hide();
$('#button-prevent-updating').show();

var groupedButtonUpdateUrl = '<?= /* @noEscape */ $block->getGroupedButtonUpdate()?>';
var serializedForm = $(form).serialize();
Expand All @@ -257,7 +267,7 @@
if (response.items) {
document.configureButton(response.items);
} else {
$('.button-prevent').show();
$('#button-prevent').show();
}
}).fail(function(error) {
var errorInfo = {
Expand Down
1 change: 1 addition & 0 deletions view/frontend/templates/breadcheckout/minicart.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

var breadConfig = {
buttonId: "bread-checkout-btn-minicart",
allowSplitPayCheckout: false,
asLowAs: <?= /* @noEscape */ $block->getAsLowAs(); ?>,
actAsLabel: false,
<?php if (!$block->isHealthcare()) : ?>
Expand Down
151 changes: 151 additions & 0 deletions view/frontend/templates/breadcheckout/price.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php /** @var $block Bread\BreadCheckout\Block\Product\View */ ?>
<?= /* @noEscape */ $block->getBeforeHtml(); ?>

<div class="splitpay-clickable-price" style="padding-bottom: 5px"></div>

<?php /** TODO: rename these javascript functions when doing refactor of template files */ ?>
<script type="text/javascript">
require(['jquery', 'splitPay'], function($, splitPay) {

document.splitPayConfigureButton = function (items) {
var buttonCss = '<?= /* @noEscape */ $block->getButtonDesign(); ?>';
var financingInfo = <?= /* @noEscape */ $block->getFinancingJson(); ?>;
var breadConfig = {
<?php if (!$block->isHealthcare()) : ?>
items: items,
<?php else : ?>
customTotal: items[0]['price'],
<?php endif; ?>
discounts: <?= /* @noEscape */ $block->getDiscountDataJson(); ?>,
allowCheckout: false,
done: function() {},

/**
* Add to cart call back used when allow checkout from product page = false
*
* @param callback
*/
addToCart: function(callback) {
document.getElementById('product_addtocart_form').submit();
}
};

if (buttonCss !== null && buttonCss !== '' && buttonCss != false) {
breadConfig.customCSS = buttonCss;
}

if(financingInfo.enabled && financingInfo.mode.cart){
var cartSizeFinancingId = financingInfo.id;
var cartSizeThreshold = financingInfo.threshold;
var itemsPriceSum = items.reduce(function(sum, item) { return sum + item.price * item.quantity; }, 0) / 100;
breadConfig.financingProgramId = (itemsPriceSum >= cartSizeThreshold) ? cartSizeFinancingId : 'null';
} else if (financingInfo.enabled && financingInfo.mode.sku){
var productSku = "<?= /* @noEscape */ $block->getProduct()->getSku(); ?>";
if(financingInfo.sku_limit.includes(productSku) === true){
breadConfig.financingProgramId = financingInfo.id;
}
}

if (!document.splitPayHasCheckedConfigData) {

var configDataUrl = '<?= /* @noEscape */ $block->getConfigDataUrl(); ?>';
$.ajax({
url: configDataUrl,
type: 'post',
context: this
}).done(function(data) {
document.splitPayHasCheckedConfigData = true;

if (data.shippingContact !== false) {
breadConfig.shippingContact = data.shippingContact;
}

if (data.billingContact !== false) {
breadConfig.billingContact = data.billingContact;
}

if (typeof bread !== 'undefined') {
splitPay.setupSplitPay(breadConfig, '.splitpay-clickable-price', true);
}
}).fail(function(error) {
document.logBreadIssue('error', {},
'Error code returned when calling ' + configDataUrl + ', with status: ' + error.statusText);
});

} else {
if (typeof bread !== 'undefined') {
splitPay.setupSplitPay(breadConfig, '.splitpay-clickable-price', true);
}
}

};

<?php if ($block->getProduct() != null) : ?>

/**
* Reconfigure Bread checkout button with updated
* price and sku values
*/
document.splitPayResetPriceAndSku = function(configurable) {
if (!configurable) {
document.splitPayConfigureButton(document.splitPayDefaultItems);
}
else {
var price = document.splitPayCalculatePrice();

if(typeof document.customOptions !== "undefined"){
sku = document.splitPaySelectedSku + document.customOptions;
} else {
sku = document.splitPaySelectedSku;
}

if (sku != document.splitPayPreviousSku || price != document.splitPayPreviousPrice) {
document.splitPayPreviousSku = sku;
document.splitPayPreviousPrice = price;
document.splitPayDefaultItems[0]["sku"] = document.splitPayPreviousSku;
document.splitPayDefaultItems[0]["price"] = document.splitPayPreviousPrice;
document.splitPayConfigureButton(document.splitPayDefaultItems);
}
}
};

/**
* Calculate updated price based on attribute selections
* and/or custom options
*
* @returns int
*/
document.splitPayCalculatePrice = function() {
var price = 0;
var customPrice = 0;

if (document.priceWithOptions) {
customPrice = document.priceWithOptions;
}

var selectedProductPrices = (typeof spConfig !== "undefined") && spConfig.optionPrices[document.splitPaySelectedSimpleProductId];

if (selectedProductPrices) {
price = parseInt(Math.round(selectedProductPrices.finalPrice.amount * 100));
}

return Math.max(price, customPrice);
};
<?php endif; ?>
document.splitPayDefaultItems = <?= /* @noEscape */ $block->getProductDataJson(); ?>;
document.splitPayPreviousPrice = document.splitPayDefaultItems[0]["price"];
document.splitPayPreviousSku = document.splitPayDefaultItems[0]["sku"];

$(document).ready(function () {
<?php if ($block->getProduct() != null) : ?>
document.splitPayProductId = '<?= /* @noEscape */ $block->getProduct()->getId(); ?>';
document.splitPayBaseProductSku = '<?= /* @noEscape */ $block->getProduct()->getSku(); ?>';
document.splitPaySelectedSku = '<?= /* @noEscape */ $block->getProduct()->getSku(); ?>';
document.splitPaySelectedSimpleProductId = '<?= /* @noEscape */ $block->getProduct()->getId(); ?>';
document.splitPayResetPriceAndSku(false);
<?php else : ?>
document.splitPayConfigureButton(document.splitPayDefaultItems);
<?php endif; ?>
});
});
</script>
Loading