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_Adminhtml
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: * Product Stores tab
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Websites extends Mage_Adminhtml_Block_Store_Switcher
35: {
36: protected $_storeFromHtml;
37:
38: /**
39: * Constructor
40: */
41: public function __construct()
42: {
43: parent::__construct();
44: $this->setTemplate('catalog/product/edit/websites.phtml');
45: }
46:
47: /**
48: * Retrieve edited product model instance
49: *
50: * @return Mage_Catalog_Model_Product
51: */
52: public function getProduct()
53: {
54: return Mage::registry('product');
55: }
56:
57: /**
58: * Get store ID of current product
59: *
60: * @return int
61: */
62: public function getStoreId()
63: {
64: return $this->getProduct()->getStoreId();
65: }
66:
67: /**
68: * Get ID of current product
69: *
70: * @return int
71: */
72: public function getProductId()
73: {
74: return $this->getProduct()->getId();
75: }
76:
77: /**
78: * Retrieve array of website IDs of current product
79: *
80: * @return array
81: */
82: public function getWebsites()
83: {
84: return $this->getProduct()->getWebsiteIds();
85: }
86:
87: /**
88: * Returns whether product associated with website with $websiteId
89: *
90: * @param int $websiteId
91: * @return bool
92: */
93: public function hasWebsite($websiteId)
94: {
95: return in_array($websiteId, $this->getProduct()->getWebsiteIds());
96: }
97:
98: /**
99: * Check websites block is readonly
100: *
101: * @return boolean
102: */
103: public function isReadonly()
104: {
105: return $this->getProduct()->getWebsitesReadonly();
106: }
107:
108: /**
109: * Retrieve store name by its ID
110: *
111: * @param int $storeId
112: * @return null|string
113: */
114: public function getStoreName($storeId)
115: {
116: return Mage::app()->getStore($storeId)->getName();
117: }
118:
119: /**
120: * Get HTML of store chooser
121: *
122: * @param Mage_Core_Model_Store $storeTo
123: * @return string
124: */
125: public function getChooseFromStoreHtml($storeTo)
126: {
127: if (!$this->_storeFromHtml) {
128: $this->_storeFromHtml = '<select name="copy_to_stores[__store_identifier__]" disabled="disabled">';
129: $this->_storeFromHtml.= '<option value="0">'.Mage::helper('catalog')->__('Default Values').'</option>';
130: foreach ($this->getWebsiteCollection() as $_website) {
131: if (!$this->hasWebsite($_website->getId())) {
132: continue;
133: }
134: $optGroupLabel = $this->escapeHtml($_website->getName());
135: $this->_storeFromHtml .= '<optgroup label="' . $optGroupLabel . '"></optgroup>';
136: foreach ($this->getGroupCollection($_website) as $_group) {
137: $optGroupName = $this->escapeHtml($_group->getName());
138: $this->_storeFromHtml .= '<optgroup label=" ' . $optGroupName . '">';
139: foreach ($this->getStoreCollection($_group) as $_store) {
140: $this->_storeFromHtml .= '<option value="' . $_store->getId() . '"> ';
141: $this->_storeFromHtml .= $this->escapeHtml($_store->getName()) . '</option>';
142: }
143: }
144: $this->_storeFromHtml .= '</optgroup>';
145: }
146: $this->_storeFromHtml .= '</select>';
147: }
148: return str_replace('__store_identifier__', $storeTo->getId(), $this->_storeFromHtml);
149: }
150: }
151: