load($categoryId)->getProductCollection(); $collection->addAttributeToSelect(array( // your selections; * not recommend as you don't need all of it, just select the attributes you need )); if ($sort != NULL) { $collection->setOrder($sort, $direction); } else $collection->setOrder('sku', 'asc'); $collection->load(); foreach ($collection as $prods) { $prodIds[] = $prods->entity_id; } return $prodIds; } } if (!function_exists('_getAttribute')) { function _getAttribute($attribute) { $product = Mage::getModel('catalog/product'); $attributes = Mage::getResourceModel('eav/entity_attribute_collection') ->setEntityTypeFilter($product->getResource()->getTypeId()) ->addFieldToFilter('attribute_code', $attribute); $_attributes = $attributes->getFirstItem()->setEntity($product->getResource()); return $_attributes->getSource()->getAllOptions(false); } } if (!function_exists('_getProductAttribute')) { function _getProductAttribute($product , $attribute_code) { $value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product); if ( $value == 'No') $value = ''; return $value; } } if (!function_exists('_getAttributeList')) { function _getAttributeList($attribute) { $array_list = array(); foreach ( _getAttribute($attribute) as $item ) { $array_list[] = "/".$item['label']."/i"; } return $array_list; } } if (!function_exists('_extSanitize')) { function _extSanitize($striing) { return str_replace("'",'',$striing); } } $items = array(); $rawData = array(); $ctr = 1; foreach( array_slice(_getProducts($categoryId, $sort, $direction),$start,$limit) as $productId) { $product = Mage::getModel('catalog/product'); $product->load($productId); $productTitle = _extSanitize($product->getName()); //sample attributes fileds for the example $rawData['id'] = $ctr; $rawData['sku'] = $product->getSku(); $rawData['name'] = $product->getName(); $rawData['url_path'] = $product->getProductUrl(); $rawData['jewelry_style'] = _extSanitize(_getProductAttribute($product , 'jewelry_style')); $rawData['jewelry_carat_total_weight'] = floatval(_getProductAttribute($product , 'jewelry_carat_total_weight')); $rawData['jewelry_main_stone'] = _getProductAttribute($product , 'jewelry_main_stone'); $rawData['jewelry_metal_purity'] = _getProductAttribute($product , 'jewelry_metal_purity'); $rawData['jewelry_metal'] = _getProductAttribute($product , 'jewelry_metal'); $rawData['jewelry_diamond_color'] = _getProductAttribute($product , 'jewelry_diamond_color'); $rawData['jewelry_diamond_clarity'] = _getProductAttribute($product , 'jewelry_diamond_clarity'); $rawData['jewelry_gemstone_color'] = _getProductAttribute($product , 'jewelry_gemstone_color'); $rawData['jewelry_gemstone_clarity'] = _getProductAttribute($product , 'jewelry_gemstone_clarity'); $rawData['special_price'] = floatval($product->getSpecialPrice()); $rawData['image'] = $product->getImage(); $rawData['addtocart'] = Mage::getUrl('checkout/cart/add', array('product'=>$productId)); $rawData['short_description'] = $product->getShortDescription(); $items[] = $rawData; $ctr++; } //start output, check if callback is defined if ( isset($_REQUEST['callback']) ) { $callback = $_REQUEST['callback']; echo $callback . '(' . json_encode(array('totalcount' => count(_getProducts($categoryId)), 'items' => $items) ) . ');'; } else { echo json_encode(array('totalcount' => count(_getProducts($categoryId)), 'items' => $items) ); } ?>