Mage_Catalog_Model_Resource_Eav_Mysql4_Url Class Reference

Inheritance diagram for Mage_Catalog_Model_Resource_Eav_Mysql4_Url:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 getStores ($storeId=null)
 getCategoryModel ()
 getProductModel ()
 getRewriteByIdPath ($idPath, $storeId)
 getRewriteByRequestPath ($requestPath, $storeId)
 prepareRewrites ($storeId, $categoryIds=null, $productIds=null)
 saveRewrite ($rewriteData, $rewrite)
 saveCategoryAttribute (Varien_Object $category, $attributeCode)
 saveProductAttribute (Varien_Object $product, $attributeCode)
 _getProductAttribute ($attributeCode, $productIds, $storeId)
 getCategory ($categoryId, $storeId)
 getCategories ($categoryIds, $storeId)
 loadCategoryChilds (Varien_Object $category)
 getCategoryParentPath (Varien_Object $category)
 getProductIdsByCategory ($category)
 getProduct ($productId, $storeId)
 getProductsByStore ($storeId, &$lastEntityId)
 getProductsByCategory (Varien_Object $category, &$lastEntityId)
 clearCategoryProduct ($storeId)
 deleteCategoryProductRewrites ($categoryId, $productIds)

Protected Member Functions

 _construct ()
 _getCategoryAttribute ($attributeCode, $categoryIds, $storeId)
 _prepareCategoryParentId (Varien_Object $category)
 _prepareStoreRootCategories ($stores)
 _getCategories ($categoryIds, $storeId=null, $path=null)
 _getProducts ($productIds=null, $storeId, $entityId=0, &$lastEntityId)

Protected Attributes

 $_stores
 $_categoryAttributes = array()
 $_productAttributes = array()
 $_productLimit = 250


Detailed Description

Definition at line 34 of file Url.php.


Member Function Documentation

_construct (  )  [protected]

Load core Url rewrite model

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 68 of file Url.php.

00069     {
00070         $this->_init('core/url_rewrite', 'url_rewrite_id');
00071     }

_getCategories ( categoryIds,
storeId = null,
path = null 
) [protected]

Definition at line 540 of file Url.php.

00541     {
00542         $isActiveAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_category', 'is_active');
00543         $categories = array();
00544 
00545         if (!is_array($categoryIds)) {
00546             $categoryIds = array($categoryIds);
00547         }
00548 
00549         $select = $this->_getWriteAdapter()->select()
00550             ->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'));
00551 
00552         if (is_null($path)) {
00553             $select->where('main_table.entity_id IN(?)', $categoryIds);
00554         }
00555         else {
00556             $select->where('main_table.path LIKE ?', $path . '%')
00557                 ->order('main_table.path');
00558         }
00559         $table = $this->getTable('catalog/category') . '_int';
00560         $select->joinLeft(array('d'=>$table), "d.attribute_id = '{$isActiveAttribute->getId()}' AND d.store_id = 0 AND d.entity_id = main_table.entity_id", array())
00561             ->joinLeft(array('c'=>$table), "c.attribute_id = '{$isActiveAttribute->getId()}' AND c.store_id = '{$storeId}' AND c.entity_id = main_table.entity_id", array());
00562 
00563         if (!is_null($storeId)) {
00564             $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
00565             $rootCategoryPathLength = strlen($rootCategoryPath);
00566         }
00567 
00568         $rowSet = $this->_getWriteAdapter()->fetchAll($select);
00569         foreach ($rowSet as $row) {
00570             if (!is_null($storeId) && substr($row['path'], 0, $rootCategoryPathLength) != $rootCategoryPath) {
00571                 continue;
00572             }
00573 
00574             $category = new Varien_Object($row);
00575             $category->setIdFieldName('entity_id');
00576             $category->setStoreId($storeId);
00577             $this->_prepareCategoryParentId($category);
00578 
00579             $categories[$category->getId()] = $category;
00580         }
00581         unset($rowSet);
00582 
00583         if (!is_null($storeId) && $categories) {
00584             foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
00585                 $attributes = $this->_getCategoryAttribute($attributeCode, array_keys($categories), $category->getStoreId());
00586                 foreach ($attributes as $categoryId => $attributeValue) {
00587                     $categories[$categoryId]->setData($attributeCode, $attributeValue);
00588                 }
00589             }
00590         }
00591 
00592         return $categories;
00593     }

