diff --git a/modules/thobbodymeasurements/views/js/front-set-product-measurements.js b/modules/thobbodymeasurements/views/js/front-set-product-measurements.js new file mode 100644 index 0000000..0ce9d9d --- /dev/null +++ b/modules/thobbodymeasurements/views/js/front-set-product-measurements.js @@ -0,0 +1,285 @@ +$(document).ready(function() { + + $('#photos-completed-button').click(function(event){ + event.preventDefault(); + + var accessCode = $('#product-additional-info-access-code').val(); + + $.ajax({ + url: 'index.php?fc=module&module=thobbodymeasurements&controller=SetProductMeasurements&ajax=true&action=getCustomerMeasurementsForMirrorSize', + method: 'POST', + dataType: 'json', + headers: { + Accepts: "application/json", + }, + data: { + ajax: true, + action: 'getCustomerMeasurementsForMirrorSize', + accessCode: accessCode, + }, + success: function(response) { + console.log(response); + // window.location.reload(); + }, + error: function(xhr, status, error) { + console.error(xhr.responseText); + } + }); + }); + + $('#set-measurements-button').click(function(event) { + // Prevent the default behavior of the anchor tag + event.preventDefault(); + + // Toggle the visibility of the modal + $('#measurements-modal').toggle(); + }); + $(document).click(function(event) { + // Check if the click target is not within the modal + if (!$(event.target).closest('#measurements-modal').length && !$(event.target).is('#set-measurements-button')) { + // Hide the modal + $('#measurements-modal').hide(); + } + }); + }); + + + // Add click event handler to the "Custom Measurements" tab + $('#custom-measurements-tab').click(function(event) { + // Prevent the default behavior of the anchor tag + event.preventDefault(); + + // Hide the "Mirror Size Measurements" tab if it's currently active + $('#mirror-size-measurements').removeClass('opacity-100 block active'); + + // Show the "Custom Measurements" tab + $('#custom-measurements').addClass('opacity-100 block active'); +}); + +// Add click event handler to the "Mirror Size Measurements" tab +$('#mirror-size-measurements-tab').click(function(event) { + // Prevent the default behavior of the anchor tag + event.preventDefault(); + + + // Show the "Mirror Size Measurements" tab + $('#mirror-size-measurements').addClass('opacity-100 block active'); +}); + + + + // Add click event handler to the "Photos Completed" button + $('#photos-completed-button').click(function(event) { + // Perform some action here + alert('Photos Completed button clicked!'); + }); + + + $('#submit-measurements-button').click(function(event) { + event.preventDefault(); + var measurements = []; + + $('.modal-set-measurements .form-group').each(function() { + var attributeId = $(this).find('input').attr('id'); + var value = $(this).find('input').val(); + console.log("Attribute id: ",attributeId) + console.log("value: ",value) + + + measurements.push({ + "attributeId": attributeId, + "value": value + }); + }); + console.log("measurements: ",measurements) + + var formId = $('#current_form_id').val(); + var formLabel = $('#current_form_label').val(); + + var productId = $('#product-additional-info-product-id').val(); + var categoryId = $('#product-additional-info-category-id').val(); + var productAttributeId = $('#product-additional-info-product-attribute-id').val(); + + $.ajax({ + url: 'index.php?fc=module&module=thobbodymeasurements&controller=SetProductMeasurements&ajax=true&action=saveProductMeasurements', + method: 'POST', + dataType: 'json', + headers: { + Accepts: "application/json", + }, + data: { + ajax: true, + action: 'saveProductMeasurements', + formId: formId, + formLabel: formLabel, + measurements: JSON.stringify(measurements), + productId: productId, + categoryId: categoryId, + productAttributeId: productAttributeId, + }, + success: function(response) { + console.log(response); + window.location.reload(); + }, + error: function(xhr, status, error) { + console.error(xhr.responseText); + } + }); + }); + + $('.add-to-cart').click( (event) => { + console.log("inside add to cart click..."); + + var productId = $('#product-additional-info-product-id').val(); + var categoryId = $('#product-additional-info-category-id').val(); + var productAttributeId = $('#product-additional-info-product-attribute-id').val(); + + if(!productId && !categoryId){ + return; + } + + event.preventDefault(); + event.stopImmediatePropagation(); + + var formId = $('#current_form_id').val(); + var formLabel = $('#current_form_label').val(); + var measurements = []; + + $('.modal-set-measurements .form-group').each(function() { + var attributeId = $(this).find('input').attr('id'); + var value = $(this).find('input').val(); + + measurements.push({ + "attributeId": attributeId, + "value": value + }); + }); + + //first check if the measurements are set by the customer + $.ajax({ + url: 'index.php?fc=module&module=thobbodymeasurements&controller=SetProductMeasurements&ajax=true&action=customerHasMeasurements', + method: 'POST', + dataType: 'json', + headers: { + Accepts: "application/json", + }, + data: { + ajax: true, + action: 'customerHasMeasurements', + productId: productId, + categoryId: categoryId, + } + }).done(function (response){ + console.log('has measurements response....'); + if(!response.hasMeasurements){ + console.log("Set measurements first..."); + $('#measurements-modal').modal('show'); + }else{ + $.ajax({ + url: 'index.php?fc=module&module=thobbodymeasurements&controller=SetProductMeasurements&ajax=true&action=saveProductMeasurements', + method: 'POST', + dataType: 'json', + headers: { + Accepts: "application/json", + }, + data: { + ajax: true, + action: 'saveProductMeasurements', + formId: formId, + formLabel: formLabel, + measurements: JSON.stringify(measurements), + productId: productId, + categoryId: categoryId, + productAttributeId: productAttributeId, + }, + success: function(response) { + console.log(response); + console.log("Proceed to add to cart...."); + + const $form = $(event.currentTarget.form); + const query = `${$form.serialize()}&add=1&action=update`; + console.log("Query: ", query); + + const actionURL = $form.attr('action'); + const addToCartButton = $(event.currentTarget); + + addToCartButton.prop('disabled', true); + + const isQuantityInputValid = ($input) => { + let validInput = true; + + $input.each((index, input) => { + const $currentInput = $(input); + const minimalValue = parseInt($currentInput.attr('min'), 10); + + if (minimalValue && $currentInput.val() < minimalValue) { + onInvalidQuantity($currentInput); + validInput = false; + } + }); + + return validInput; + }; + + let onInvalidQuantity = ($input) => { + $input + .parents(prestashop.selectors.product.addToCart) + .first() + .find(prestashop.selectors.product.minimalQuantity) + .addClass('error'); + $input + .parent() + .find('label') + .addClass('error'); + }; + + const $quantityInput = $form.find('input[min]'); + + if (!isQuantityInputValid($quantityInput)) { + onInvalidQuantity($quantityInput); + return; + } + + $.post(actionURL, query, null, 'json') + .then((resp) => { + console.log('Resp: ', resp); + if (!resp.hasError) { + prestashop.emit('updateCart', { + reason: { + idProduct: resp.id_product, + idProductAttribute: resp.id_product_attribute, + idCustomization: resp.id_customization, + linkAction: 'add-to-cart', + cart: resp.cart, + }, + resp, + }); + } else { + prestashop.emit('handleError', { + eventType: 'addProductToCart', + resp, + }); + } + }) + .fail((resp) => { + prestashop.emit('handleError', { + eventType: 'addProductToCart', + resp, + }); + }) + .always(() => { + setTimeout(() => { + addToCartButton.prop('disabled', false); + }, 1000); + }); + }, + error: function(xhr, status, error) { + console.error(xhr.responseText); + } + }); + } + }); + }); + + + diff --git a/modules/thobbodymeasurements/views/templates/front/customer_account_section.tpl b/modules/thobbodymeasurements/views/templates/front/customer_account_section.tpl new file mode 100644 index 0000000..a0177f4 --- /dev/null +++ b/modules/thobbodymeasurements/views/templates/front/customer_account_section.tpl @@ -0,0 +1,86 @@ +{** + * 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 Academic Free License 3.0 (AFL-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/AFL-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. + * + * @author PrestaShop SA + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + *} +{extends file='customer/page.tpl'} + +{block name='page_title'} + {l s='thob - Manual Body Measurements' mod='thobbodymeasurements'} +{/block} + +{block name='page_content'} +
+
+ {if isset($selectedForm)} +

{l s='Form:' mod='thobbodymeasurements'} {$selectedForm.label_form}

+
+ {foreach from=$selectedForm.attributes item=attribute} +
+
+ +
+ +
+
+ {$attribute.unit} +
+
+ + +
+ {/foreach} + +
+ +
+
+ {else} +
+
+ +
+ +
+
+ +
+
+ +
+
+
+ {/if} +
+
+{/block} diff --git a/modules/thobbodymeasurements/views/templates/hook/customer_account.tpl b/modules/thobbodymeasurements/views/templates/hook/customer_account.tpl new file mode 100644 index 0000000..f5c5e5a --- /dev/null +++ b/modules/thobbodymeasurements/views/templates/hook/customer_account.tpl @@ -0,0 +1,7 @@ + + + + + {l s='thob Body Measurements' mod='thobbodymeasurements'} + + \ No newline at end of file diff --git a/modules/thobbodymeasurements/views/templates/hook/display_measurements_section_cart.tpl b/modules/thobbodymeasurements/views/templates/hook/display_measurements_section_cart.tpl new file mode 100644 index 0000000..5e25114 --- /dev/null +++ b/modules/thobbodymeasurements/views/templates/hook/display_measurements_section_cart.tpl @@ -0,0 +1,22 @@ +{if $measurements} +
+ + + + + + + + + + {foreach from=$measurements item="measurement"} + + + + + + {/foreach} + +
AttributeValueUnit
{$measurement.label}{$measurement.value}{$measurement.unit}
+
+{/if} diff --git a/modules/thobbodymeasurements/views/templates/hook/set-measurements-button.tpl b/modules/thobbodymeasurements/views/templates/hook/set-measurements-button.tpl new file mode 100644 index 0000000..c192473 --- /dev/null +++ b/modules/thobbodymeasurements/views/templates/hook/set-measurements-button.tpl @@ -0,0 +1,76 @@ + + + + + + + + Set Measurements + + + +