-
Notifications
You must be signed in to change notification settings - Fork 0
/
categoryproducts.php
76 lines (53 loc) · 1.77 KB
/
categoryproducts.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
<?php
/**
* @author alok dubey
* @2018
*/
require_once 'config.php';
Mage::app();
Mage::app()->getTranslator()->init('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$cat_id=$_REQUEST['id'];
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($category)
->load();
foreach($products as $product){
$img= Mage::helper('catalog/image')->init($product, 'small_image');
//print_r($product->getOptions());
$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());
if($product->getRatingSummary()):
$ret[$id] ['reviews']=$product->getRatingSummary();
else:
$ret[$id] ['reviews']='None';
endif;
$ret[$id]['img']=(string) $img;
$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 />";
}
}
}
// exit;
}
$ret=array_values($ret);
$result=json_encode($ret,JSON_PRETTY_PRINT) ;
echo $result;
?>