_getCategoryAttribute ( attributeCode,
categoryIds,
storeId 
) [protected]

Retrieve category attributes

Parameters:
string $attributeCode
int|array $categoryIds
int $storeId
Returns:
array

Definition at line 296 of file Url.php.

00297     {
00298         if (!isset($this->_categoryAttributes[$attributeCode])) {
00299             $attribute = $this->getCategoryModel()->getResource()->getAttribute($attributeCode);
00300 
00301             $this->_categoryAttributes[$attributeCode] = array(
00302                 'entity_type_id' => $attribute->getEntityTypeId(),
00303                 'attribute_id'   => $attribute->getId(),
00304                 'table'          => $attribute->getBackend()->getTable(),
00305                 'is_global'      => $attribute->getIsGlobal(),
00306                 'is_static'      => $attribute->isStatic()
00307             );
00308             unset($attribute);
00309         }
00310 
00311         if (!is_array($categoryIds)) {
00312             $categoryIds = array($categoryIds);
00313         }
00314 
00315         $attributeTable = $this->_categoryAttributes[$attributeCode]['table'];
00316         if ($this->_categoryAttributes[$attributeCode]['is_static']) {
00317             $select = $this->_getWriteAdapter()->select()
00318                 ->from(
00319                     $this->getTable('catalog/category'),
00320                     array('value'=>$attributeCode, 'entity_id'=>'entity_id')
00321                 )
00322                 ->where('entity_id IN(?)', $categoryIds);
00323         } elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) {
00324             $select = $this->_getWriteAdapter()->select()
00325                 ->from($attributeTable, array('entity_id', 'value'))
00326                 ->where('attribute_id = ?', $this->_categoryAttributes[$attributeCode]['attribute_id'])
00327                 ->where('store_id=?', 0)
00328                 ->where('entity_id IN(?)', $categoryIds);
00329         } else {
00330             $select = $this->_getWriteAdapter()->select()
00331                 ->from(array('t1'=>$attributeTable), array('entity_id', 'IFNULL(t2.value, t1.value) as value'))
00332                 ->joinLeft(
00333                     array('t2'=>$attributeTable),
00334                     $this->_getWriteAdapter()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId),
00335                     array()
00336                 )
00337                 ->where('t1.store_id = ?', 0)
00338                 ->where('t1.attribute_id = ?', $this->_categoryAttributes[$attributeCode]['attribute_id'])
00339                 ->where('t1.entity_id IN(?)', $categoryIds);
00340         }
00341 
00342 
00343         $rowSet = $this->_getWriteAdapter()->fetchAll($select);
00344 
00345         $attributes = array();
00346         foreach ($rowSet as $row) {
00347             $attributes[$row['entity_id']] = $row['value'];
00348         }
00349         unset($rowSet);
00350         foreach ($categoryIds as $categoryId) {
00351             if (!isset($attributes[$categoryId])) {
00352                 $attributes[$categoryId] = null;
00353             }
00354         }
00355 
00356         return $attributes;
00357     }

_getProductAttribute ( attributeCode,
productIds,
storeId 
)

Retrieve product attribute

Parameters:
string $attributeCode
int|array $productIds
string $storeId
Returns:
array

Definition at line 437 of file Url.php.

00438     {
00439         if (!isset($this->_productAttributes[$attributeCode])) {
00440             $attribute = $this->getProductModel()->getResource()->getAttribute($attributeCode);
00441 
00442             $this->_productAttributes[$attributeCode] = array(
00443                 'entity_type_id' => $attribute->getEntityTypeId(),
00444                 'attribute_id'   => $attribute->getId(),
00445                 'table'          => $attribute->getBackend()->getTable(),
00446                 'is_global'      => $attribute->getIsGlobal()
00447             );
00448             unset($attribute);
00449         }
00450 
00451         if (!is_array($productIds)) {
00452             $productIds = array($productIds);
00453         }
00454 
00455         $attributeTable = $this->_productAttributes[$attributeCode]['table'];
00456         if ($this->_productAttributes[$attributeCode]['is_global'] || $storeId == 0) {
00457             $select = $this->_getWriteAdapter()->select()
00458                 ->from($attributeTable, array('entity_id', 'value'))
00459                 ->where('attribute_id = ?', $this->_productAttributes[$attributeCode]['attribute_id'])
00460                 ->where('store_id=?', 0)
00461                 ->where('entity_id IN(?)', $productIds);
00462         }
00463         else {
00464             $select = $this->_getWriteAdapter()->select()
00465                 ->from(array('t1'=>$attributeTable), array('entity_id', 'IFNULL(t2.value, t1.value) as value'))
00466                 ->joinLeft(
00467                     array('t2'=>$attributeTable),
00468                     $this->_getWriteAdapter()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId),
00469                     array()
00470                 )
00471                 ->where('t1.store_id = ?', 0)
00472                 ->where('t1.attribute_id = ?', $this->_productAttributes[$attributeCode]['attribute_id'])
00473                 ->where('t1.entity_id IN(?)', $productIds);
00474         }
00475 
00476 
00477         $rowSet = $this->_getWriteAdapter()->fetchAll($select);
00478 
00479         $attributes = array();
00480         foreach ($rowSet as $row) {
00481             $attributes[$row['entity_id']] = $row['value'];
00482         }
00483         unset($rowSet);
00484         foreach ($productIds as $productIds) {
00485             if (!isset($attributes[$productIds])) {
00486                 $attributes[$productIds] = null;
00487             }
00488         }
00489 
00490         return $attributes;
00491     }

_getProducts ( productIds = null,
storeId,
entityId = 0,
&$  lastEntityId 
) [protected]

Definition at line 682 of file Url.php.

00683     {
00684         $products = array();
00685 
00686         $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
00687         if (!is_null($productIds)) {
00688             if (!is_array($productIds)) {
00689                 $productIds = array($productIds);
00690             }
00691         }
00692         $select = $this->_getWriteAdapter()->select()
00693             ->from(array('e' => $this->getTable('catalog/product')), array('entity_id', 'category_ids'))
00694             ->join(
00695                 array('w' => $this->getTable('catalog/product_website')),
00696                 $this->_getWriteAdapter()->quoteInto('e.entity_id=w.product_id AND w.website_id=?', $websiteId),
00697                 array()
00698             )
00699             ->where('e.entity_id>?', $entityId)
00700             ->order('e.entity_id')
00701             ->limit($this->_productLimit);
00702         if (!is_null($productIds)) {
00703             $select->where('e.entity_id IN(?)', $productIds);
00704         }
00705 
00706         $query = $this->_getWriteAdapter()->query((string)$select);
00707         while ($row = $query->fetch()) {
00708             $product = new Varien_Object($row);
00709             $product->setIdFieldName('entity_id');
00710             $product->setCategoryIds(split(',', $product->getCategoryIds()));
00711             $products[$product->getId()] = $product;
00712             $lastEntityId = $product->getId();
00713         }
00714 
00715         unset($query);
00716 
00717         if ($products) {
00718             foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
00719                 $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
00720                 foreach ($attributes as $productId => $attributeValue) {
00721                     $products[$productId]->setData($attributeCode, $attributeValue);
00722                 }
00723             }
00724         }
00725 
00726         return $products;
00727     }

_prepareCategoryParentId ( Varien_Object category  )  [protected]

Prepare category parentId

Parameters:
Varien_Object $category
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Url

Definition at line 499 of file Url.php.

00500     {
00501         if ($category->getPath() != $category->getId()) {
00502             $split = split('/', $category->getPath());
00503             $category->setParentId($split[(count($split) - 2)]);
00504         }
00505         else {
00506             $category->setParentId(0);
00507         }
00508         return $this;
00509     }

_prepareStoreRootCategories ( stores  )  [protected]

Prepare stores root categories

Parameters:
array $stores
Returns:
array

Definition at line 517 of file Url.php.

