uploadimagesSuccess.php 4.69 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
print_r("HERE");
die();
$children_clean = array();
$all_cats = array();
$catFolder_idx = array();
foreach($cat_parents as $cat_parent)
{
  $children_clean[$cat_parent['parent_id']][] = $cat_parent;
  $all_cats[$cat_parent['cat_id']][] = $cat_parent;
}

$root_cats = array();
foreach ($cats as $k => $cat)
{
  $catFolder_idx[$cat['id']] = $k;
  if(!$cat['parent_id'])
  {
    $root_cats[] = $k + 1;
  }
}

$catFolder[] = "{id:0,title:'Каталог',parents:[0],children:[" . implode(',', $root_cats) . "],all_children:false}";

foreach ($cats as $k => $cat)
{
  $children = array();
  $parents = array();
  $check_pr = array();
  if(isset($children_clean[$cat['id']]))
  {
    foreach($children_clean[$cat['id']] as $child)
    {
      if($child['order_id'] == 0)
      {
        $children[] = $catFolder_idx[$child['cat_id']] + 1;
      }
    }
  }

  if(isset($all_cats[$cat['id']]))
  {
    foreach($all_cats[$cat['id']] as $record)
    {
      $parents[] = $catFolder_idx[$record['parent_id']] + 1;   
    }
    $parents[] = $catFolder_idx[$cat['id']] + 1;
  }


  $catFolder[] = "{id:" . $cat['id'] . ",parent_id:" . ($cat['parent_id'] ? ($catFolder_idx[$cat['parent_id']] + 1) : '0') . ",title:'" . $cat['title'] . "',parents:[0," .(empty($parents)? ($catFolder_idx[$cat['id']] + 1) :  implode(',', $parents))  . "],children:[" . implode(',', $children) . "]}";


}

$products_a = array();

$context = sfContext::getInstance();
$d = $context->getDatabaseManager()->getDatabase('doctrine');
$dsn = explode(';', $d->getParameter('dsn'));
$e = explode('=', $dsn[0]);
mysql_connect($e[1], $d->getParameter('username'), $d->getParameter('password'));
$e = explode('=', $dsn[1]);
mysql_select_db($e[1]);
mysql_query('SET CHARACTER SET utf8');





$q = "SELECT p.*, cp.*, pi.*, psc.value AS stock_count, pp.value AS price
      FROM product AS p
      INNER JOIN cat_product as cp ON p.id = cp.product_id
      LEFT JOIN product_image as pi ON p.id = pi.product_id
      LEFT JOIN product_stock_count as psc ON p.id = psc.product_id
      INNER JOIN product_price as pp ON p.id = pp.product_id
      WHERE (pp.price_type_id = 1)";

$res = mysql_query($q);

$idx = 1;
$cat_idx = array();
$product_idx = array();

while($product = mysql_fetch_assoc($res))
{
  /*print_r($product);
  die();*/
  if (isset($product['src']) && $product['sizes'] != 0 && $product['src'] != 'no image')
  {
    $path = sfConfig::get('sf_data_dir') . '/1cbitrix/' . $product['src'];
    /*print_r($path);
    die();*/
    $type = pathinfo($path, PATHINFO_EXTENSION);
    $data = file_get_contents($path);
    $base64 = base64_encode($data);

    $products_a[] = "{id:" . $product['id'] . ",article:'" . $product['product_code'] . "',name:'" . addslashes($product['title']) . "',price:" . rand(1000, 10000) . ",image:'" . $base64 . "',min_purchase:1,number_product:" . $product['stock_count'] . "}";
  }
  else
  {
    $products_a[] = "{id:" . $product['id'] . ",article:'" . $product['product_code'] . "',name:'" . addslashes($product['title']) . "',price:" . rand(1000, 10000) . ",min_purchase:1,number_product:" . $product['stock_count'] . "}";
  }
 /* $products_a[] = "{id:" . $product['id'] . ",article:'" . $product['product_code'] . "',name:'" . addslashes($product['title']) . "',price:" . rand(100, 10000) . ",min_purchase:10,number_product:" . rand(1000, 10000) . "}";*/
  $cat_idx[$product['cat_id']][$idx] = true;
  $product_idx[$product['id']] = $idx;
  $idx++;
}

$cat_idx_var = array('[]');
foreach($catFolder_idx as $catFolder_idx_k => $catFolder_idx)
{
  $products = array();
  if(isset($cat_idx[$catFolder_idx_k]))
  {
    $products = array_keys($cat_idx[$catFolder_idx_k]);
  }
  if(isset($children_clean[$catFolder_idx_k]))
  {
    foreach($children_clean[$catFolder_idx_k] as $child)
    {
      if(isset($cat_idx[$child['cat_id']]))
      {
        $products = array_merge($products, array_keys($cat_idx[$child['cat_id']]));
      }
    }
  }
  $cat_idx_var[] = '[' . implode(',', array_unique($products)) . ']';
}

$q = "SELECT k.* FROM keyword k ORDER BY k.rank DESC LIMIT 10000";

$res = mysql_query($q);

$idx = 0;
$keywords = array();
$keywords_idx = array();

while($keyword = mysql_fetch_assoc($res))
{
  $keywords[] = "'" . $keyword['word'] . "'";
  $pidx = array();
  foreach(unserialize($keyword['ids']) as $id)
  {
    if(isset($product_idx[$id]))
    {
      $pidx[] = $product_idx[$id];
    }
  }
  $keywords_idx[] = '[' . implode(',', $pidx) . ']';
}


?>
var db = {
  catFolder: [
<?php echo implode(",\n", $catFolder);?>
  ],
  cat: [
<?php echo implode(",\n", $products_a);?>
  ],
  cat_idx: {
    title: [
<?php echo implode(",\n", $cat_idx_var);?>
    ]
  },
  keywords: [<?php echo implode(",", $keywords);?>],
  keywords_idx: [<?php echo implode(",", $keywords_idx);?>]
};