Public Member Functions | |
removeProducts ($websiteIds, $productIds) | |
addProducts ($websiteIds, $productIds) | |
getWebsites ($productIds) | |
Protected Member Functions | |
_construct () | |
_getProductResource () |
Definition at line 35 of file Website.php.
_construct | ( | ) | [protected] |
Initialize connection and define resource table
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 41 of file Website.php.
00042 { 00043 $this->_init('catalog/product_website', 'product_id'); 00044 }
_getProductResource | ( | ) | [protected] |
Get catalog product resource model
Definition at line 51 of file Website.php.
00052 { 00053 return Mage::getResourceSingleton('catalog/product'); 00054 }
addProducts | ( | $ | websiteIds, | |
$ | productIds | |||
) |
Add products to websites
array | $websiteIds | |
array | $productIds |
Definition at line 97 of file Website.php.
00098 { 00099 if (!is_array($websiteIds) || !is_array($productIds) 00100 || count($websiteIds) == 0 || count($productIds) == 0) 00101 { 00102 return $this; 00103 } 00104 00105 $this->_getWriteAdapter()->beginTransaction(); 00106 00107 // Before adding of products we should remove it old rows with same ids 00108 $this->removeProducts($websiteIds, $productIds); 00109 00110 foreach ($websiteIds as $websiteId) { 00111 foreach ($productIds as $productId) { 00112 if (!$productId) { 00113 continue; 00114 } 00115 $this->_getWriteAdapter()->insert($this->getMainTable(), array( 00116 'product_id' => $productId, 00117 'website_id' => $websiteId 00118 )); 00119 } 00120 00121 // Refresh product enabled index 00122 $storeIds = Mage::app()->getWebsite($websiteId)->getStoreIds(); 00123 foreach ($storeIds as $storeId) { 00124 $store = Mage::app()->getStore($storeId); 00125 $this->_getProductResource()->refreshEnabledIndex($store, $productIds); 00126 } 00127 } 00128 00129 $this->_getWriteAdapter()->commit(); 00130 00131 return $this; 00132 }
getWebsites | ( | $ | productIds | ) |
Retrieve product(s) website ids.
array | $productIds |
Definition at line 140 of file Website.php.
00141 { 00142 $select = $this->_getReadAdapter()->select() 00143 ->from($this->getMainTable(), array('product_id', 'website_id')) 00144 ->where('product_id IN (?)', $productIds); 00145 $rowset = $this->_getReadAdapter()->fetchAll($select); 00146 00147 $result = array(); 00148 foreach ($rowset as $row) { 00149 $result[$row['product_id']][] = $row['website_id']; 00150 } 00151 00152 return $result; 00153 }
removeProducts | ( | $ | websiteIds, | |
$ | productIds | |||
) |
Removes products from websites
array | $websiteIds | |
array | $productIds |
Definition at line 63 of file Website.php.
00064 { 00065 if (!is_array($websiteIds) || !is_array($productIds) 00066 || count($websiteIds) == 0 || count($productIds) == 0) 00067 { 00068 return $this; 00069 } 00070 00071 $whereCond = array( 00072 $this->_getWriteAdapter()->quoteInto('website_id IN(?)', $websiteIds), 00073 $this->_getWriteAdapter()->quoteInto('product_id IN(?)', $productIds) 00074 ); 00075 $whereCond = join(' AND ', $whereCond); 00076 00077 $this->_getWriteAdapter()->beginTransaction(); 00078 try { 00079 $this->_getWriteAdapter()->delete($this->getMainTable(), $whereCond); 00080 $this->_getWriteAdapter()->commit(); 00081 } 00082 catch (Exception $e) { 00083 $this->_getWriteAdapter()->rollBack(); 00084 throw $e; 00085 } 00086 00087 return $this; 00088 }