00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Model_Resource_Eav_Mysql4_Url extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036
00037
00038
00039
00040
00041 protected $_stores;
00042
00043
00044
00045
00046
00047
00048 protected $_categoryAttributes = array();
00049
00050
00051
00052
00053
00054
00055 protected $_productAttributes = array();
00056
00057
00058
00059
00060
00061
00062 protected $_productLimit = 250;
00063
00064
00065
00066
00067
00068 protected function _construct()
00069 {
00070 $this->_init('core/url_rewrite', 'url_rewrite_id');
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 public function getStores($storeId = null)
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 }
00089
00090
00091
00092
00093
00094
00095 public function getCategoryModel()
00096 {
00097 return Mage::getSingleton('catalog/category');
00098 }
00099
00100
00101
00102
00103
00104
00105 public function getProductModel()
00106 {
00107 return Mage::getSingleton('catalog/product');
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 public function getRewriteByIdPath($idPath, $storeId)
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 }
00131
00132
00133
00134
00135
00136
00137
00138 public function getRewriteByRequestPath($requestPath, $storeId)
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 }
00153
00154 public function prepareRewrites($storeId, $categoryIds = null, $productIds = null)
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 }
00186
00187
00188
00189
00190
00191
00192
00193
00194 public function saveRewrite($rewriteData, $rewrite)
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 }
00217
00218
00219
00220
00221
00222
00223
00224
00225 public function saveCategoryAttribute(Varien_Object $category, $attributeCode)
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 }
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
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 }
00358
00359
00360
00361
00362
00363
00364
00365
00366 public function saveProductAttribute(Varien_Object $product, $attributeCode)
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 }
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 public function _getProductAttribute($attributeCode, $productIds, $storeId)
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 }
00492
00493
00494
00495
00496
00497
00498
00499 protected function _prepareCategoryParentId(Varien_Object $category)
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 }
00510
00511
00512
00513
00514
00515
00516
00517 protected function _prepareStoreRootCategories($stores)
00518 {
00519 $rootCategoryIds = array();
00520 foreach ($stores as $store) {
00521
00522 $rootCategoryIds[$store->getRootCategoryId()] = $store->getRootCategoryId();
00523 }
00524 if ($rootCategoryIds) {
00525 $categories = $this->_getCategories($rootCategoryIds);
00526 }
00527 foreach ($stores as $store) {
00528
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 }
00539
00540 protected function _getCategories($categoryIds, $storeId = null, $path = null)
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 }
00594
00595 public function getCategory($categoryId, $storeId)
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 }
00607
00608 public function getCategories($categoryIds, $storeId)
00609 {
00610 if (!$categoryIds || !$storeId) {
00611 return false;
00612 }
00613
00614 return $this->_getCategories($categoryIds, $storeId);
00615 }
00616
00617 public function loadCategoryChilds(Varien_Object $category)
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 }
00645
00646 public function getCategoryParentPath(Varien_Object $category)
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 }
00660
00661 public function getProductIdsByCategory($category)
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 }
00681
00682 protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId)
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 }
00728
00729 public function getProduct($productId, $storeId)
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 }
00738
00739 public function getProductsByStore($storeId, &$lastEntityId)
00740 {
00741 return $this->_getProducts(null, $storeId, $lastEntityId, $lastEntityId);
00742 }
00743
00744 public function getProductsByCategory(Varien_Object $category, &$lastEntityId)
00745 {
00746 $productIds = $this->getProductIdsByCategory($category);
00747 if (!$productIds) {
00748 return array();
00749 }
00750 return $this->_getProducts($productIds, $category->getStoreId(), $lastEntityId, $lastEntityId);
00751 }
00752
00753 public function clearCategoryProduct($storeId)
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 }
00775
00776
00777
00778
00779
00780
00781
00782
00783 public function deleteCategoryProductRewrites($categoryId, $productIds)
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 }
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890 }