/** * prepare categories * * @return array */ protected function prepareCategories() { $result = array(); $maxSortOrderByCategoryNumber = $this->getCategoryMaxSortOrder(); foreach ($this->getCategoriesFromDb($this->currentProduct->id) as $category) { $categoryPathItem = new Shopgate_Model_Catalog_CategoryPath(); $categoryPathItem->setUid($category['id_category']); $maxPosition = array_key_exists($category['id_category'], $maxSortOrderByCategoryNumber) ? $maxSortOrderByCategoryNumber[$category['id_category']] : 0; $productPosition = $this->getProductPositionByIdAndCategoryId($this->currentProduct->id, $category['id_category']); $categoryPathItem->setSortOrder($maxPosition - $productPosition); foreach ($this->getCategoryPathsFromModel($category['id_category']) as $path) { $categoryPathItem->addItem($path['level_depth'], $path['name']); } $result[] = $categoryPathItem; } return $result; }
/** * set category path */ public function setCategoryPaths() { $result = array(); if ($this->_getExportHelper()->isProductVisibleInCategories($this->item)) { $itemsOrderOption = Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_ITEM_SORT); $linkedCategories = Mage::getResourceSingleton('shopgate/product')->getCategoryIdsAndPosition($this->item); foreach ($linkedCategories as $link) { $categoryItemObject = new Shopgate_Model_Catalog_CategoryPath(); $categoryItemObject->setUid($link['category_id']); switch ($itemsOrderOption) { case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_LAST_UPDATED: $sortIndex = Mage::getModel('core/date')->timestamp(strtotime($this->item->getUpdatedAt())); $categoryItemObject->setSortOrder($sortIndex); break; case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_NEWEST: $sortIndex = Mage::getModel('core/date')->timestamp(strtotime($this->item->getCreatedAt())); $categoryItemObject->setSortOrder(Shopgate_Framework_Model_Export_Product_Csv::MAX_TIMESTAMP - $sortIndex); break; case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_PRICE_DESC: $sortIndex = round($this->item->getFinalPrice() * 100, 0); $categoryItemObject->setSortOrder($sortIndex); break; case Shopgate_Framework_Model_System_Config_Source_Item_Sort::SORT_TYPE_POSITION: $categoryItemObject->setSortOrder($link['max_position'] - $link['position']); break; default: $categoryItemObject->setSortOrder($link['position']); } $result[$link['category_id']] = $categoryItemObject; } } parent::setCategoryPaths($result); }