Skip to main content

Overview

The Damacana Limits API manages time-based restrictions for water jug orders, including cutoff times and product identification. Source: src/config/damacanaLimits.js

Functions

checkCartForDamacana()

Checks if the cart contains damacana items and validates whether damacana orders are allowed at the current time.
import { checkCartForDamacana } from '@/config/damacanaLimits';
import { useCart } from '@/context/CartContext';

const CartSummary = () => {
  const { items } = useCart();
  const damacanaCheck = checkCartForDamacana(items);
  
  if (damacanaCheck.hasDamacana && !damacanaCheck.isAllowed) {
    return <Alert>{damacanaCheck.message}</Alert>;
  }
  
  return <CheckoutButton />;
};
cartItems
array
required
Array of cart items. Each item must have an id property
returns
object
Damacana validation result object
Example Return Values
// No damacana items
{ hasDamacana: false, isAllowed: true, message: null }

// Has damacana, allowed
{ 
  hasDamacana: true, 
  damacanaItems: [{id: 11, name: "19L Damacana", ...}],
  isAllowed: true, 
  message: null 
}

// Has damacana, not allowed
{ 
  hasDamacana: true,
  damacanaItems: [{id: 11, name: "19L Damacana", ...}],
  isAllowed: false,
  message: "Damacana siparişleri 19:00'dan sonra alınmamaktadır"
}

isDamacana()

Checks if a product ID matches the damacana pattern.
import { isDamacana } from '@/config/damacanaLimits';

const productId = 11;
if (isDamacana(productId)) {
  console.log('This is a damacana product');
}
productId
number | string
required
Product ID to check
returns
boolean
Returns true if the ID matches the damacana pattern (ends with 1)
Pattern Matching
Uses regex /1$/ to match IDs ending with 1:
  • Damacana IDs: 11, 21, 31, 41, 51, 61, 71, 81
  • Non-damacana: 12, 23, 34, etc.
Console logs result for debugging: "Damacana Check: ID 11 -> DAMACANA"

isDamacanaOrderAllowed()

Checks whether damacana orders are currently allowed based on time restrictions.
import { isDamacanaOrderAllowed } from '@/config/damacanaLimits';

const checkDamacana = () => {
  const result = isDamacanaOrderAllowed();
  
  if (!result.isAllowed) {
    alert(result.message);
  }
};
returns
object
Validation result object
Behavior
  • Returns { isAllowed: true } if enabled is false or testMode is true
  • Checks if current time is in restricted period (after cutoff or before start time)
  • Uses different cutoff times for weekdays vs weekends (if weekendEnabled is true)
  • Extensive console logging for debugging time calculations

getDamacanaOrderHoursText()

Returns formatted string of damacana order hours.
import { getDamacanaOrderHoursText } from '@/config/damacanaLimits';

const hours = getDamacanaOrderHoursText();
console.log(hours); // "08:30 - 19:00"
// or with weekend hours:
// "Hafta içi: 08:30 - 19:00, Hafta sonu: 08:30 - 18:00"
returns
string
Formatted damacana order hours. Includes separate weekend hours if weekendEnabled is true

Configuration

DAMACANA_LIMITS

Damacana restrictions configuration object.
import { DAMACANA_LIMITS } from '@/config/damacanaLimits';

console.log(DAMACANA_LIMITS.cutoffHour); // 19

ID Pattern Matching

Damacana products are identified by IDs ending with 1:
// Damacana products (ID ends with 1)
11 → 19L Damacana
21 → 19L Damacana (2 pack) ✓
31 → 19L Damacana (3 pack) ✓
41, 51, 61, 71, 81All damacanas

// Non-damacana products
12 → 6x1.5L Pack
23 → 12x0.5L Pack
The pattern uses regex: /1$/ which matches any ID ending with the digit 1.

Usage Example

import { 
  checkCartForDamacana, 
  isDamacana,
  getDamacanaOrderHoursText 
} from '@/config/damacanaLimits';
import { useCart } from '@/context/CartContext';

const OrderRestrictionAlert = () => {
  const { items } = useCart();
  const damacanaCheck = checkCartForDamacana(items);
  
  if (!damacanaCheck.hasDamacana) {
    return null; // No damacana in cart
  }
  
  if (!damacanaCheck.isAllowed) {
    return (
      <Alert severity="warning">
        <p>{damacanaCheck.message}</p>
        <p>Damacana sipariş saatleri: {getDamacanaOrderHoursText()}</p>
        <p>Damacana ürünleri: {damacanaCheck.damacanaItems.length} adet</p>
      </Alert>
    );
  }
  
  return null;
};

Time Logic

The damacana restriction creates a blocked time window:
  • Blocked period: After cutoff time until next day’s start time
  • Allowed period: Start time to cutoff time
Example with default settings:
  • Blocked: 19:00 - 08:30 (next day)
  • Allowed: 08:30 - 19:00
The function handles midnight crossing automatically.

Build docs developers (and LLMs) love