download all files

This commit is contained in:
Roman Pyrih
2025-06-24 14:14:35 +02:00
parent ebed09c00b
commit 4c71b5d9c2
72007 changed files with 10407727 additions and 40029 deletions

View File

@@ -0,0 +1,181 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from './create-order-map';
import Router from '../../../components/router';
const $ = window.$;
/**
* Renders Delivery & Invoice addresses select
*/
export default class AddressesRenderer {
constructor() {
this.router = new Router();
}
/**
* @param {Array} addresses
* @param {int} cartId
*/
render(addresses, cartId) {
this._cleanAddresses();
if (addresses.length === 0) {
this._hideAddressesContent();
this._showEmptyAddressesWarning();
this._showAddressesBlock();
return;
}
this._showAddressesContent();
this._hideEmptyAddressesWarning();
for (const key in addresses) {
const address = addresses[key];
this._renderDeliveryAddress(address, cartId);
this._renderInvoiceAddress(address, cartId);
}
this._showAddressesBlock();
}
/**
* Renders delivery address content
*
* @param address
* @param cartId
*
* @private
*/
_renderDeliveryAddress(address, cartId) {
const deliveryAddressOption = {
value: address.addressId,
text: address.alias,
};
if (address.delivery) {
$(createOrderMap.deliveryAddressDetails).html(address.formattedAddress);
deliveryAddressOption.selected = 'selected';
$(createOrderMap.deliveryAddressEditBtn).prop('href', this.router.generate('admin_cart_addresses_edit', {
addressId: address.addressId,
cartId,
addressType: 'delivery',
liteDisplaying: 1,
submitFormAjax: 1,
}));
}
$(createOrderMap.deliveryAddressSelect).append($('<option>', deliveryAddressOption));
}
/**
* Renders invoice address content
*
* @param address
* @param cartId
*
* @private
*/
_renderInvoiceAddress(address, cartId) {
const invoiceAddressOption = {
value: address.addressId,
text: address.alias,
};
if (address.invoice) {
$(createOrderMap.invoiceAddressDetails).html(address.formattedAddress);
invoiceAddressOption.selected = 'selected';
$(createOrderMap.invoiceAddressEditBtn).prop('href', this.router.generate('admin_cart_addresses_edit', {
addressId: address.addressId,
cartId,
addressType: 'invoice',
liteDisplaying: 1,
submitFormAjax: 1,
}));
}
$(createOrderMap.invoiceAddressSelect).append($('<option>', invoiceAddressOption));
}
/**
* Shows addresses block
*
* @private
*/
_showAddressesBlock() {
$(createOrderMap.addressesBlock).removeClass('d-none');
}
/**
* Empties addresses content
*
* @private
*/
_cleanAddresses() {
$(createOrderMap.deliveryAddressDetails).empty();
$(createOrderMap.deliveryAddressSelect).empty();
$(createOrderMap.invoiceAddressDetails).empty();
$(createOrderMap.invoiceAddressSelect).empty();
}
/**
* Shows addresses content and hides warning
*
* @private
*/
_showAddressesContent() {
$(createOrderMap.addressesContent).removeClass('d-none');
$(createOrderMap.addressesWarning).addClass('d-none');
}
/**
* Hides addresses content and shows warning
*
* @private
*/
_hideAddressesContent() {
$(createOrderMap.addressesContent).addClass('d-none');
$(createOrderMap.addressesWarning).removeClass('d-none');
}
/**
* Shows warning empty addresses warning
*
* @private
*/
_showEmptyAddressesWarning() {
$(createOrderMap.addressesWarning).removeClass('d-none');
}
/**
* Hides empty addresses warning
*
* @private
*/
_hideEmptyAddressesWarning() {
$(createOrderMap.addressesWarning).addClass('d-none');
}
}

View File