00518     {
00519         $rootCategoryIds = array();
00520         foreach ($stores as $store) {
00521             /* @var $store Mage_Core_Model_Store */
00522             $rootCategoryIds[$store->getRootCategoryId()] = $store->getRootCategoryId();
00523         }
00524         if ($rootCategoryIds) {
00525             $categories = $this->_getCategories($rootCategoryIds);
00526         }
00527         foreach ($stores as $store) {
00528             /* @var $store Mage_Core_Model_Store */
00529             if (isset($categories[$store->getRootCategoryId()])) {
00530                 $store->setRootCategoryPath($categories[$store->getRootCategoryId()]->getPath());
00531                 $store->setRootCategory($categories[$store->getRootCategoryId()]);
00532             }
00533             else {
00534                 unset($stores[$store->getId()]);
00535             }
00536         }
00537         return $stores;
00538     }

clearCategoryProduct ( storeId  ) 

Definition at line 753 of file Url.php.

00754     {
00755         $select = $this->_getWriteAdapter()->select()
00756             ->from(array('tur' => $this->getMainTable()), $this->getIdFieldName())
00757             ->joinLeft(
00758                 array('tcp' => $this->getTable('catalog/category_product')),
00759                 'tur.category_id=tcp.category_id AND tur.product_id=tcp.product_id',
00760                 array()
00761             )->where('tur.store_id=?', $storeId)
00762             ->where('tur.category_id IS NOT NULL')
00763             ->where('tur.product_id IS NOT NULL')
00764             ->where('tcp.category_id IS NULL');
00765         $rowSet = $this->_getWriteAdapter()->fetchAll($select);
00766         $rewriteIds = array();
00767         foreach ($rowSet as $row) {
00768             $rewriteIds[] = $row[$this->getIdFieldName()];
00769         }
00770         if ($rewriteIds) {
00771             $where = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $rewriteIds);
00772             $this->_getWriteAdapter()->delete($this->getMainTable(), $where);
00773         }
00774     }

deleteCategoryProductRewrites ( categoryId,
productIds 
)

Delete rewrites for associated to category products

Parameters:
int $categoryId
array $productIds
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Url

Definition at line 783 of file Url.php.

00784     {
00785         $condition = $this->_getWriteAdapter()->quoteInto('category_id=?', $categoryId);
00786         $condition = $this->_getWriteAdapter()->quoteInto(
00787             $condition.' AND product_id IN (?)',
00788             $productIds
00789         );
00790         $this->_getWriteAdapter()->delete($this->getMainTable(), $condition);
00791         return $this;
00792     }

getCategories ( categoryIds,
storeId 
)

Definition at line 608 of file Url.php.

00609     {
00610         if (!$categoryIds || !$storeId) {
00611             return false;
00612         }
00613 
00614         return $this->_getCategories($categoryIds, $storeId);
00615     }

getCategory ( categoryId,
storeId 
)

Definition at line 595 of file Url.php.

00596     {
00597         if (!$categoryId || !$storeId) {
00598             return false;
00599         }
00600 
00601         $categories = $this->_getCategories($categoryId, $storeId);
00602         if (isset($categories[$categoryId])) {
00603             return $categories[$categoryId];
00604         }
00605         return false;
00606     }

getCategoryModel (  ) 

Retrieve Category model singleton

Returns:
Mage_Catalog_Model_Category

Definition at line 95 of file Url.php.

00096     {
00097         return Mage::getSingleton('catalog/category');
00098     }

getCategoryParentPath ( Varien_Object category  ) 

Definition at line 646 of file Url.php.

00647     {
00648         $store = Mage::app()->getStore($category->getStoreId());
00649         if ($category->getId() == $store->getRootCategoryId()) {
00650             return '';
00651         }
00652         elseif ($category->getParentId() == 1 || $category->getParentId() == $store->getRootCategoryId()) {
00653             return '';
00654         }
00655         else {
00656             $parentCategory = $this->getCategory($category->getParentId(), $store->getId());
00657             return $parentCategory->getUrlPath() . '/';
00658         }
00659     }

getProduct ( productId,
storeId 
)

Definition at line 729 of file Url.php.

00730     {
00731         $lastId   = 0;
00732         $products = $this->_getProducts($productId, $storeId, 0, $lastId);
00733         if (isset($products[$productId])) {
00734             return $products[$productId];
00735         }
00736         return false;
00737     }

getProductIdsByCategory ( category  ) 

Definition at line 661 of file Url.php.

00662     {
00663         $productIds = array();
00664         if ($category instanceof Varien_Object) {
00665             $categoryId = $category->getId();
00666         }
00667         else {
00668             $categoryId = $category;
00669         }
00670         $select = $this->_getWriteAdapter()->select()
00671             ->from($this->getTable('catalog/category_product'))
00672             ->where('category_id=?', $categoryId)
00673             ->order('product_id');
00674         $rowSet = $this->_getWriteAdapter()->fetchAll($select);
00675         foreach ($rowSet as $row) {
00676             $productIds[$row['product_id']] = $row['product_id'];
00677         }
00678 
00679         return $productIds;
00680     }

getProductModel (  ) 

Retrieve product model singleton

Returns:
Mage_Catalog_Model_Product

Definition at line 105 of file Url.php.

00106     {
00107         return Mage::getSingleton('catalog/product');
00108     }

getProductsByCategory ( Varien_Object category,
&$  lastEntityId 
)

Definition at line 744 of file Url.php.

00745     {
00746         $productIds = $this->getProductIdsByCategory($category);
00747         if (!$productIds) {
00748             return array();
00749         }
00750         return $this->_getProducts($productIds, $category->getStoreId(), $lastEntityId, $lastEntityId);
00751     }

getProductsByStore ( storeId,
&$  lastEntityId 
)

Definition at line 739 of file Url.php.

00740     {
00741         return $this->_getProducts(null, $storeId, $lastEntityId, $lastEntityId);
00742     }

getRewriteByIdPath ( idPath,
storeId 
)

Retrieve rewrite by idPath

Parameters:
string $idPath
Returns:
Varien_Object

Definition at line 116 of file Url.php.

00117     {
00118         $select = $this->_getWriteAdapter()->select()
00119             ->from($this->getMainTable())
00120             ->where('store_id=?', $storeId)
00121             ->where('id_path=?', $idPath);
00122         $row = $this->_getWriteAdapter()->fetchRow($select);
00123 
00124         if (!$row) {
00125             return false;
00126         }
00127         $rewrite = new Varien_Object($row);
00128         $rewrite->setIdFieldName($this->getIdFieldName());
00129         return $rewrite;
00130     }

getRewriteByRequestPath ( requestPath,
storeId 
)

Retrieve rewrite by requestPath

Parameters:
string $requestPath
Returns:
Varien_Object

Definition at line 138 of file Url.php.

00139     {
00140         $select = $this->_getWriteAdapter()->select()
00141             ->from($this->getMainTable())
00142             ->where('store_id=?', $storeId)
00143             ->where('request_path=?', $requestPath);
00144         $row = $this->_getWriteAdapter()->fetchRow($select);
00145 
00146         if (!$row) {
00147             return false;
00148         }
00149         $rewrite = new Varien_Object($row);
00150         $rewrite->setIdFieldName($this->getIdFieldName());
00151         return $rewrite;
00152     }

getStores ( storeId = null  ) 

Retrieve stores array or store model

Parameters:
int $storeId
Returns:
Mage_Core_Model_Store|array

Definition at line 79 of file Url.php.

00080     {
00081         if (is_null($this->_stores)) {
00082             $this->_stores = $this->_prepareStoreRootCategories(Mage::app()->getStores());
00083         }
00084         if ($storeId && isset($this->_stores[$storeId])) {
00085             return $this->_stores[$storeId];
00086         }
00087         return $this->_stores;
00088     }

loadCategoryChilds ( Varien_Object category  ) 

Definition at line 617 of file Url.php.

00618     {
00619         if (is_null($category->getId()) || is_null($category->getStoreId())) {
00620             return $category;
00621         }
00622 
00623         $categories = $this->_getCategories(null, $category->getStoreId(), $category->getPath() . '/');
00624         $category->setChilds(array());
00625         foreach ($categories as $child) {
00626             if (!is_array($child->getChilds())) {
00627                 $child->setChilds(array());
00628             }
00629             if ($child->getParentId() == $category->getId()) {
00630                 $category->setChilds($category->getChilds() + array($child->getId() => $child));
00631             }
00632             else {
00633                 if (isset($categories[$child->getParentId()])) {
00634                     if (!is_array($categories[$child->getParentId()]->getChilds())) {
00635                         $categories[$child->getParentId()]->setChilds(array());
00636                     }
00637                     $categories[$child->getParentId()]->setChilds($categories[$child->getParentId()]->getChilds() + array($child->getId() => $child));
00638                 }
00639             }
00640         }
00641         $category->setAllChilds($categories);
00642 
00643         return $category;
00644     }

