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_GoogleBase_Model_Mysql4_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00035 {
00036 protected function _construct()
00037 {
00038 $this->_init('googlebase/item');
00039 }
00040
00041 protected function _initSelect()
00042 {
00043 parent::_initSelect();
00044 $this->_joinTables();
00045 return $this;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054 public function addStoreFilterId($storeId)
00055 {
00056 return $this->addStoreFilter($storeId);
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 public function addStoreFilter($storeIds)
00066 {
00067 $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
00068 return $this;
00069 }
00070
00071 public function addProductFilterId($productId)
00072 {
00073 $this->getSelect()->where('main_table.product_id=?', $productId);
00074 return $this;
00075 }
00076
00077 public function addFieldToFilter($field, $condition=null)
00078 {
00079 if ($field == 'name') {
00080 $conditionSql = $this->_getConditionSql('p.value', $condition);
00081 $this->getSelect()->where($conditionSql);
00082 } else {
00083 parent::addFieldToFilter($field, $condition);
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092 protected function _joinTables()
00093 {
00094 $entityType = Mage::getSingleton('eav/config')->getEntityType('catalog_product');
00095 $attribute = Mage::getModel('eav/config')->getAttribute($entityType->getEntityTypeId(),'name');
00096
00097 $joinConditionDefault = sprintf("p_d.attribute_id=%d AND p_d.store_id='0' AND main_table.product_id=p_d.entity_id",
00098 $attribute->getAttributeId()
00099 );
00100 $joinCondition = sprintf("p.attribute_id=%d AND p.store_id=main_table.store_id AND main_table.product_id=p.entity_id",
00101 $attribute->getAttributeId()
00102 );
00103
00104 $this->getSelect()
00105 ->joinLeft(
00106 array('p_d' => $attribute->getBackend()->getTable()),
00107 $joinConditionDefault,
00108 array());
00109
00110 $this->getSelect()
00111 ->joinLeft(
00112 array('p' => $attribute->getBackend()->getTable()),
00113 $joinCondition,
00114 array('name' => new Zend_Db_Expr('IFNULL(p.value, p_d.value)')));
00115
00116 $this->getSelect()
00117 ->joinLeft(
00118 array('types' => $this->getTable('googlebase/types')),
00119 'main_table.type_id=types.type_id',
00120 array('gbase_itemtype' => new Zend_Db_Expr('IFNULL(types.gbase_itemtype, \''.Mage_GoogleBase_Model_Service_Item::DEFAULT_ITEM_TYPE .'\')')));
00121
00122 return $this;
00123 }
00124 }