-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.php
executable file
·263 lines (176 loc) · 6.91 KB
/
product.php
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
session_start(); //look into cookies later
//gets the Solarium library (it's a solr php wrapper)
require('./scripts/php/Solarium/library/Solarium/Autoloader.php');
Solarium_Autoloader::register();
//the intial config that looks at local host at port 8983
$config = array(
'adapteroptions' => array(
'host' => '127.0.0.1',
'port' => 8983,
'path' => '/solr/',
)
);
// creates a client instance for an actual search
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setStart(0)->setRows(1);
//Gets the search terms and categories from the URL
$id=$_GET['id'];
$query->setQuery("id:$id");
// set fields to fetch certain things from my schema
$query->setFields(array('productssid','sellprice','picy','id'));
//sets the query
$totalresultset = $client->select($query);
// show documents using the resultset iterator
foreach ($totalresultset as $document) {
$items=array();
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
if ($field=='productssid'){
$items[0]=$value;
}
if ($field=='sellprice'){
$items[1]=money_format("%1.2n",$value);
}
if ($field=='picy'){
$items[2]=$value;
}
if ($field=='id'){
$items[3]=$value;
}
}
$picture='<a href="./product.php?&id='.$items[3].'"><img src="'.$items[2].'" width="250" height="250" alt="image 01" border="0" /></a>';
$productinfo=' <p><h3> '.$items[0].'</h3></p> <p><h4> Price: $'.$items[1].'</h4></p>';
$arr = unserialize($_COOKIE['RecentlyViewed']);
//new add
$arr[] = '<li class="span3"><div class="thumbnail"> <a href="./product.php?&id='.$items[3].'"><img src="'.$items[2].'" width="150" height="150" alt="image 01" border="0" /></a> <br /><p> '.$items[0].'</p> <p> Price: $'.$items[1].'</p> </div></li>';
if(sizeof($arr)>8){
array_splice($arr, 0, 1);
}
setcookie("RecentlyViewed",'',time()-10);
setcookie('RecentlyViewed', serialize($arr), time()+10000);
}
$queryMORE = $client->createMoreLikeThis();
$queryMORE->setQuery("id:$id");
$queryMORE->setMltFields('productssid,cat4');
$queryMORE->setrows(8);
$queryMORE->setMinimumDocumentFrequency(1);
$queryMORE->setMinimumTermFrequency(1);
//$queryMORE->createFilterQuery('stock')->setQuery('inStock:true');
//$queryMORE->setInterestingTerms('details');
$queryMORE->setMatchInclude(true);
// this executes the query and returns the result
$resultsetMore = $client->select($queryMORE);
$iter=0;
// show MLT documents using the resultset iterator
foreach ($resultsetMore as $document) {
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
if ($field=='id'){
$id=$value;
}
if ($field=='productssid'){
$name=$value;
}
if ($field=='sellprice'){
$price=money_format("%1.2n",$value);
}
if ($field=='picy'){
$URL=$value;
}
}
$MoreOutput= '<li class="span3"><div class="thumbnail"><a href="./product.php?&id='.$id.'"><img src="'.$URL.'" width="150" height="150" alt="image 01" border="0" /></a> <br /><p> '.$name.'</p> <p> $'.$price.'</p> </div> </li>';
if ($iter==0){
$MoreLikeThisOutput.='<div class="item active">';
$MoreLikeThisOutput.= '<ul class="thumbnails">';
$MoreLikeThisOutput.=$MoreOutput;
}elseif ($iter==4){
$MoreLikeThisOutput.='</ul></div><div class="item">';
$MoreLikeThisOutput.= '<ul class="thumbnails">';
$MoreLikeThisOutput.=$MoreOutput;
}else {
$MoreLikeThisOutput.=$MoreOutput;
}
$iter=$iter+1;
}
$MoreLikeThisOutput.= '</ul></div>';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ucalypt</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="style/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="style/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<?php include_once("template_header.php");?>
<div class="container-fluid">
<hr>
<div class="row-fluid">
<div class="span6">
<?php echo $picture; ?>
</div><!--/span-->
<div class="span6">
<?php echo $productinfo; ?>
<div class="row-fluid">
<p>
<form id="addcart" name="addcart" method="post" action="./cart.php">
<input type="hidden" name="name" id="name" value="<?php echo $items[0]; ?> "/>
<input type="hidden" name="price" id="price" value="<?php echo $items[1]; ?> "/>
<input type="hidden" name="id" id="id" value="<?php echo $items[3]; ?> "/>
<input type="hidden" name="URL" id="URL" value="<?php echo $items[2]; ?> "/>
<input type="submit" name="button" class="btn" id="button" value="Add to Cart" />
</form>
</p>
<p><a class="btn" href="#">Add to Favorites »</a></p>
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
<hr>
<div class="container-fluid">
<div class="row-fluid">
<div class="row-fluid">
<header id="overview">
<h1>More Like This:</h1>
</div>
<div class="carousel slide" id="myCarousel">
<div style= "margin-left:40px;" class="carousel-inner">
<?php echo $MoreLikeThisOutput; ?>
</div>
<a data-slide="prev" href="#myCarousel" class="left carousel-control">‹</a>
<a data-slide="next" href="#myCarousel" class="right carousel-control">›</a>
</div>
</div>
</div>
<hr>
<footer>
<p>© Company 2012</p>
</footer>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script>
$(document).ready(function(){
$('.carousel').carousel();
});
</script>
</body>
</html>