Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. <?php
  2. namespace VendorModuleModelResourceModelBrandwisereport;
  3. //use VendorModuleModelTempdataFactory;
  4.  
  5. class Collection extends MagentoFrameworkModelResourceModelDbCollectionAbstractCollection
  6. {
  7.  
  8. /**
  9. * Define resource model
  10. *
  11. * @return void
  12. */
  13. protected function _construct()
  14. {
  15. $this->_init('VendorModuleModelBrandwisereport', 'VendorModuleModelResourceModelBrandwisereport');
  16. $this->_map['fields']['page_id'] = 'main_table.page_id';
  17. $this->addFilterToMap('brand', 'eavatt.value');
  18. $this->addFilterToMap('sku', 'main_table.sku');
  19. $this->addFilterToMap('name', 'main_table.name');
  20.  
  21. //$this->_modelTempdataFactory = $modelTempdataFactory;
  22. //$this->authSession = $authSession;
  23.  
  24. }
  25.  
  26. public function filterOrder()
  27. {
  28.  
  29. $catalog_product_entity_table = $this->getTable("catalog_product_entity");
  30. $catalog_product_entity_inttable = $this->getTable("catalog_product_entity_int");
  31. $eav_attributeoptionvalue = $this->getTable("eav_attribute_option_value");
  32. $sales_order = $this->getTable("sales_order");
  33. $sales_order_address = $this->getTable("sales_order_address");
  34.  
  35.  
  36. $this->getSelect()->joinLeft(array('cpe' =>$catalog_product_entity_table), 'main_table.product_id = cpe.entity_id')
  37. ->columns(array('sum_qty_ordered' => new Zend_Db_Expr("SUM(main_table.qty_ordered)"), 'total_amount' => new Zend_Db_Expr("SUM(main_table.base_row_total)")))
  38. ->joinLeft(array('cpei' =>$catalog_product_entity_inttable),'cpei.row_id= cpe.row_id
  39. AND cpei.attribute_id = "83" AND cpei.store_id = 0')
  40. ->joinLeft(array('eavatt' =>$eav_attributeoptionvalue), 'eavatt.option_id= cpei.value',array('brand' => 'eavatt.value'))
  41. ->joinLeft(array('so' =>$sales_order), 'so.entity_id= main_table.order_id',array('status' => 'so.status'))
  42. ->joinLeft(array('soa' =>$sales_order_address), 'soa.parent_id= main_table.order_id AND soa.address_type = "shipping"',array('shippingcity' => 'soa.city'))
  43. ->group('cpe.entity_id');
  44.  
  45. $this->getSelect()->where("cpe.sku IS NOT NULL");
  46.  
  47. $authSession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
  48. $username = $authSession->getUser()->getUsername();
  49. $TempdataModel = MagentoFrameworkAppObjectManager::getInstance()->create('VendorModuleModelTempdataFactory')->create();
  50.  
  51.  
  52. $TempdataCollection = $TempdataModel->getCollection()->addFieldToFilter('identifier','brandwisereport')->addFieldToFilter('data_1',$username);
  53.  
  54. if($TempdataCollection->count()) {
  55. foreach ($TempdataCollection as $Tempdata){
  56. $datearray = explode('_',$Tempdata->getData2());
  57. $orderstatuses = $Tempdata->getData3();
  58. $brand = $Tempdata->getData4();
  59. }
  60. $orderstatusesarray = explode(',',$orderstatuses);
  61. $orderstatusesforquery = implode("','",$orderstatusesarray);
  62.  
  63.  
  64. $from = date('Y-m-d', strtotime($datearray[0]));
  65. $to = date('Y-m-d', strtotime($datearray[1]));
  66.  
  67. $this->getSelect()->where("main_table.created_at >= '".$from." 00:00:00'");
  68. $this->getSelect()->where("main_table.created_at <= '".$to." 23:59:59'");
  69. $this->getSelect()->where("so.status IN ('$orderstatusesforquery')");
  70. $this->getSelect()->where('eavatt.value LIKE "'.$brand.'"');
  71. }
  72. else {
  73. $this->getSelect()->where("cpe.entity_id = 0");
  74. }
  75. //echo $this->getSelect();
  76. //die;
  77. }
  78.  
  79. }
  80. ?>
  81.  
  82. <?php
  83. namespace VendorModuleBlockAdminhtmlBrandwisereport;
  84.  
  85. class Grid extends MagentoBackendBlockWidgetGridExtended
  86. {
  87.  
  88. protected $_countTotals = true;
  89. /**
  90. * @var MagentoFrameworkModuleManager
  91. */
  92. protected $moduleManager;
  93.  
  94. /**
  95. * @var VendorModuleModelbrandwisereportFactory
  96. */
  97. protected $_brandwisereportFactory;
  98.  
  99. /**
  100. * @var VendorModuleModelStatus
  101. */
  102. protected $_status;
  103.  
  104. /**
  105. * @param MagentoBackendBlockTemplateContext $context
  106. * @param MagentoBackendHelperData $backendHelper
  107. * @param VendorModuleModelbrandwisereportFactory $brandwisereportFactory
  108. * @param VendorModuleModelStatus $status
  109. * @param MagentoFrameworkModuleManager $moduleManager
  110. * @param array $data
  111. *
  112. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  113. */
  114. public function __construct(
  115. MagentoBackendBlockTemplateContext $context,
  116. MagentoBackendHelperData $backendHelper,
  117. VendorModuleModelBrandwisereportFactory $BrandwisereportFactory,
  118. VendorModuleModelStatus $status,
  119. MagentoFrameworkModuleManager $moduleManager,
  120. array $data = []
  121. ) {
  122. $this->_brandwisereportFactory = $BrandwisereportFactory;
  123. $this->_status = $status;
  124. $this->moduleManager = $moduleManager;
  125. parent::__construct($context, $backendHelper, $data);
  126. }
  127.  
  128. /**
  129. * @return void
  130. */
  131. protected function _construct()
  132. {
  133. parent::_construct();
  134. $this->setId('postGrid');
  135. $this->setDefaultSort('item_id');
  136. $this->setDefaultDir('DESC');
  137. $this->setSaveParametersInSession(true);
  138. $this->setUseAjax(false);
  139. //$this->setVarNameFilter('post_filter');
  140. $this->setFilterVisibility(false);
  141. //$this->buttonList->remove('selectall');
  142. //$this->buttonList->remove('save');
  143. //$this->buttonList->remove('reset');
  144. //$this->_removeButton('selectall');
  145. //$this->buttonList->remove('delete');
  146. }
  147.  
  148. public function getTotals()
  149. {
  150. $totals = new MagentoFrameworkDataObject;
  151. $fields = array(
  152. 'sum_qty_ordered' => 0,
  153. 'base_price' => 0,
  154. 'total_amount' => 0
  155. );
  156. foreach ($this->getCollection() as $item) {
  157. foreach($fields as $field=>$value){
  158. $fields[$field] += $item->getData($field);
  159. }
  160. }
  161. $fields['name']='Totals';
  162. $totals->setData($fields);
  163. return $totals;
  164. }
  165.  
  166.  
  167. /**
  168. * @return $this
  169. */
  170. protected function _prepareCollection()
  171. {
  172. $collection = $this->_brandwisereportFactory->create()->getCollection();
  173.  
  174. /********************** This code will apply filter on grid collection *****/
  175. $collection->filterOrder();
  176.  
  177. $this->setCollection($collection);
  178.  
  179. parent::_prepareCollection();
  180.  
  181. return $this;
  182. }
  183.  
  184. /**
  185. * @return $this
  186. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  187. */
  188. protected function _prepareColumns()
  189. {
  190. $this->addColumn(
  191. 'brand',
  192. [
  193. 'header' => __('Brand'),
  194. 'index' => 'brand',
  195. 'filter' => false
  196. ]
  197. );
  198.  
  199.  
  200.  
  201. $this->addColumn(
  202. 'sku',
  203. [
  204. 'header' => __('SKU'),
  205. 'index' => 'sku',
  206. 'filter' => false
  207. ]
  208. );
  209.  
  210. $this->addColumn(
  211. 'name',
  212. [
  213. 'header' => __('Name'),
  214. 'index' => 'name',
  215. 'filter' => false
  216. ]
  217. );
  218.  
  219. $this->addColumn(
  220. 'sum_qty_ordered',
  221. [
  222. 'header' => __('Sold Count'),
  223. 'type' => 'number',
  224. 'index' => 'sum_qty_ordered',
  225. 'filter' => false
  226. ]
  227. );
  228.  
  229. $this->addColumn(
  230. 'base_price',
  231. [
  232. 'header' => __('Unit Price'),
  233. 'type' => 'currency',
  234. 'index' => 'base_price',
  235. 'filter' => false
  236. ]
  237. );
  238.  
  239. $this->addColumn(
  240. 'total_amount',
  241. [
  242. 'header' => __('Total Amount'),
  243. 'type' => 'currency',
  244. 'index' => 'total_amount',
  245. 'filter' => false,
  246. 'format' => true
  247. ]
  248. );
  249.  
  250. $this->addColumn('action', array(
  251. 'header' => __('Action'),
  252. 'width' => '100',
  253. 'type' => 'action',
  254. 'getter' => 'getProductId',
  255. 'actions' => array(
  256. array(
  257. 'caption' => __('View'),
  258. 'url' => array('base' => 'catalog/product/edit'),
  259. 'target'=>'_blank',
  260. 'field' => 'id'
  261. )
  262. ),
  263. 'renderer' => 'VendorModuleBlockAdminhtmlBrandwisereportEditTabRendererBrandwiseviewaction',
  264. 'filter' => false,
  265. 'sortable' => false,
  266. 'index' => 'id',
  267. 'is_system' => true,
  268. ));
  269.  
  270.  
  271. $this->addExportType($this->getUrl('module/*/exportCsv', ['_current' => true]),__('CSV'));
  272. $this->addExportType($this->getUrl('module/*/exportExcel', ['_current' => true]),__('Excel XML'));
  273.  
  274. $block = $this->getLayout()->getBlock('grid.bottom.links');
  275. if ($block) {
  276. $this->setChild('grid.bottom.links', $block);
  277. }
  278.  
  279. return parent::_prepareColumns();
  280. }
  281.  
  282.  
  283.  
  284. /**
  285. * @return string
  286. */
  287. public function getGridUrl()
  288. {
  289. return $this->getUrl('module/*/index', ['_current' => true]);
  290. }
  291.  
  292. /**
  293. * @param VendorModuleModelbrandwisereport|MagentoFrameworkObject $row
  294. * @return string
  295. */
  296. public function getRowUrl($row)
  297. {
  298. return '#';
  299. }
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement