Mark-Lasfar commited on
Commit
6f8023f
·
1 Parent(s): 3b8241c

Fix: Optimize loadStore function, fix preview mode and follow-status

Browse files
Files changed (1) hide show
  1. server.js +413 -78
server.js CHANGED
@@ -409,6 +409,7 @@ const excludedPaths = [
409
 
410
  '/api/store/layout-template',
411
  '/api/store/layout-template/reset',
 
412
  '/api/store/layout-templates',
413
  '/api/templates',
414
  '/api/templates/featured',
@@ -1745,6 +1746,7 @@ const storeSettingsSchema = new mongoose.Schema({
1745
 
1746
  // إعدادات التخطيط المتقدمة
1747
  layoutSettings: {
 
1748
  headerLayout: { type: String, enum: ['default', 'centered', 'minimal', 'transparent'], default: 'default' },
1749
  footerLayout: { type: String, enum: ['default', 'minimal', 'columns'], default: 'default' },
1750
  sidebarPosition: { type: String, enum: ['left', 'right', 'none'], default: 'none' },
@@ -1757,14 +1759,66 @@ const storeSettingsSchema = new mongoose.Schema({
1757
  enableWishlist: { type: Boolean, default: false },
1758
  enableRecentlyViewed: { type: Boolean, default: true },
1759
  enableProductReviews: { type: Boolean, default: true },
1760
- layoutTemplate: {
1761
- type: String,
1762
- enum: ['default', 'sidebar-left', 'sidebar-right', 'product-focused', 'minimal', 'magazine'],
1763
- default: 'default'
1764
- }
1765
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1766
  },
1767
-
1768
  // ============================================
1769
  // سلوك المنتجات
1770
  // ============================================
@@ -19270,26 +19324,294 @@ app.put('/api/store/settings', authenticateToken, async (req, res) => {
19270
 
19271
 
19272
  // ============================================
19273
- // PUT /api/store/layout-template - حفظ قالب التخطيط
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19274
  // ============================================
19275
  app.put('/api/store/layout-template', authenticateToken, async (req, res) => {
19276
  try {
19277
- const { layoutTemplate } = req.body;
 
 
 
 
 
 
 
 
 
 
 
 
 
19278
 
19279
- const validLayouts = ['default', 'sidebar-left', 'sidebar-right', 'product-focused', 'minimal', 'magazine'];
19280
 
19281
  if (!validLayouts.includes(layoutTemplate)) {
19282
  return res.status(400).json({ error: 'Invalid layout template' });
19283
  }
19284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19285
  const settings = await StoreSettings.findOneAndUpdate(
19286
  { userId: req.user.userId },
19287
- {
19288
- $set: {
19289
- 'layoutSettings.layoutTemplate': layoutTemplate,
19290
- updatedAt: Date.now()
19291
- }
19292
- },
19293
  { upsert: true, new: true }
19294
  );
19295
 
@@ -19298,28 +19620,68 @@ app.put('/api/store/layout-template', authenticateToken, async (req, res) => {
19298
  res.json({
19299
  success: true,
19300
  layoutTemplate: layoutTemplate,
 
19301
  message: 'Layout template saved successfully'
19302
  });
19303
 
19304
  } catch (error) {
19305
  console.error('Error saving layout template:', error);
19306
- res.status(500).json({ error: 'Failed to save layout template' });
19307
  }
19308
  });
19309
 
19310
  // ============================================
19311
- // POST /api/store/layout-template/reset - إعادة تعيين قالب التخطيط
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19312
  // ============================================
19313
  app.post('/api/store/layout-template/reset', authenticateToken, async (req, res) => {
19314
  try {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19315
  const settings = await StoreSettings.findOneAndUpdate(
19316
  { userId: req.user.userId },
19317
- {
19318
- $set: {
19319
- 'layoutSettings.layoutTemplate': 'default',
19320
- updatedAt: Date.now()
19321
- }
19322
- },
19323
  { upsert: true, new: true }
19324
  );
19325
 
@@ -19328,6 +19690,7 @@ app.post('/api/store/layout-template/reset', authenticateToken, async (req, res)
19328
  res.json({
19329
  success: true,
19330
  layoutTemplate: 'default',
 
19331
  message: 'Layout template reset to default'
19332
  });
19333
 
@@ -19337,70 +19700,42 @@ app.post('/api/store/layout-template/reset', authenticateToken, async (req, res)
19337
  }
19338
  });
19339
 
19340
-
19341
  // ============================================
19342
- // GET /api/store/layout-templates - جلب قوالب التخطيط المتاحة
19343
  // ============================================
19344
- app.get('/api/store/layout-templates', authenticateToken, async (req, res) => {
19345
  try {
19346
- const templates = [
19347
- {
19348
- id: 'default',
19349
- name: 'Default Layout',
19350
- description: 'Standard grid with 4 columns',
19351
- previewImage: '/assets/layouts/default.svg',
19352
- features: ['4 column grid', 'Full header', 'Standard footer', 'Products first']
19353
- },
19354
- {
19355
- id: 'sidebar-left',
19356
- name: 'Sidebar Left',
19357
- description: 'Categories menu on the left side',
19358
- previewImage: '/assets/layouts/sidebar-left.svg',
19359
- features: ['Left sidebar', '3 column grid', 'Categories visible', 'Compact design']
19360
- },
19361
- {
19362
- id: 'sidebar-right',
19363
- name: 'Sidebar Right',
19364
- description: 'Categories menu on the right side',
19365
- previewImage: '/assets/layouts/sidebar-right.svg',
19366
- features: ['Right sidebar', '3 column grid', 'Categories visible', 'Modern layout']
19367
- },
19368
- {
19369
- id: 'product-focused',
19370
- name: 'Product Focused',
19371
- description: 'Large product cards in list view',
19372
- previewImage: '/assets/layouts/product-focused.svg',
19373
- features: ['List view layout', 'Large product images', 'Detailed descriptions', '2 column grid']
19374
- },
19375
- {
19376
- id: 'minimal',
19377
- name: 'Minimal Store',
19378
- description: 'Clean and simple design',
19379
- previewImage: '/assets/layouts/minimal.svg',
19380
- features: ['2 column grid', 'Simple header', 'Minimal footer', 'Fast loading']
19381
- },
19382
- {
19383
- id: 'magazine',
19384
- name: 'Magazine Style',
19385
- description: 'Editorial style with featured sections',
19386
- previewImage: '/assets/layouts/magazine.svg',
19387
- features: ['Hero section', 'Featured content', 'Blog style', '4 column grid']
19388
- }
19389
- ];
19390
 
19391
- // جلب القالب الحالي للمستخدم
19392
- const settings = await StoreSettings.findOne({ userId: req.user.userId });
19393
- const currentLayout = settings?.layoutSettings?.layoutTemplate || 'default';
 
 
 
19394
 
19395
  res.json({
19396
  success: true,
19397
- templates: templates,
19398
- currentLayout: currentLayout
 
 
 
 
 
 
 
 
 
 
 
 
 
19399
  });
19400
 
19401
  } catch (error) {
19402
- console.error('Error fetching layout templates:', error);
19403
- res.status(500).json({ error: 'Failed to fetch layout templates' });
19404
  }
19405
  });
19406
  // ============================================
 
409
 
410
  '/api/store/layout-template',
411
  '/api/store/layout-template/reset',
412
+ '/api/store/apply-layout/:userId',
413
  '/api/store/layout-templates',
414
  '/api/templates',
415
  '/api/templates/featured',
 
1746
 
1747
  // إعدادات التخطيط المتقدمة
1748
  layoutSettings: {
1749
+ // الأساسية
1750
  headerLayout: { type: String, enum: ['default', 'centered', 'minimal', 'transparent'], default: 'default' },
1751
  footerLayout: { type: String, enum: ['default', 'minimal', 'columns'], default: 'default' },
1752
  sidebarPosition: { type: String, enum: ['left', 'right', 'none'], default: 'none' },
 
1759
  enableWishlist: { type: Boolean, default: false },
1760
  enableRecentlyViewed: { type: Boolean, default: true },
1761
  enableProductReviews: { type: Boolean, default: true },
1762
+
1763
+ // قالب التخطيط (محدث)
1764
+ layoutTemplate: {
1765
+ type: String,
1766
+ enum: ['default', 'sidebar-left', 'sidebar-right', 'product-focused', 'minimal', 'magazine', 'compact', 'dark-store'],
1767
+ default: 'default'
1768
+ },
1769
+
1770
+ // أنماط البطاقات و Hero
1771
+ cardStyle: { type: String, enum: ['default', 'compact', 'minimal', 'detailed'], default: 'default' },
1772
+ heroStyle: { type: String, enum: ['default', 'large', 'fullscreen', 'minimal', 'none'], default: 'default' },
1773
+
1774
+ // إظهار/إخفاء الأقسام
1775
+ showStats: { type: Boolean, default: true },
1776
+ showAnalytics: { type: Boolean, default: true },
1777
+ showHero: { type: Boolean, default: true },
1778
+ showFeatured: { type: Boolean, default: true },
1779
+ showCategories: { type: Boolean, default: true },
1780
+
1781
+ // الثيم ونمط العرض
1782
+ theme: { type: String, enum: ['light', 'dark', 'auto'], default: 'light' },
1783
+ productViewType: { type: String, enum: ['grid', 'list', 'masonry'], default: 'grid' },
1784
+
1785
+ // إعدادات الـ compact layout
1786
+ compactMode: {
1787
+ enabled: { type: Boolean, default: false },
1788
+ hidePrices: { type: Boolean, default: false },
1789
+ hideRatings: { type: Boolean, default: false },
1790
+ hideDescription: { type: Boolean, default: false },
1791
+ showQuickAdd: { type: Boolean, default: true }
1792
+ },
1793
+
1794
+ // إعدادات الـ magazine layout
1795
+ magazineMode: {
1796
+ showHeroSlider: { type: Boolean, default: true },
1797
+ heroSlidesCount: { type: Number, default: 3, min: 1, max: 5 },
1798
+ showFeaturedGrid: { type: Boolean, default: true },
1799
+ showLatestPosts: { type: Boolean, default: true },
1800
+ postsCount: { type: Number, default: 3, min: 1, max: 6 }
1801
+ },
1802
+
1803
+ // إعدادات الـ dark store
1804
+ darkStoreMode: {
1805
+ neonAccents: { type: Boolean, default: true },
1806
+ accentColor: { type: String, default: '#00d4ff', match: /^#[0-9A-Fa-f]{6}$/ },
1807
+ glowEffect: { type: Boolean, default: true },
1808
+ blurEffect: { type: Boolean, default: true }
1809
+ },
1810
+
1811
+ // ترتيب الأقسام المخصص
1812
+ sectionsOrder: [{ type: String }],
1813
+
1814
+ // إعدادات متقدمة
1815
+ advanced: {
1816
+ containerMaxWidth: { type: String, default: '1400px' },
1817
+ enableParallax: { type: Boolean, default: false },
1818
+ enableParticles: { type: Boolean, default: false },
1819
+ customBackgroundImage: { type: String, default: '' }
1820
+ }
1821
  },
 
1822
  // ============================================
1823
  // سلوك المنتجات
1824
  // ============================================
 
19324
 
19325
 
19326
  // ============================================
19327
+ // 🎨 COMPLETE LAYOUT & DESIGN API - VERSION 2.0 (FIXED)
19328
+ // ============================================
19329
+
19330
+ // ============================================
19331
+ // GET /api/store/layout-templates - جلب قوالب التخطيط مع تفاصيل كاملة
19332
+ // ============================================
19333
+ app.get('/api/store/layout-templates', authenticateToken, async (req, res) => {
19334
+ try {
19335
+ const templates = [
19336
+ {
19337
+ id: 'default',
19338
+ name: 'Default Layout',
19339
+ description: 'Standard grid with 4 columns',
19340
+ previewImage: '/assets/layouts/default.svg',
19341
+ features: ['4 column grid', 'Full header', 'Standard footer', 'Products first'],
19342
+ structure: {
19343
+ headerPosition: 'top',
19344
+ sidebarPosition: 'none',
19345
+ footerPosition: 'bottom',
19346
+ productsPerRow: 4,
19347
+ showCategories: true,
19348
+ showHero: true
19349
+ },
19350
+ cssClasses: ['layout-default'],
19351
+ order: 1
19352
+ },
19353
+ {
19354
+ id: 'sidebar-left',
19355
+ name: 'Sidebar Left',
19356
+ description: 'Categories menu on the left side',
19357
+ previewImage: '/assets/layouts/sidebar-left.svg',
19358
+ features: ['Left sidebar', '3 column grid', 'Categories visible', 'Compact design'],
19359
+ structure: {
19360
+ headerPosition: 'top',
19361
+ sidebarPosition: 'left',
19362
+ footerPosition: 'bottom',
19363
+ productsPerRow: 3,
19364
+ showCategories: true,
19365
+ showHero: true
19366
+ },
19367
+ cssClasses: ['layout-sidebar-left', 'flex-row-reverse'],
19368
+ order: 2
19369
+ },
19370
+ {
19371
+ id: 'sidebar-right',
19372
+ name: 'Sidebar Right',
19373
+ description: 'Categories menu on the right side',
19374
+ previewImage: '/assets/layouts/sidebar-right.svg',
19375
+ features: ['Right sidebar', '3 column grid', 'Categories visible', 'Modern layout'],
19376
+ structure: {
19377
+ headerPosition: 'top',
19378
+ sidebarPosition: 'right',
19379
+ footerPosition: 'bottom',
19380
+ productsPerRow: 3,
19381
+ showCategories: true,
19382
+ showHero: true
19383
+ },
19384
+ cssClasses: ['layout-sidebar-right'],
19385
+ order: 3
19386
+ },
19387
+ {
19388
+ id: 'product-focused',
19389
+ name: 'Product Focused',
19390
+ description: 'Large product cards in list view',
19391
+ previewImage: '/assets/layouts/product-focused.svg',
19392
+ features: ['List view layout', 'Large product images', 'Detailed descriptions', '2 column grid'],
19393
+ structure: {
19394
+ headerPosition: 'top',
19395
+ sidebarPosition: 'none',
19396
+ footerPosition: 'bottom',
19397
+ productsPerRow: 2,
19398
+ productViewType: 'list',
19399
+ showCategories: false,
19400
+ showHero: true
19401
+ },
19402
+ cssClasses: ['layout-product-focused', 'list-view'],
19403
+ order: 4
19404
+ },
19405
+ {
19406
+ id: 'minimal',
19407
+ name: 'Minimal Store',
19408
+ description: 'Clean and simple design',
19409
+ previewImage: '/assets/layouts/minimal.svg',
19410
+ features: ['2 column grid', 'Simple header', 'Minimal footer', 'Fast loading'],
19411
+ structure: {
19412
+ headerPosition: 'top',
19413
+ headerStyle: 'minimal',
19414
+ sidebarPosition: 'none',
19415
+ footerStyle: 'minimal',
19416
+ productsPerRow: 2,
19417
+ showCategories: false,
19418
+ showHero: false,
19419
+ showStats: false,
19420
+ showAnalytics: false
19421
+ },
19422
+ cssClasses: ['layout-minimal', 'hide-stats', 'hide-analytics', 'minimal-header'],
19423
+ order: 5
19424
+ },
19425
+ {
19426
+ id: 'magazine',
19427
+ name: 'Magazine Style',
19428
+ description: 'Editorial style with featured sections',
19429
+ previewImage: '/assets/layouts/magazine.svg',
19430
+ features: ['Hero section', 'Featured content', 'Blog style', '4 column grid'],
19431
+ structure: {
19432
+ headerPosition: 'top',
19433
+ sidebarPosition: 'none',
19434
+ footerPosition: 'bottom',
19435
+ productsPerRow: 4,
19436
+ showCategories: true,
19437
+ showHero: true,
19438
+ heroStyle: 'large',
19439
+ showFeatured: true
19440
+ },
19441
+ cssClasses: ['layout-magazine', 'hero-large'],
19442
+ order: 6
19443
+ },
19444
+ {
19445
+ id: 'compact',
19446
+ name: 'Compact Store',
19447
+ description: 'Dense grid for many products',
19448
+ previewImage: '/assets/layouts/compact.svg',
19449
+ features: ['6 column grid', 'Compact cards', 'Fast browsing', 'High density'],
19450
+ structure: {
19451
+ headerPosition: 'top',
19452
+ sidebarPosition: 'none',
19453
+ footerPosition: 'bottom',
19454
+ productsPerRow: 6,
19455
+ cardStyle: 'compact',
19456
+ showCategories: false,
19457
+ showHero: false
19458
+ },
19459
+ cssClasses: ['layout-compact', 'compact-cards'],
19460
+ order: 7
19461
+ },
19462
+ {
19463
+ id: 'dark-store',
19464
+ name: 'Dark Store',
19465
+ description: 'Dark theme optimized for night browsing',
19466
+ previewImage: '/assets/layouts/dark-store.svg',
19467
+ features: ['Dark theme', 'Neon accents', 'Modern design', 'Eye friendly'],
19468
+ structure: {
19469
+ headerPosition: 'top',
19470
+ sidebarPosition: 'none',
19471
+ footerPosition: 'bottom',
19472
+ productsPerRow: 4,
19473
+ theme: 'dark',
19474
+ glassEffect: true
19475
+ },
19476
+ cssClasses: ['layout-dark-store', 'dark-theme'],
19477
+ order: 8
19478
+ }
19479
+ ];
19480
+
19481
+ const settings = await StoreSettings.findOne({ userId: req.user.userId });
19482
+ const currentLayout = settings?.layoutSettings?.layoutTemplate || 'default';
19483
+
19484
+ const designSettings = {
19485
+ primaryColor: settings?.primaryColor || '#3b82f6',
19486
+ secondaryColor: settings?.secondaryColor || '#8b5cf6',
19487
+ fontFamily: settings?.fontFamily || 'Inter, sans-serif',
19488
+ borderRadius: settings?.borderRadius || 16,
19489
+ shadowType: settings?.shadowType || 'md',
19490
+ animationType: settings?.animationType || 'lift',
19491
+ glassEffect: settings?.glassEffect || false,
19492
+ backgroundType: settings?.backgroundType || 'default',
19493
+ backgroundValue: settings?.backgroundValue || '',
19494
+ customCss: settings?.customCss || ''
19495
+ };
19496
+
19497
+ res.json({
19498
+ success: true,
19499
+ templates: templates,
19500
+ currentLayout: currentLayout,
19501
+ designSettings: designSettings,
19502
+ layoutSettings: settings?.layoutSettings || {}
19503
+ });
19504
+
19505
+ } catch (error) {
19506
+ console.error('Error fetching layout templates:', error);
19507
+ res.status(500).json({ error: 'Failed to fetch layout templates' });
19508
+ }
19509
+ });
19510
+
19511
+ // ============================================
19512
+ // PUT /api/store/layout-template - حفظ قالب التخطيط مع كامل الإعدادات (مصحح)
19513
  // ============================================
19514
  app.put('/api/store/layout-template', authenticateToken, async (req, res) => {
19515
  try {
19516
+ const {
19517
+ layoutTemplate,
19518
+ // إعدادات إضافية ممكن يبعتهم الفرونت
19519
+ headerLayout,
19520
+ footerLayout,
19521
+ sidebarPosition,
19522
+ productsPerRowDesktop,
19523
+ enableStickyAddToCart,
19524
+ enableQuickView,
19525
+ enableCompareProducts,
19526
+ enableWishlist,
19527
+ enableRecentlyViewed,
19528
+ enableProductReviews
19529
+ } = req.body;
19530
 
19531
+ const validLayouts = ['default', 'sidebar-left', 'sidebar-right', 'product-focused', 'minimal', 'magazine', 'compact', 'dark-store'];
19532
 
19533
  if (!validLayouts.includes(layoutTemplate)) {
19534
  return res.status(400).json({ error: 'Invalid layout template' });
19535
  }
19536
 
19537
+ // الحصول على هيكل القالب المحدد
19538
+ const templateStructure = getLayoutStructure(layoutTemplate);
19539
+
19540
+ // بناء كائن التحديث
19541
+ const updateData = {
19542
+ 'layoutSettings.layoutTemplate': layoutTemplate,
19543
+ 'layoutSettings.sidebarPosition': sidebarPosition || templateStructure.sidebarPosition || 'none',
19544
+ 'layoutSettings.productsPerRowDesktop': productsPerRowDesktop || templateStructure.productsPerRow || 4,
19545
+ 'layoutSettings.headerLayout': headerLayout || templateStructure.headerStyle || templateStructure.headerPosition || 'default',
19546
+ 'layoutSettings.footerLayout': footerLayout || templateStructure.footerStyle || 'default',
19547
+ updatedAt: Date.now()
19548
+ };
19549
+
19550
+ // إضافة إعدادات التبديلات (toggles) إذا وجدت
19551
+ if (enableStickyAddToCart !== undefined) {
19552
+ updateData['layoutSettings.enableStickyAddToCart'] = enableStickyAddToCart;
19553
+ }
19554
+ if (enableQuickView !== undefined) {
19555
+ updateData['layoutSettings.enableQuickView'] = enableQuickView;
19556
+ }
19557
+ if (enableCompareProducts !== undefined) {
19558
+ updateData['layoutSettings.enableCompareProducts'] = enableCompareProducts;
19559
+ }
19560
+ if (enableWishlist !== undefined) {
19561
+ updateData['layoutSettings.enableWishlist'] = enableWishlist;
19562
+ }
19563
+ if (enableRecentlyViewed !== undefined) {
19564
+ updateData['layoutSettings.enableRecentlyViewed'] = enableRecentlyViewed;
19565
+ }
19566
+ if (enableProductReviews !== undefined) {
19567
+ updateData['layoutSettings.enableProductReviews'] = enableProductReviews;
19568
+ }
19569
+
19570
+ // ✅ ت��بيق إعدادات خاصة بكل قالب
19571
+ switch(layoutTemplate) {
19572
+ case 'minimal':
19573
+ updateData['layoutSettings.enableStickyAddToCart'] = false;
19574
+ updateData['layoutSettings.enableQuickView'] = false;
19575
+ updateData['layoutSettings.enableProductReviews'] = false;
19576
+ updateData['layoutSettings.headerLayout'] = 'minimal';
19577
+ updateData['layoutSettings.footerLayout'] = 'minimal';
19578
+ break;
19579
+
19580
+ case 'product-focused':
19581
+ updateData.productViewType = 'list';
19582
+ updateData['layoutSettings.enableQuickView'] = true;
19583
+ updateData['layoutSettings.enableProductReviews'] = true;
19584
+ updateData['layoutSettings.sidebarPosition'] = 'none';
19585
+ break;
19586
+
19587
+ case 'magazine':
19588
+ updateData['layoutSettings.enableQuickView'] = true;
19589
+ updateData['layoutSettings.enableStickyAddToCart'] = true;
19590
+ updateData['layoutSettings.enableRecentlyViewed'] = true;
19591
+ updateData['layoutSettings.headerLayout'] = 'centered';
19592
+ break;
19593
+
19594
+ case 'compact':
19595
+ updateData['layoutSettings.productsPerRowDesktop'] = 6;
19596
+ updateData['layoutSettings.productsPerRowTablet'] = 3;
19597
+ updateData['layoutSettings.productsPerRowMobile'] = 2;
19598
+ updateData['layoutSettings.enableQuickView'] = false;
19599
+ updateData['layoutSettings.cardStyle'] = 'compact';
19600
+ break;
19601
+
19602
+ case 'dark-store':
19603
+ updateData.primaryColor = '#8b5cf6';
19604
+ updateData.secondaryColor = '#a78bfa';
19605
+ updateData.glassEffect = true;
19606
+ updateData.backgroundType = 'color'; // ✅ مصحح
19607
+ updateData.backgroundValue = '#0f0f0f'; // ✅ مصحح
19608
+ updateData['layoutSettings.glassEffect'] = true;
19609
+ break;
19610
+ }
19611
+
19612
  const settings = await StoreSettings.findOneAndUpdate(
19613
  { userId: req.user.userId },
19614
+ { $set: updateData },
 
 
 
 
 
19615
  { upsert: true, new: true }
19616
  );
19617
 
 
19620
  res.json({
19621
  success: true,
19622
  layoutTemplate: layoutTemplate,
19623
+ appliedSettings: updateData,
19624
  message: 'Layout template saved successfully'
19625
  });
19626
 
19627
  } catch (error) {
19628
  console.error('Error saving layout template:', error);
19629
+ res.status(500).json({ error: 'Failed to save layout template: ' + error.message });
19630
  }
19631
  });
19632
 
19633
  // ============================================
19634
+ // دالة مساعدة لجلب هيكل القالب (محدثة)
19635
+ // ============================================
19636
+ function getLayoutStructure(layoutId) {
19637
+ const structures = {
19638
+ 'default': { sidebarPosition: 'none', productsPerRow: 4, headerPosition: 'top' },
19639
+ 'sidebar-left': { sidebarPosition: 'left', productsPerRow: 3, headerPosition: 'top' },
19640
+ 'sidebar-right': { sidebarPosition: 'right', productsPerRow: 3, headerPosition: 'top' },
19641
+ 'product-focused': { sidebarPosition: 'none', productsPerRow: 2, headerPosition: 'top', productViewType: 'list' },
19642
+ 'minimal': { sidebarPosition: 'none', productsPerRow: 2, headerStyle: 'minimal', footerStyle: 'minimal' },
19643
+ 'magazine': { sidebarPosition: 'none', productsPerRow: 4, headerPosition: 'top', heroStyle: 'large' },
19644
+ 'compact': { sidebarPosition: 'none', productsPerRow: 6, headerPosition: 'top', cardStyle: 'compact' },
19645
+ 'dark-store': { sidebarPosition: 'none', productsPerRow: 4, theme: 'dark', glassEffect: true }
19646
+ };
19647
+ return structures[layoutId] || structures['default'];
19648
+ }
19649
+
19650
+ // ============================================
19651
+ // POST /api/store/layout-template/reset - إعادة تعيين قالب التخطيط (محدث)
19652
  // ============================================
19653
  app.post('/api/store/layout-template/reset', authenticateToken, async (req, res) => {
19654
  try {
19655
+ const defaultSettings = {
19656
+ 'layoutSettings.layoutTemplate': 'default',
19657
+ 'layoutSettings.sidebarPosition': 'none',
19658
+ 'layoutSettings.productsPerRowDesktop': 4,
19659
+ 'layoutSettings.productsPerRowTablet': 3,
19660
+ 'layoutSettings.productsPerRowMobile': 2,
19661
+ 'layoutSettings.headerLayout': 'default',
19662
+ 'layoutSettings.footerLayout': 'default',
19663
+ 'layoutSettings.enableStickyAddToCart': true,
19664
+ 'layoutSettings.enableQuickView': true,
19665
+ 'layoutSettings.enableCompareProducts': false,
19666
+ 'layoutSettings.enableWishlist': false,
19667
+ 'layoutSettings.enableRecentlyViewed': true,
19668
+ 'layoutSettings.enableProductReviews': true,
19669
+ productViewType: 'modal',
19670
+ primaryColor: '#3b82f6',
19671
+ secondaryColor: '#8b5cf6',
19672
+ fontFamily: 'Inter, sans-serif',
19673
+ borderRadius: 16,
19674
+ shadowType: 'md',
19675
+ animationType: 'lift',
19676
+ glassEffect: false,
19677
+ backgroundType: 'default',
19678
+ backgroundValue: '',
19679
+ updatedAt: Date.now()
19680
+ };
19681
+
19682
  const settings = await StoreSettings.findOneAndUpdate(
19683
  { userId: req.user.userId },
19684
+ { $set: defaultSettings },
 
 
 
 
 
19685
  { upsert: true, new: true }
19686
  );
19687
 
 
19690
  res.json({
19691
  success: true,
19692
  layoutTemplate: 'default',
19693
+ defaultSettings: defaultSettings,
19694
  message: 'Layout template reset to default'
19695
  });
19696
 
 
19700
  }
19701
  });
19702
 
 
19703
  // ============================================
19704
+ // GET /api/store/apply-layout/:userId - تطبيق القالب على متجر معين (للزوار)
19705
  // ============================================
19706
+ app.get('/api/store/apply-layout/:userId', async (req, res) => {
19707
  try {
19708
+ const settings = await StoreSettings.findOne({ userId: req.params.userId });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19709
 
19710
+ if (!settings) {
19711
+ return res.json({ layout: 'default', design: {} });
19712
+ }
19713
+
19714
+ const layoutTemplate = settings.layoutSettings?.layoutTemplate || 'default';
19715
+ const structure = getLayoutStructure(layoutTemplate);
19716
 
19717
  res.json({
19718
  success: true,
19719
+ layout: layoutTemplate,
19720
+ structure: structure,
19721
+ design: {
19722
+ primaryColor: settings.primaryColor,
19723
+ secondaryColor: settings.secondaryColor,
19724
+ fontFamily: settings.fontFamily,
19725
+ borderRadius: settings.borderRadius,
19726
+ shadowType: settings.shadowType,
19727
+ animationType: settings.animationType,
19728
+ glassEffect: settings.glassEffect,
19729
+ backgroundType: settings.backgroundType,
19730
+ backgroundValue: settings.backgroundValue,
19731
+ customCss: settings.customCss
19732
+ },
19733
+ layoutSettings: settings.layoutSettings
19734
  });
19735
 
19736
  } catch (error) {
19737
+ console.error('Error applying layout:', error);
19738
+ res.status(500).json({ error: 'Failed to apply layout' });
19739
  }
19740
  });
19741
  // ============================================