/** * Save product attribute * * @param Varien_Object $product Product we want to save the attribute for * @param string $attributeCode Attribute code to be saved * * @return Mage_Catalog_Model_Resource_Url */ public function saveProductAttribute(Varien_Object $product, $attributeCode) { parent::saveProductAttribute($product, $attributeCode); $adapter = Mage::getSingleton('mongocore/resource_connection_adapter'); $updateCond = $adapter->getQueryBuilder()->getIdsFilter($product->getId()); $updateField = sprintf('attr_%d_%s', $product->getStoreId(), $attributeCode); $attributeValue = $product->getData($attributeCode); Mage::getResourceModel('catalog/product')->updateProductFieldFromFilter($updateCond, $updateField, $attributeValue); return $this; }
/** * Set store specific data to category * * @param Mage_Catalog_Model_Category $category * @param Mage_Core_Model_Store $store * @return Mage_Catalog_Model_Category */ protected function _setStoreSpecificData(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store) { $category->setStoreId($store->getId()); $storeCategoryData = $this->_urlResource->getCategory($category->getId(), $store->getId()); if ($storeCategoryData) { foreach ($storeCategoryData->toArray() as $key => $data) { $category->setData($key, $data); } } $rewrites = $this->_categoryRelation->loadByCategory($category); $category->setRequestPath($rewrites->getRequestPath()); return $category; }
/** * @magentoDataFixture Mage/Catalog/Model/Resource/_files/url_rewrites.php */ public function testGetLastUsedRewriteRequestIncrement() { $this->markTestIncomplete('Bug MAGETWO-724'); $this->assertEquals(1000, $this->_model->getLastUsedRewriteRequestIncrement('url-key-', '.html', 1)); }
/** * Save rewrite URL * * @param array $rewriteData * @param int|Varien_Object $rewrite * @return Loewenstark_UrlIndexer_Model_Resource_Url */ public function saveRewrite($rewriteData, $rewrite) { parent::saveRewrite($rewriteData, $rewrite); if ($this->_helper()->OptimizeCategoriesLeftJoin($rewriteData['store_id'])) { $this->_saveUrlIndexerRewrite($rewriteData, $rewrite); } return $this; }
/** * 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; }