1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Catalog
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Catalog Product Website Model
30: *
31: * @method Mage_Catalog_Model_Resource_Product_Website _getResource()
32: * @method Mage_Catalog_Model_Resource_Product_Website getResource()
33: * @method int getWebsiteId()
34: * @method Mage_Catalog_Model_Product_Website setWebsiteId(int $value)
35: *
36: * @category Mage
37: * @package Mage_Catalog
38: * @author Magento Core Team <core@magentocommerce.com>
39: */
40: class Mage_Catalog_Model_Product_Website extends Mage_Core_Model_Abstract
41: {
42: /**
43: * Initialize resource model
44: *
45: */
46: protected function _construct()
47: {
48: $this->_init('catalog/product_website');
49: }
50:
51: /**
52: * Retrieve Resource instance wrapper
53: *
54: * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Website
55: */
56: protected function _getResource()
57: {
58: return parent::_getResource();
59: }
60:
61: /**
62: * Removes products from websites
63: *
64: * @param array $websiteIds
65: * @param array $productIds
66: * @return Mage_Catalog_Model_Product_Website
67: */
68: public function removeProducts($websiteIds, $productIds)
69: {
70: try {
71: $this->_getResource()->removeProducts($websiteIds, $productIds);
72: }
73: catch (Exception $e) {
74: Mage::throwException(
75: Mage::helper('catalog')->__('An error occurred while removing products from websites.')
76: );
77: }
78: return $this;
79: }
80:
81: /**
82: * Add products to websites
83: *
84: * @param array $websiteIds
85: * @param array $productIds
86: * @return Mage_Catalog_Model_Product_Website
87: */
88: public function addProducts($websiteIds, $productIds)
89: {
90: try {
91: $this->_getResource()->addProducts($websiteIds, $productIds);
92: }
93: catch (Exception $e) {
94: Mage::throwException(
95: Mage::helper('catalog')->__('An error occurred while adding products to websites.')
96: );
97: }
98: return $this;
99: }
100:
101: /**
102: * Retrieve product websites
103: * Return array with key as product ID and value array of websites
104: *
105: * @param int|array $productIds
106: * @return array
107: */
108: public function getWebsites($productIds)
109: {
110: return $this->_getResource()->getWebsites($productIds);
111: }
112: }
113: