Exemple #1
0
 public function testGetProductCount()
 {
     $this->_model->load(6);
     $this->assertEquals(0, $this->_model->getProductCount());
     $this->_model->setData(array());
     $this->_model->load(3);
     $this->assertEquals(1, $this->_model->getProductCount());
 }
 protected function exportData(Mage_Catalog_Model_Category $category, $file, $depth = 0)
 {
     $data = array('id' => $category->getId(), 'parent_id' => $category->getParentId(), 'attribute_set_id' => $category->getAttributeSetId(), 'urlPath' => $category->getUrlPath(), 'urlKey' => $category->getUrlKey(), 'path' => $category->getPath(), 'position' => $category->getPosition(), 'page_layout' => $category->getPageLayout(), 'description' => $category->getDescription(), 'display_mode' => $category->getDisplayMode(), 'is_active' => $category->getIsActive(), 'is_anchor' => $category->getIsAnchor(), 'include_in_menu' => $category->getIncludeInMenu(), 'custom_design' => $category->getCustomDesign(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'metaTitle' => $category->getMetaTitle(), 'metaKeywords' => $category->getMetaKeywords(), 'metaDescription' => $category->getMetaDescription());
     echo str_repeat('  ', $depth);
     echo '* ' . $category->getName() . sprintf(' (%s products)', $category->getProductCount()) . PHP_EOL;
     fputcsv($file, $data);
     if ($category->hasChildren()) {
         $children = Mage::getModel('catalog/category')->getCategories($category->getId());
         foreach ($children as $child) {
             $child = Mage::getModel('catalog/category')->load($child->getId());
             $this->exportData($child, $file, $depth + 1);
         }
     }
 }
 /**
  * @param Mage_Catalog_Model_Category $category
  * @return mixed
  */
 protected function _getProductCount($category)
 {
     /** @var Amasty_Shopby_Helper_Data $helper */
     $helper = Mage::helper('amshopby');
     if ($helper->useSolr()) {
         // not implemented yet
         return null;
     } else {
         return $category->getProductCount();
     }
 }
 public function getObject(Mage_Catalog_Model_Category $category)
 {
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $productCollection = $category->getProductCollection();
     $category->setProductCount($productCollection->addMinimalPrice()->count());
     $transport = new Varien_Object();
     Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport));
     $customData = $transport->getData();
     $storeId = $category->getStoreId();
     $category->getUrlInstance()->setStore($storeId);
     $path = '';
     foreach ($category->getPathIds() as $categoryId) {
         if ($path != '') {
             $path .= ' / ';
         }
         $path .= $this->getCategoryName($categoryId, $storeId);
     }
     $image_url = NULL;
     try {
         $image_url = $category->getImageUrl();
     } catch (Exception $e) {
         /* no image, no default: not fatal */
     }
     $data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount());
     if (!empty($image_url)) {
         $data['image_url'] = $image_url;
     }
     foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
         $value = $category->getData($attribute['attribute']);
         $attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']);
         if ($attribute_ressource) {
             $value = $attribute_ressource->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;
 }
Exemple #5
0
 /**
  * Return the number of products assigned to the category
  *
  * @param Mage_Catalog_Model_Category|Varien_Data_Tree_Node $category
  * @return int
  */
 protected function _getProductCount($category)
 {
     if (null === ($count = $category->getData('product_count'))) {
         $count = 0;
         if ($category instanceof Mage_Catalog_Model_Category) {
             $count = $category->getProductCount();
         } elseif ($category instanceof Varien_Data_Tree_Node) {
             $count = $this->_getProductCountFromTreeNode($category);
         }
     }
     return $count;
 }
Exemple #6
0
 /**
  * Prepare category row
  * @param Mage_Catalog_Model_Category $category
  * @param unknown_type $id
  * @param unknown_type $isSelected
  * @param unknown_type $level
  * @param unknown_type $isFolded
  * @return array
  */
 protected function _prepareItemData($category, $id, $isSelected, $level = 1, $isFolded = false, $skipCount = false)
 {
     $row = null;
     /*
      * Display only active category and having products or being parents 
      */
     if ($category->getIsActive() && ($skipCount || $category->getProductCount())) {
         $row = array('label' => Mage::helper('core')->htmlEscape($category->getName()), 'value' => Mage::helper('amshopby/url')->getCategoryUrl($category), 'count' => $skipCount ? 0 : $category->getProductCount(), 'level' => $level, 'id' => $id, 'is_folded' => $isFolded, 'is_selected' => $isSelected);
     }
     return $row;
 }
Exemple #7
0
 /**
  * @param Mage_Catalog_Model_Category $category
  * @return mixed
  */
 protected function _getProductCount($category)
 {
     if ($this->_getDataHelper()->useSolr()) {
         /** @var Enterprise_Search_Model_Resource_Collection $productCollection */
         //            $productCollection = $this->getLayer()->getProductCollection();
         //            $categoriesCount = $productCollection->getFacetedData('category_ids');
         //            return isset($categoriesCount[$category->getId()]) ? $categoriesCount[$category->getId()] : null;
         // Disabled, course still buggy
         return null;
     } else {
         return $category->getProductCount();
     }
 }