@@ -0,0 +1,236 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import Router from '@components/router';
import {EventEmitter} from '@components/event-emitter';
import eventMap from '@pages/order/create/event-map';
import createOrderMap from './create-order-map';
const $ = window.$;
/**
* Provides ajax calls for cart editing actions
* Each method emits an event with updated cart information after success.
*/
export default class CartEditor {
constructor() {
this.router = new Router();
}
/**
* Changes cart addresses
*
* @param {Number} cartId
* @param {Object} addresses
*/
changeCartAddresses(cartId, addresses) {
$.post(this.router.generate('admin_carts_edit_addresses', {cartId}), addresses)
.then((cartInfo) => EventEmitter.emit(eventMap.cartAddressesChanged, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
/**
* Modifies cart delivery option
*
* @param {Number} cartId
* @param {Number} value
*/
changeDeliveryOption(cartId, value) {
$.post(this.router.generate('admin_carts_edit_carrier', {cartId}), {
carrierId: value,
})
.then((cartInfo) => EventEmitter.emit(eventMap.cartDeliveryOptionChanged, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
/**
* Changes cart free shipping value
*
* @param {Number} cartId
*/
updateDeliveryOptions(cartId) {
const freeShippingEnabled = $(createOrderMap.freeShippingSwitch)[1].checked;
const isAGiftEnabled = $(createOrderMap.isAGiftSwitchValue).val() === '1';
const useRecycledPackagingEnabled = $(createOrderMap.recycledPackagingSwitchValue).val() === '1';
const giftMessage = $(createOrderMap.giftMessageField).val();
$.post(this.router.generate('admin_carts_set_delivery_settings', {cartId}), {
freeShipping: freeShippingEnabled,
isAGift: isAGiftEnabled,
useRecycledPackaging: useRecycledPackagingEnabled,
giftMessage,
})
.then((cartInfo) => EventEmitter.emit(eventMap.cartDeliverySettingChanged, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
/**
* Adds cart rule to cart
*
* @param {Number} cartRuleId
* @param {Number} cartId
*/
addCartRuleToCart(cartRuleId, cartId) {
$.post(this.router.generate('admin_carts_add_cart_rule', {cartId}), {
cartRuleId,
})
.then((cartInfo) => EventEmitter.emit(eventMap.cartRuleAdded, cartInfo))
.catch((response) => EventEmitter.emit(eventMap.cartRuleFailedToAdd, response.responseJSON.message));
}
/**
* Removes cart rule from cart
*
* @param {Number} cartRuleId
* @param {Number} cartId
*/
removeCartRuleFromCart(cartRuleId, cartId) {
$.post(
this.router.generate('admin_carts_delete_cart_rule', {
cartId,
cartRuleId,
})
)
.then((cartInfo) => EventEmitter.emit(eventMap.cartRuleRemoved, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
/**
* Adds product to cart
*
* @param {Number} cartId
* @param {Object} data
*/
addProduct(cartId, data) {
let fileSizeHeader = '';
if (!$.isEmptyObject(data.fileSizes)) {
fileSizeHeader = JSON.stringify(data.fileSizes);
}
$.ajax(this.router.generate('admin_carts_add_product', {cartId}), {
headers: {
// Adds custom headers with submitted file sizes, to track if all files reached server side.
'file-sizes': fileSizeHeader,
},
method: 'POST',
data: data.product,
processData: false,
contentType: false,
})
.then((cartInfo) => EventEmitter.emit(eventMap.productAddedToCart, cartInfo))
.catch((response) => EventEmitter.emit(eventMap.productAddToCartFailed, response.responseJSON.message));
}
/**
* Removes product from cart
*
* @param {Number} cartId
* @param {Object} product
*/
removeProductFromCart(cartId, product) {
$.post(this.router.generate('admin_carts_delete_product', {cartId}), {
productId: product.productId,
attributeId: product.attributeId,
customizationId: product.customizationId,
})
.then((cartInfo) => EventEmitter.emit(eventMap.productRemovedFromCart, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
/**
* Changes product price in cart
*
* @param {Number} cartId
* @param {Number} customerId
* @param {Object} product the updated product
*/
changeProductPrice(cartId, customerId, product) {
$.post(
this.router.generate('admin_carts_edit_product_price', {
cartId,
productId: product.productId,
productAttributeId: product.attributeId,
}),
{
newPrice: product.price,
customerId,
}
)
.then((cartInfo) => EventEmitter.emit(eventMap.productPriceChanged, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
/**
* Updates product quantity in cart
*
* @param cartId
* @param product
*/
changeProductQty(cartId, product) {
$.post(
this.router.generate('admin_carts_edit_product_quantity', {
cartId,
productId: product.productId,
}),
{
newQty: product.newQty,
attributeId: product.attributeId,
customizationId: product.customizationId,
}
)
.then((cartInfo) => EventEmitter.emit(eventMap.productQtyChanged, cartInfo))
.catch((response) => EventEmitter.emit(eventMap.productQtyChangeFailed, response));
}
/**
* Changes cart currency
*
* @param {Number} cartId
* @param {Number} currencyId
*/
changeCartCurrency(cartId, currencyId) {
$(createOrderMap.cartCurrencySelect).data('selectedCurrencyId', currencyId);
$.post(this.router.generate('admin_carts_edit_currency', {cartId}), {
currencyId,
})
.then((cartInfo) => EventEmitter.emit(eventMap.cartCurrencyChanged, cartInfo))
.catch((response) => EventEmitter.emit(eventMap.cartCurrencyChangeFailed, response));
}
/**
* Changes cart language
*
* @param {Number} cartId
* @param {Number} languageId
*/
changeCartLanguage(cartId, languageId) {
$.post(this.router.generate('admin_carts_edit_language', {cartId}), {
languageId,
})
.then((cartInfo) => EventEmitter.emit(eventMap.cartLanguageChanged, cartInfo))
.catch((response) => showErrorMessage(response.responseJSON.message));
}
}

View File

@@ -0,0 +1,82 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderPageMap from '@pages/order/create/create-order-map';
import Router from '@components/router';
import {EventEmitter} from '@components/event-emitter';
import eventMap from '@pages/order/create/event-map';
const $ = window.$;
/**
* Provides ajax calls for getting cart information
*/
export default class CartProvider {
constructor() {
this.$container = $(createOrderPageMap.orderCreationContainer);
this.router = new Router();
}
/**
* Gets cart information
*
* @param cartId
*
* @returns {jqXHR}. Object with cart information in response.
*/
getCart(cartId) {
$.get(this.router.generate('admin_carts_info', {cartId})).then((cartInfo) => {
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
});
}
/**
* Gets existing empty cart or creates new empty cart for customer.
*
* @param customerId
*
* @returns {jqXHR}. Object with cart information in response
*/
loadEmptyCart(customerId) {
$.post(this.router.generate('admin_carts_create'), {
customerId,
}).then((cartInfo) => {
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
});
}
/**
* Duplicates cart from provided order
*
* @param orderId
*
* @returns {jqXHR}. Object with cart information in response
*/
duplicateOrderCart(orderId) {
$.post(this.router.generate('admin_orders_duplicate_cart', {orderId})).then((cartInfo) => {
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
});
}
}

View File

@@ -0,0 +1,149 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import CartEditor from '@pages/order/create/cart-editor';
import CartRulesRenderer from '@pages/order/create/cart-rules-renderer';
import {EventEmitter} from '@components/event-emitter';
import eventMap from '@pages/order/create/event-map';
import Router from '@components/router';
import SummaryRenderer from '@pages/order/create/summary-renderer';
import ShippingRenderer from '@pages/order/create/shipping-renderer';
import ProductRenderer from '@pages/order/create/product-renderer';
const $ = window.$;
/**
* Responsible for searching cart rules and managing cart rules search block
*/
export default class CartRuleManager {
constructor() {
this.activeSearchRequest = null;
this.router = new Router();
this.cartRulesRenderer = new CartRulesRenderer();
this.cartEditor = new CartEditor();
this.summaryRenderer = new SummaryRenderer();
this.shippingRenderer = new ShippingRenderer();
this.productRenderer = new ProductRenderer();
this._initListeners();
return {
search: searchPhrase => this._search(searchPhrase),
stopSearching: () => this.cartRulesRenderer.hideResultsDropdown(),
addCartRuleToCart: (cartRuleId, cartId) => this.cartEditor.addCartRuleToCart(cartRuleId, cartId),
removeCartRuleFromCart: (cartRuleId, cartId) => this.cartEditor.removeCartRuleFromCart(cartRuleId, cartId),
};
}
/**
* Initiates event listeners for cart rule actions
*
* @private
*/
_initListeners() {
this._onCartRuleSearch();
this._onAddCartRuleToCart();
this._onAddCartRuleToCartFailure();
this._onRemoveCartRuleFromCart();
}
/**
* Listens for cart rule search action
*
* @private
*/
_onCartRuleSearch() {
EventEmitter.on(eventMap.cartRuleSearched, (cartRules) => {
this.cartRulesRenderer.renderSearchResults(cartRules);
});
}
/**
* Listens event of add cart rule to cart action
*
* @private
*/
_onAddCartRuleToCart() {
EventEmitter.on(eventMap.cartRuleAdded, (cartInfo) => {
const cartIsEmpty = cartInfo.products.length === 0;
this.cartRulesRenderer.renderCartRulesBlock(cartInfo.cartRules, cartIsEmpty);
this.productRenderer.renderList(cartInfo.products);
this.shippingRenderer.render(cartInfo.shipping, cartIsEmpty);
this.summaryRenderer.render(cartInfo);
});
}
/**
* Listens event when add cart rule to cart fails
*
* @private
*/
_onAddCartRuleToCartFailure() {
EventEmitter.on(eventMap.cartRuleFailedToAdd, (message) => {
this.cartRulesRenderer.displayErrorMessage(message);
});
}
/**
* Listens event for remove cart rule from cart action
*
* @private
*/
_onRemoveCartRuleFromCart() {
EventEmitter.on(eventMap.cartRuleRemoved, (cartInfo) => {
const cartIsEmpty = cartInfo.products.length === 0;
this.shippingRenderer.render(cartInfo.shipping, cartIsEmpty);
this.cartRulesRenderer.renderCartRulesBlock(cartInfo.cartRules, cartIsEmpty);
this.summaryRenderer.render(cartInfo);
this.productRenderer.renderList(cartInfo.products);
});
}
/**
* Searches for cart rules by search phrase
*
* @private
*/
_search(searchPhrase) {
if (this.activeSearchRequest !== null) {
this.activeSearchRequest.abort();
}
this.activeSearchRequest = $.get(this.router.generate('admin_cart_rules_search'), {
search_phrase: searchPhrase,
});
this.activeSearchRequest.then((cartRules) => {
EventEmitter.emit(eventMap.cartRuleSearched, cartRules);
}).catch((e) => {
if (e.statusText === 'abort') {
return;
}
showErrorMessage(e.responseJSON.message);
});
}
}

View File

@@ -0,0 +1,240 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from './create-order-map';
const $ = window.$;
/**
* Renders cart rules (cartRules) block
*/
export default class CartRulesRenderer {
constructor() {
this.$cartRulesBlock = $(createOrderMap.cartRulesBlock);
this.$cartRulesTable = $(createOrderMap.cartRulesTable);
this.$searchResultBox = $(createOrderMap.cartRulesSearchResultBox);
}
/**
* Responsible for rendering cartRules (a.k.a cart rules/discounts) block
*
* @param {Array} cartRules
* @param {Boolean} emptyCart
*/
renderCartRulesBlock(cartRules, emptyCart) {
this._hideErrorBlock();
// do not render cart rules block at all if cart has no products
if (emptyCart) {
this._hideCartRulesBlock();
return;
}
this._showCartRulesBlock();
// do not render cart rules list when there are no cart rules
if (cartRules.length === 0) {
this._hideCartRulesList();
return;
}
this._renderList(cartRules);
}
/**
* Responsible for rendering search results dropdown
*
* @param searchResults
*/
renderSearchResults(searchResults) {
this._clearSearchResults();
if (searchResults.cart_rules.length === 0) {
this._renderNotFound();
} else {
this._renderFoundCartRules(searchResults.cart_rules);
}
this._showResultsDropdown();
}
/**
* Displays error message bellow search input
*
* @param message
*/
displayErrorMessage(message) {
$(createOrderMap.cartRuleErrorText).text(message);
this._showErrorBlock();
}
/**
* Hides cart rules search result dropdown
*/
hideResultsDropdown() {
this.$searchResultBox.addClass('d-none');
}
/**
* Displays cart rules search result dropdown
*
* @private
*/
_showResultsDropdown() {
this.$searchResultBox.removeClass('d-none');
}
/**
* Renders warning that no cart rule was found
*
* @private
*/
_renderNotFound() {
const $template = $($(createOrderMap.cartRulesNotFoundTemplate).html()).clone();
this.$searchResultBox.html($template);
}
/**
* Empties cart rule search results block
*
* @private
*/
_clearSearchResults() {
this.$searchResultBox.empty();
}
/**
* Renders found cart rules after search
*
* @param cartRules
*
* @private
*/
_renderFoundCartRules(cartRules) {
const $cartRuleTemplate = $($(createOrderMap.foundCartRuleTemplate).html());
for (const key in cartRules) {
const $template = $cartRuleTemplate.clone();
const cartRule = cartRules[key];
let cartRuleName = cartRule.name;
if (cartRule.code !== '') {
cartRuleName = `${cartRule.name} - ${cartRule.code}`;
}
$template.text(cartRuleName);
$template.data('cart-rule-id', cartRule.cartRuleId);
this.$searchResultBox.append($template);
}
}
/**
* Responsible for rendering the list of cart rules
*
* @param {Array} cartRules
*
* @private
*/
_renderList(cartRules) {
this._cleanCartRulesList();
const $cartRulesTableRowTemplate = $($(createOrderMap.cartRulesTableRowTemplate).html());
for (const key in cartRules) {
const cartRule = cartRules[key];
const $template = $cartRulesTableRowTemplate.clone();
$template.find(createOrderMap.cartRuleNameField).text(cartRule.name);
$template.find(createOrderMap.cartRuleDescriptionField).text(cartRule.description);
$template.find(createOrderMap.cartRuleValueField).text(cartRule.value);
$template.find(createOrderMap.cartRuleDeleteBtn).data('cart-rule-id', cartRule.cartRuleId);
this.$cartRulesTable.find('tbody').append($template);
}
this._showCartRulesList();
}
/**
* Shows error block
*
* @private
*/
_showErrorBlock() {
$(createOrderMap.cartRuleErrorBlock).removeClass('d-none');
}
/**
* Hides error block
*
* @private
*/
_hideErrorBlock() {
$(createOrderMap.cartRuleErrorBlock).addClass('d-none');
}
/**
* Shows cartRules block
*
* @private
*/
_showCartRulesBlock() {
this.$cartRulesBlock.removeClass('d-none');
}
/**
* hide cartRules block
*
* @private
*/
_hideCartRulesBlock() {
this.$cartRulesBlock.addClass('d-none');
}
/**
* Display the list block of cart rules
*
* @private
*/
_showCartRulesList() {
this.$cartRulesTable.removeClass('d-none');
}
/**
* Hide list block of cart rules
*
* @private
*/
_hideCartRulesList() {
this.$cartRulesTable.addClass('d-none');
}
/**
* remove items in cart rules list
*
* @private
*/
_cleanCartRulesList() {
this.$cartRulesTable.find('tbody').empty();
}
}

View File

@@ -0,0 +1,182 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
/**
* Encapsulates selectors for "Create order" page
*/
export default {
productCustomizationFieldTypeFile: 0,
productCustomizationFieldTypeText: 1,
orderCreationContainer: '#order-creation-container',
requiredFieldMark: '.js-required-field-mark',
cartInfoWrapper: '#js-cart-info-wrapper',
// selectors related to customer block
customerSearchInput: '#customer-search-input',
customerSearchResultsBlock: '.js-customer-search-results',
customerSearchResultTemplate: '#customer-search-result-template',
customerSearchEmptyResultWarning: '#customer-search-empty-result-warn',
customerSearchLoadingNotice: '#customer-search-loading-notice',
customerAddBtn: '#customer-add-btn',
changeCustomerBtn: '.js-change-customer-btn',
customerSearchRow: '.js-search-customer-row',
chooseCustomerBtn: '.js-choose-customer-btn',
notSelectedCustomerSearchResults: '.js-customer-search-result:not(.border-success)',
customerSearchResultName: '.js-customer-name',
customerSearchResultEmail: '.js-customer-email',
customerSearchResultId: '.js-customer-id',
customerSearchResultBirthday: '.js-customer-birthday',
customerDetailsBtn: '.js-details-customer-btn',
customerSearchResultColumn: '.js-customer-search-result-col',
customerSearchBlock: '#customer-search-block',
customerCartsTab: '.js-customer-carts-tab',
customerOrdersTab: '.js-customer-orders-tab',
customerCartsTable: '#customer-carts-table',
customerCartsTableRowTemplate: '#customer-carts-table-row-template',
customerCheckoutHistory: '#customer-checkout-history',
customerOrdersTable: '#customer-orders-table',
customerOrdersTableRowTemplate: '#customer-orders-table-row-template',
cartRulesTable: '#cart-rules-table',
cartRulesTableRowTemplate: '#cart-rules-table-row-template',
useCartBtn: '.js-use-cart-btn',
cartDetailsBtn: '.js-cart-details-btn',
cartIdField: '.js-cart-id',
cartDateField: '.js-cart-date',
cartTotalField: '.js-cart-total',
useOrderBtn: '.js-use-order-btn',
orderDetailsBtn: '.js-order-details-btn',
orderIdField: '.js-order-id',
orderDateField: '.js-order-date',
orderProductsField: '.js-order-products',
orderTotalField: '.js-order-total-paid',
orderPaymentMethod: '.js-order-payment-method',
orderStatusField: '.js-order-status',
emptyListRowTemplate: '#js-empty-list-row',
loadingListRowTemplate: '#js-loading-list-row',
emptyListRow: '.js-empty-row',
// selectors related to cartRules block
cartRulesBlock: '#cart-rules-block',
cartRuleSearchInput: '#search-cart-rules-input',
cartRulesSearchResultBox: '#search-cart-rules-result-box',
cartRulesNotFoundTemplate: '#cart-rules-not-found-template',
foundCartRuleTemplate: '#found-cart-rule-template',
foundCartRuleListItem: '.js-found-cart-rule',
cartRuleNameField: '.js-cart-rule-name',
cartRuleDescriptionField: '.js-cart-rule-description',
cartRuleValueField: '.js-cart-rule-value',
cartRuleDeleteBtn: '.js-cart-rule-delete-btn',
cartRuleErrorBlock: '#js-cart-rule-error-block',
cartRuleErrorText: '#js-cart-rule-error-text',
// selectors related to addresses block
addressesBlock: '#addresses-block',
deliveryAddressDetails: '#delivery-address-details',
invoiceAddressDetails: '#invoice-address-details',
deliveryAddressSelect: '#delivery-address-select',
invoiceAddressSelect: '#invoice-address-select',
addressSelect: '.js-address-select',
addressesContent: '#addresses-content',
addressesWarning: '#addresses-warning',
deliveryAddressEditBtn: '#js-delivery-address-edit-btn',
invoiceAddressEditBtn: '#js-invoice-address-edit-btn',
addressAddBtn: '#js-add-address-btn',
// selectors related to summary block
summaryBlock: '#summary-block',
summaryTotalProducts: '.js-total-products',
summaryTotalDiscount: '.js-total-discounts',
summaryTotalShipping: '.js-total-shipping',
summaryTotalTaxes: '.js-total-taxes',
summaryTotalWithoutTax: '.js-total-without-tax',
summaryTotalWithTax: '.js-total-with-tax',
placeOrderCartIdField: '.js-place-order-cart-id',
processOrderLinkTag: '#js-process-order-link',
orderMessageField: '#js-order-message-wrap textarea',
sendProcessOrderEmailBtn: '#js-send-process-order-email-btn',
summarySuccessAlertBlock: '#js-summary-success-block',
summaryErrorAlertBlock: '#js-summary-error-block',
summarySuccessAlertText: '#js-summary-success-block .alert-text',
summaryErrorAlertText: '#js-summary-error-block .alert-text',
// selectors related to shipping block
shippingBlock: '#shipping-block',
shippingForm: '.js-shipping-form',
noCarrierBlock: '.js-no-carrier-block',
deliveryOptionSelect: '#delivery-option-select',
totalShippingField: '.js-total-shipping-tax-inc',
freeShippingSwitch: '.js-free-shipping-switch',
recycledPackagingSwitch: '.js-recycled-packaging-switch',
recycledPackagingSwitchValue: '.js-recycled-packaging-switch:checked',
isAGiftSwitch: '.js-is-gift-switch',
isAGiftSwitchValue: '.js-is-gift-switch:checked',
giftMessageField: '#cart_gift_message',
// selectors related to cart block
cartBlock: '#cart-block',
cartCurrencySelect: '#js-cart-currency-select',
cartLanguageSelect: '#js-cart-language-select',
productSearch: '#product-search',
combinationsSelect: '#combination-select',
productResultBlock: '#product-search-results',
productSelect: '#product-select',
quantityInput: '#quantity-input',
inStockCounter: '.js-in-stock-counter',
combinationsTemplate: '#combinations-template',
combinationsRow: '.js-combinations-row',
productSelectRow: '.js-product-select-row',
productCustomFieldsContainer: '#js-custom-fields-container',
productCustomizationContainer: '#js-customization-container',
productCustomFileTemplate: '#js-product-custom-file-template',
productCustomTextTemplate: '#js-product-custom-text-template',
productCustomInputLabel: '.js-product-custom-input-label',
productCustomInput: '.js-product-custom-input',
quantityRow: '.js-quantity-row',
addToCartButton: '#add-product-to-cart-btn',
productsTable: '#products-table',
productsTableRowTemplate: '#products-table-row-template',
productsTableGiftRowTemplate: '#products-table-gift-row-template',
listedProductImageField: '.js-product-image',
listedProductNameField: '.js-product-name',
listedProductAttrField: '.js-product-attr',
listedProductReferenceField: '.js-product-ref',
listedProductUnitPriceInput: '.js-product-unit-input',
listedProductQtyInput: '.js-product-qty-input',
listedProductGiftQty: '.js-product-gift-qty',
productTotalPriceField: '.js-product-total-price',
listedProductCustomizedTextTemplate: '#js-table-product-customized-text-template',
listedProductCustomizedFileTemplate: '#js-table-product-customized-file-template',
listedProductCustomizationName: '.js-customization-name',
listedProductCustomizationValue: '.js-customization-value',
listedProductDefinition: '.js-product-definition-td',
productRemoveBtn: '.js-product-remove-btn',
productTaxWarning: '.js-tax-warning',
noProductsFoundWarning: '.js-no-products-found',
searchingProductsNotice: '.js-searching-products',
productAddForm: '#js-add-product-form',
cartErrorAlertBlock: '#js-cart-error-block',
cartErrorAlertText: '#js-cart-error-block .alert-text',
};

View File

@@ -0,0 +1,617 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from './create-order-map';
import CustomerManager from './customer-manager';
import ShippingRenderer from './shipping-renderer';
import CartProvider from './cart-provider';
import AddressesRenderer from './addresses-renderer';
import CartRulesRenderer from './cart-rules-renderer';
import Router from '../../../components/router';
import {EventEmitter} from '../../../components/event-emitter';
import CartEditor from './cart-editor';
import eventMap from './event-map';
import CartRuleManager from './cart-rule-manager';
import ProductManager from './product-manager';
import ProductRenderer from './product-renderer';
import SummaryRenderer from './summary-renderer';
import SummaryManager from './summary-manager';
import _ from 'lodash';
const $ = window.$;
/**
* Page Object for "Create order" page
*/
export default class CreateOrderPage {
constructor() {
this.cartId = null;
this.customerId = null;
this.$container = $(createOrderMap.orderCreationContainer);
this.cartProvider = new CartProvider();
this.customerManager = new CustomerManager();
this.shippingRenderer = new ShippingRenderer();
this.addressesRenderer = new AddressesRenderer();
this.cartRulesRenderer = new CartRulesRenderer();
this.router = new Router();
this.cartEditor = new CartEditor();
this.cartRuleManager = new CartRuleManager();
this.productManager = new ProductManager();
this.productRenderer = new ProductRenderer();
this.summaryRenderer = new SummaryRenderer();
this.summaryManager = new SummaryManager();
this._initListeners();
this._loadCartFromUrlParams();
return {
refreshAddressesList: refreshCartAddresses => this.refreshAddressesList(refreshCartAddresses),
refreshCart: refreshCart => this.refreshCart(refreshCart),
search: string => this.customerManager.search(string)
};
}
/**
* Checks if correct addresses are selected.
* There is a case when options list cannot contain cart addresses 'selected' values
* because those are outdated in db (e.g. deleted after cart creation or country is disabled)
*
* @param {Array} addresses
*
* @returns {boolean}
*/
static validateSelectedAddresses(addresses) {
let deliveryValid = false;
let invoiceValid = false;
for (const key in addresses) {
const address = addresses[key];
if (address.delivery) {
deliveryValid = true;
}
if (address.invoice) {
invoiceValid = true;
}
if (deliveryValid && invoiceValid) {
return true;
}
}
return false;
}
/**
* Hides whole cart information wrapper
*/
hideCartInfo() {
$(createOrderMap.cartInfoWrapper).addClass('d-none');
}
/**
* Shows whole cart information wrapper
*/
showCartInfo() {
$(createOrderMap.cartInfoWrapper).removeClass('d-none');
}
/**
* Loads cart if query params contains valid cartId
*
* @private
*/
_loadCartFromUrlParams() {
const urlParams = new URLSearchParams(window.location.search);
const cartId = Number(urlParams.get('cartId'));
if (!isNaN(cartId) && cartId !== 0) {
this.cartProvider.getCart(cartId);
}
}
/**
* Initializes event listeners
*
* @private
*/
_initListeners() {
this.$container.on('input', createOrderMap.customerSearchInput, e => this._initCustomerSearch(e));
this.$container.on('click', createOrderMap.chooseCustomerBtn, e => this._initCustomerSelect(e));
this.$container.on('click', createOrderMap.useCartBtn, e => this._initCartSelect(e));
this.$container.on('click', createOrderMap.useOrderBtn, e => this._initDuplicateOrderCart(e));
this.$container.on('input', createOrderMap.productSearch, e => this._initProductSearch(e));
this.$container.on('input', createOrderMap.cartRuleSearchInput, e => this._initCartRuleSearch(e));
this.$container.on('blur', createOrderMap.cartRuleSearchInput, () => this.cartRuleManager.stopSearching());
this._listenForCartEdit();
this._onCartLoaded();
this.onCustomersNotFound();
this._onCustomerSelected();
this.initAddressButtonsIframe();
this.initCartRuleButtonsIframe();
}
/**
* @private
*/
initAddressButtonsIframe() {
$(createOrderMap.addressAddBtn).fancybox({
type: 'iframe',
width: '90%',
height: '90%'
});
$(createOrderMap.invoiceAddressEditBtn).fancybox({
type: 'iframe',
width: '90%',
height: '90%'
});
$(createOrderMap.deliveryAddressEditBtn).fancybox({
type: 'iframe',
width: '90%',
height: '90%'
});
}
initCartRuleButtonsIframe() {
$('#js-add-cart-rule-btn').fancybox({
type: 'iframe',
width: '90%',
height: '90%'
});
}
/**
* Delegates actions to events associated with cart update (e.g. change cart address)
*
* @private
*/
_listenForCartEdit() {
this._onCartAddressesChanged();
this._onDeliveryOptionChanged();
this._onDeliverySettingChanged();
this._addCartRuleToCart();
this._removeCartRuleFromCart();
this._onCartCurrencyChanged();
this._onCartLanguageChanged();
this.$container.on('change', createOrderMap.deliveryOptionSelect, e =>
this.cartEditor.changeDeliveryOption(this.cartId, e.currentTarget.value)
);
this.$container.on('change', createOrderMap.freeShippingSwitch, e =>
this.cartEditor.updateDeliveryOptions(this.cartId)
);
this.$container.on('change', createOrderMap.recycledPackagingSwitch, e =>
this.cartEditor.updateDeliveryOptions(this.cartId)
);
this.$container.on('change', createOrderMap.isAGiftSwitch, e => this.cartEditor.updateDeliveryOptions(this.cartId));
this.$container.on('blur', createOrderMap.giftMessageField, e =>
this.cartEditor.updateDeliveryOptions(this.cartId)
);
this.$container.on('click', createOrderMap.addToCartButton, () =>
this.productManager.addProductToCart(this.cartId)
);
this.$container.on('change', createOrderMap.cartCurrencySelect, e =>
this.cartEditor.changeCartCurrency(this.cartId, e.currentTarget.value)
);
this.$container.on('change', createOrderMap.cartLanguageSelect, e =>
this.cartEditor.changeCartLanguage(this.cartId, e.currentTarget.value)
);
this.$container.on('click', createOrderMap.sendProcessOrderEmailBtn, () =>
this.summaryManager.sendProcessOrderEmail(this.cartId)
);
this.$container.on('change', createOrderMap.listedProductUnitPriceInput, e => this._initProductChangePrice(e));
this.$container.on(
'change',
createOrderMap.listedProductQtyInput,
_.debounce(e => {
const inputsQty = document.querySelectorAll(createOrderMap.listedProductQtyInput);
inputsQty.forEach(inputQty => {
inputQty.setAttribute('disabled', true);
});
this._initProductChangeQty(e);
}, 500)
);
this.$container.on('change', createOrderMap.addressSelect, () => this._changeCartAddresses());
this.$container.on('click', createOrderMap.productRemoveBtn, e => this._initProductRemoveFromCart(e));
}
/**
* Listens for event when cart is loaded
*
* @private
*/
_onCartLoaded() {
EventEmitter.on(eventMap.cartLoaded, cartInfo => {
this.cartId = cartInfo.cartId;
this._renderCartInfo(cartInfo);
if (cartInfo.addresses.length !== 0 && !CreateOrderPage.validateSelectedAddresses(cartInfo.addresses)) {
this._changeCartAddresses();
}
this.customerManager.loadCustomerCarts(this.cartId);
this.customerManager.loadCustomerOrders();
});
}
/**
* Listens for event when no customers were found by search
*
* @private
*/
onCustomersNotFound() {
EventEmitter.on(eventMap.customersNotFound, () => {
this.hideCartInfo();
});
}
/**
* Listens for event when customer is selected
*
* @private
*/
_onCustomerSelected() {
EventEmitter.on(eventMap.customerSelected, () => {
this.showCartInfo();
});
}
/**
* Listens for cart addresses update event
*
* @private
*/
_onCartAddressesChanged() {
EventEmitter.on(eventMap.cartAddressesChanged, cartInfo => {
this.addressesRenderer.render(cartInfo.addresses, cartInfo.cartId);
this.cartRulesRenderer.renderCartRulesBlock(cartInfo.cartRules, cartInfo.products.length === 0);
this.shippingRenderer.render(cartInfo.shipping, cartInfo.products.length === 0);
this.summaryRenderer.render(cartInfo);
});
}
/**
* Listens for cart delivery option update event
*
* @private
*/
_onDeliveryOptionChanged() {
EventEmitter.on(eventMap.cartDeliveryOptionChanged, cartInfo => {
this.cartRulesRenderer.renderCartRulesBlock(cartInfo.cartRules, cartInfo.products.length === 0);
this.shippingRenderer.render(cartInfo.shipping, cartInfo.products.length === 0);
this.summaryRenderer.render(cartInfo);
});
}
/**
* @private
*/
_onDeliverySettingChanged() {
EventEmitter.on(eventMap.cartDeliverySettingChanged, cartInfo => {
this.cartRulesRenderer.renderCartRulesBlock(cartInfo.cartRules, cartInfo.products.length === 0);
this.shippingRenderer.render(cartInfo.shipping, cartInfo.products.length === 0);
this.summaryRenderer.render(cartInfo);
});
}
/**
* Listens for cart language update event
*
* @private
*/
_onCartLanguageChanged() {
EventEmitter.on(eventMap.cartLanguageChanged, cartInfo => {
this._preselectCartLanguage(cartInfo.langId);
this._renderCartInfo(cartInfo);
});
}
/**
* Listens for cart currency update event
*
* @private
*/
_onCartCurrencyChanged() {
// on success
EventEmitter.on(eventMap.cartCurrencyChanged, cartInfo => {
this._renderCartInfo(cartInfo);
this.productRenderer.reset();
});
// on failure
EventEmitter.on(eventMap.cartCurrencyChangeFailed, response => {
this.productRenderer.renderCartBlockErrorAlert(response.responseJSON.message);
});
}
/**
* Init customer searching
*
* @param event
*
* @private
*/
_initCustomerSearch(event) {
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => this.customerManager.search($(event.currentTarget).val()), 300);
}
/**
* Init selecting customer for which order is being created
*
* @param event
*
* @private
*/
_initCustomerSelect(event) {
const customerId = this.customerManager.selectCustomer(event);
this.customerId = customerId;
this.cartProvider.loadEmptyCart(customerId);
}
/**
* Inits selecting cart to load
*
* @param event
*
* @private
*/
_initCartSelect(event) {
const cartId = $(event.currentTarget).data('cart-id');
this.cartProvider.getCart(cartId);
}
/**
* Inits duplicating order cart
*
* @private
*/
_initDuplicateOrderCart(event) {
const orderId = $(event.currentTarget).data('order-id');
this.cartProvider.duplicateOrderCart(orderId);
}
/**
* Triggers cart rule searching
*
* @private
*/
_initCartRuleSearch(event) {
const searchPhrase = event.currentTarget.value;
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => this.cartRuleManager.search(searchPhrase), 300);
}
/**
* Triggers cart rule select
*
* @private
*/
_addCartRuleToCart() {
this.$container
.on('mousedown', createOrderMap.foundCartRuleListItem, event => {
// prevent blur event to allow selecting cart rule
event.preventDefault();
const cartRuleId = $(event.currentTarget).data('cart-rule-id');
this.cartRuleManager.addCartRuleToCart(cartRuleId, this.cartId);
// manually fire blur event after cart rule is selected.
})
.on('click', createOrderMap.foundCartRuleListItem, () => {
$(createOrderMap.cartRuleSearchInput).blur();
});
}
/**
* Triggers cart rule removal from cart
*
* @private
*/
_removeCartRuleFromCart() {
this.$container.on('click', createOrderMap.cartRuleDeleteBtn, event => {
this.cartRuleManager.removeCartRuleFromCart($(event.currentTarget).data('cart-rule-id'), this.cartId);
});
}
/**
* Inits product searching
*
* @param event
*
* @private
*/
_initProductSearch(event) {
const $productSearchInput = $(event.currentTarget);
const searchPhrase = $productSearchInput.val();
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => this.productManager.search(searchPhrase), 300);
}
/**
* Inits product removing from cart
*
* @param event
*
* @private
*/
_initProductRemoveFromCart(event) {
const product = {
productId: $(event.currentTarget).data('product-id'),
attributeId: $(event.currentTarget).data('attribute-id'),
customizationId: $(event.currentTarget).data('customization-id')
};
this.productManager.removeProductFromCart(this.cartId, product);
}
/**
* Inits product in cart price change
*
* @param event
*
* @private
*/
_initProductChangePrice(event) {
const product = {
productId: $(event.currentTarget).data('product-id'),
attributeId: $(event.currentTarget).data('attribute-id'),
customizationId: $(event.currentTarget).data('customization-id'),
price: $(event.currentTarget).val()
};
this.productManager.changeProductPrice(this.cartId, this.customerId, product);
}
/**
* Inits product in cart quantity update
*
* @param event
*
* @private
*/
_initProductChangeQty(event) {
const product = {
productId: $(event.currentTarget).data('product-id'),
attributeId: $(event.currentTarget).data('attribute-id'),
customizationId: $(event.currentTarget).data('customization-id'),
newQty: $(event.currentTarget).val()
};
if (
typeof product.productId !== 'undefined' &&
product.productId !== null &&
typeof product.attributeId !== 'undefined' &&
product.attributeId !== null
) {
this.productManager.changeProductQty(this.cartId, product);
} else {
const inputsQty = document.querySelectorAll(createOrderMap.listedProductQtyInput);
inputsQty.forEach(inputQty => {
inputQty.disabled = false;
});
}
}
/**
* Renders cart summary on the page
*
* @param {Object} cartInfo
*
* @private
*/
_renderCartInfo(cartInfo) {
this.addressesRenderer.render(cartInfo.addresses, cartInfo.cartId);
this.cartRulesRenderer.renderCartRulesBlock(cartInfo.cartRules, cartInfo.products.length === 0);
this.shippingRenderer.render(cartInfo.shipping, cartInfo.products.length === 0);
this.productRenderer.cleanCartBlockAlerts();
this.productRenderer.renderList(cartInfo.products);
this.summaryRenderer.render(cartInfo);
this._preselectCartCurrency(cartInfo.currencyId);
this._preselectCartLanguage(cartInfo.langId);
$(createOrderMap.cartBlock).removeClass('d-none');
$(createOrderMap.cartBlock).data('cartId', cartInfo.cartId);
}
/**
* Sets cart currency selection value
*
* @param currencyId
*
* @private
*/
_preselectCartCurrency(currencyId) {
$(createOrderMap.cartCurrencySelect).val(currencyId);
}
/**
* Sets cart language selection value
*
* @param langId
*
* @private
*/
_preselectCartLanguage(langId) {
$(createOrderMap.cartLanguageSelect).val(langId);
}
/**
* Changes cart addresses
*
* @private
*/
_changeCartAddresses() {
const addresses = {
deliveryAddressId: $(createOrderMap.deliveryAddressSelect).val(),
invoiceAddressId: $(createOrderMap.invoiceAddressSelect).val()
};
this.cartEditor.changeCartAddresses(this.cartId, addresses);
}
/**
* Refresh addresses list
*
* @param {boolean} refreshCartAddresses optional
*
* @private
*/
refreshAddressesList(refreshCartAddresses) {
const cartId = $(createOrderMap.cartBlock).data('cartId');
$.get(this.router.generate('admin_carts_info', {cartId}))
.then(cartInfo => {
this.addressesRenderer.render(cartInfo.addresses, cartInfo.cartId);
if (refreshCartAddresses) {
this._changeCartAddresses();
}
})
.catch(e => {
showErrorMessage(e.responseJSON.message);
});
}
/**
* proxy to allow other scripts within the page to refresh addresses list
*/
refreshCart() {
const cartId = $(createOrderMap.cartBlock).data('cartId');
this.cartProvider.getCart(cartId);
}
}

View File

@@ -0,0 +1,220 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from '@pages/order/create/create-order-map';
import CustomerRenderer from '@pages/order/create/customer-renderer';
import {EventEmitter} from '@components/event-emitter';
import eventMap from '@pages/order/create/event-map';
import Router from '@components/router';
const $ = window.$;
/**
* Responsible for customers managing. (search, select, get customer info etc.)
*/
export default class CustomerManager {
constructor() {
this.customerId = null;
this.activeSearchRequest = null;
this.router = new Router();
this.$container = $(createOrderMap.customerSearchBlock);
this.$searchInput = $(createOrderMap.customerSearchInput);
this.$customerSearchResultBlock = $(createOrderMap.customerSearchResultsBlock);
this.customerRenderer = new CustomerRenderer();
this._initListeners();
this.initAddCustomerIframe();
return {
search: searchPhrase => this._search(searchPhrase),
selectCustomer: event => this._selectCustomer(event),
loadCustomerCarts: currentCartId => this._loadCustomerCarts(currentCartId),
loadCustomerOrders: () => this._loadCustomerOrders(),
};
}
/**
* Initializes event listeners
*
* @private
*/
_initListeners() {
this.$container.on('click', createOrderMap.changeCustomerBtn, () => this._changeCustomer());
this._onCustomerSearch();
this._onCustomerSelect();
this.onCustomersNotFound();
}
/**
* @private
*/
initAddCustomerIframe() {
$(createOrderMap.customerAddBtn).fancybox({
'type': 'iframe',
'width': '90%',
'height': '90%',
});
}
/**
* Listens for customer search event
*
* @private
*/
_onCustomerSearch() {
EventEmitter.on(eventMap.customerSearched, (response) => {
this.activeSearchRequest = null;
this.customerRenderer.hideSearchingCustomers();
if (response.customers.length === 0) {
EventEmitter.emit(eventMap.customersNotFound);
return;
}
this.customerRenderer.renderSearchResults(response.customers);
});
}
/**
* Listens for event of when no customers were found by search
*
* @private
*/
onCustomersNotFound() {
EventEmitter.on(eventMap.customersNotFound, () => {
this.customerRenderer.showNotFoundCustomers();
this.customerRenderer.hideCheckoutHistoryBlock();
});
}
/**
* Listens for customer select event
*
* @private
*/
_onCustomerSelect() {
EventEmitter.on(eventMap.customerSelected, (event) => {
const $chooseBtn = $(event.currentTarget);
this.customerId = $chooseBtn.data('customer-id');
const createAddressUrl = this.router.generate(
'admin_addresses_create',
{
'liteDisplaying': 1,
'submitFormAjax': 1,
'id_customer': this.customerId,
}
);
$(createOrderMap.addressAddBtn).attr('href', createAddressUrl);
this.customerRenderer.displaySelectedCustomerBlock($chooseBtn);
});
}
/**
* Handles use case when customer is changed
*
* @private
*/
_changeCustomer() {
this.customerRenderer.showCustomerSearch();
}
/**
* Loads customer carts list
*
* @param currentCartId
*/
_loadCustomerCarts(currentCartId) {
const customerId = this.customerId;
this.customerRenderer.showLoadingCarts();
$.get(this.router.generate('admin_customers_carts', {customerId})).then((response) => {
this.customerRenderer.renderCarts(response.carts, currentCartId);
}).catch((e) => {
showErrorMessage(e.responseJSON.message);
});
}
/**
* Loads customer orders list
*/
_loadCustomerOrders() {
const customerId = this.customerId;
this.customerRenderer.showLoadingOrders();
$.get(this.router.generate('admin_customers_orders', {customerId})).then((response) => {
this.customerRenderer.renderOrders(response.orders);
}).catch((e) => {
showErrorMessage(e.responseJSON.message);
});
}
/**
* @param {Event} chooseCustomerEvent
*
* @return {Number}
*/
_selectCustomer(chooseCustomerEvent) {
EventEmitter.emit(eventMap.customerSelected, chooseCustomerEvent);
return this.customerId;
}
/**
* Searches for customers
*
* @private
*/
_search(searchPhrase) {
if (searchPhrase.length === 0) {
return;
}
if (this.activeSearchRequest !== null) {
this.activeSearchRequest.abort();
}
this.customerRenderer.clearShownCustomers();
this.customerRenderer.hideNotFoundCustomers();
this.customerRenderer.showSearchingCustomers();
const $searchRequest = $.get(this.router.generate('admin_customers_search'), {
customer_search: searchPhrase,
});
this.activeSearchRequest = $searchRequest;
$searchRequest.then((response) => {
EventEmitter.emit(eventMap.customerSearched, response);
}).catch((response) => {
if (response.statusText === 'abort') {
return;
}
showErrorMessage(response.responseJSON.message);
});
}
}

View File

@@ -0,0 +1,346 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from '@pages/order/create/create-order-map';
import Router from '@components/router';
import eventMap from '@pages/order/create/event-map';
import {EventEmitter} from '@components/event-emitter';
const {$} = window;
/**
* Responsible for customer information rendering
*/
export default class CustomerRenderer {
constructor() {
this.$container = $(createOrderMap.customerSearchBlock);
this.$customerSearchResultBlock = $(createOrderMap.customerSearchResultsBlock);
this.router = new Router();
}
/**
* Renders customer search results
*
* @param foundCustomers
*/
renderSearchResults(foundCustomers) {
if (foundCustomers.length === 0) {
EventEmitter.emit(eventMap.customersNotFound);
return;
}
for (const customerId in foundCustomers) {
const customerResult = foundCustomers[customerId];
const customer = {
id: customerId,
firstName: customerResult.firstname,
lastName: customerResult.lastname,
email: customerResult.email,
birthday: customerResult.birthday !== '0000-00-00' ? customerResult.birthday : ' ',
};
this._renderFoundCustomer(customer);
}
// Show customer details in fancy box
$(createOrderMap.customerDetailsBtn).fancybox({
'type': 'iframe',
'width': '90%',
'height': '90%',
});
}
/**
* Responsible for displaying customer block after customer select
*
* @param $targetedBtn
*/
displaySelectedCustomerBlock($targetedBtn) {
this.showCheckoutHistoryBlock();
$targetedBtn.addClass('d-none');
const $customerCard = $targetedBtn.closest('.card');
$customerCard.addClass('border-success');
$customerCard.find(createOrderMap.changeCustomerBtn).removeClass('d-none');
this.$container.find(createOrderMap.customerSearchRow).addClass('d-none');
this.$container.find(createOrderMap.notSelectedCustomerSearchResults)
.closest(createOrderMap.customerSearchResultColumn)
.remove()
;
// Initial display of the customer, the cart is gonna be created then customer's carts
// and orders are going to be fetched, but we can display the loading messages right now
this.showLoadingCarts();
this.showLoadingOrders();
}
/**
* Shows customer search block
*/
showCustomerSearch() {
this.$container.find(createOrderMap.customerSearchRow).removeClass('d-none');
}
/**
* Empty the cart list and display a loading message.
*/
showLoadingCarts() {
const $cartsTable = $(createOrderMap.customerCartsTable);
$cartsTable.find('tbody').empty();
this.renderLoading($cartsTable);
}
/**
* Renders customer carts list
*
* @param {Array} carts
* @param {Int} currentCartId
*/
renderCarts(carts, currentCartId) {
const $cartsTable = $(createOrderMap.customerCartsTable);
const $cartsTableRowTemplate = $($(createOrderMap.customerCartsTableRowTemplate).html());
$cartsTable.find('tbody').empty();
this.showCheckoutHistoryBlock();
this._removeEmptyListRowFromTable($cartsTable);
for (const key in carts) {
const cart = carts[key];
// do not render current cart
if (cart.cartId === currentCartId) {
// render 'No records found' warn if carts only contain current cart
if (carts.length === 1) {
this._renderEmptyList($cartsTable);
}
continue;
}
const $cartsTableRow = $cartsTableRowTemplate.clone();
$cartsTableRow.find(createOrderMap.cartIdField).text(cart.cartId);
$cartsTableRow.find(createOrderMap.cartDateField).text(cart.creationDate);
$cartsTableRow.find(createOrderMap.cartTotalField).text(cart.totalPrice);
$cartsTableRow.find(createOrderMap.cartDetailsBtn).prop(
'href',
this.router.generate('admin_carts_view', {
cartId: cart.cartId,
liteDisplaying: 1,
}),
);
$cartsTableRow.find(createOrderMap.useCartBtn).data('cart-id', cart.cartId);
$cartsTable.find('thead').removeClass('d-none');
$cartsTable.find('tbody').append($cartsTableRow);
}
// Show cart details in fancy box
$(createOrderMap.cartDetailsBtn).fancybox({
'type': 'iframe',
'width': '90%',
'height': '90%',
});
}
/**
* Empty the order list and display a loading message.
*/
showLoadingOrders() {
const $ordersTable = $(createOrderMap.customerOrdersTable);
$ordersTable.find('tbody').empty();
this.renderLoading($ordersTable);
}
/**
* Renders customer orders list
*
* @param {Array} orders
*/
renderOrders(orders) {
const $ordersTable = $(createOrderMap.customerOrdersTable);
const $rowTemplate = $($(createOrderMap.customerOrdersTableRowTemplate).html());
$ordersTable.find('tbody').empty();
this.showCheckoutHistoryBlock();
this._removeEmptyListRowFromTable($ordersTable);
//render 'No records found' when list is empty
if (orders.length === 0) {
this._renderEmptyList($ordersTable);
return;
}
for (const key in Object.keys(orders)) {
const order = orders[key];
const $template = $rowTemplate.clone();
$template.find(createOrderMap.orderIdField).text(order.orderId);
$template.find(createOrderMap.orderDateField).text(order.orderPlacedDate);
$template.find(createOrderMap.orderProductsField).text(order.orderProductsCount);
$template.find(createOrderMap.orderTotalField).text(order.totalPaid);
$template.find(createOrderMap.orderPaymentMethod).text(order.paymentMethodName);
$template.find(createOrderMap.orderStatusField).text(order.orderStatus);
$template.find(createOrderMap.orderDetailsBtn).prop(
'href',
this.router.generate('admin_orders_view', {
orderId: order.orderId,
liteDisplaying: 1
}),
);
$template.find(createOrderMap.useOrderBtn).data('order-id', order.orderId);
$ordersTable.find('thead').removeClass('d-none');
$ordersTable.find('tbody').append($template);
}
// Show order details in fancy box
$(createOrderMap.orderDetailsBtn).fancybox({
'type': 'iframe',
'width': '90%',
'height': '90%',
});
}
/**
* Shows empty result when customer is not found
*/
showNotFoundCustomers() {
$(createOrderMap.customerSearchEmptyResultWarning).removeClass('d-none');
}
/**
* Hides not found customers warning
*/
hideNotFoundCustomers() {
$(createOrderMap.customerSearchEmptyResultWarning).addClass('d-none');
}
/**
* Shows checkout history block where carts and orders are rendered
*
* @private
*/
showCheckoutHistoryBlock() {
$(createOrderMap.customerCheckoutHistory).removeClass('d-none');
}
/**
* Hides checkout history block where carts and orders are rendered
*/
hideCheckoutHistoryBlock() {
$(createOrderMap.customerCheckoutHistory).addClass('d-none');
}
/**
* Shows searching customers notice during request
*/
showSearchingCustomers() {
$(createOrderMap.customerSearchLoadingNotice).removeClass('d-none');
}
/**
* Hide searching notice
*/
hideSearchingCustomers() {
$(createOrderMap.customerSearchLoadingNotice).addClass('d-none');
}
/**
* Renders 'No records' warning in list
*
* @param $table
*
* @private
*/
_renderEmptyList($table) {
const $emptyTableRow = $($(createOrderMap.emptyListRowTemplate).html()).clone();
$table.find('tbody').append($emptyTableRow);
}
/**
* Renders 'Loading' message in list
*
* @param $table
*
* @private
*/
renderLoading($table) {
const $emptyTableRow = $($(createOrderMap.loadingListRowTemplate).html()).clone();
$table.find('tbody').append($emptyTableRow);
}
/**
* Removes empty list row in case it was rendered
*/
_removeEmptyListRowFromTable($table) {
$table.find(createOrderMap.emptyListRow).remove();
}
/**
* Renders customer information after search action
*
* @param {Object} customer
*
* @return {jQuery}
*
* @private
*/
_renderFoundCustomer(customer) {
this.hideNotFoundCustomers();
const $customerSearchResultTemplate = $($(createOrderMap.customerSearchResultTemplate).html());
const $template = $customerSearchResultTemplate.clone();
$template.find(createOrderMap.customerSearchResultName).text(`${customer.firstName} ${customer.lastName}`);
$template.find(createOrderMap.customerSearchResultEmail).text(customer.email);
$template.find(createOrderMap.customerSearchResultId).text(customer.id);
$template.find(createOrderMap.customerSearchResultBirthday).text(customer.birthday);
$template.find(createOrderMap.chooseCustomerBtn).data('customer-id', customer.id);
$template.find(createOrderMap.customerDetailsBtn).prop(
'href',
this.router.generate('admin_customers_view', {
customerId: customer.id,
liteDisplaying: 1
}),
);
return this.$customerSearchResultBlock.append($template);
}
/**
* Clears shown customers
*/
clearShownCustomers() {
this.$customerSearchResultBlock.empty();
}
}

View File

@@ -0,0 +1,77 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
/**
* Encapsulates js events used in create order page
*/
export default {
// when customer search action is done
customerSearched: 'OrderCreateCustomerSearched',
// when new customer is selected
customerSelected: 'OrderCreateCustomerSelected',
// when no customers found by search
customersNotFound: 'OrderCreateSearchCustomerNotFound',
// when new cart is loaded,
// no matter if its empty, selected from carts list or duplicated by order.
cartLoaded: 'OrderCreateCartLoaded',
// when cart currency has been changed
cartCurrencyChanged: 'OrderCreateCartCurrencyChanged',
// when cart currency changing fails
cartCurrencyChangeFailed: 'OrderCreateCartCurrencyChangeFailed',
// when cart language has been changed
cartLanguageChanged: 'OrderCreateCartLanguageChanged',
// when cart addresses information has been changed
cartAddressesChanged: 'OrderCreateCartAddressesChanged',
// when cart delivery option has been changed
cartDeliveryOptionChanged: 'OrderCreateCartDeliveryOptionChanged',
// when cart delivery setting has been changed
cartDeliverySettingChanged: 'OrderCreateCartDeliverySettingChangedSet',
// when cart rules search action is done
cartRuleSearched: 'OrderCreateCartRuleSearched',
// when cart rule is removed from cart
cartRuleRemoved: 'OrderCreateCartRuleRemoved',
// when cart rule is added to cart
cartRuleAdded: 'OrderCreateCartRuleAdded',
// when cart rule cannot be added to cart
cartRuleFailedToAdd: 'OrderCreateCartRuleFailedToAdd',
// when product search action is done
productSearched: 'OrderCreateProductSearched',
// when product is added to cart
productAddedToCart: 'OrderCreateProductAddedToCart',
// when adding product to cart fails
productAddToCartFailed: 'OrderCreateProductAddToCartFailed',
// when product is removed from cart
productRemovedFromCart: 'OrderCreateProductRemovedFromCart',
// when product in cart price has been changed
productPriceChanged: 'OrderCreateProductPriceChanged',
// when product quantity in cart has been changed
productQtyChanged: 'OrderCreateProductQtyChanged',
// when changing product quantity in cart failed
productQtyChangeFailed: 'OrderCreateProductQtyChangeFailed',
// when order process email has been sent to customer
processOrderEmailSent: 'OrderCreateProcessOrderEmailSent',
// when order process email sending failed
processOrderEmailFailed: 'OrderCreateProcessOrderEmailFailed',
};

View File

@@ -0,0 +1,337 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import CartEditor from '@pages/order/create/cart-editor';
import createOrderMap from '@pages/order/create/create-order-map';
import eventMap from '@pages/order/create/event-map';
import {EventEmitter} from '@components/event-emitter';
import ProductRenderer from '@pages/order/create/product-renderer';
import Router from '@components/router';
const $ = window.$;
/**
* Product component Object for "Create order" page
*/
export default class ProductManager {
constructor() {
this.products = [];
this.selectedProduct = null;
this.selectedCombinationId = null;
this.activeSearchRequest = null;
this.productRenderer = new ProductRenderer();
this.router = new Router();
this.cartEditor = new CartEditor();
this._initListeners();
return {
search: searchPhrase => this._search(searchPhrase),
addProductToCart: cartId => this.cartEditor.addProduct(cartId, this._getProductData()),
removeProductFromCart: (cartId, product) => this.cartEditor.removeProductFromCart(cartId, product),
changeProductPrice: (cartId, customerId, updatedProduct) =>
this.cartEditor.changeProductPrice(cartId, customerId, updatedProduct),
changeProductQty: (cartId, updatedProduct) => this.cartEditor.changeProductQty(cartId, updatedProduct)
};
}
/**
* Initializes event listeners
*
* @private
*/
_initListeners() {
$(createOrderMap.productSelect).on('change', e => this._initProductSelect(e));
$(createOrderMap.combinationsSelect).on('change', e => this._initCombinationSelect(e));
this._onProductSearch();
this._onAddProductToCart();
this._onRemoveProductFromCart();
this._onProductPriceChange();
this._onProductQtyChange();
}
/**
* Listens for product search event
*
* @private
*/
_onProductSearch() {
EventEmitter.on(eventMap.productSearched, response => {
this.products = response.products;
this.productRenderer.renderSearchResults(this.products);
this._selectFirstResult();
});
}
/**
* Listens for add product to cart event
*
* @private
*/
_onAddProductToCart() {
// on success
EventEmitter.on(eventMap.productAddedToCart, cartInfo => {
this.productRenderer.cleanCartBlockAlerts();
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
});
// on failure
EventEmitter.on(eventMap.productAddToCartFailed, errorMessage => {
this.productRenderer.renderCartBlockErrorAlert(errorMessage);
});
}
/**
* Listens for remove product from cart event
*
* @private
*/
_onRemoveProductFromCart() {
EventEmitter.on(eventMap.productRemovedFromCart, cartInfo => {
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
});
}
/**
* Listens for product price change in cart event
*
* @private
*/
_onProductPriceChange() {
EventEmitter.on(eventMap.productPriceChanged, cartInfo => {
this.productRenderer.cleanCartBlockAlerts();
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
});
}
/**
* Listens for product quantity change in cart success/failure event
*
* @private
*/
_onProductQtyChange() {
const enableQtyInputs = () => {
const inputsQty = document.querySelectorAll(createOrderMap.listedProductQtyInput);
inputsQty.forEach(inputQty => {
inputQty.disabled = false;
});
};
// on success
EventEmitter.on(eventMap.productQtyChanged, cartInfo => {
this.productRenderer.cleanCartBlockAlerts();
EventEmitter.emit(eventMap.cartLoaded, cartInfo);
enableQtyInputs();
});
// on failure
EventEmitter.on(eventMap.productQtyChangeFailed, e => {
this.productRenderer.renderCartBlockErrorAlert(e.responseJSON.message);
enableQtyInputs();
});
}
/**
* Initializes product select
*
* @param event
*
* @private
*/
_initProductSelect(event) {
const productId = Number(
$(event.currentTarget)
.find(':selected')
.val()
);
this._selectProduct(productId);
}
/**
* Initializes combination select
*
* @param event
*
* @private
*/
_initCombinationSelect(event) {
const combinationId = Number(
$(event.currentTarget)
.find(':selected')
.val()
);
this._selectCombination(combinationId);
}
/**
* Searches for product
*
* @private
*/
_search(searchPhrase) {
if (searchPhrase.length < 2) {
return;
}
this.productRenderer.renderSearching();
if (this.activeSearchRequest !== null) {
this.activeSearchRequest.abort();
}
const params = {
search_phrase: searchPhrase
};
if ($(createOrderMap.cartCurrencySelect).data('selectedCurrencyId') != undefined) {
params.currency_id = $(createOrderMap.cartCurrencySelect).data('selectedCurrencyId');
}
const $searchRequest = $.get(this.router.generate('admin_orders_products_search'), params);
this.activeSearchRequest = $searchRequest;
$searchRequest
.then(response => {
EventEmitter.emit(eventMap.productSearched, response);
})
.catch(response => {
if (response.statusText === 'abort') {
return;
}
showErrorMessage(response.responseJSON.message);
});
}
/**
* Initiate first result dataset after search
*
* @private
*/
_selectFirstResult() {
this._unsetProduct();
const values = Object.values(this.products);
if (values.length !== 0) {
this._selectProduct(values[0].productId);
}
}
/**
* Handles use case when product is selected from search results
*
* @private
*
* @param {Number} productId
*/
_selectProduct(productId) {
this._unsetCombination();
for (const key in this.products) {
if (this.products[key].productId === productId) {
this.selectedProduct = this.products[key];
break;
}
}
this.productRenderer.renderProductMetadata(this.selectedProduct);
// if product has combinations select the first else leave it null
if (this.selectedProduct.combinations.length !== 0) {
this._selectCombination(Object.keys(this.selectedProduct.combinations)[0]);
}
return this.selectedProduct;
}
/**
* Handles use case when new combination is selected
*
* @param combinationId
*
* @private
*/
_selectCombination(combinationId) {
const combination = this.selectedProduct.combinations[combinationId];
this.selectedCombinationId = combinationId;
this.productRenderer.renderStock(
combination.stock,
this.selectedProduct.availableOutOfStock || combination.stock <= 0
);
return combination;
}
/**
* Sets the selected combination id to null
*
* @private
*/
_unsetCombination() {
this.selectedCombinationId = null;
}
/**
* Sets the selected product to null
*
* @private
*/
_unsetProduct() {
this.selectedProduct = null;
}
/**
* Retrieves product data from product search result block fields
*
* @returns {Object}
*
* @private
*/
_getProductData() {
const $fileInputs = $(createOrderMap.productCustomizationContainer).find('input[type="file"]');
const formData = new FormData(document.querySelector(createOrderMap.productAddForm));
const fileSizes = {};
// adds key value pairs {input name: file size} of each file in separate object in case formData size exceeds server settings.
$.each($fileInputs, (key, input) => {
if (input.files.length !== 0) {
fileSizes[$(input).data('customization-field-id')] = input.files[0].size;
}
});
return {
product: formData,
fileSizes
};
}
}

View File

@@ -0,0 +1,495 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from './create-order-map';
const $ = window.$;
export default class ProductRenderer {
constructor() {
this.$productsTable = $(createOrderMap.productsTable);
}
/**
* Renders cart products list
*
* @param products
*/
renderList(products) {
this._cleanProductsList();
if (products.length === 0) {
this._hideProductsList();
return;
}
for (const key in products) {
const product = products[key];
const $template = this.cloneProductTemplate(product);
let customizationId = 0;
if (product.customization) {
customizationId = product.customization.customizationId;
this._renderListedProductCustomization(product.customization, $template);
}
$template.find(createOrderMap.listedProductImageField).prop('src', product.imageLink);
$template.find(createOrderMap.listedProductNameField).text(product.name);
$template.find(createOrderMap.listedProductAttrField).text(product.attribute);
$template.find(createOrderMap.listedProductReferenceField).text(product.reference);
if (product.gift !== true) {
$template.find(createOrderMap.listedProductUnitPriceInput).val(product.unitPrice);
$template.find(createOrderMap.listedProductUnitPriceInput).data('product-id', product.productId);
$template.find(createOrderMap.listedProductUnitPriceInput).data('attribute-id', product.attributeId);
$template.find(createOrderMap.listedProductUnitPriceInput).data('customization-id', customizationId);
$template.find(createOrderMap.listedProductQtyInput).val(product.quantity);
$template.find(createOrderMap.listedProductQtyInput).data('product-id', product.productId);
$template.find(createOrderMap.listedProductQtyInput).data('attribute-id', product.attributeId);
$template.find(createOrderMap.listedProductQtyInput).data('customization-id', customizationId);
$template.find(createOrderMap.listedProductQtyInput).data('prev-qty', product.quantity);
$template.find(createOrderMap.productTotalPriceField).text(product.price);
$template.find(createOrderMap.productRemoveBtn).data('product-id', product.productId);
$template.find(createOrderMap.productRemoveBtn).data('attribute-id', product.attributeId);
$template.find(createOrderMap.productRemoveBtn).data('customization-id', customizationId);
} else {
$template.find(createOrderMap.listedProductGiftQty).text(product.quantity);
}
this.$productsTable.find('tbody').append($template);
}
this._showTaxWarning();
this._showProductsList();
}
/**
* Renders customization data for listed product
*
* @param customization
* @param $productRowTemplate
*
* @private
*/
_renderListedProductCustomization(customization, $productRowTemplate) {
const $customizedTextTemplate = $($(createOrderMap.listedProductCustomizedTextTemplate).html());
const $customizedFileTemplate = $($(createOrderMap.listedProductCustomizedFileTemplate).html());
for (const key in customization.customizationFieldsData) {
const customizedData = customization.customizationFieldsData[key];
let $customizationTemplate = $customizedTextTemplate.clone();
if (customizedData.type === createOrderMap.productCustomizationFieldTypeFile) {
$customizationTemplate = $customizedFileTemplate.clone();
$customizationTemplate.find(createOrderMap.listedProductCustomizationName).text(customizedData.name);
$customizationTemplate
.find(`${createOrderMap.listedProductCustomizationValue} img`)
.prop('src', customizedData.value);
} else {
$customizationTemplate.find(createOrderMap.listedProductCustomizationName).text(customizedData.name);
$customizationTemplate.find(createOrderMap.listedProductCustomizationValue).text(customizedData.value);
}
$productRowTemplate.find(createOrderMap.listedProductDefinition).append($customizationTemplate);
}
}
renderSearching() {
this.reset();
this.toggleSearchingNotice(true);
}
/**
* Renders cart products search results block
*
* @param foundProducts
*/
renderSearchResults(foundProducts) {
this._cleanSearchResults();
this.toggleSearchingNotice(false);
if (foundProducts.length === 0) {
this._showNotFound();
this._hideTaxWarning();
return;
}
this._renderFoundProducts(foundProducts);
this._hideNotFound();
this._showTaxWarning();
this._showResultBlock();
}
reset() {
this._cleanSearchResults();
this._hideTaxWarning();
this._hideResultBlock();
this.toggleSearchingNotice(false);
}
/**
* Renders available fields related to selected product
*
* @param {object} product
*/
renderProductMetadata(product) {
this.renderStock(product.stock, product.availableOutOfStock || (product.stock <= 0));
this._renderCombinations(product.combinations);
this._renderCustomizations(product.customizationFields);
}
/**
* Updates stock text helper value
*
* @param {number} stock
* @param {boolean} infinitMax
*/
renderStock(stock, infinitMax) {
$(createOrderMap.inStockCounter).text(stock);
if (!infinitMax) {
$(createOrderMap.quantityInput).attr('max', stock);
} else {
$(createOrderMap.quantityInput).removeAttr('max');
}
}
/**
* @param product
*
* @private
*/
cloneProductTemplate(product) {
return product.gift === true
? $($(createOrderMap.productsTableGiftRowTemplate).html()).clone()
: $($(createOrderMap.productsTableRowTemplate).html()).clone();
}
/**
* Renders found products select
*
* @param foundProducts
*
* @private
*/
_renderFoundProducts(foundProducts) {
for (const key in foundProducts) {
const product = foundProducts[key];
let name = product.name;
if (product.combinations.length === 0) {
name += ` - ${product.formattedPrice}`;
}
$(createOrderMap.productSelect).append(`<option value="${product.productId}">${name}</option>`);
}
}
/**
* Cleans product search result fields
*
* @private
*/
_cleanSearchResults() {
$(createOrderMap.productSelect).empty();
$(createOrderMap.combinationsSelect).empty();
$(createOrderMap.quantityInput).empty();
}
/**
* Renders combinations row with select options
*
* @param {Array} combinations
*
* @private
*/
_renderCombinations(combinations) {
this._cleanCombinations();
if (combinations.length === 0) {
this._hideCombinations();
return;
}
for (const key in combinations) {
const combination = combinations[key];
$(createOrderMap.combinationsSelect).append(
`<option
value="${combination.attributeCombinationId}">
${combination.attribute} - ${combination.formattedPrice}
</option>`
);
}
this._showCombinations();
}
/**
* Resolves weather to add customization fields to result block and adds them if needed
*
* @param customizationFields
*
* @private
*/
_renderCustomizations(customizationFields) {
// represents customization field type "file".
const fieldTypeFile = createOrderMap.productCustomizationFieldTypeFile;
// represents customization field type "text".
const fieldTypeText = createOrderMap.productCustomizationFieldTypeText;
this._cleanCustomizations();
if (customizationFields.length === 0) {
this._hideCustomizations();
return;
}
const $customFieldsContainer = $(createOrderMap.productCustomFieldsContainer);
const $fileInputTemplate = $($(createOrderMap.productCustomFileTemplate).html());
const $textInputTemplate = $($(createOrderMap.productCustomTextTemplate).html());
const templateTypeMap = {
[fieldTypeFile]: $fileInputTemplate,
[fieldTypeText]: $textInputTemplate,
};
for (const key in customizationFields) {
const customField = customizationFields[key];
const $template = templateTypeMap[customField.type].clone();
if (customField.type === fieldTypeFile) {
$template.on('change', (e) => {
const fileName = e.target.files[0].name;
$(e.target).next('.custom-file-label').html(fileName);
});
}
$template
.find(createOrderMap.productCustomInput)
.attr('name', `customizations[${customField.customizationFieldId}]`)
.data('customization-field-id', customField.customizationFieldId);
$template
.find(createOrderMap.productCustomInputLabel)
.attr('for', `customizations[${customField.customizationFieldId}]`)
.text(customField.name);
if (customField.required === true) {
$template.find(createOrderMap.requiredFieldMark).removeClass('d-none');
}
$customFieldsContainer.append($template);
}
this._showCustomizations();
}
/**
* Renders error alert for cart block
*
* @param message
*/
renderCartBlockErrorAlert(message) {
$(createOrderMap.cartErrorAlertText).text(message);
this._showCartBlockError();
}
/**
* Cleans cart block alerts content and hides them
*/
cleanCartBlockAlerts() {
$(createOrderMap.cartErrorAlertText).text('');
this._hideCartBlockError();
}
/**
* Shows error alert block of cart block
*
* @private
*/
_showCartBlockError() {
$(createOrderMap.cartErrorAlertBlock).removeClass('d-none');
}
/**
* Hides error alert block of cart block
*
* @private
*/
_hideCartBlockError() {
$(createOrderMap.cartErrorAlertBlock).addClass('d-none');
}
/**
* Shows product customization container
*
* @private
*/
_showCustomizations() {
$(createOrderMap.productCustomizationContainer).removeClass('d-none');
}
/**
* Hides product customization container
*
* @private
*/
_hideCustomizations() {
$(createOrderMap.productCustomizationContainer).addClass('d-none');
}
/**
* Empties customization fields container
*
* @private
*/
_cleanCustomizations() {
$(createOrderMap.productCustomFieldsContainer).empty();
}
/**
* Shows result block
*
* @private
*/
_showResultBlock() {
$(createOrderMap.productResultBlock).removeClass('d-none');
}
/**
* Hides result block
*
* @private
*/
_hideResultBlock() {
$(createOrderMap.productResultBlock).addClass('d-none');
}
/**
* Shows products list
*
* @private
*/
_showProductsList() {
this.$productsTable.removeClass('d-none');
}
/**
* Hides products list
*
* @private
*/
_hideProductsList() {
this.$productsTable.addClass('d-none');
}
/**
* Empties products list
*
* @private
*/
_cleanProductsList() {
this.$productsTable.find('tbody').empty();
}
/**
* Empties combinations select
*
* @private
*/
_cleanCombinations() {
$(createOrderMap.combinationsSelect).empty();
}
/**
* Shows combinations row
*
* @private
*/
_showCombinations() {
$(createOrderMap.combinationsRow).removeClass('d-none');
}
/**
* Hides combinations row
*
* @private
*/
_hideCombinations() {
$(createOrderMap.combinationsRow).addClass('d-none');
}
/**
* Shows warning of tax included/excluded
*
* @private
*/
_showTaxWarning() {
$(createOrderMap.productTaxWarning).removeClass('d-none');
}
/**
* Hides warning of tax included/excluded
*
* @private
*/
_hideTaxWarning() {
$(createOrderMap.productTaxWarning).addClass('d-none');
}
/**
* Shows product not found warning
*
* @private
*/
_showNotFound() {
$(createOrderMap.noProductsFoundWarning).removeClass('d-none');
}
/**
* Hides product not found warning
*
* @private
*/
_hideNotFound() {
$(createOrderMap.noProductsFoundWarning).addClass('d-none');
}
/**
* Toggles searching product notice
*
* @private
*/
toggleSearchingNotice(visible) {
$(createOrderMap.searchingProductsNotice).toggleClass('d-none', !visible);
}
}

View File

@@ -0,0 +1,235 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from './create-order-map';
const $ = window.$;
/**
* Manipulates UI of Shipping block in Order creation page
*/
export default class ShippingRenderer {
constructor() {
this.$container = $(createOrderMap.shippingBlock);
this.$form = $(createOrderMap.shippingForm);
this.$noCarrierBlock = $(createOrderMap.noCarrierBlock);
}
/**
* @param {Object} shipping
* @param {Boolean} emptyCart
*/
render(shipping, emptyCart) {
if (emptyCart) {
this._hideContainer();
} else if (shipping !== null) {
this._displayForm(shipping);
} else {
this._displayNoCarriersWarning();
}
}
/**
* Show form block with rendered delivery options instead of warning message
*
* @param shipping
*
* @private
*/
_displayForm(shipping) {
this._hideNoCarrierBlock();
this._renderDeliveryOptions(shipping.deliveryOptions, shipping.selectedCarrierId);
this._renderTotalShipping(shipping.shippingPrice);
this._renderFreeShippingSwitch(shipping.freeShipping);
this.renderRecycledPackagingSwitch(shipping.recycledPackaging);
this.renderGiftMessageField(shipping.giftMessage);
this.renderGiftSwitch(shipping.gift);
this._showForm();
this._showContainer();
}
/**
* Renders free shipping switch depending on free shipping value
*
* @param isFreeShipping
*
* @private
*/
_renderFreeShippingSwitch(isFreeShipping) {
$(createOrderMap.freeShippingSwitch).each((key, input) => {
if (input.value === '1') {
input.checked = isFreeShipping;
} else {
input.checked = !isFreeShipping;
}
});
}
/**
* @param useRecycledPackaging
*
* @private
*/
renderRecycledPackagingSwitch(useRecycledPackaging) {
$(createOrderMap.recycledPackagingSwitch).each((key, input) => {
if (input.value === '1') {
input.checked = useRecycledPackaging;
} else {
input.checked = !useRecycledPackaging;
}
});
}
/**
* @param isAGift
*
* @private
*/
renderGiftSwitch(isAGift) {
$(createOrderMap.isAGiftSwitch).each((key, input) => {
if (input.value === '1') {
input.checked = isAGift;
} else {
input.checked = !isAGift;
}
});
}
/**
* @param giftMessage
*
* @private
*/
renderGiftMessageField(giftMessage) {
$(createOrderMap.giftMessageField).val(giftMessage);
}
/**
* Show warning message that no carriers are available and hide form block
*
* @private
*/
_displayNoCarriersWarning() {
this._showContainer();
this._hideForm();
this._showNoCarrierBlock();
}
/**
* Renders delivery options selection block
*
* @param deliveryOptions
* @param selectedVal
*
* @private
*/
_renderDeliveryOptions(deliveryOptions, selectedVal) {
const $deliveryOptionSelect = $(createOrderMap.deliveryOptionSelect);
$deliveryOptionSelect.empty();
for (const key in Object.keys(deliveryOptions)) {
const option = deliveryOptions[key];
const deliveryOption = {
value: option.carrierId,
text: `${option.carrierName} - ${option.carrierDelay}`,
};
if (selectedVal === deliveryOption.value) {
deliveryOption.selected = 'selected';
}
$deliveryOptionSelect.append($('<option>', deliveryOption));
}
}
/**
* Renders dynamic value of shipping price
*
* @param shippingPrice
*
* @private
*/
_renderTotalShipping(shippingPrice) {
const $totalShippingField = $(createOrderMap.totalShippingField);
$totalShippingField.empty();
$totalShippingField.append(shippingPrice);
}
/**
* Show whole shipping container
*
* @private
*/
_showContainer() {
this.$container.removeClass('d-none');
}
/**
* Hide whole shipping container
*
* @private
*/
_hideContainer() {
this.$container.addClass('d-none');
}
/**
* Show form block
*
* @private
*/
_showForm() {
this.$form.removeClass('d-none');
}
/**
* Hide form block
*
* @private
*/
_hideForm() {
this.$form.addClass('d-none');
}
/**
* Show warning message block which warns that no carriers are available
*
* @private
*/
_showNoCarrierBlock() {
this.$noCarrierBlock.removeClass('d-none');
}
/**
* Hide warning message block which warns that no carriers are available
*
* @private
*/
_hideNoCarrierBlock() {
this.$noCarrierBlock.addClass('d-none');
}
}

View File

@@ -0,0 +1,93 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import {EventEmitter} from '../../../components/event-emitter';
import eventMap from './event-map';
import SummaryRenderer from './summary-renderer';
import Router from '../../../components/router';
const $ = window.$;
/**
* Manages summary block
*/
export default class SummaryManager {
constructor() {
this.router = new Router();
this.summaryRenderer = new SummaryRenderer();
this._initListeners();
return {
sendProcessOrderEmail: cartId => this._sendProcessOrderEmail(cartId),
};
}
/**
* Inits event listeners
*
* @private
*/
_initListeners() {
this._onProcessOrderEmailError();
this._onProcessOrderEmailSuccess();
}
/**
* Listens for process order email sending success event
*
* @private
*/
_onProcessOrderEmailSuccess() {
EventEmitter.on(eventMap.processOrderEmailSent, (response) => {
this.summaryRenderer.cleanAlerts();
this.summaryRenderer.renderSuccessMessage(response.message);
});
}
/**
* Listens for process order email failed event
*
* @private
*/
_onProcessOrderEmailError() {
EventEmitter.on(eventMap.processOrderEmailFailed, (response) => {
this.summaryRenderer.cleanAlerts();
this.summaryRenderer.renderErrorMessage(response.responseJSON.message);
});
}
/**
* Sends email to customer with link of order processing
*
* @param {Number} cartId
*/
_sendProcessOrderEmail(cartId) {
$.post(this.router.generate('admin_orders_send_process_order_email'), {
cartId,
}).then(response => EventEmitter.emit(eventMap.processOrderEmailSent, response)).catch((e) => {
EventEmitter.emit(eventMap.processOrderEmailFailed, e);
});
}
}

View File

@@ -0,0 +1,177 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
import createOrderMap from './create-order-map';
import CreateOrderPage from "./create-order-page";
const $ = window.$;
/**
* Responsible for summary block rendering
*/
export default class SummaryRenderer {
constructor() {
this.$totalProducts = $(createOrderMap.summaryTotalProducts);
this.$totalDiscount = $(createOrderMap.summaryTotalDiscount);
this.$totalShipping = $(createOrderMap.totalShippingField);
this.$summaryTotalShipping = $(createOrderMap.summaryTotalShipping);
this.$totalTaxes = $(createOrderMap.summaryTotalTaxes);
this.$totalWithoutTax = $(createOrderMap.summaryTotalWithoutTax);
this.$totalWithTax = $(createOrderMap.summaryTotalWithTax);
this.$placeOrderCartIdField = $(createOrderMap.placeOrderCartIdField);
this.$orderMessageField = $(createOrderMap.orderMessageField);
this.$processOrderLink = $(createOrderMap.processOrderLinkTag);
}
/**
* Renders summary block
*
* @param {Object} cartInfo
*/
render(cartInfo) {
this._cleanSummary();
const noProducts = cartInfo.products.length === 0;
const noShippingOptions = cartInfo.shipping === null;
const addressesAreValid = CreateOrderPage.validateSelectedAddresses(cartInfo.addresses);
if (noProducts || noShippingOptions || !addressesAreValid) {
this._hideSummaryBlock();
return;
}
const cartSummary = cartInfo.summary;
this.$totalProducts.text(cartSummary.totalProductsPrice);
this.$totalDiscount.text(cartSummary.totalDiscount);
this.$summaryTotalShipping.text(cartSummary.totalShippingWithoutTaxes);
this.$totalShipping.text(cartSummary.totalShippingPrice);
this.$totalTaxes.text(cartSummary.totalTaxes);
this.$totalWithoutTax.text(cartSummary.totalPriceWithoutTaxes);
this.$totalWithTax.text(cartSummary.totalPriceWithTaxes);
this.$processOrderLink.prop('href', cartSummary.processOrderLink);
this.$orderMessageField.text(cartSummary.orderMessage);
this.$placeOrderCartIdField.val(cartInfo.cartId);
this._showSummaryBlock();
}
/**
* Renders summary success message
*
* @param message
*/
renderSuccessMessage(message) {
$(createOrderMap.summarySuccessAlertText).text(message);
this._showSummarySuccessAlertBlock();
}
/**
* Renders summary error message
*
* @param message
*/
renderErrorMessage(message) {
$(createOrderMap.summaryErrorAlertText).text(message);
this._showSummaryErrorAlertBlock();
}
/**
* Cleans content of success/error summary alerts and hides them
*/
cleanAlerts() {
$(createOrderMap.summarySuccessAlertText).text('');
$(createOrderMap.summaryErrorAlertText).text('');
this._hideSummarySuccessAlertBlock();
this._hideSummaryErrorAlertBlock();
}
/**
* Shows summary block
*
* @private
*/
_showSummaryBlock() {
$(createOrderMap.summaryBlock).removeClass('d-none');
}
/**
* Hides summary block
*
* @private
*/
_hideSummaryBlock() {
$(createOrderMap.summaryBlock).addClass('d-none');
}
/**
* Shows error alert of summary block
*
* @private
*/
_showSummaryErrorAlertBlock() {
$(createOrderMap.summaryErrorAlertBlock).removeClass('d-none');
}
/**
* Hides error alert of summary block
*
* @private
*/
_hideSummaryErrorAlertBlock() {
$(createOrderMap.summaryErrorAlertBlock).addClass('d-none');
}
/**
* Shows success alert of summary block
*
* @private
*/
_showSummarySuccessAlertBlock() {
$(createOrderMap.summarySuccessAlertBlock).removeClass('d-none');
}
/**
* Hides success alert of summary block
*
* @private
*/
_hideSummarySuccessAlertBlock() {
$(createOrderMap.summarySuccessAlertBlock).addClass('d-none');
}
/**
* Empties cart summary fields
*/
_cleanSummary() {
this.$totalProducts.empty();
this.$totalDiscount.empty();
this.$totalShipping.empty();
this.$totalTaxes.empty();
this.$totalWithoutTax.empty();
this.$totalWithTax.empty();
this.$processOrderLink.prop('href', '');
this.$orderMessageField.text('');
this.cleanAlerts();
}
}