1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Catalog_Product_Edit extends Mage_Adminhtml_Block_Widget
35: {
36: public function __construct()
37: {
38: parent::__construct();
39: $this->setTemplate('catalog/product/edit.phtml');
40: $this->setId('product_edit');
41: }
42:
43: 44: 45: 46: 47:
48: public function getProduct()
49: {
50: return Mage::registry('current_product');
51: }
52:
53: protected function _prepareLayout()
54: {
55: if (!$this->getRequest()->getParam('popup')) {
56: $this->setChild('back_button',
57: $this->getLayout()->createBlock('adminhtml/widget_button')
58: ->setData(array(
59: 'label' => Mage::helper('catalog')->__('Back'),
60: 'onclick' => 'setLocation(\''.$this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store', 0))).'\')',
61: 'class' => 'back'
62: ))
63: );
64: } else {
65: $this->setChild('back_button',
66: $this->getLayout()->createBlock('adminhtml/widget_button')
67: ->setData(array(
68: 'label' => Mage::helper('catalog')->__('Close Window'),
69: 'onclick' => 'window.close()',
70: 'class' => 'cancel'
71: ))
72: );
73: }
74:
75: if (!$this->getProduct()->isReadonly()) {
76: $this->setChild('reset_button',
77: $this->getLayout()->createBlock('adminhtml/widget_button')
78: ->setData(array(
79: 'label' => Mage::helper('catalog')->__('Reset'),
80: 'onclick' => 'setLocation(\''.$this->getUrl('*/*/*', array('_current'=>true)).'\')'
81: ))
82: );
83:
84: $this->setChild('save_button',
85: $this->getLayout()->createBlock('adminhtml/widget_button')
86: ->setData(array(
87: 'label' => Mage::helper('catalog')->__('Save'),
88: 'onclick' => 'productForm.submit()',
89: 'class' => 'save'
90: ))
91: );
92: }
93:
94: if (!$this->getRequest()->getParam('popup')) {
95: if (!$this->getProduct()->isReadonly()) {
96: $this->setChild('save_and_edit_button',
97: $this->getLayout()->createBlock('adminhtml/widget_button')
98: ->setData(array(
99: 'label' => Mage::helper('catalog')->__('Save and Continue Edit'),
100: 'onclick' => 'saveAndContinueEdit(\''.$this->getSaveAndContinueUrl().'\')',
101: 'class' => 'save'
102: ))
103: );
104: }
105: if ($this->getProduct()->isDeleteable()) {
106: $this->setChild('delete_button',
107: $this->getLayout()->createBlock('adminhtml/widget_button')
108: ->setData(array(
109: 'label' => Mage::helper('catalog')->__('Delete'),
110: 'onclick' => 'confirmSetLocation(\''.Mage::helper('catalog')->__('Are you sure?').'\', \''.$this->getDeleteUrl().'\')',
111: 'class' => 'delete'
112: ))
113: );
114: }
115:
116: if ($this->getProduct()->isDuplicable()) {
117: $this->setChild('duplicate_button',
118: $this->getLayout()->createBlock('adminhtml/widget_button')
119: ->setData(array(
120: 'label' => Mage::helper('catalog')->__('Duplicate'),
121: 'onclick' => 'setLocation(\'' . $this->getDuplicateUrl() . '\')',
122: 'class' => 'add'
123: ))
124: );
125: }
126: }
127:
128: return parent::_prepareLayout();
129: }
130:
131: public function getBackButtonHtml()
132: {
133: return $this->getChildHtml('back_button');
134: }
135:
136: public function getCancelButtonHtml()
137: {
138: return $this->getChildHtml('reset_button');
139: }
140:
141: public function getSaveButtonHtml()
142: {
143: return $this->getChildHtml('save_button');
144: }
145:
146: public function getSaveAndEditButtonHtml()
147: {
148: return $this->getChildHtml('save_and_edit_button');
149: }
150:
151: public function getDeleteButtonHtml()
152: {
153: return $this->getChildHtml('delete_button');
154: }
155:
156: public function getDuplicateButtonHtml()
157: {
158: return $this->getChildHtml('duplicate_button');
159: }
160:
161: public function getValidationUrl()
162: {
163: return $this->getUrl('*/*/validate', array('_current'=>true));
164: }
165:
166: public function getSaveUrl()
167: {
168: return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null));
169: }
170:
171: public function getSaveAndContinueUrl()
172: {
173: return $this->getUrl('*/*/save', array(
174: '_current' => true,
175: 'back' => 'edit',
176: 'tab' => '{{tab_id}}',
177: 'active_tab' => null
178: ));
179: }
180:
181: public function getProductId()
182: {
183: return $this->getProduct()->getId();
184: }
185:
186: public function getProductSetId()
187: {
188: $setId = false;
189: if (!($setId = $this->getProduct()->getAttributeSetId()) && $this->getRequest()) {
190: $setId = $this->getRequest()->getParam('set', null);
191: }
192: return $setId;
193: }
194:
195: public function getIsGrouped()
196: {
197: return $this->getProduct()->isGrouped();
198: }
199:
200: public function getDeleteUrl()
201: {
202: return $this->getUrl('*/*/delete', array('_current'=>true));
203: }
204:
205: public function getDuplicateUrl()
206: {
207: return $this->getUrl('*/*/duplicate', array('_current'=>true));
208: }
209:
210: public function ()
211: {
212: $header = '';
213: if ($this->getProduct()->getId()) {
214: $header = $this->htmlEscape($this->getProduct()->getName());
215: }
216: else {
217: $header = Mage::helper('catalog')->__('New Product');
218: }
219: if ($setName = $this->getAttributeSetName()) {
220: $header.= ' (' . $setName . ')';
221: }
222: return $header;
223: }
224:
225: public function getAttributeSetName()
226: {
227: if ($setId = $this->getProduct()->getAttributeSetId()) {
228: $set = Mage::getModel('eav/entity_attribute_set')
229: ->load($setId);
230: return $set->getAttributeSetName();
231: }
232: return '';
233: }
234:
235: public function getIsConfigured()
236: {
237: if ($this->getProduct()->isConfigurable()
238: && !($superAttributes = $this->getProduct()->getTypeInstance(true)->getUsedProductAttributeIds($this->getProduct()))) {
239: $superAttributes = false;
240: }
241:
242: return !$this->getProduct()->isConfigurable() || $superAttributes !== false;
243: }
244:
245: public function getSelectedTabId()
246: {
247: return addslashes(htmlspecialchars($this->getRequest()->getParam('tab')));
248: }
249: }
250: