-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
executable file
·167 lines (139 loc) · 4.98 KB
/
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
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
<?php
include('lib/token.php');
require_once('../app/Mage.php');
Mage::app();
include('lib/global.php');
header('Content-Type: application/json; Charset=UTF-8');
$mainURLApi = 'http://tcstaging.trendycounty.com/mobileapi/';
$mainURL = 'http://tcstaging.trendycounty.com/media/catalog/product';
$keyword = $_REQUEST['keyword'];
$customerid = $_REQUEST['customerid'];
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', 'configurable')
->addAttributeToFilter('name', array('like' => '%'.$keyword.'%'))
->load();
$data['status'] = true;
$data['message'] = '';
$isLike = false;
foreach ($collection as $_product):
//$cat = Mage::getModel('catalog/category')->load($categoryid) ;
//$categoryName = $cat->getName();
$discountedPrice = number_format($_product->getFinalPrice(), 2);
if($customerid != ''){
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerid, true);
$wishListItemCollection = $wishlist->getItemCollection();
$productID = $_product->getId();
foreach ($wishListItemCollection as $ProductItem):
if($ProductItem->getProductId() == $productID){
$isLike = true;
}else{
$isLike = false;
}
endforeach;
}
$cats = $_product->getCategoryIds();
$categoryParent = array();
$categoryChild = array();
foreach ($cats as $category_id) {
$_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($category_id);
$categoryID = $category_id;
$categoryName = $_cat->getName();
}
$categoryParent = array(
'id' => $categoryID,
'name' => $categoryName
);
$categoryChild = array(
'id' => $categoryID,
'name' => $categoryName
);
//$categoryParent = array(
// 'id' => $categoryid,
// 'name' => $categoryName
//);
//
//$categoryChild = array(
// 'id' => $categoryid,
// 'name' => $categoryName
//);
$image = array($_product->getImageUrl());
$_product_new = Mage::getModel('catalog/product')->load($productID);
$galleryImgArr = $_product_new->getMediaGallery();
//var_dump($image[0]);
//echo "<br />";
$prdImages = "";
for($i=0;$i<count($galleryImgArr['images']);$i++){
$prdImages[$i]['value_id'] = $galleryImgArr['images'][$i]['value_id'];
$prdImages[$i]['file'] = $mainURL.$galleryImgArr['images'][$i]['file'];
$prdImages[$i]['label'] = $galleryImgArr['images'][$i]['label'];
$prdImages[$i]['position'] = $galleryImgArr['images'][$i]['position'];
$prdImages[$i]['disabled'] = $galleryImgArr['images'][$i]['disabled'];
$prdImages[$i]['label_default'] = $galleryImgArr['images'][$i]['label_default'];
$prdImages[$i]['position_default'] = $galleryImgArr['images'][$i]['position_default'];
$prdImages[$i]['disabled_default'] = $galleryImgArr['images'][$i]['disabled_default'];
}
if(empty($prdImages)){
//$prdImages = $image;
$prdImages[0]['value_id'] = "";
$prdImages[0]['file'] = $image[0];
$prdImages[0]['label'] = "";
$prdImages[0]['position'] = "";
$prdImages[0]['disabled'] = "";
$prdImages[0]['label_default'] = "";
$prdImages[0]['position_default'] = "";
$prdImages[0]['disabled_default'] = "";
}
// $colorOptions="";
// $sizeOptions="";
// $attributes = $_product->getAttributes();
// foreach ($attributes as $attribute) {
// if($attribute->getAttributeCode() == "color_lee_cooper"){
// $colorOptions = $attribute->getSource()->getAllOptions(false);
// }
//
// if($attribute->getAttributeCode() == "size_lee_cooper"){
// $sizeOptions = $attribute->getSource()->getAllOptions(false);
// }
// }
// if($colorOptions !="" && !empty($colorOptions))
// $color = $colorOptions;
// else
// $color = array();
//
// if($sizeOptions !="" && !empty($sizeOptions))
// $size = $sizeOptions;
// else
// $size = array();
$size = get_final_product_size_mm($_product);
if($size == "")
$size = array();
$color = get_final_product_color_mm($_product);
if($color == "")
$color = array();
//$productType = $_product->getTypeID();
$variants = get_associated_products($_product);
$productType = $_product->getTypeID();
$data['data'][] = array(
'id' => $_product->getId(),
'productsku' => $_product->getSKU(),
'productType' => $productType,
'name' => $_product->getName(),
'price' => number_format($_product->getPrice(), 2),
'discounted' => $discountedPrice,
'category' => $categoryParent,
'subcategory' => $categoryChild,
'images' => $image,
'imagesgallery' => $prdImages,
'is_like' => $isLike,
'size' => $size,
'color' => $color,
'variants' => $variants,
'description' => $_product->getDescription(),
'share_url' => $baseURL.$_product->getUrlPath()
//'share_url' => $mainURLApi.'shareproduct.php?productid='.$_product->getId()
);
endforeach;
$json_data = json_encode($data);
$json_data = str_replace('\/','/',$json_data);
echo $json_data;