prepareRewrites ( storeId,
categoryIds = null,
productIds = null 
)

Definition at line 154 of file Url.php.

00155     {
00156         $rewrites = array();
00157         $select = $this->_getWriteAdapter()->select()
00158             ->from($this->getMainTable())
00159             ->where('store_id=?', $storeId)
00160             ->where('is_system=?', 1);
00161 
00162         if (is_null($categoryIds)) {
00163             $select->where('category_id IS NULL');
00164         }
00165         elseif ($categoryIds) {
00166             $select->where('category_id IN(?)', $categoryIds);
00167         }
00168         if (is_null($productIds)) {
00169             $select->where('product_id IS NULL');
00170         }
00171         elseif ($productIds) {
00172             $select->where('product_id IN(?)', $productIds);
00173         }
00174 
00175         $query = $this->_getWriteAdapter()->query((string)$select);
00176 
00177         while ($row = $query->fetch()) {
00178             $rewrite = new Varien_Object($row);
00179             $rewrite->setIdFieldName($this->getIdFieldName());
00180             $rewrites[$rewrite->getIdPath()] = $rewrite;
00181         }
00182         unset($query);
00183 
00184         return $rewrites;
00185     }

saveCategoryAttribute ( Varien_Object category,
attributeCode 
)

Save category attribute

Parameters:
Varien_Object $category
string $attributeCode
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Url

Definition at line 225 of file Url.php.

00226     {
00227         if (!isset($this->_categoryAttributes[$attributeCode])) {
00228             $attribute = $this->getCategoryModel()->getResource()->getAttribute($attributeCode);
00229 
00230             $this->_categoryAttributes[$attributeCode] = array(
00231                 'entity_type_id' => $attribute->getEntityTypeId(),
00232                 'attribute_id'   => $attribute->getId(),
00233                 'table'          => $attribute->getBackend()->getTable(),
00234                 'is_global'      => $attribute->getIsGlobal()
00235             );
00236             unset($attribute);
00237         }
00238 
00239         $attributeTable = $this->_categoryAttributes[$attributeCode]['table'];
00240 
00241         $attributeData = array(
00242             'entity_type_id'    => $this->_categoryAttributes[$attributeCode]['entity_type_id'],
00243             'attribute_id'      => $this->_categoryAttributes[$attributeCode]['attribute_id'],
00244             'store_id'          => $category->getStoreId(),
00245             'entity_id'         => $category->getId(),
00246             'value'             => $category->getData($attributeCode)
00247         );
00248 
00249         if ($this->_categoryAttributes[$attributeCode]['is_global'] || $category->getStoreId() == 0) {
00250             $attributeData['store_id'] = 0;
00251         }
00252 
00253         $select = $this->_getWriteAdapter()->select()
00254             ->from($attributeTable)
00255             ->where('entity_type_id=?', $attributeData['entity_type_id'])
00256             ->where('attribute_id=?', $attributeData['attribute_id'])
00257             ->where('store_id=?', $attributeData['store_id'])
00258             ->where('entity_id=?', $attributeData['entity_id']);
00259         if ($row = $this->_getWriteAdapter()->fetchRow($select)) {
00260             $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']);
00261             $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond);
00262         }
00263         else {
00264             $this->_getWriteAdapter()->insert($attributeTable, $attributeData);
00265         }
00266 
00267         if ($attributeData['store_id'] != 0) {
00268             $attributeData['store_id'] = 0;
00269             $select = $this->_getWriteAdapter()->select()
00270                 ->from($attributeTable)
00271                 ->where('entity_type_id=?', $attributeData['entity_type_id'])
00272                 ->where('attribute_id=?', $attributeData['attribute_id'])
00273                 ->where('store_id=?', $attributeData['store_id'])
00274                 ->where('entity_id=?', $attributeData['entity_id']);
00275             if ($row = $this->_getWriteAdapter()->fetchRow($select)) {
00276                 $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']);
00277                 $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond);
00278             }
00279             else {
00280                 $this->_getWriteAdapter()->insert($attributeTable, $attributeData);
00281             }
00282         }
00283 
00284         unset($attributeData);
00285         return $this;
00286     }

