protected function _prepareData() { $chartLabels = array(); if (count($this->getSkus())) { # primary analise foreach ($this->getCollection()->getIntervals() as $_index => $_item) { $items = $this->_getOrderCollection($_item['start'], $_item['end']); $row['period'] = $_item['title']; $this->_addCustomData($row); foreach ($items as $item) { if (in_array(strtolower($item->getSku()), $this->_skus) || $this->_isInAdditional($item->getSku()) || $this->_isInVirtualSku($item->getSku())) { $row['period'] = $_item['title']; $row['sku'] = strtolower($item->getSku()); $row['column_id'] = $this->getColumnBySku(strtolower($item->getSku())); $row['ordered_qty'] = $item->getSumQty(); $row['total'] = $item->getSumTotal(); $this->_addCustomData($row); } } } # final preporation of data if (count($this->_customData)) { foreach ($this->getSkus() as $sku) { foreach ($this->_customData as &$d) { if (!isset($d[$sku])) { $d[$sku] = 0; } } if ($this->getGrouped()) { # If result is grouped if (isset($this->_additionalSkus[$sku]) && count($this->_additionalSkus[$sku])) { foreach ($this->_additionalSkus[$sku] as $addSku) { foreach ($this->_customData as &$d) { if (isset($d[$addSku])) { $d[$sku] += $d[$addSku]; $d[$this->getColumnBySku($sku)] = $d[$sku]; } } } } if ($this->_isVirtualSku($sku)) { if (isset($this->_maskedSkus[$sku])) { foreach ($this->_maskedSkus[$sku] as $chSku) { # Check additional masked skus if (isset($this->_additionalSkus[$chSku]) && count($this->_additionalSkus[$chSku])) { foreach ($this->_additionalSkus[$chSku] as $addSku) { foreach ($this->_customData as &$d) { if (isset($d[$addSku]) && isset($d[$chSku])) { $d[$chSku] += $d[$addSku]; $d[$this->getColumnBySku($chSku)] = $d[$chSku]; } } } } # Check basical masked sku foreach ($this->_customData as &$d) { if (isset($d[$chSku])) { $d[$sku] = (string) ($d[$sku] + $d[$chSku]); $d[$this->getColumnBySku($sku)] = (string) $d[$sku]; } } } } } } else { # If result is detailed if (isset($this->_additionalSkus[$sku]) && count($this->_additionalSkus[$sku])) { foreach ($this->_additionalSkus[$sku] as $addSku) { foreach ($this->_customData as &$d) { if (!isset($d[$addSku])) { $d[$addSku] = 0; } } } } } } } foreach ($this->_skus as $sku) { if ($this->_isVirtualSku($sku)) { $chartLabels[$sku] = $sku; } else { $chartLabels[$sku] = $this->_helper()->getProductNameBySku($sku); } if ($this->getGrouped()) { } else { if (isset($this->_additionalSkus[$sku]) && count($this->_additionalSkus[$sku])) { foreach ($this->_additionalSkus[$sku] as $addSku) { $chartLabels[$addSku] = $this->_getProductName($sku, $addSku, true); } } } } } $chartKeys = array(); foreach ($this->_skus as $sku) { if (array_search($sku, $chartKeys) === false) { $chartKeys[] = $sku; } if ($this->getGrouped()) { # Do somthing } else { if (isset($this->_additionalSkus[$sku]) && count($this->_additionalSkus[$sku])) { foreach ($this->_additionalSkus[$sku] as $addSku) { if (array_search($addSku, $chartKeys) === false) { $chartKeys[] = $addSku; } } } } } # Reclean data $newData = array(); foreach ($this->_customData as $data) { $newSubData = array(); foreach ($data as $k => $v) { if ($k) { $newSubData[$k] = $v; } } $newData[] = $newSubData; } $this->_customData = $newData; $this->_helper()->setChartData($this->_customData, $this->_helper()->getDataKey($this->_routeOption)); $this->_helper()->setChartKeys($chartKeys, $this->_helper()->getDataKey($this->_routeOption)); $this->_helper()->setChartLabels($chartLabels, $this->_helper()->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { foreach ($this->_helper()->getWeekChain() as $i) { $row['weekday'] = $i; $row['title'] = $this->_helper()->getWeekday($row['weekday']); $row['qty_ordered'] = 0; $row['total'] = 0; $this->_addCustomData($row); } foreach ($this->getCollection() as $order) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[$column->getIndex()] = $order->getData($column->getIndex()); } } $row['weekday'] = $order->getDayOfWeek() - 1; $row['qty_ordered'] = $order->getSumQty(); $row['total'] = $order->getSumTotal(); $this->_addCustomData($row); } if (!count($this->_customData)) { return $this; } $key = $this->getFilter('reload_key'); if ($key === 'qty') { //All qty $qty = 0; foreach ($this->_customData as $d) { $qty += $d['qty_ordered']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; if ($qty) { $d['percent'] = round($d['qty_ordered'] * 100 / $qty) . ' %'; $d['percent_data'] = round($d['qty_ordered'] * 100 / $qty); $d['data_for_chart'] = $d['qty_ordered']; } else { $d['percent'] = '0 %'; $d['percent_data'] = 0; $d['data_for_chart'] = $d['qty_ordered']; } } } elseif ($key === 'total') { //All qty $total = 0; foreach ($this->_customData as $d) { $total += $d['total']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; if ($total) { $d['percent'] = round($d['total'] * 100 / $total) . ' %'; $d['percent_data'] = round($d['total'] * 100 / $total); $d['data_for_chart'] = $d['total']; } else { $d['percent'] = '0 %'; $d['percent_data'] = 0; $d['data_for_chart'] = $d['total']; } } } else { return $this; } Mage::helper('advancedreports')->setChartData($this->_customData, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { for ($i = 0; $i < 24; $i++) { $row['hours'] = date('H:i', mktime($i, 0)); $row['title'] = date('H', mktime($i, 0)); $row['qty_ordered'] = 0; $row['total'] = 0; $this->_addCustomData($row); } // echo $this->getCollection()->getSelect()->__toString(); foreach ($this->getCollection() as $order) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[$column->getIndex()] = $order->getData($column->getIndex()); } } $row['hours'] = date('H:i', mktime($order->getHour(), 0)); $row['qty_ordered'] = $order->getSumQty(); $row['total'] = $order->getSumTotal(); $this->_addCustomData($row); } // print_r( $this->_customData ); if (!count($this->_customData)) { return $this; } $key = $this->getFilter('reload_key'); if ($key === 'qty') { //All qty $qty = 0; foreach ($this->_customData as $d) { $qty += $d['qty_ordered']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; if ($qty) { $d['percent'] = round($d['qty_ordered'] * 100 / $qty) . ' %'; $d['percent_data'] = round($d['qty_ordered'] * 100 / $qty); $d['data_for_chart'] = $d['qty_ordered']; } else { $d['percent'] = '0 %'; $d['percent_data'] = 0; $d['data_for_chart'] = $d['qty_ordered']; } } } elseif ($key === 'total') { //All qty $total = 0; foreach ($this->_customData as $d) { $total += $d['total']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; if ($total) { $d['percent'] = round($d['total'] * 100 / $total) . ' %'; $d['percent_data'] = round($d['total'] * 100 / $total); $d['data_for_chart'] = $d['total']; } else { $d['percent'] = '0 %'; $d['percent_data'] = 0; $d['data_for_chart'] = $d['total']; } } } else { return $this; } Mage::helper('advancedreports')->setChartData($this->_customData, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { $chartLabels = array(); if (count($this->getSkus())) { # primary analise foreach ($this->getCollection()->getIntervals() as $_index => $_item) { $items = $this->_getOrderCollection($_item['start'], $_item['end']); // echo $items->getSelect()->__toString().'<hr>'; $row['period'] = $_item['title']; $this->_addCustomData($row); foreach ($items as $item) { if (in_array(strtolower($item->getSku()), $this->_skus)) { $row['period'] = $_item['title']; $row['sku'] = strtolower($item->getSku()); $row['column_id'] = $this->getColumnBySku(strtolower($item->getSku())); $row['ordered_qty'] = $item->getSumQty(); $row['total'] = $item->getSumTotal(); $this->_addCustomData($row); } } } # final preporation of data if (count($this->_customData)) { foreach ($this->getSkus() as $sku) { foreach ($this->_customData as &$d) { if (!isset($d[$sku])) { $d[$sku] = 0; } } } } foreach ($this->_skus as $sku) { $chartLabels[$sku] = Mage::helper('advancedreports')->getProductNameBySku($sku); } } // echo '<pre>'; // var_dump($this->_skus); // var_dump($this->_skuColumns); // var_dump($this->_customData); // echo '</pre>'; Mage::helper('advancedreports')->setChartData($this->_customData, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); Mage::helper('advancedreports')->setChartKeys($this->_skus, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); Mage::helper('advancedreports')->setChartLabels($chartLabels, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { //Remember available keys $keys = array(); foreach ($this->getChartParams() as $param) { $keys[] = $param['value']; } $dataKeys = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem() && in_array($column->getIndex(), $keys)) { $dataKeys[] = $column->getIndex(); } } //Get data $data = array(); foreach ($this->getCollection()->getIntervals() as $_index => $_item) { $report = $this->getReport($_item['start'], $_item['end']); $row = array(); foreach ($report as $_subIndex => $_subItem) { $row = array(); foreach ($this->_columns as $column) { $row[$column->getIndex()] = $_subItem->getData($column->getIndex()); } } $row['period'] = $_index; $data[] = $row; $this->_addCustomData($row); } // var_dump($this->_customData); if ($data) { Mage::helper('advancedreports')->setChartData($data, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); } parent::_prepareData(); }
/** * Prepare data array for Pie and Grid * @return AW_Advancedreports_Block_Advanced_Purchased_Grid */ protected function _prepareData() { foreach ($this->getCollection() as $order) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[$column->getIndex()] = $order->getData($column->getIndex()); } } $row['customers'] = 1; $row['title'] = round($row['sum_qty']); $this->_addCustomData($row); } if (!count($this->_customData)) { return $this; } usort($this->_customData, array(&$this, "_compareQtyElements")); $this->_helper()->setChartData($this->_customData, $this->_helper()->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
/** * Prepare data for Chart and Grid * @return AW_Advancedreports_Block_Advanced_Users_Grid */ protected function _prepareData() { # primary analise foreach ($this->getCollection()->getIntervals() as $_index => $_item) { $row['period'] = $_item['title']; $row['accounts'] = $this->_getAccountsCount($_item['start'], $_item['end']); $row['orders'] = $this->_getOrdersCount($_item['start'], $_item['end']); $row['reviews'] = $this->_getReviewsCount($_item['start'], $_item['end']); $this->_addCustomData($row); } $chartLabels = array('accounts' => Mage::helper('advancedreports')->__('New Accounts'), 'orders' => Mage::helper('advancedreports')->__('Orders'), 'reviews' => Mage::helper('advancedreports')->__('Reviews')); $keys = array(); foreach ($chartLabels as $key => $value) { $keys[] = $key; } // echo '<pre>'; // var_dump($chartLabels); // var_dump($this->_customData); // echo '</pre>'; Mage::helper('advancedreports')->setChartData($this->_customData, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); Mage::helper('advancedreports')->setChartKeys($keys, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); Mage::helper('advancedreports')->setChartLabels($chartLabels, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { # Extract data from collection $col = $this->getCollection(); if ($col && count($col)) { foreach ($col as $_subItem) { $row = array(); # Get all colummns values foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[$column->getIndex()] = $column->getRowField($_subItem); } } # Add quantity $row['ordered_qty'] = $_subItem->getSumQty(); # Add total $row['total'] = $_subItem->getSumTotal(); # Add product id $row['id'] = $_subItem->getProductId(); if (isset($row['id']) && isset($row['name'])) { $_product = Mage::getModel('catalog/product')->load($row['id']); if ($_product->getData()) { $row['name'] = $_product->getName(); } unset($_product); } $this->_addBestsellerData($row); } } if (!count($this->_customData)) { return $this; } $key = $this->getFilter('reload_key'); if ($key === 'qty') { # Sort data usort($this->_customData, array(&$this, "_compareQtyElements")); # Splice array array_splice($this->_customData, $this->getCustomOption('advancedreports_bestsellers_options_bestsellers_count')); # All qty $qty = 0; foreach ($this->_customData as $d) { $qty += $d['ordered_qty']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; $d['percent'] = round($d['ordered_qty'] * 100 / $qty) . ' %'; $d['percent_data'] = round($d['ordered_qty'] * 100 / $qty); //Add title $d['title'] = $d['name'] . ' (' . $d['percent'] . ')'; } } elseif ($key === 'total') { //Sort data usort($this->_customData, array(&$this, "_compareTotalElements")); //Splice array array_splice($this->_customData, $this->getCustomOption('advancedreports_bestsellers_options_bestsellers_count')); //All qty $total = 0; foreach ($this->_customData as $d) { $total += $d['total']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; $d['percent'] = round($d['total'] * 100 / $total) . ' %'; $d['percent_data'] = round($d['total'] * 100 / $total); //Add title $d['title'] = $d['name'] . ' (' . $d['percent'] . ')'; } } else { return $this; } $this->_helper()->setChartData($this->_customData, $this->_helper()->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { // echo $this->getCollection()->getSelect()->__toString(); foreach ($this->getCollection() as $item) { $row = $item->getData(); if (isset($row['order_ship_country_id'])) { // $row['order_ship_country'] = Mage::getSingleton('directory/country')->loadByCode( $row['order_ship_country_id'] )->getName(); $row['order_ship_country'] = $row['order_ship_country_id']; } if (isset($row['order_bil_country_id'])) { // $row['order_bil_country'] = Mage::getSingleton('directory/country')->loadByCode( $row['order_bil_country_id'] )->getName(); $row['order_bil_country'] = $row['order_bil_country_id']; } # Billing/Shipping logic if (isset($row['order_ship_country'])) { $row['order_country'] = $row['order_ship_country']; } elseif (isset($row['order_bil_country'])) { $row['order_country'] = $row['order_bil_country']; } if (isset($row['order_ship_region'])) { $row['order_region'] = $row['order_ship_region']; } elseif (isset($row['order_bil_region'])) { $row['order_region'] = $row['order_bil_region']; } if (isset($row['order_ship_city'])) { $row['order_city'] = $row['order_ship_city']; } elseif (isset($row['order_bil_city'])) { $row['order_city'] = $row['order_bil_city']; } if (isset($row['order_ship_postcode'])) { $row['order_postcode'] = $row['order_ship_postcode']; } elseif (isset($row['order_bil_postcode'])) { $row['order_postcode'] = $row['order_bil_postcode']; } $row['base_row_subtotal'] = $row['base_row_total']; $row['base_row_total'] = $row['base_row_total'] + $row['base_tax_amount'] - abs($row['base_discount_amount']); if ($row['base_row_total'] < 0) { $row['base_row_total'] = 0; } if ($row['base_row_invoiced'] > $row['base_row_total']) { $row['base_row_invoiced'] = $row['base_row_total']; } if (isset($row['base_row_refunded'])) { if ($row['base_row_refunded'] > $row['base_row_total']) { $row['base_row_refunded'] = $row['base_row_total']; } } else { if ($row['base_amount_refunded'] > $row['base_row_total']) { $row['base_row_refunded'] = $row['base_row_total']; } else { $row['base_row_refunded'] = $row['base_amount_refunded']; } } if (isset($row['simple_sku'])) { $row['sku'] = $row['simple_sku']; } // elseif (isset($row['product_id'])){ // // } // Varien_Profiler::start('aw:advancedreports::sales::prepare_data::load_product'); // if (isset($row['product_id']) && $product = Mage::getSingleton('catalog/product')->load($row['product_id'])){ // $opt_id = $product->getManufacturer(); // $row['product_manufacturer'] = $this->_getManufacturer($opt_id); // } // Varien_Profiler::stop('aw:advancedreports::sales::prepare_data::load_product'); if (isset($row['sku'])) { $this->_addCustomData($row); } } // var_dump('speed:'.Varien_Profiler::fetch('aw:advancedreports::sales::prepare_data::load_product') ); // var_dump('mem:'.Varien_Profiler::fetch('aw:advancedreports::sales::prepare_data::load_product', 'emalloc') ); // echo '<pre>'; // var_dump($chartLabels); // var_dump($this->_customData); // echo '</pre>'; parent::_prepareData(); $this->_setColumnFilters(); return $this; }
/** * Prepare Custom Data to show chart * @return AW_Advancedreports_Block_Advanced_Country_Grid */ protected function _prepareData() { foreach ($this->getCollection() as $order) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[$column->getIndex()] = $order->getData($column->getIndex()); } } if ($order->getCountryId()) { $row['country_id'] = $order->getCountryId(); $row['qty_ordered'] = $order->getSumQty(); $row['total'] = $order->getSumTotal(); $this->_addCustomData($row); } } if (!count($this->_customData)) { return $this; } $key = $this->getFilter('reload_key'); if ($key === 'qty') { //Sort data usort($this->_customData, array(&$this, "_compareQtyElements")); //All qty $qty = 0; foreach ($this->_customData as $d) { $qty += $d['qty_ordered']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; $d['percent'] = round($d['qty_ordered'] * 100 / $qty) . ' %'; $d['percent_data'] = round($d['qty_ordered'] * 100 / $qty); //Add title $d['country_name'] = Mage::getSingleton('directory/country')->loadByCode($d['country_id'])->getName(); } } elseif ($key === 'total') { //Sort data usort($this->_customData, array(&$this, "_compareTotalElements")); //All qty $total = 0; foreach ($this->_customData as $d) { $total += $d['total']; } foreach ($this->_customData as $i => &$d) { $d['order'] = $i + 1; if ($total != 0) { $d['percent'] = round($d['total'] * 100 / $total) . ' %'; $d['percent_data'] = round($d['total'] * 100 / $total); } else { $d['percent'] = '0 %'; $d['percent_data'] = 0; } //Add title $d['country_name'] = Mage::getSingleton('directory/country')->loadByCode($d['country_id'])->getName(); } } else { return $this; } $this->_helper()->setChartData($this->_customData, $this->_helper()->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
/** * Prepare data for Chart and Grid * @return AW_Advancedreports_Block_Advanced_Users_Grid */ protected function _prepareData() { # primary analise $postition = 0; foreach ($this->getCollection()->getIntervals() as $_index => $_item) { $row['period'] = $_item['title']; $row['sort_position'] = $postition++; $row['accounts'] = $this->_getAccountsCount($_item['start'], $_item['end']); $row['orders'] = $this->_getOrdersCount($_item['start'], $_item['end']); $row['reviews'] = $this->_getReviewsCount($_item['start'], $_item['end']); $this->_addCustomData($row); } $chartLabels = array('accounts' => $this->_helper()->__('New Accounts'), 'orders' => $this->_helper()->__('Orders'), 'reviews' => $this->_helper()->__('Reviews')); $keys = array(); foreach ($chartLabels as $key => $value) { $keys[] = $key; } $this->_helper()->setChartData($this->_customData, $this->_helper()->getDataKey($this->_routeOption)); $this->_helper()->setChartKeys($keys, $this->_helper()->getDataKey($this->_routeOption)); $this->_helper()->setChartLabels($chartLabels, $this->_helper()->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }
protected function _prepareData() { // echo $this->getCollection()->getSelect()->__toString(); foreach ($this->getCollection() as $order) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[$column->getIndex()] = $order->getData($column->getIndex()); } } $row['customers'] = 1; $row['title'] = round($row['sum_qty']); $this->_addCustomData($row); } // var_dump( $this->_customData ); if (!count($this->_customData)) { return $this; } usort($this->_customData, array(&$this, "_compareQtyElements")); Mage::helper('advancedreports')->setChartData($this->_customData, Mage::helper('advancedreports')->getDataKey($this->_routeOption)); parent::_prepareData(); return $this; }