/** * Update attribute values for entity list per store * * @param array $entityIds * @param array $attrData * @param int $storeId * @return Mage_Catalog_Model_Product_Action */ public function updateAttributes($entityIds, $attrData, $storeId) { $object = new Varien_Object(); $object->setIdFieldName('entity_id')->setStoreId($storeId); $this->_getWriteAdapter()->beginTransaction(); try { foreach ($attrData as $attrCode => $value) { $attribute = $this->getAttribute($attrCode); if (!$attribute->getAttributeId()) { continue; } $i = 0; foreach ($entityIds as $entityId) { $object->setId($entityId); // collect data for save $this->_saveAttributeValue($object, $attribute, $value); // save collected data every 1000 rows if ($i % 1000 == 0) { $this->_processAttributeValues(); } } } $this->_processAttributeValues(); $this->_getWriteAdapter()->commit(); } catch (Exception $e) { $this->_getWriteAdapter()->rollBack(); throw $e; } return $this; }
protected function _prepareCollection() { $sort = $this->getParam('sort', $this->_defaultSort); $dir = $this->getParam('dir', $this->_defaultDir); $files = $this->_helper->getLogFiles(); if (isset($sort) && !empty($files) && isset($files[0][$sort])) { usort($files, function ($a, $b) use($sort, $dir) { $a = $a[$sort]; $b = $b[$sort]; if (is_numeric($a)) { return $dir == 'asc' ? $a - $b : $b - $a; } else { return $dir == 'asc' ? strcmp($a, $b) : -strcmp($a, $b); } }); } $collection = new Varien_Data_Collection(); foreach ($files as $file) { $item = new Varien_Object(); $item->setIdFieldName('filename'); $item->setFilename($file['filename']); $item->setFilesize($this->_helper->humanFilesize($file['filesize'])); $item->setLines($file['lines']); $collection->addItem($item); } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Test isEverythingAllowed method * * @dataProvider isEverythingAllowedDataProvider * @param array $selectedResources * @param bool $expectedResult */ public function testIsEverythingAllowed($selectedResources, $expectedResult) { $apiRole = new Varien_Object(array('role_id' => 1)); $apiRole->setIdFieldName('role_id'); $this->_block->setApiRole($apiRole); $this->_ruleResource->expects($this->once())->method('getResourceIdsByRole')->with($apiRole->getId())->will($this->returnValue($selectedResources)); $this->assertEquals($expectedResult, $this->_block->isEverythingAllowed()); }
/** * Test _prepareForm method * * @dataProvider prepareFormDataProvider * @param array $originResTree * @param array $selectedRes * @param array $expectedRes */ public function testPrepareForm($originResTree, $selectedRes, $expectedRes) { // TODO Move to unit tests after MAGETWO-4015 complete $apiRole = new Varien_Object(array('role_id' => 1)); $apiRole->setIdFieldName('role_id'); $this->_block->setApiRole($apiRole); $this->_authorizationConfig->expects($this->once())->method('getAclResourcesAsArray')->with(false)->will($this->returnValue($originResTree)); $this->_ruleResource->expects($this->once())->method('getResourceIdsByRole')->with($apiRole->getId())->will($this->returnValue($selectedRes)); $this->_block->toHtml(); $this->assertEquals($expectedRes, $this->_block->getResourcesTree()); }
/** * Mage_Catalog_Model_Resource_Eav_Mysql4_Import_Product_Action::update() * * @param mixed $entityId * @param mixed $data = array('statics' => , 'attributes' => , 'inventories' => ) * @param mixed $storeId * @return void */ public function update($entityId, $data, $storeId, $obj = null) { $object = new Varien_Object(); $object->setIdFieldName('entity_id')->setStoreId($storeId); $this->_getWriteAdapter()->beginTransaction(); try { if ($obj == null) { $obj = new Varien_Object(); } if (!$obj->getId()) { $this->simpleLoad($obj, $entityId); } //update attributes foreach ($data['attributes'] as $attrCode => $value) { $attribute = $this->getAttribute($attrCode); if (!$this->__checkApply($obj, $attribute)) { continue; } $object->setId($entityId); // collect data for save $this->_saveAttributeValue($object, $attribute, $value); // save collected data every 1000 rows } //update $this->__updateProductValues($entityId, $data['statics']); //update inventory if (count($data['inventories']) > 0) { $stockItem = Mage::getSingleton('cataloginventory/stock_item'); $stockItem->setData(array()); $stockItem->loadByProduct($entityId)->setProductId($entityId); $stockDataChanged = false; foreach ($data['inventories'] as $k => $v) { $stockItem->setDataUsingMethod($k, $v); if ($stockItem->dataHasChangedFor($k)) { $stockDataChanged = true; } } if ($stockDataChanged) { $stockItem->save(); } } $this->_processAttributeValues(); $this->_getWriteAdapter()->commit(); } catch (Exception $e) { $this->_getWriteAdapter()->rollBack(); throw $e; } }
protected function _getCategories($categoryIds, $storeId = null, $path = null) { $isActiveAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_category', 'is_active'); $categories = array(); if (!is_array($categoryIds)) { $categoryIds = array($categoryIds); } $select = $this->_getWriteAdapter()->select()->from(array('main_table' => $this->getTable('catalog/category')), array('main_table.entity_id', 'main_table.parent_id', 'is_active' => 'IFNULL(c.value, d.value)', 'main_table.path')); if (is_null($path)) { $select->where('main_table.entity_id IN(?)', $categoryIds); } else { $select->where('main_table.path LIKE ?', $path . '%')->order('main_table.path'); } $table = $this->getTable('catalog/category') . '_int'; $select->joinLeft(array('d' => $table), "d.attribute_id = '{$isActiveAttribute->getId()}' AND d.store_id = 0 AND d.entity_id = main_table.entity_id", array())->joinLeft(array('c' => $table), "c.attribute_id = '{$isActiveAttribute->getId()}' AND c.store_id = '{$storeId}' AND c.entity_id = main_table.entity_id", array()); if (!is_null($storeId)) { $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath(); $rootCategoryPathLength = strlen($rootCategoryPath); } $rowSet = $this->_getWriteAdapter()->fetchAll($select); foreach ($rowSet as $row) { if (!is_null($storeId) && substr($row['path'], 0, $rootCategoryPathLength) != $rootCategoryPath) { continue; } $category = new Varien_Object($row); $category->setIdFieldName('entity_id'); $category->setStoreId($storeId); $this->_prepareCategoryParentId($category); $categories[$category->getId()] = $category; } unset($rowSet); if (!is_null($storeId) && $categories) { foreach (array('name', 'url_key', 'url_path') as $attributeCode) { $attributes = $this->_getCategoryAttribute($attributeCode, array_keys($categories), $category->getStoreId()); foreach ($attributes as $categoryId => $attributeValue) { $categories[$categoryId]->setData($attributeCode, $attributeValue); } } } return $categories; }
protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId) { $products = array(); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); if (!is_null($productIds)) { if (!is_array($productIds)) { $productIds = array($productIds); } } $select = $this->_getWriteAdapter()->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), $this->_getWriteAdapter()->quoteInto('e.entity_id=w.product_id AND w.website_id=?', $websiteId), array())->where('e.entity_id>?', $entityId)->order('e.entity_id')->limit($this->_productLimit); if (!is_null($productIds)) { $select->where('e.entity_id IN(?)', $productIds); } $query = $this->_getWriteAdapter()->query($select); while ($row = $query->fetch()) { $product = new Varien_Object($row); $product->setIdFieldName('entity_id'); $product->setCategoryIds(array()); $product->setStoreId($storeId); $products[$product->getId()] = $product; $lastEntityId = $product->getId(); } unset($query); if ($products) { $select = $this->_getReadAdapter()->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products)); $categories = $this->_getReadAdapter()->fetchAll($select); foreach ($categories as $category) { $productId = $category['product_id']; $categoryIds = $products[$productId]->getCategoryIds(); $categoryIds[] = $category['category_id']; $products[$productId]->setCategoryIds($categoryIds); } foreach (array('name', 'url_key', 'url_path', 'visibility', "status") as $attributeCode) { $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId); foreach ($attributes as $productId => $attributeValue) { $products[$productId]->setData($attributeCode, $attributeValue); } } } return $products; }
/** * Synchronize flat data with eav model. * * @param Mage_Catalog_Model_Category|int $category * @param array $storeIds * @return Mage_Catalog_Model_Resource_Category_Flat */ public function synchronize($category = null, $storeIds = array()) { if (is_null($category)) { if (empty($storeIds)) { $storeIds = null; } $stores = $this->getStoresRootCategories($storeIds); $storesObjects = array(); foreach ($stores as $storeId => $rootCategoryId) { $_store = new Varien_Object(array('store_id' => $storeId, 'root_category_id' => $rootCategoryId)); $_store->setIdFieldName('store_id'); $storesObjects[] = $_store; } $this->rebuild($storesObjects); } else { if ($category instanceof Mage_Catalog_Model_Category) { $categoryId = $category->getId(); foreach ($category->getStoreIds() as $storeId) { if ($storeId == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) { continue; } $attributeValues = $this->_getAttributeValues($categoryId, $storeId); $data = new Varien_Object($category->getData()); $data->addData($attributeValues[$categoryId])->setStoreId($storeId); $this->_synchronize($data); } } else { if (is_numeric($category)) { $write = $this->_getWriteAdapter(); $select = $write->select()->from($this->getTable('catalog/category'))->where('entity_id=?', $category); $row = $write->fetchRow($select); if (!$row) { return $this; } $stores = $this->getStoresRootCategories(); $path = explode('/', $row['path']); foreach ($stores as $storeId => $rootCategoryId) { if (in_array($rootCategoryId, $path)) { $attributeValues = $this->_getAttributeValues($category, $storeId); $data = new Varien_Object($row); $data->addData($attributeValues[$category])->setStoreId($storeId); $this->_synchronize($data); } else { $where = $write->quoteInto('entity_id = ?', $category); $write->delete($this->getMainStoreTable($storeId), $where); } } } } } return $this; }
/** * Retrieve Product Emulator (Varien Object) * * @return Varien_Object */ protected function _getProductEmulator() { $productEmulator = new Varien_Object(); $productEmulator->setIdFieldName('entity_id'); return $productEmulator; }
/** * Retrieve table status * * @param string $tableName * @return Varien_Object */ public function getTableStatus($tableName) { $row = $this->_write->showTableStatus($tableName); if ($row) { $statusObject = new Varien_Object(); $statusObject->setIdFieldName('name'); foreach ($row as $field => $value) { $statusObject->setData(strtolower($field), $value); } $cntRow = $this->_write->fetchRow($this->_write->select()->from($tableName, 'COUNT(1) as rows')); $statusObject->setRows($cntRow['rows']); return $statusObject; } return false; }
/** * Retrieve table status * * @param string $tableName * @return Varien_Object */ public function getTableStatus($tableName) { $sql = $this->_read->quoteInto('SHOW TABLE STATUS LIKE ?', $tableName); $row = $this->_read->fetchRow($sql); if ($row) { $statusObject = new Varien_Object(); $statusObject->setIdFieldName('name'); foreach ($row as $field => $value) { $statusObject->setData(strtolower($field), $value); } $cntRow = $this->_read->fetchRow($this->_read->select()->from($tableName, 'COUNT(*) as rows')); $statusObject->setRows($cntRow['rows']); return $statusObject; } return false; }
*/ /* @var $this Mage_Core_Model_Resource_Setup */ /** @var $indexHelper Enterprise_Index_Helper_Data */ $indexHelper = Mage::helper('enterprise_index'); /** @var $client Enterprise_Mview_Model_Client */ $client = Mage::getModel('enterprise_mview/client'); $client->init('catalogsearch_fulltext'); $client->getMetadata()->setKeyColumn('product_id')->setViewName('catalogsearch_fulltext_cl')->setStatus(Enterprise_Mview_Model_Metadata::STATUS_INVALID)->setGroupCode('catalogsearch_fulltext')->save(); $client->execute('enterprise_index/action_index_changelog_create'); $subscriptions = array($this->getTable('catalog/product') => 'entity_id', $this->getTable(array('catalog/product', 'decimal')) => 'entity_id', $this->getTable(array('catalog/product', 'int')) => 'entity_id', $this->getTable(array('catalog/product', 'text')) => 'entity_id', $this->getTable(array('catalog/product', 'varchar')) => 'entity_id', $this->getTable(array('catalog/product', 'datetime')) => 'entity_id'); /** @var $resources mage_core_model_resource */ $resources = Mage::getSingleton('core/resource'); /** @var $productType mage_catalog_model_product_type */ $productType = Mage::getSingleton('catalog/product_type'); $productEmulator = new Varien_Object(); $productEmulator->setIdFieldName('entity_id'); foreach (Mage_Catalog_Model_Product_Type::getCompositeTypes() as $typeId) { $productEmulator->setTypeId($typeId); /** @var $typeInstance Mage_Catalog_Model_Product_Type_Abstract */ $typeInstance = $productType->factory($productEmulator); /** @var $relation bool|Varien_Object */ $relation = $typeInstance->isComposite() ? $typeInstance->getRelationInfo() : false; if ($relation && $relation->getTable()) { $tableName = $resources->getTableName($relation->getTable()); $subscriptions[$tableName] = $relation->getParentFieldName(); } } foreach ($subscriptions as $targetTable => $targetColumn) { $arguments = array('target_table' => $targetTable, 'target_column' => $targetColumn); $client->execute('enterprise_mview/action_changelog_subscription_create', $arguments); }
/** * Retrieve Product data objects * LOE: remove if status(=2) is disabled or visibility(=1) false * * @param int|array $productIds * @param int $storeId * @param int $entityId * @param int $lastEntityId * @return array */ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId) { $products = array(); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); $adapter = $this->_getReadAdapter(); if ($productIds !== null) { if (!is_array($productIds)) { $productIds = array($productIds); } } $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId); $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit); if ($productIds !== null) { $select->where('e.entity_id IN(?)', $productIds); } //if we are to ignore disabled products... add the necessary joins and conditions if ($this->_helper()->HideDisabledProducts($storeId)) { $statusCode = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'status'); $bind['status_id'] = (int) $statusCode; $bind['disabled'] = Mage_Catalog_Model_Product_Status::STATUS_DISABLED; $bind['store_id'] = (int) $storeId; $bind['default_store_id'] = 0; $select->joinLeft(array('s' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = s.entity_id AND s.attribute_id = :status_id AND s.store_id = :store_id', array()); $select->joinLeft(array('ds' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = ds.entity_id AND ds.attribute_id = :status_id AND ds.store_id = :default_store_id', array()); $select->where('s.value <> :disabled OR (s.value IS NULL AND ds.value <> :disabled)'); } //if we are to ignore not visible products... add the necessary joins and conditions if ($this->_helper()->HideNotVisibileProducts($storeId)) { $visibilityCode = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'visibility'); $bind['not_visible'] = Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE; $bind['visibility_id'] = (int) $visibilityCode; $bind['store_id'] = (int) $storeId; $bind['default_store_id'] = 0; $select->joinLeft(array('v' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = v.entity_id AND v.attribute_id = :visibility_id AND v.store_id = :store_id', array()); $select->joinLeft(array('dv' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = dv.entity_id AND dv.attribute_id = :visibility_id AND dv.store_id = :default_store_id', array()); $select->where('v.value <> :not_visible OR (v.value IS NULL AND dv.value <> :not_visible)'); } $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { $product = new Varien_Object($row); $product->setIdFieldName('entity_id'); $product->setCategoryIds(array()); $product->setStoreId($storeId); $products[$product->getId()] = $product; $lastEntityId = $product->getId(); } unset($rowSet); if ($products) { $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products)); $categories = $adapter->fetchAll($select); foreach ($categories as $category) { $productId = $category['product_id']; $categoryIds = $products[$productId]->getCategoryIds(); $categoryIds[] = $category['category_id']; $products[$productId]->setCategoryIds($categoryIds); } foreach (array('name', 'url_key', 'url_path') as $attributeCode) { $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId); foreach ($attributes as $productId => $attributeValue) { $products[$productId]->setData($attributeCode, $attributeValue); } } } return $products; }
/** * Retrieve entities children ids (simple products for configurable, grouped and bundles). * * @param array $entityIds Parent entities ids. * @param int $websiteId Current website ids * * @return array */ protected function _getChildrenIds($entityIds, $websiteId) { $children = array(); $productTypes = array_keys(Mage::getModel('catalog/product_type')->getOptionArray()); foreach ($productTypes as $productType) { $productEmulator = new Varien_Object(); $productEmulator->setIdFieldName('entity_id'); $productEmulator->setTypeId($productType); $typeInstance = Mage::getSingleton('catalog/product_type')->factory($productEmulator); $relation = $typeInstance->isComposite() ? $typeInstance->getRelationInfo() : false; if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) { $select = $this->getConnection()->select()->from(array('main' => $this->getTable($relation->getTable())), array($relation->getParentFieldName(), $relation->getChildFieldName()))->where("main.{$relation->getParentFieldName()} in (?)", $entityIds); if (!is_null($relation->getWhere())) { $select->where($relation->getWhere()); } Mage::dispatchEvent('prepare_product_children_id_list_select', array('select' => $select, 'entity_field' => 'main.product_id', 'website_field' => $websiteId)); $data = $this->getConnection()->fetchAll($select); foreach ($data as $link) { $parentId = $link[$relation->getParentFieldName()]; $childId = $link[$relation->getChildFieldName()]; if (!isset($children[$parentId])) { $children[$parentId] = array(); } $children[$parentId][] = $childId; } } } return $children; }
/** * Get the (uploaded) catalog files * * @return Varien_Object[] */ public function getFiles() { $files = array(); $filenames = scandir($this->getBaseDir()); foreach ($filenames as $filename) { if (strpos($filename, '.') === 0) { continue; } $file = $this->getFilePath($filename); $filesize = filesize($file); $filemtime = filemtime($file); $inProgress = $this->isInProgress($filename); $data = array('filename' => $filename, 'file' => $file, 'filesize' => $filesize, 'filemtime' => $filemtime, 'status' => $inProgress); $object = new Varien_Object($data); $object->setIdFieldName('filename'); $files[] = $object; } return $files; }
/** * Retrieve Product data objects * * @param int|array $productIds * @param int $storeId * @param int $entityId * @param int $lastEntityId * @return array */ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId) { $products = array(); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); $adapter = $this->_getReadAdapter(); if ($productIds !== null) { if (!is_array($productIds)) { $productIds = array($productIds); } } $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId); $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit); if ($productIds !== null) { $select->where('e.entity_id IN(?)', $productIds); } $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { $product = new Varien_Object($row); $product->setIdFieldName('entity_id'); $product->setCategoryIds(array()); $product->setStoreId($storeId); $products[$product->getId()] = $product; $lastEntityId = $product->getId(); } unset($rowSet); if ($products) { $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products)); $categories = $adapter->fetchAll($select); foreach ($categories as $category) { $productId = $category['product_id']; $categoryIds = $products[$productId]->getCategoryIds(); $categoryIds[] = $category['category_id']; $products[$productId]->setCategoryIds($categoryIds); } foreach (array('name', 'url_key', 'url_path') as $attributeCode) { $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId); foreach ($attributes as $productId => $attributeValue) { $products[$productId]->setData($attributeCode, $attributeValue); } } } return $products; }
/** * Retrieve Product Emulator (Varien Object) * * @param string $typeId * @return Varien_Object */ protected function _getProductEmulator($typeId) { if (!isset($this->_productEmulators[$typeId])) { $productEmulator = new Varien_Object(); $productEmulator->setIdFieldName('entity_id')->setTypeId($typeId); $this->_productEmulators[$typeId] = $productEmulator; } return $this->_productEmulators[$typeId]; }
/** * Retrieve categories objects * Either $categoryIds or $path (with ending slash) must be specified * * @param int|array $categoryIds * @param int $storeId * @param string $path * * @return array */ protected function _getCategories($categoryIds, $storeId = null, $path = null) { if (false === $this->_getHelper()->excludeDisabledCategories($storeId)) { return parent::_getCategories($categoryIds, $storeId, $path); } /** @var Mage_Catalog_Model_Resource_Eav_Attribute $isActiveAttribute */ $isActiveAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_active'); $categories = array(); $adapter = $this->_getReadAdapter(); if (!is_array($categoryIds)) { $categoryIds = array($categoryIds); } // the method parent::_getCategories has a bug in getCheckSql $isActiveExpr = $adapter->getCheckSql('IFNULL(c.value_id,0) > 0', 'c.value', 'd.value'); $select = $adapter->select()->from(array('main_table' => $this->getTable('catalog/category')), array('main_table.entity_id', 'main_table.parent_id', 'main_table.level', 'is_active' => $isActiveExpr, 'main_table.path')); // Prepare variables for checking whether categories belong to store if ($path === null) { $select->where('main_table.entity_id IN(?)', $categoryIds); } else { // Ensure that path ends with '/', otherwise we can get wrong results - e.g. $path = '1/2' will get '1/20' if (substr($path, -1) != '/') { $path .= '/'; } $select->where('main_table.path LIKE ?', $path . '%')->order('main_table.path'); } $table = $this->getTable(array('catalog/category', 'int')); $select->joinLeft(array('d' => $table), 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = main_table.entity_id', array())->joinLeft(array('c' => $table), 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = main_table.entity_id', array()); if (true === $this->_getHelper()->excludeDisabledCategories($storeId)) { $select->where($isActiveExpr . '=1'); } if ($storeId !== null) { $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath(); $rootCategoryPathLength = strlen($rootCategoryPath); } $bind = array('attribute_id' => (int) $isActiveAttribute->getId(), 'store_id' => (int) $storeId); $this->_addCategoryAttributeToSelect($select, 'name', $storeId); $this->_addCategoryAttributeToSelect($select, 'url_key', $storeId); $this->_addCategoryAttributeToSelect($select, 'url_path', $storeId); Mage::dispatchEvent('fastindexer_get_categories_select', array('model' => $this, 'select' => $select, 'store_id' => $storeId)); $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { if ($storeId !== null) { // Check the category to be either store's root or its descendant // First - check that category's start is the same as root category if (substr($row['path'], 0, $rootCategoryPathLength) !== $rootCategoryPath) { continue; } // Second - check non-root category - that it's really a descendant, not a simple string match if (strlen($row['path']) > $rootCategoryPathLength && $row['path'][$rootCategoryPathLength] !== '/') { continue; } } $category = new Varien_Object($row); $category->setIdFieldName('entity_id'); $category->setStoreId($storeId); $this->_prepareCategoryParentId($category); $categories[$category->getId()] = $category; } unset($rowSet); return $categories; }