saveProductAttribute ( Varien_Object product,
attributeCode 
)

Save product attribute

Parameters:
Varien_Object $product
string $attributeCode
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Url

Definition at line 366 of file Url.php.

00367     {
00368         if (!isset($this->_productAttributes[$attributeCode])) {
00369             $attribute = $this->getProductModel()->getResource()->getAttribute($attributeCode);
00370 
00371             $this->_productAttributes[$attributeCode] = array(
00372                 'entity_type_id' => $attribute->getEntityTypeId(),
00373                 'attribute_id'   => $attribute->getId(),
00374                 'table'          => $attribute->getBackend()->getTable(),
00375                 'is_global'      => $attribute->getIsGlobal()
00376             );
00377             unset($attribute);
00378         }
00379 
00380         $attributeTable = $this->_productAttributes[$attributeCode]['table'];
00381 
00382         $attributeData = array(
00383             'entity_type_id'    => $this->_productAttributes[$attributeCode]['entity_type_id'],
00384             'attribute_id'      => $this->_productAttributes[$attributeCode]['attribute_id'],
00385             'store_id'          => $product->getStoreId(),
00386             'entity_id'         => $product->getId(),
00387             'value'             => $product->getData($attributeCode)
00388         );
00389 
00390         if ($this->_productAttributes[$attributeCode]['is_global'] || $product->getStoreId() == 0) {
00391             $attributeData['store_id'] = 0;
00392         }
00393 
00394         $select = $this->_getWriteAdapter()->select()
00395             ->from($attributeTable)
00396             ->where('entity_type_id=?', $attributeData['entity_type_id'])
00397             ->where('attribute_id=?', $attributeData['attribute_id'])
00398             ->where('store_id=?', $attributeData['store_id'])
00399             ->where('entity_id=?', $attributeData['entity_id']);
00400         if ($row = $this->_getWriteAdapter()->fetchRow($select)) {
00401             $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']);
00402             $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond);
00403         }
00404         else {
00405             $this->_getWriteAdapter()->insert($attributeTable, $attributeData);
00406         }
00407 
00408         if ($attributeData['store_id'] != 0) {
00409             $attributeData['store_id'] = 0;
00410             $select = $this->_getWriteAdapter()->select()
00411                 ->from($attributeTable)
00412                 ->where('entity_type_id=?', $attributeData['entity_type_id'])
00413                 ->where('attribute_id=?', $attributeData['attribute_id'])
00414                 ->where('store_id=?', $attributeData['store_id'])
00415                 ->where('entity_id=?', $attributeData['entity_id']);
00416             if ($row = $this->_getWriteAdapter()->fetchRow($select)) {
00417                 $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']);
00418                 $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond);
00419             }
00420             else {
00421                 $this->_getWriteAdapter()->insert($attributeTable, $attributeData);
00422             }
00423         }
00424 
00425         unset($attributeData);
00426         return $this;
00427     }

saveRewrite ( rewriteData,
rewrite 
)

Save rewrite url

Parameters:
array $rewriteData
Varien_Object $rewriteObject
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Url

Definition at line 194 of file Url.php.

00195     {
00196         if ($rewrite && $rewrite->getId()) {
00197             if ($rewriteData['request_path'] != $rewrite->getRequestPath()) {
00198                 $where = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $rewrite->getId());
00199                 $this->_getWriteAdapter()->update(
00200                     $this->getMainTable(),
00201                     $rewriteData,
00202                     $where
00203                 );
00204             }
00205         }
00206         else {
00207             try {
00208                 $this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData);
00209             }
00210             catch (Exception $e) {
00211                 Mage::throwException(Mage::helper('catalog')->__('Url rewrie save problem.'));
00212             }
00213         }
00214         unset($rewriteData);
00215         return $this;
00216     }


Member Data Documentation

$_categoryAttributes = array() [protected]

Definition at line 48 of file Url.php.

$_productAttributes = array() [protected]

Definition at line 55 of file Url.php.

$_productLimit = 250 [protected]

Definition at line 62 of file Url.php.

$_stores [protected]

Definition at line 41 of file Url.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:45 2009 for Magento by  doxygen 1.5.8