Public Member Functions | |
getConnection () | |
getSelect () | |
getTable ($table) | |
getProductEntity ($field=null) | |
getSkuAttribute ($field='attribute_id') | |
getProductIdBySku ($sku) | |
addProductToStore ($productId, $storeId) | |
exportAttributes () | |
exportAttributeSets () | |
exportAttributeOptions () | |
exportProductLinks () | |
exportProductsInCategories () | |
exportProductsInStores () | |
exportCategories () | |
exportProducts () | |
exportImageGallery () | |
getProductAttributeOption ($attribute, $value) | |
importProducts (array $data) | |
Protected Attributes | |
$_productsBySku | |
$_productEntity | |
$_skuAttribute |
Definition at line 28 of file Catalogold.php.
addProductToStore | ( | $ | productId, | |
$ | storeId | |||
) |
Definition at line 81 of file Catalogold.php.
00082 { 00083 $write = $this->getConnection(); 00084 $table = $this->getTable('catalog/product_store'); 00085 try { 00086 if (!$write->fetchOne("select * from $table where product_id=".(int)$productId." and store_id=".(int)$storeId)) { 00087 $write->query("insert into $table (product_id, store_id) values (".(int)$productId.",".(int)$storeId.")"); 00088 } 00089 } catch (Exception $e) { 00090 throw $e; 00091 } 00092 return $this; 00093 }
exportAttributeOptions | ( | ) |
Definition at line 134 of file Catalogold.php.
00135 { 00136 $select = $this->getSelect() 00137 ->from(array('et'=>$this->getTable('eav/entity_type')), 'entity_type_code') 00138 ->join(array('a'=>$this->getTable('eav/attribute')), 'a.entity_type_id=et.entity_type_id', 'attribute_code') 00139 ->join(array('ao'=>$this->getTable('eav/attribute_option')), 'ao.attribute_id=a.attribute_id', array()) 00140 ->where('et.entity_type_code in (?)', array('catalog_product', 'catalog_category')) 00141 ->order('a.attribute_code')->order('ao.sort_order'); 00142 00143 $stores = Mage::getConfig()->getNode('stores')->children(); 00144 foreach ($stores as $storeName=>$storeConfig) { 00145 $select->joinLeft( 00146 array($storeName=>$this->getTable('eav/attribute_option_value')), 00147 "$storeName.option_id=ao.option_id and $storeName.store_id=".$storeConfig->descend('system/store/id'), 00148 array($storeName=>"$storeName.value") 00149 ); 00150 } 00151 00152 $options = $this->getConnection()->fetchAll($select); 00153 00154 return $options; 00155 }
exportAttributes | ( | ) |
Definition at line 95 of file Catalogold.php.
00096 { 00097 $attributeFields = array( 00098 'attribute_code', 00099 'frontend_label', 'frontend_input', 'frontend_class', 'frontend_model', 00100 'backend_type', 'backend_table', 'backend_model', 00101 'source_model', 'attribute_model', 00102 'is_visible', 'is_user_defined', 'is_global', 'is_required', 'is_unique', 00103 'is_visible_on_front', 'is_searchable', 'is_filterable', 'is_comparable', 00104 'default_value', 'apply_to', 'use_in_super_product', 00105 ); 00106 00107 $select = $this->getSelect() 00108 ->from(array('et'=>$this->getTable('eav/entity_type')), 'entity_type_code') 00109 ->join(array('a'=>$this->getTable('eav/attribute')), 'a.entity_type_id=et.entity_type_id', $attributeFields) 00110 ->where('et.entity_type_code in (?)', array('catalog_product', 'catalog_category')) 00111 ->order('if(not a.is_user_defined, 1, 2)')->order('attribute_code'); 00112 00113 $attributes = $this->getConnection()->fetchAll($select); 00114 00115 return $attributes; 00116 }
exportAttributeSets | ( | ) |
Definition at line 118 of file Catalogold.php.
00119 { 00120 $select = $this->getSelect() 00121 ->from(array('et'=>$this->getTable('eav/entity_type')), 'entity_type_code') 00122 ->join(array('s'=>$this->getTable('eav/attribute_set')), 's.entity_type_id=et.entity_type_id', 'attribute_set_name') 00123 ->join(array('g'=>$this->getTable('eav/attribute_group')), 'g.attribute_set_id=s.attribute_set_id', 'attribute_group_name') 00124 ->join(array('ea'=>$this->getTable('eav/entity_attribute')), 'ea.attribute_group_id=g.attribute_group_id', array()) 00125 ->join(array('a'=>$this->getTable('eav/attribute')), 'a.attribute_id=ea.attribute_id', 'attribute_code') 00126 ->where('et.entity_type_code in (?)', array('catalog_product', 'catalog_category')) 00127 ->order('et.entity_type_code')->order('s.sort_order')->order('g.sort_order'); 00128 00129 $sets = $this->getConnection()->fetchAll($select); 00130 00131 return $sets; 00132 }
exportCategories | ( | ) |
Definition at line 204 of file Catalogold.php.
00205 { 00206 $collection = Mage::getResourceModel('catalog/category_collection') 00207 ->addAttributeToSelect('*') 00208 ->load(); 00209 00210 $categories = array(); 00211 foreach ($collection as $object) { 00212 $row = $object->getData(); 00213 $categories[] = $row; 00214 } 00215 00216 return $categories; 00217 }
exportImageGallery | ( | ) |
exportProductLinks | ( | ) |
Definition at line 157 of file Catalogold.php.
00158 { 00159 $skuTable = $this->getTable('catalog/product').'_'.$this->getSkuAttribute('backend_type'); 00160 $skuCond = ' and sku.store_id=0 and sku.attribute_id='.$this->getSkuAttribute('attribute_id'); 00161 00162 $select = $this->getSelect() 00163 ->from(array('lt'=>$this->getTable('catalog/product_link_type')), array('link_type'=>'code')) 00164 ->join(array('l'=>$this->getTable('catalog/product_link')), 'l.link_type_id=lt.link_type_id', array()) 00165 ->join(array('sku'=>$skuTable), 'sku.entity_id=l.product_id'.$skuCond, array('sku'=>'value')) 00166 ->join(array('linked'=>$skuTable), 'linked.entity_id=l.product_id'.$skuCond, array('linked'=>'value')) 00167 ->order('sku')->order('link_type'); 00168 $links = $this->getConnection()->fetchAll($select); 00169 00170 return $links; 00171 }
exportProducts | ( | ) |
Definition at line 219 of file Catalogold.php.
00220 { 00221 $attrSets = Mage::getResourceModel('eav/entity_attribute_set_collection')->load(); 00222 $attrSetName = array(); 00223 foreach ($attrSets as $attrSet) { 00224 $attrSetName[$attrSet->getId()] = $attrSet->getAttributeSetName(); 00225 } 00226 00227 $select = $this->getSelect() 00228 ->from(array('ao'=>$this->getTable('eav/attribute_option')), array('attribute_id', 'option_id')) 00229 ->join(array('aov'=>$this->getTable('eav/attribute_option_value')), 'aov.option_id=ao.option_id', array('value_id', 'value')) 00230 ->where('aov.store_id=0'); 00231 00232 echo $select->__toString(); 00233 die(); 00234 00235 $collection = Mage::getResourceModel('catalog/product_collection') 00236 ->addAttributeToSelect('*') 00237 ->load(); 00238 00239 $products = array(); 00240 foreach ($collection as $object) { 00241 $r = $object->getData(); 00242 00243 unset($r['entity_id'], $r['entity_type_id']); 00244 $r['attribute_set_id'] = $attrSetName[$r['attribute_set_id']]; 00245 00246 $products[] = $r; 00247 } 00248 00249 return $products; 00250 }
exportProductsInCategories | ( | ) |
Definition at line 173 of file Catalogold.php.
00174 { 00175 $skuTable = $this->getTable('catalog/product').'_'.$this->getSkuAttribute('backend_type'); 00176 $skuCond = ' and sku.store_id=0 and sku.attribute_id='.$this->getSkuAttribute('attribute_id'); 00177 00178 $select = $this->getSelect() 00179 ->from(array('cp'=>$this->getTable('catalog/category_product')), array('category_id', 'position')) 00180 ->join(array('sku'=>$skuTable), 'sku.entity_id=cp.product_id'.$skuCond, array('sku'=>'value')) 00181 ->order('category_id')->order('position')->order('sku'); 00182 00183 $prodCats = $this->getConnection()->fetchAll($select); 00184 00185 return $prodCats; 00186 }
exportProductsInStores | ( | ) |
Definition at line 188 of file Catalogold.php.
00189 { 00190 $skuTable = $this->getTable('catalog/product').'_'.$this->getSkuAttribute('backend_type'); 00191 $skuCond = ' and sku.store_id=0 and sku.attribute_id='.$this->getSkuAttribute('attribute_id'); 00192 00193 $select = $this->getSelect() 00194 ->from(array('ps'=>$this->getTable('catalog/product_store')), array()) 00195 ->join(array('s'=>$this->getTable('core/store')), 's.store_id=ps.store_id', array('store'=>'code')) 00196 ->join(array('sku'=>$skuTable), 'sku.entity_id=ps.product_id'.$skuCond, array('sku'=>'value')) 00197 ->order('store')->order('sku'); 00198 00199 $prodStores = $this->getConnection()->fetchAll($select); 00200 00201 return $prodStores; 00202 }
getConnection | ( | ) |
Definition at line 34 of file Catalogold.php.
00035 { 00036 return Mage::getSingleton('core/resource')->getConnection('catalog_write'); 00037 }
getProductAttributeOption | ( | $ | attribute, | |
$ | value | |||
) |
getProductEntity | ( | $ | field = null |
) |
Definition at line 49 of file Catalogold.php.
00050 { 00051 if (!$this->_productEntity) { 00052 $this->_productEntity = Mage::getResourceModel('catalog/product') 00053 ->loadAllAttributes(); 00054 } 00055 return is_null($field) ? $this->_productEntity : $this->_productEntity->getData($field); 00056 }
getProductIdBySku | ( | $ | sku | ) |
Definition at line 66 of file Catalogold.php.
00067 { 00068 if (!$this->_productsBySku) { 00069 $select = $this->getSelect() 00070 ->from($this->getTable('catalog/product'), array('entity_id', 'sku')); 00071 $products = $this->getConnection()->fetchAll($select); 00072 00073 $this->_productsBySku = array(); 00074 foreach ($products as $p) { 00075 $this->_productsBySku[$p['sku']] = $p['entity_id']; 00076 } 00077 } 00078 return isset($this->_productsBySku[$sku]) ? $this->_productsBySku[$sku] : false; 00079 }
getSelect | ( | ) |
Definition at line 39 of file Catalogold.php.
00040 { 00041 return $this->getConnection()->select(); 00042 }
getSkuAttribute | ( | $ | field = 'attribute_id' |
) |
Definition at line 58 of file Catalogold.php.
00059 { 00060 if (!$this->_skuAttribute) { 00061 $this->_skuAttribute = $this->getProductEntity()->getAttribute('sku'); 00062 } 00063 return $this->_skuAttribute->getData($field); 00064 }
getTable | ( | $ | table | ) |
Definition at line 44 of file Catalogold.php.
00045 { 00046 return Mage::getSingleton('core/resource')->getTableName($table); 00047 }
importProducts | ( | array $ | data | ) |
Definition at line 262 of file Catalogold.php.
00263 { 00264 /* 00265 $entity = Mage::getResourceModel('catalog/product') 00266 ->loadAllAttributes(); 00267 00268 $options = 00269 00270 foreach ($data as $row) { 00271 if (empty($row['sku'])) { 00272 continue; 00273 } 00274 $sku = $row['sku']; 00275 } 00276 */ 00277 }
$_productEntity [protected] |
Definition at line 31 of file Catalogold.php.
$_productsBySku [protected] |
Definition at line 30 of file Catalogold.php.
$_skuAttribute [protected] |
Definition at line 32 of file Catalogold.php.