Skip to content

Commit

Permalink
feat(payments): PAYPAL-903 Product Page Banners (Cornerstone) - creat…
Browse files Browse the repository at this point in the history
…e custom price event
  • Loading branch information
bc-fetisov committed Jan 13, 2021
1 parent c169162 commit d38686e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets/js/theme/common/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import modalFactory, { showAlertModal, modalTypes } from '../global/modal';
import { isEmpty, isPlainObject } from 'lodash';
import { normalizeFormData } from './utils/api';
import { isBrowserIE, convertIntoArray } from './utils/ie-helpers';
import bannerUtils from "./utils/banner-utils";

export default class ProductDetails extends ProductDetailsBase {
constructor($scope, context, productAttributesData = {}) {
Expand Down Expand Up @@ -40,6 +41,7 @@ export default class ProductDetails extends ProductDetailsBase {
utils.api.productAttributes.optionChange($productId, $form.serialize(), 'products/bulk-discount-rates', optionChangeCallback);
} else {
this.updateProductAttributes(productAttributesData);
bannerUtils.dispatchProductBannerEvent(productAttributesData);
}

$productOptionsElement.show();
Expand Down Expand Up @@ -181,6 +183,7 @@ export default class ProductDetails extends ProductDetailsBase {
const productAttributesContent = response.content || {};
this.updateProductAttributes(productAttributesData);
this.updateView(productAttributesData, productAttributesContent);
bannerUtils.dispatchProductBannerEvent(response.data);
});
}

Expand Down
25 changes: 25 additions & 0 deletions assets/js/theme/common/utils/banner-utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const bannerUtils = {
dispatchProductBannerEvent: (productAttributes) => {
let price = 0;

if(!productAttributes.price) return;

if (productAttributes.price.without_tax && !productAttributes.price.price_range) {
price = productAttributes.price.without_tax.value
}

if (productAttributes.price.with_tax && !productAttributes.price.price_range) {
price = productAttributes.price.with_tax.value
}

const evt = new CustomEvent('productpricechanged', {
detail: {
amount: price
}
});

window.dispatchEvent(evt);
},
};

export default bannerUtils;

0 comments on commit d38686e

Please sign in to comment.