Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.11 KB | None | 0 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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26.  
  27. /**
  28. * Adminhtml customer grid block
  29. *
  30. * @category Mage
  31. * @package Mage_Adminhtml
  32. * @author Magento Core Team <core@magentocommerce.com>
  33. */
  34. class Mage_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
  35. {
  36.  
  37. public function __construct()
  38. {
  39. parent::__construct();
  40. $this->setId('productGrid');
  41. $this->setDefaultSort('entity_id');
  42. $this->setDefaultDir('DESC');
  43. $this->setSaveParametersInSession(true);
  44. $this->setUseAjax(true);
  45. $this->setVarNameFilter('product_filter');
  46.  
  47. }
  48.  
  49. protected function _getStore()
  50. {
  51. $storeId = (int) $this->getRequest()->getParam('store', 0);
  52. return Mage::app()->getStore($storeId);
  53. }
  54.  
  55. protected function _prepareCollection()
  56. {
  57. $store = $this->_getStore();
  58. $collection = Mage::getModel('catalog/product')->getCollection()
  59. ->addAttributeToSelect('sku')
  60. ->addAttributeToSelect('name')
  61. ->addAttributeToSelect('attribute_set_id')
  62. ->addAttributeToSelect('type_id');
  63.  
  64. if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
  65. $collection->joinField('qty',
  66. 'cataloginventory/stock_item',
  67. 'qty',
  68. 'product_id=entity_id',
  69. '{{table}}.stock_id=1',
  70. 'left');
  71. }
  72. if ($store->getId()) {
  73. //$collection->setStoreId($store->getId());
  74. $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
  75. $collection->addStoreFilter($store);
  76. $collection->joinAttribute(
  77. 'name',
  78. 'catalog_product/name',
  79. 'entity_id',
  80. null,
  81. 'inner',
  82. $adminStore
  83. );
  84. $collection->joinAttribute(
  85. 'custom_name',
  86. 'catalog_product/name',
  87. 'entity_id',
  88. null,
  89. 'inner',
  90. $store->getId()
  91. );
  92. $collection->joinAttribute(
  93. 'status',
  94. 'catalog_product/status',
  95. 'entity_id',
  96. null,
  97. 'inner',
  98. $store->getId()
  99. );
  100. $collection->joinAttribute(
  101. 'visibility',
  102. 'catalog_product/visibility',
  103. 'entity_id',
  104. null,
  105. 'inner',
  106. $store->getId()
  107. );
  108. $collection->joinAttribute(
  109. 'price',
  110. 'catalog_product/price',
  111. 'entity_id',
  112. null,
  113. 'left',
  114. $store->getId()
  115. );
  116. }
  117. else {
  118. $collection->addAttributeToSelect('price');
  119. $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
  120. $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
  121. }
  122.  
  123. $this->setCollection($collection);
  124.  
  125. parent::_prepareCollection();
  126. $this->getCollection()->addWebsiteNamesToResult();
  127. return $this;
  128. }
  129.  
  130. protected function _addColumnFilterToCollection($column)
  131. {
  132. if ($this->getCollection()) {
  133. if ($column->getId() == 'websites') {
  134. $this->getCollection()->joinField('websites',
  135. 'catalog/product_website',
  136. 'website_id',
  137. 'product_id=entity_id',
  138. null,
  139. 'left');
  140. }
  141. }
  142. return parent::_addColumnFilterToCollection($column);
  143. }
  144.  
  145. protected function _prepareColumns()
  146. {
  147. $this->addColumn('entity_id',
  148. array(
  149. 'header'=> Mage::helper('catalog')->__('ID'),
  150. 'width' => '50px',
  151. 'type' => 'number',
  152. 'index' => 'entity_id',
  153. ));
  154. $this->addColumn('name',
  155. array(
  156. 'header'=> Mage::helper('catalog')->__('Name'),
  157. 'index' => 'name',
  158. ));
  159.  
  160. $store = $this->_getStore();
  161. if ($store->getId()) {
  162. $this->addColumn('custom_name',
  163. array(
  164. 'header'=> Mage::helper('catalog')->__('Name in %s', $store->getName()),
  165. 'index' => 'custom_name',
  166. ));
  167. }
  168.  
  169. $this->addColumn('type',
  170. array(
  171. 'header'=> Mage::helper('catalog')->__('Type'),
  172. 'width' => '60px',
  173. 'index' => 'type_id',
  174. 'type' => 'options',
  175. 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
  176. ));
  177.  
  178. $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
  179. ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
  180. ->load()
  181. ->toOptionHash();
  182.  
  183. $this->addColumn('set_name',
  184. array(
  185. 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
  186. 'width' => '100px',
  187. 'index' => 'attribute_set_id',
  188. 'type' => 'options',
  189. 'options' => $sets,
  190. ));
  191.  
  192. $this->addColumn('sku',
  193. array(
  194. 'header'=> Mage::helper('catalog')->__('SKU'),
  195. 'width' => '80px',
  196. 'index' => 'sku',
  197. ));
  198.  
  199. $this->addColumn('number',
  200. array(
  201. 'header'=> Mage::helper('catalog')->__('Поръчка №'),
  202. 'width' => '50px',
  203. 'index' => 'entity_id',
  204. 'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer',
  205. ));
  206.  
  207. $store = $this->_getStore();
  208. $this->addColumn('price',
  209. array(
  210. 'header'=> Mage::helper('catalog')->__('Price'),
  211. 'type' => 'price',
  212. 'currency_code' => $store->getBaseCurrency()->getCode(),
  213. 'index' => 'price',
  214. ));
  215.  
  216. if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
  217. $this->addColumn('qty',
  218. array(
  219. 'header'=> Mage::helper('catalog')->__('Qty'),
  220. 'width' => '100px',
  221. 'type' => 'number',
  222. 'index' => 'qty',
  223. ));
  224. }
  225.  
  226. $this->addColumn('visibility',
  227. array(
  228. 'header'=> Mage::helper('catalog')->__('Visibility'),
  229. 'width' => '70px',
  230. 'index' => 'visibility',
  231. 'type' => 'options',
  232. 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
  233. ));
  234.  
  235. $this->addColumn('status',
  236. array(
  237. 'header'=> Mage::helper('catalog')->__('Status'),
  238. 'width' => '70px',
  239. 'index' => 'status',
  240. 'type' => 'options',
  241. 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
  242. ));
  243.  
  244. if (!Mage::app()->isSingleStoreMode()) {
  245. $this->addColumn('websites',
  246. array(
  247. 'header'=> Mage::helper('catalog')->__('Websites'),
  248. 'width' => '100px',
  249. 'sortable' => false,
  250. 'index' => 'websites',
  251. 'type' => 'options',
  252. 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
  253. ));
  254. }
  255.  
  256. $this->addColumn('action',
  257. array(
  258. 'header' => Mage::helper('catalog')->__('Action'),
  259. 'width' => '50px',
  260. 'type' => 'action',
  261. 'getter' => 'getId',
  262. 'actions' => array(
  263. array(
  264. 'caption' => Mage::helper('catalog')->__('Edit'),
  265. 'url' => array(
  266. 'base'=>'*/*/edit',
  267. 'params'=>array('store'=>$this->getRequest()->getParam('store'))
  268. ),
  269. 'field' => 'id'
  270. )
  271. ),
  272. 'filter' => false,
  273. 'sortable' => false,
  274. 'index' => 'stores',
  275. ));
  276.  
  277. if (Mage::helper('catalog')->isModuleEnabled('Mage_Rss')) {
  278. $this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS'));
  279. }
  280.  
  281. return parent::_prepareColumns();
  282. }
  283.  
  284. protected function _prepareMassaction()
  285. {
  286. $this->setMassactionIdField('entity_id');
  287. $this->getMassactionBlock()->setFormFieldName('product');
  288.  
  289. $this->getMassactionBlock()->addItem('delete', array(
  290. 'label'=> Mage::helper('catalog')->__('Delete'),
  291. 'url' => $this->getUrl('*/*/massDelete'),
  292. 'confirm' => Mage::helper('catalog')->__('Are you sure?')
  293. ));
  294.  
  295. $statuses = Mage::getSingleton('catalog/product_status')->getOptionArray();
  296.  
  297. array_unshift($statuses, array('label'=>'', 'value'=>''));
  298. $this->getMassactionBlock()->addItem('status', array(
  299. 'label'=> Mage::helper('catalog')->__('Change status'),
  300. 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
  301. 'additional' => array(
  302. 'visibility' => array(
  303. 'name' => 'status',
  304. 'type' => 'select',
  305. 'class' => 'required-entry',
  306. 'label' => Mage::helper('catalog')->__('Status'),
  307. 'values' => $statuses
  308. )
  309. )
  310. ));
  311.  
  312. if (Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes')){
  313. $this->getMassactionBlock()->addItem('attributes', array(
  314. 'label' => Mage::helper('catalog')->__('Update Attributes'),
  315. 'url' => $this->getUrl('*/catalog_product_action_attribute/edit', array('_current'=>true))
  316. ));
  317. }
  318.  
  319. Mage::dispatchEvent('adminhtml_catalog_product_grid_prepare_massaction', array('block' => $this));
  320. return $this;
  321. }
  322.  
  323. public function getGridUrl()
  324. {
  325. return $this->getUrl('*/*/grid', array('_current'=>true));
  326. }
  327.  
  328. public function getRowUrl($row)
  329. {
  330. return $this->getUrl('*/*/edit', array(
  331. 'store'=>$this->getRequest()->getParam('store'),
  332. 'id'=>$row->getId())
  333. );
  334. }
  335. }
  336.  
  337. <?PHP
  338. class Mage_Adminhtml_Block_Catalog_Product_Renderer extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
  339. {
  340. public function render(Varien_Object $row)
  341. {
  342.  
  343. $productId = $row->getData($this->getColumn()->getIndex());
  344. $orders = array();
  345. $collection = Mage::getResourceModel('sales/order_item_collection')
  346. ->addAttributeToFilter('product_id', array('eq' => $productId))
  347. ->load();
  348. foreach($collection as $orderItem) {
  349. $orders[$orderItem->getOrder()->getIncrementId()] = $orderItem->getOrder();
  350. }
  351.  
  352. $first_key = key($orders);
  353. return $first_key;
  354.  
  355.  
  356. }
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement