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: class Mage_Adminhtml_Promo_WidgetController extends Mage_Adminhtml_Controller_Action
29: {
30: 31: 32: 33: 34:
35: public function chooserAction()
36: {
37: $request = $this->getRequest();
38:
39: switch ($request->getParam('attribute')) {
40: case 'sku':
41: $block = $this->getLayout()->createBlock(
42: 'adminhtml/promo_widget_chooser_sku', 'promo_widget_chooser_sku',
43: array('js_form_object' => $request->getParam('form'),
44: ));
45: break;
46:
47: case 'category_ids':
48: $ids = $request->getParam('selected', array());
49: if (is_array($ids)) {
50: foreach ($ids as $key => &$id) {
51: $id = (int) $id;
52: if ($id <= 0) {
53: unset($ids[$key]);
54: }
55: }
56:
57: $ids = array_unique($ids);
58: } else {
59: $ids = array();
60: }
61:
62:
63: $block = $this->getLayout()->createBlock(
64: 'adminhtml/catalog_category_checkboxes_tree', 'promo_widget_chooser_category_ids',
65: array('js_form_object' => $request->getParam('form'))
66: )
67: ->setCategoryIds($ids)
68: ;
69: break;
70:
71: default:
72: $block = false;
73: break;
74: }
75:
76: if ($block) {
77: $this->getResponse()->setBody($block->toHtml());
78: }
79: }
80:
81: protected function _isAllowed()
82: {
83: return Mage::getSingleton('admin/session')->isAllowed('promo/catalog');
84: }
85:
86: 87: 88:
89: public function categoriesJsonAction()
90: {
91: if ($categoryId = (int) $this->getRequest()->getPost('id')) {
92: $this->getRequest()->setParam('id', $categoryId);
93:
94: if (!$category = $this->_initCategory()) {
95: return;
96: }
97: $this->getResponse()->setBody(
98: $this->getLayout()->createBlock('adminhtml/catalog_category_tree')
99: ->getTreeJson($category)
100: );
101: }
102: }
103:
104: 105: 106: 107: 108:
109: protected function _initCategory()
110: {
111: $categoryId = (int) $this->getRequest()->getParam('id',false);
112: $storeId = (int) $this->getRequest()->getParam('store');
113:
114: $category = Mage::getModel('catalog/category');
115: $category->setStoreId($storeId);
116:
117: if ($categoryId) {
118: $category->load($categoryId);
119: if ($storeId) {
120: $rootId = Mage::app()->getStore($storeId)->getRootCategoryId();
121: if (!in_array($rootId, $category->getPathIds())) {
122: $this->_redirect('*/*/', array('_current'=>true, 'id'=>null));
123: return false;
124: }
125: }
126: }
127:
128: Mage::register('category', $category);
129: Mage::register('current_category', $category);
130:
131: return $category;
132: }
133: }
134: