PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/Mage/Adminhtml/Block/Catalog/Product.php

https://github.com/JackoPlane/magento2
PHP | 117 lines | 50 code | 9 blank | 58 comment | 2 complexity | 654633183e66424b070b14efc9b59754 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  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) 2013 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Catalog manage products block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Catalog_Product extends Mage_Adminhtml_Block_Widget_Container
  34. {
  35. protected $_template = 'catalog/product.phtml';
  36. /**
  37. * Prepare button and grid
  38. *
  39. * @return Mage_Adminhtml_Block_Catalog_Product
  40. */
  41. protected function _prepareLayout()
  42. {
  43. /** @var $limitation Mage_Catalog_Model_Product_Limitation */
  44. $limitation = Mage::getObjectManager()->get('Mage_Catalog_Model_Product_Limitation');
  45. if (!$limitation->isCreateRestricted()) {
  46. $this->_addButton('add_new', array(
  47. 'id' => 'add_new_product',
  48. 'label' => Mage::helper('Mage_Catalog_Helper_Data')->__('Add Product'),
  49. 'class' => 'btn-add',
  50. 'class_name' => 'Mage_Backend_Block_Widget_Button_Split',
  51. 'options' => $this->_getAddProductButtonOptions()
  52. ));
  53. }
  54. $this->setChild(
  55. 'grid',
  56. $this->getLayout()->createBlock('Mage_Adminhtml_Block_Catalog_Product_Grid', 'product.grid')
  57. );
  58. return parent::_prepareLayout();
  59. }
  60. /**
  61. * Retrieve options for 'Add Product' split button
  62. *
  63. * @return array
  64. */
  65. protected function _getAddProductButtonOptions()
  66. {
  67. $splitButtonOptions = array();
  68. foreach (Mage::getModel('Mage_Catalog_Model_Product_Type')->getOptionArray() as $key => $label) {
  69. $splitButtonOptions[$key] = array(
  70. 'label' => $label,
  71. 'onclick' => "setLocation('" . $this->_getProductCreateUrl($key) . "')",
  72. 'default' => Mage_Catalog_Model_Product_Type::DEFAULT_TYPE == $key
  73. );
  74. }
  75. return $splitButtonOptions;
  76. }
  77. /**
  78. * Retrieve product create url by specified product type
  79. *
  80. * @param string $type
  81. * @return string
  82. */
  83. protected function _getProductCreateUrl($type)
  84. {
  85. return $this->getUrl('*/*/new', array(
  86. 'set' => Mage::getModel('Mage_Catalog_Model_Product')->getDefaultAttributeSetId(),
  87. 'type' => $type
  88. ));
  89. }
  90. /**
  91. * Render grid
  92. *
  93. * @return string
  94. */
  95. public function getGridHtml()
  96. {
  97. return $this->getChildHtml('grid');
  98. }
  99. /**
  100. * Check whether it is single store mode
  101. *
  102. * @return bool
  103. */
  104. public function isSingleStoreMode()
  105. {
  106. return Mage::app()->isSingleStoreMode();
  107. }
  108. }