/** * Gets the absolute preview URL to the current store view category page. * The category is the first one found in the database for the store. * The preview url includes "nostodebug=true" parameter. * * @param Mage_Core_Model_Store $store the store to get the url for. * * @return string the url. */ public function getPreviewUrlCategory(Mage_Core_Model_Store $store) { $rootCategoryId = (int) $store->getRootCategoryId(); $collection = Mage::getModel('catalog/category')->getCollection()->addFieldToFilter('is_active', 1)->addFieldToFilter('path', array('like' => "1/{$rootCategoryId}/%"))->addAttributeToSelect('*')->setPageSize(1)->setCurPage(1); foreach ($collection as $category) { /** @var Mage_Catalog_Model_Category $category */ $url = $category->getUrl(); $url = NostoHttpRequest::replaceQueryParamInUrl('___store', $store->getCode(), $url); return NostoHttpRequest::replaceQueryParamInUrl('nostodebug', 'true', $url); } return ''; }
/** * @magentoConfigFixture current_store catalog/frontend/flat_catalog_category 1 * @magentoDbIsolation enabled */ public function testSaveWithFlatIndexer() { $categoryName = 'Indexer Category Name ' . uniqid(); /** @var $parentCategory Mage_Catalog_Model_Category */ $parentCategory = self::$_objectManager->create('Mage_Catalog_Model_Category'); $parentCategory->load($this->_store->getRootCategoryId()); // init category model with EAV entity resource model $resourceModel = self::$_objectManager->create('Mage_Catalog_Model_Resource_Category'); $this->_model = self::$_objectManager->create('Mage_Catalog_Model_Category', array('resource' => $resourceModel)); $this->_model->setName($categoryName)->setParentId($parentCategory->getId())->setPath($parentCategory->getPath())->setLevel(2)->setPosition(1)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->save(); // check if category record exists in flat table /** @var $collection Mage_Catalog_Model_Resource_Category_Flat_Collection */ $collection = self::$_objectManager->create('Mage_Catalog_Model_Resource_Category_Flat_Collection'); $collection->addFieldToFilter('name', $categoryName); $this->assertCount(1, $collection->getItems()); }
/** * Get allow categories by store * @param Mage_Core_Model_Store $store * @return array */ public function getAllowCategoriesByStore($store) { $rootCatId = $store->getRootCategoryId(); $rootCat = Mage::getModel('catalog/category')->load($rootCatId); $allowCatIds = Mage::getModel('catalog/category')->getResource()->getChildren($rootCat, true); $excludedCategoriesIds = Mage::helper('solrsearch')->getSetting('excluded_categories'); $excludedCategoriesIdsArray = array(); if (!empty($excludedCategoriesIds)) { $excludedCategoriesIdsArray = explode(',', trim($excludedCategoriesIds, ',')); //Loaded categories recusive for excluding $recusiveExcludedCategory = Mage::helper('solrsearch')->getSetting('excluded_categories_recusive'); if (isset($recusiveExcludedCategory) && intval($recusiveExcludedCategory) > 0) { $excludedChildrenCategoriesIdsArray = array(); foreach ($excludedCategoriesIdsArray as $catId) { $parentCat = Mage::getModel('catalog/category')->load($catId); $excludedChildrenCategoriesIds = Mage::getModel('catalog/category')->getResource()->getChildren($parentCat, true); if (count($excludedChildrenCategoriesIds)) { $excludedChildrenCategoriesIdsArray = array_merge($excludedChildrenCategoriesIdsArray, $excludedChildrenCategoriesIds); } } //Merge categories id from settings and its children, $excludedCategoriesIdsArray = array_merge($excludedCategoriesIdsArray, $excludedChildrenCategoriesIdsArray); } if (count($excludedCategoriesIdsArray)) { $allowCatIds = array_diff($allowCatIds, $excludedCategoriesIdsArray); } } return $allowCatIds; }
/** * @param Mage_Core_Model_Store $store * @param bool $startingFromRoot */ public function makeCategoriesAnchor($store, $startingFromRoot = true) { $this->_makeCategoryAnchorRecursively($store->getRootCategoryId(), $startingFromRoot); }
/** * Get select for all products * * @param $store * @return Varien_Db_Select */ protected function _getAllProducts(Mage_Core_Model_Store $store) { if (!isset($this->_allProductsSelect[$store->getId()])) { /** @var $eavConfig Mage_Eav_Model_Config */ $eavConfig = $this->_factory->getSingleton('eav/config'); $statusAttributeId = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'status')->getId(); $visibilityAttributeId = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'visibility')->getId(); $select = $this->_connection->select()->from(array('cp' => $this->_getTable('catalog/product')), array())->joinInner(array('cpw' => $this->_getTable('catalog/product_website')), 'cpw.product_id = cp.entity_id', array())->joinInner(array('cpsd' => $this->_getTable(array('catalog/product', 'int'))), 'cpsd.entity_id = cp.entity_id AND cpsd.store_id = 0 AND cpsd.attribute_id = ' . $statusAttributeId, array())->joinLeft(array('cpss' => $this->_getTable(array('catalog/product', 'int'))), 'cpss.entity_id = cp.entity_id AND cpss.attribute_id = cpsd.attribute_id' . ' AND cpss.store_id = ' . $store->getId(), array())->joinInner(array('cpvd' => $this->_getTable(array('catalog/product', 'int'))), 'cpvd.entity_id = cp.entity_id AND cpvd.store_id = 0' . ' AND cpvd.attribute_id = ' . $visibilityAttributeId, array())->joinLeft(array('cpvs' => $this->_getTable(array('catalog/product', 'int'))), 'cpvs.entity_id = cp.entity_id AND cpvs.attribute_id = cpvd.attribute_id ' . 'AND cpvs.store_id = ' . $store->getId(), array())->joinLeft(array('ccp' => $this->_getTable('catalog/category_product')), 'ccp.product_id = cp.entity_id', array())->where('cpw.website_id = ?', $store->getWebsiteId())->where($this->_connection->getIfNullSql('cpss.value', 'cpsd.value') . ' = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->where($this->_connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)', array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH))->group('cp.entity_id')->columns(array('category_id' => new Zend_Db_Expr($store->getRootCategoryId()), 'product_id' => 'cp.entity_id', 'position' => new Zend_Db_Expr($this->_connection->getCheckSql('ccp.product_id IS NOT NULL', 'ccp.position', '0')), 'is_parent' => new Zend_Db_Expr($this->_connection->getCheckSql('ccp.product_id IS NOT NULL', '0', '1')), 'store_id' => new Zend_Db_Expr($store->getId()), 'visibility' => new Zend_Db_Expr($this->_connection->getIfNullSql('cpvs.value', 'cpvd.value')))); $this->_allProductsSelect[$store->getId()] = $select; } return $this->_allProductsSelect[$store->getId()]; }
/** * Delete non stores categories * * @param Mage_Core_Model_Store $store * @return void */ protected function _deleteNonStoreCategories($store) { $rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID; $rootIdExpr = $this->_connection->quote((string) $rootId); $rootCatIdExpr = $this->_connection->quote("{$rootId}/{$store->getRootCategoryId()}"); $catIdExpr = $this->_connection->quote("{$rootId}/{$store->getRootCategoryId()}/%"); $select = $this->_connection->select()->from(array('cf' => $this->_getMainStoreTable($store->getId())))->joinLeft(array('ce' => $this->_productHelper->getTable('catalog/category')), 'cf.path = ce.path', array())->where("cf.path = {$rootIdExpr} OR cf.path = {$rootCatIdExpr} OR cf.path like {$catIdExpr}")->where('ce.entity_id IS NULL'); $sql = $select->deleteFromSelect('cf'); $this->_connection->query($sql); }