-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_search.php
134 lines (94 loc) · 3.48 KB
/
home_search.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
<?php
/**
* @author alok dubey
* @ 2018
*/
$find_a_medvacation=$_REQUEST['find_a_medvacation'];
$location=$_REQUEST['location'];
$product_type=$_REQUEST['product_type'];
if(!$find_a_medvacation && !$location && !$product_type)
{
$ret="Parameter missing need atleast one";
echo json_encode(array('sucess'=>"false",'message'=>$ret),JSON_PRETTY_PRINT);
exit;
}
require_once 'config.php';
Mage::app();
Mage::app()->getTranslator()->init('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));
if($find_a_medvacation && $location && $product_type)
{
$product_collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('find_a_medvacation',array('like' => $find_a_medvacation))
->addAttributeToFilter('product_vendor',array('like' => $location))
->addAttributeToFilter('product_type',array('like' => $product_type))->load();
}
elseif($find_a_medvacation && $location)
{
$product_collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('find_a_medvacation',array('like' => $find_a_medvacation))
->addAttributeToFilter('product_vendor',array('like' => $location))->load();
}
elseif($find_a_medvacation && $product_type)
{
$product_collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('find_a_medvacation',array('like' => $find_a_medvacation))
->addAttributeToFilter('product_type',array('like' => $product_type))->load();
}
elseif($location && $product_type)
{
$product_collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('product_vendor',array('like' => $location))
->addAttributeToFilter('product_type',array('like' => $product_type))->load();
}
else{
$product_collection=Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter(
array(
array('attribute'=> 'find_a_medvacation','like' => $find_a_medvacation),
array('attribute'=> 'product_vendor','like' => $location),
array('attribute'=> 'product_type','like' => $product_type)
)
)->load();
}
foreach($product_collection as $product) {
$id=$product->getId();
$ret[$id]['id']=$id;
$ret [$id]['name']=strip_tags($product->getName());
$ret[$id] ['price']= number_format($product->getFinalPrice(),2) ;
$ret[$id]['regular_price']=number_format($product->getPrice(),2);
$ret[$id] ['shortdescription']=strip_tags($product->getShortDescription());
$ret[$id] ['description']=strip_tags($product->getDescription());
$productimage=Mage::helper('catalog/image')->init($product, 'image');
$ret[$id] ['image']=(string)$productimage;
$product_2=Mage::getModel('catalog/product')->load($id);
if($product_2->getOptions())
{
$i=0;
foreach ($product_2->getOptions() as $_option) {
$i++;
$values = $_option->getValues();
// print_r($_option->default_title);exit;
//$ret[$id]['custom']['title'.$i]= $_option->default_title;
foreach ($values as $v) {
// print_r($v->getId());
$ret[$id]['custom'][$_option->default_title][$v->getId()]=$v->getTitle();
//echo "<br />";
}
}
}
}
$ret=array_values($ret);
if (empty($ret))
{
$ret="No data found in database";
echo json_encode(array('sucess'=>"false",'message'=>$ret),JSON_PRETTY_PRINT);
exit;
}
echo json_encode(array('sucess'=>"true",'data'=>$ret),JSON_PRETTY_PRINT);
?>