Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
export default {
switchCustomer: 'switchCartRuleCustomer',
};

View File

@@ -0,0 +1,24 @@
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
const discountContainer = '.discount-container';
export default {
codeGeneratorBtn: '#cart_rule_information .js-generator-btn',
codeInput: '#cart_rule_information_code',
currencySelect: '#cart_rule_actions_discount_reduction_currency',
customerItem: '#cart_rule_conditions_customer_list .entity-item',
customerSearchContainer: '#cart_rule_conditions_customer',
discountApplicationSelect: '#cart_rule_actions_discount_discount_application',
discountContainer,
giftProductSearchContainer: '#cart_rule_actions_gift_product',
applyToDiscountedProductsContainer: '.apply-to-discounted-products',
highlightSwitchContainer: '.js-highlight-switch-container',
includeTaxInput: '#cart_rule_actions_discount_reduction_include_tax',
reductionTypeSelect: '#cart_rule_actions_discount_reduction_type',
// eslint-disable-next-line max-len
reductionValueSymbol: `${discountContainer} .price-reduction-value .input-group .input-group-append .input-group-text, .price-reduction-value .input-group .input-group-prepend .input-group-text`,
specificProductSearchComponent: '#cart_rule_actions_discount_specific_product',
specificProductSearchContainer: '.specific-product-search-container',
};

View File

@@ -0,0 +1,99 @@
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
import CartRuleMap from '@pages/cart-rule/cart-rule-map';
import ProductSearchInput from '@components/form/product-search-input';
export default class DiscountApplicationManager {
private readonly reductionTypeSelector: string;
private readonly applicationSelect: string;
constructor() {
this.reductionTypeSelector = CartRuleMap.reductionTypeSelect;
this.applicationSelect = CartRuleMap.discountApplicationSelect;
this.init();
}
private init(): void {
new ProductSearchInput(CartRuleMap.specificProductSearchComponent);
this.updateChoices(this.getReductionTypeSelect().value);
this.toggleExcludeDiscountedProducts(this.getReductionTypeSelect().value);
this.toggleSpecificProductsSearch(this.getApplicationSelect().value);
this.listenReductionTypeChanges();
this.listenDiscountApplicationChanges();
}
private listenReductionTypeChanges(): void {
const reductionTypeSelect = this.getReductionTypeSelect();
reductionTypeSelect.addEventListener('change', (e: Event) => {
const currentTarget = <HTMLSelectElement> e.currentTarget;
this.updateChoices(currentTarget.value);
this.toggleExcludeDiscountedProducts(currentTarget.value);
});
}
private listenDiscountApplicationChanges(): void {
const applicationSelect = this.getApplicationSelect();
applicationSelect.addEventListener('change', (e: Event) => {
const currentTarget = <HTMLSelectElement> e.currentTarget;
this.toggleSpecificProductsSearch(currentTarget.value);
});
}
private updateChoices(reductionType: string): void {
const discountApplicationSelect = <HTMLSelectElement> document.querySelector(CartRuleMap.discountApplicationSelect);
const selectedValue = discountApplicationSelect.value;
$(discountApplicationSelect).empty();
let choices: Record<string, string> = JSON.parse(<string> discountApplicationSelect.dataset.amountChoices);
if (reductionType === 'percentage') {
choices = JSON.parse(<string> discountApplicationSelect.dataset.percentageChoices);
}
Object.entries(choices).forEach(([label, value]) => {
const newOption = document.createElement('option');
newOption.label = label;
newOption.value = value;
newOption.selected = selectedValue === value;
discountApplicationSelect.add(newOption);
});
}
private toggleExcludeDiscountedProducts(reductionType: string): void {
const excludeDiscountedProductsEl = <HTMLDivElement> document.querySelector(CartRuleMap.applyToDiscountedProductsContainer);
if (reductionType === 'percentage') {
$(excludeDiscountedProductsEl).fadeIn();
} else {
$(excludeDiscountedProductsEl).fadeOut();
}
}
private toggleSpecificProductsSearch(applicationChoice: string): void {
const specificProductSearchContainer = <HTMLDivElement> document.querySelector(CartRuleMap.specificProductSearchContainer);
if (applicationChoice === 'specific_product') {
$(specificProductSearchContainer).fadeIn();
} else {
$(specificProductSearchContainer).fadeOut();
}
}
private getReductionTypeSelect(): HTMLSelectElement {
return <HTMLSelectElement> document.querySelector(this.reductionTypeSelector);
}
private getApplicationSelect(): HTMLSelectElement {
return <HTMLSelectElement> document.querySelector(this.applicationSelect);
}
}

View File

@@ -0,0 +1,34 @@
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
import CartRuleMap from '@pages/cart-rule/cart-rule-map';
import PriceReductionManager from '@components/form/price-reduction-manager';
import DiscountApplicationManager from '@pages/cart-rule/form/discount-application-manager';
export default class DiscountManager {
constructor() {
this.init();
}
private init(): void {
new DiscountApplicationManager();
new PriceReductionManager(
CartRuleMap.reductionTypeSelect,
CartRuleMap.includeTaxInput,
CartRuleMap.currencySelect,
CartRuleMap.reductionValueSymbol,
);
this.toggleCurrency();
document.querySelector(CartRuleMap.reductionTypeSelect)?.addEventListener('change', this.toggleCurrency);
}
private toggleCurrency(): void {
if ($(CartRuleMap.reductionTypeSelect).val() === 'percentage') {
$(CartRuleMap.currencySelect).fadeOut();
} else {
$(CartRuleMap.currencySelect).fadeIn();
}
}
}

View File

@@ -0,0 +1,45 @@
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
import CartRuleMap from '@pages/cart-rule/cart-rule-map';
import FormFieldToggler from '@components/form/form-field-toggler';
import CartRuleEventMap from '@pages/cart-rule/cart-rule-event-map';
import CustomerSearchInput from '@components/form/customer-search-input';
import DiscountManager from '@pages/cart-rule/form/discount-manager';
import ProductSearchInput from '@components/form/product-search-input';
$(() => {
window.prestashop.component.initComponents([
'TranslatableField',
'TranslatableInput',
'EventEmitter',
]);
// It is important that discountManager is initialized before DisablingSwitch
// or else it won't find reduction type value when it is disabled therefore not toggling some inputs correctly on init
new DiscountManager();
window.prestashop.component.initComponents([
'DisablingSwitch',
'GeneratableInput',
]);
window.prestashop.instance.generatableInput.attachOn(CartRuleMap.codeGeneratorBtn);
new FormFieldToggler({
disablingInputSelector: CartRuleMap.codeInput,
targetSelector: CartRuleMap.highlightSwitchContainer,
matchingValue: '',
});
new CustomerSearchInput(
CartRuleMap.customerSearchContainer,
CartRuleMap.customerItem,
// use all shops constraint
() => null,
CartRuleEventMap.switchCustomer,
);
new ProductSearchInput(CartRuleMap.giftProductSearchContainer);
});

View File

@@ -0,0 +1,18 @@
/**
* For the full copyright and license information, please view the
* docs/licenses/LICENSE.txt file that was distributed with this source code.
*/
$(() => {
const cartRuleGrid = new window.prestashop.component.Grid('cart_rule');
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.ExportToSqlManagerExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.ReloadListExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.SortingExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.FiltersResetExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.ColumnTogglingExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.SubmitRowActionExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.SubmitBulkActionExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.BulkActionCheckboxExtension());
cartRuleGrid.addExtension(new window.prestashop.component.GridExtensions.FiltersSubmitButtonEnablerExtension());
});