public function getObject(Mage_Catalog_Model_Category $category)
{
$storeId = $category->getStoreId();
/** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $productHelper */
$productHelper = Mage::helper('algoliasearch/entity_producthelper');
$collection = $productHelper->getProductCollectionQuery($storeId, null, true, true);
$productCollection = clone $collection;
$productCollection = $productCollection->addCategoryFilter($category);
$category->setProductCount($productCollection->getSize());
$transport = new Varien_Object();
Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport));
$customData = $transport->getData();
$category->getUrlInstance()->setStore($storeId);
$path = '';
foreach ($category->getPathIds() as $categoryId) {
if ($path != '') {
$path .= ' / ';
}
$path .= $this->getCategoryName($categoryId, $storeId);
}
$data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), 'include_in_menu' => $category->getIncludeInMenu(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount());
try {
$imageUrl = $this->getThumbnailUrl($category) ?: $category->getImageUrl();
if ($imageUrl) {
/** @var Algolia_Algoliasearch_Helper_Image $imageHelper */
$imageHelper = Mage::helper('algoliasearch/image');
$data['image_url'] = $imageHelper->removeProtocol($imageUrl);
}
} catch (\Exception $e) {
// no image, no default, not fatal
}
foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
$value = $category->getData($attribute['attribute']);
$attribute_resource = $category->getResource()->getAttribute($attribute['attribute']);
if ($attribute_resource) {
$value = $attribute_resource->getFrontend()->getValue($category);
}
if (isset($data[$attribute['attribute']])) {
$value = $data[$attribute['attribute']];
}
if ($value) {
$data[$attribute['attribute']] = $value;
}
}
$data = array_merge($data, $customData);
foreach ($data as &$data0) {
$data0 = $this->try_cast($data0);
}
return $data;
}