feat: Enhance product support in Cart and OrderItem models
- Added new fields 'billing_cycle' and 'product_pricing_id' to Cart and OrderItem models. - Updated product retrieval logic to support both new and legacy systems. - Introduced relationships for Product and ProductPricings in Cart and OrderItem models. - Created migration to add new fields to the carts and order_item tables. - Updated frontend service index to handle new pricing structure and billing cycles. - Improved UI components for better user experience in product selection and pricing display. - Refactored action buttons in various views for consistency and improved styling.
This commit is contained in:
@@ -27,15 +27,22 @@ $(document).ready(function () {
|
||||
$(document).on("click", ".dropdown-option", function (e) {
|
||||
e.stopPropagation();
|
||||
const $option = $(this);
|
||||
const $dropdown = $option.closest(".custom-dropdown");
|
||||
const $selected = $dropdown.find(".dropdown-selected");
|
||||
const $options = $dropdown.find(".dropdown-options");
|
||||
const $selectedText = $selected.find(".selected-text");
|
||||
|
||||
// Ignore disabled options
|
||||
if ($option.hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $dropdown = $option.closest('.custom-dropdown');
|
||||
const $selected = $dropdown.find('.dropdown-selected');
|
||||
const $options = $dropdown.find('.dropdown-options');
|
||||
const $selectedText = $selected.find('.selected-text');
|
||||
|
||||
// Get data from selected option
|
||||
const value = $option.data("value");
|
||||
const months = $option.data("months");
|
||||
const price = $option.data("price");
|
||||
const value = $option.data('value');
|
||||
const months = $option.data('months');
|
||||
const price = $option.data('price');
|
||||
const cycle = $option.data('cycle'); // Get billing cycle
|
||||
// Get text from the first span element to avoid getting badge text
|
||||
const text = $option.find('span').first().text();
|
||||
|
||||
@@ -43,19 +50,21 @@ $(document).ready(function () {
|
||||
$selectedText.text(text);
|
||||
|
||||
// Update hidden inputs
|
||||
$dropdown.closest("form").find(".hiddenMonths").val(months);
|
||||
$dropdown.closest("form").find(".hiddenTotalPrice").val(price);
|
||||
const $form = $dropdown.closest('form');
|
||||
$form.find('.hiddenMonths').val(months);
|
||||
$form.find('.hiddenProductPrice').val(price); // Update product price
|
||||
$form.find('.hiddenBillingCycle').val(cycle); // Update billing cycle
|
||||
|
||||
// Update selected state
|
||||
$options.find(".dropdown-option").removeClass("selected");
|
||||
$option.addClass("selected");
|
||||
$options.find('.dropdown-option').removeClass('selected');
|
||||
$option.addClass('selected');
|
||||
|
||||
// Close dropdown
|
||||
$options.removeClass("show");
|
||||
$selected.removeClass("active");
|
||||
$options.removeClass('show');
|
||||
$selected.removeClass('active');
|
||||
|
||||
// Trigger custom event for other components
|
||||
$dropdown.trigger("dropdown:changed", {
|
||||
$dropdown.trigger('dropdown:changed', {
|
||||
value: value,
|
||||
months: months,
|
||||
price: price,
|
||||
@@ -66,19 +75,19 @@ $(document).ready(function () {
|
||||
const $productContainer = $dropdown.closest('[data-product-id]');
|
||||
const basePrice = parseFloat($productContainer.data('base-price'));
|
||||
const selectedMonths = parseInt(months);
|
||||
|
||||
|
||||
// Calculate prices
|
||||
const originalPrice = basePrice * selectedMonths;
|
||||
const savings = selectedMonths >= 12 ? Math.round(originalPrice * 0.1) : 0;
|
||||
const finalPrice = originalPrice - savings;
|
||||
|
||||
|
||||
// Update display
|
||||
$productContainer.find('.total-price-display').text('₫' + finalPrice.toLocaleString());
|
||||
$productContainer.find('.months-display').text(selectedMonths + ' tháng');
|
||||
$productContainer.find('.price-per-month').text('₫' + basePrice.toLocaleString() + '/tháng');
|
||||
$productContainer.find('.original-price').text('₫' + originalPrice.toLocaleString());
|
||||
$productContainer.find('.savings-amount').text('₫' + savings.toLocaleString());
|
||||
|
||||
|
||||
// Show/hide savings info
|
||||
if (savings > 0) {
|
||||
$productContainer.find('.savings-info').show();
|
||||
|
||||
Reference in New Issue
Block a user