예제 #1
0
     $this->setId('lifetimesalesReportGrid');
     $this->setDefaultSort('orders_sum_amount');
     $this->setDefaultDir('desc');
 }
 /**
  * @return $this
  * @throws Mage_Core_Exception
  * @throws Zend_Date_Exception
  */
 protected function _prepareCollection()
 {
     // Get the session
     $session = Mage::getSingleton('core/session');
     // Dates for one week
     $store = Mage_Core_Model_App::ADMIN_STORE_ID;
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     date_default_timezone_set($timezone);
     // Automatic -30 days if no dates provided
     if ($session->getLifetimesalesFrom()) {
         $sDate = $session->getLifetimesalesFrom();
     } else {
         $sDate = date('Y-m-d 00:00:00', Mage::getModel('core/date')->timestamp(strtotime('-30 days')));
     }
     if ($session->getLifetimesalesTo()) {
         $eDate = $session->getLifetimesalesTo();
     } else {
         $eDate = date('Y-m-d 23:59:59', Mage::getModel('core/date')->timestamp(time()));
     }
     ###############################################################################
     $start = new Zend_Date($sDate);
     $start->setTimeZone("UTC");
     $end = new Zend_Date($eDate);
     $end->setTimeZone("UTC");
예제 #2
0
     $wishlistItemsCollection = Mage::getModel('wishlist/item')->getCollection();
     // Call iterator walk method with collection query string and callback method as parameters
     // Has to be used to handle massive collection instead of foreach
     Mage::getSingleton('core/resource_iterator')->walk($wishlistItemsCollection->getSelect(), array(array($this, 'fillArray')));
     return $this->filterArray;
 }
 /**
  * @return $this
  * @throws Zend_Date_Exception
  */
 protected function _prepareCollection()
 {
     // Get the session
     $session = Mage::getSingleton('core/session');
     // Dates for one week
     $store = Mage_Core_Model_App::ADMIN_STORE_ID;
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     date_default_timezone_set($timezone);
     // Automatic -30 days if no dates provided
     if ($session->getWishlistFrom()) {
         $sDate = $session->getWishlistFrom();
     } else {
         $sDate = date('Y-m-d 00:00:00', Mage::getModel('core/date')->timestamp(strtotime('-30 days')));
     }
     if ($session->getWishlistTo()) {
         $eDate = $session->getWishlistTo();
     } else {
         $eDate = date('Y-m-d 23:59:59', Mage::getModel('core/date')->timestamp(time()));
     }
     ###############################################################################
     $start = new Zend_Date($sDate);
     $start->setTimeZone("UTC");
     $end = new Zend_Date($eDate);
     $end->setTimeZone("UTC");
예제 #3
0
 /**
  * @throws Zend_Date_Exception
  */
 protected function _setToday()
 {
     // Date handling
     $store = Mage_Core_Model_App::ADMIN_STORE_ID;
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     date_default_timezone_set($timezone);
     // Current date
     $currentdate = date("Ymd");
     $day = (int) substr($currentdate, -2);
     $month = (int) substr($currentdate, 4, 2);
     $year = (int) substr($currentdate, 0, 4);
     $date = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => 23, 'minute' => 59, 'second' => 59);
     $today = new Zend_Date($date);
     $today->setTimeZone("UTC");
     date_default_timezone_set($timezone);
     $this->_today = $today->toString("Y-MM-dd HH:mm:ss");
 }
예제 #4
0
 /**
  * @return $this
  * @throws Exception
  * @throws Zend_Date_Exception
  */
 protected function _prepareCollection()
 {
     // Get the session
     $session = Mage::getSingleton('core/session');
     // Dates for one week
     $store = Mage_Core_Model_App::ADMIN_STORE_ID;
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     date_default_timezone_set($timezone);
     // Automatic -30 days if no dates provided
     if ($session->getOrderedbycustomergroupsFrom()) {
         $sDate = $session->getOrderedbycustomergroupsFrom();
     } else {
         $sDate = date('Y-m-d 00:00:00', Mage::getModel('core/date')->timestamp(strtotime('-30 days')));
     }
     if ($session->getOrderedbycustomergroupsTo()) {
         $eDate = $session->getOrderedbycustomergroupsTo();
     } else {
         $eDate = date('Y-m-d 23:59:59', Mage::getModel('core/date')->timestamp(time()));
     }
     ###############################################################################
     $start = new Zend_Date($sDate);
     $start->setTimeZone("UTC");
     $end = new Zend_Date($eDate);
     $end->setTimeZone("UTC");
     ###############################################################################
     $from = $start->toString("Y-MM-dd HH:mm:ss");
     $to = $end->toString("Y-MM-dd HH:mm:ss");
     // Get the products with their ordered quantity
     $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addOrderedQty($from, $to)->setOrder('ordered_qty');
     $collection->getSelect()->reset(Zend_Db_Select::GROUP);
     $collection->getSelect()->columns('order.customer_group_id');
     $collection->getSelect()->group(array('order_items.product_id', 'order.customer_group_id'));
     // Call iterator walk method with collection query string and callback method as parameters
     // Has to be used to handle massive collection instead of foreach
     Mage::getSingleton('core/resource_iterator')->walk($collection->getSelect(), array(array($this, 'fillCollection')));
     // Convert the array to a collection
     $finalCollection = new Varien_Data_Collection();
     foreach ($this->arrayCollection as $entry) {
         $rowObj = new Varien_Object();
         $rowObj->setData($entry);
         $finalCollection->addItem($rowObj);
     }
     $this->setCollection($finalCollection);
     parent::_prepareCollection();
     return $this;
 }
예제 #5
0
파일: DateTest.php 프로젝트: jsnshrmn/Suma
 /**
  * @ZF-7154
  */
 public function testZF7154()
 {
     $locale = new Zend_Locale('de_AT');
     $date = new Zend_Date(1577833200, $locale);
     $date2 = new Zend_Date(2006, Zend_Date::YEAR);
     $date->setTimeZone(date_default_timezone_get());
     $date->setYear(2000);
     $date->setMonth('Apr.');
     $this->assertSame('2000-04-01T04:00:00+05:00', $date->get(Zend_Date::W3C));
     $date->setYear(2004);
     $date->setMonth('Februar');
     $this->assertSame('2004-02-01T04:00:00+05:00', $date->get(Zend_Date::W3C));
 }
예제 #6
0
 /**
  * test setting dates to specify weekdays
  */
 public function testDay()
 {
     // all tests and calculations below are in GMT (that is intention for this test)
     $date = new Zend_Date(0, 'de_AT');
     $date->setTimeZone('UTC');
     $dw = $date->getDay();
     $this->assertSame($dw->toString(), '01.01.1970 00:00:00');
     for ($day = 1; $day < 31; $day++) {
         $date->setDay($day);
         $dw = $date->getDay();
         $weekday = str_pad($day, 2, '0', STR_PAD_LEFT);
         $this->assertSame($dw->toString(), "{$weekday}.01.1970 00:00:00");
     }
 }
예제 #7
0
파일: date.php 프로젝트: nveid/concrete5
	/**
	 * Gets the localized date according to a specific mask
	 * @param object $datetime A PHP DateTime Object
	 * @param string $mask 
	 * @return string 
	 */
	public function dateTimeFormatLocal(&$datetime,$mask) {
		$locale = new Zend_Locale(Localization::activeLocale());

		$date = new Zend_Date($datetime->format(DATE_ATOM),DATE_ATOM, $locale);
		$date->setTimeZone($datetime->format("e"));
		return $date->toString($mask);
	}
예제 #8
0
 /**
  * @return $this
  * @throws Exception
  * @throws Zend_Date_Exception
  */
 protected function _prepareCollection()
 {
     // Get the session
     $session = Mage::getSingleton('core/session');
     // Dates for one week
     $store = Mage_Core_Model_App::ADMIN_STORE_ID;
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     date_default_timezone_set($timezone);
     // Automatic -30 days if no dates provided
     if ($session->getWorstsellersFrom()) {
         $sDate = $session->getWorstsellersFrom();
     } else {
         $sDate = date('Y-m-d 00:00:00', Mage::getModel('core/date')->timestamp(strtotime('-30 days')));
     }
     if ($session->getWorstsellersTo()) {
         $eDate = $session->getWorstsellersTo();
     } else {
         $eDate = date('Y-m-d 23:59:59', Mage::getModel('core/date')->timestamp(time()));
     }
     ###############################################################################
     $start = new Zend_Date($sDate);
     $start->setTimeZone("UTC");
     $end = new Zend_Date($eDate);
     $end->setTimeZone("UTC");
     ###############################################################################
     $from = $start->toString("Y-MM-dd HH:mm:ss");
     $to = $end->toString("Y-MM-dd HH:mm:ss");
     // Get the products with their ordered quantity
     $bestSellers = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addOrderedQty($from, $to)->setOrder('ordered_qty');
     $bestSellers->getSelect()->join(array('catalog_product' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), 'catalog_product.entity_id = order_items.product_id', array('catalog_product.sku'));
     //echo $bestSellers->printlogquery(true);
     // Call iterator walk method with collection query string and callback method as parameters
     // Has to be used to handle massive collection instead of foreach
     Mage::getSingleton('core/resource_iterator')->walk($bestSellers->getSelect(), array(array($this, 'fillBestsellersArray')));
     // Get the most viewed products
     $mostViewed = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addViewsCount($from, $to);
     //echo $mostViewed->printlogquery(true);
     // Call iterator walk method with collection query string and callback method as parameters
     // Has to be used to handle massive collection instead of foreach
     Mage::getSingleton('core/resource_iterator')->walk($mostViewed->getSelect(), array(array($this, 'addMostViewedData')));
     // Obtain a list of columns to sort the array using subkeys
     $views = array();
     $qty = array();
     foreach ($this->arrayBestSellers as $key => $row) {
         // Remove the unexisting products
         if ($row['sku'] == "UNKNOWN") {
             unset($this->arrayBestSellers[$key]);
             continue;
         }
         $views[$key] = $row['views'];
         $qty[$key] = $row['ordered_qty'];
     }
     // Sort the data with qty ascending, views descending
     // Add $arrayBestSellers as the last parameter, to sort by the common key
     array_multisort($qty, SORT_ASC, $views, SORT_DESC, $this->arrayBestSellers);
     // Convert the array to a collection
     $collection = new Varien_Data_Collection();
     foreach ($this->arrayBestSellers as $product) {
         $rowObj = new Varien_Object();
         $rowObj->setData($product);
         $collection->addItem($rowObj);
     }
     $this->setCollection($collection);
     parent::_prepareCollection();
     return $this;
 }
예제 #9
0
 /**
  * Convert a date to a Zend_Date instance.
  * @param string|DateTime|Zend_Date|int $value It can be:<ul>
  *	<li>the special value 'now' (default) to return the current date/time</li>
  *	<li>a DateTime instance</li>
  *	<li>a Zend_Date instance</li>
  *	<li>a string parsable by strtotime (the current system timezone is used)</li>
  *	<li>a timestamp</li>
  * </ul>
  * @param string $timezone The timezone to set. Special values are:<ul>
  *	<li>'system' (default) for the current system timezone</li>
  *	<li>'user' for the user's timezone</li>
  *	<li>'app' for the app's timezone</li>
  *	<li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
  * </ul>
  * @return Zend_Date|null Returns the Zend_Date instance (or null if $value couldn't be parsed)
  */
 public function toZendDate($value = 'now', $timezone = 'system')
 {
     $zendDate = null;
     if (is_int($value)) {
         $zendDate = new Zend_Date($value, Zend_Date::TIMESTAMP);
     } elseif ($value instanceof DateTime) {
         $zendDate = new Zend_Date($value->format(DATE_ATOM), DATE_ATOM);
         $zendDate->setTimeZone($value->format('e'));
     } elseif (is_a($value, 'Zend_Date')) {
         $zendDate = clone $value;
     } elseif (is_string($value) && strlen($value)) {
         if ($value === 'now') {
             $zendDate = new Zend_Date();
         } elseif (is_numeric($value)) {
             $zendDate = new Zend_Date($value, Zend_Date::TIMESTAMP);
         } else {
             $timestamp = @strtotime($value);
             if ($timestamp !== false) {
                 $zendDate = new Zend_Date($timestamp, Zend_Date::TIMESTAMP);
             }
         }
     }
     if (is_null($zendDate)) {
         return null;
     }
     $zendDate->setLocale(Localization::activeLocale());
     $zendDate->setTimezone($this->getTimezone($timezone));
     return $zendDate;
 }
예제 #10
0
 /**
  * @return $this
  * @throws Exception
  * @throws Mage_Core_Exception
  * @throws Zend_Date_Exception
  */
 protected function _prepareCollection()
 {
     // Get the session
     $session = Mage::getSingleton('core/session');
     // Dates for one week
     $store = Mage_Core_Model_App::ADMIN_STORE_ID;
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     date_default_timezone_set($timezone);
     // Automatic -30 days if no dates provided
     if ($session->getFrom()) {
         $sDate = $session->getFrom();
         $sDate = str_replace('/', '-', $sDate);
         $sDate = strtotime($sDate);
         $sDate = date('Y-m-d H:i:s', $sDate);
     } else {
         $sDate = date('Y-m-d 00:00:00', Mage::getModel('core/date')->timestamp(strtotime('-30 days')));
     }
     if ($session->getTo()) {
         $eDate = $session->getTo();
         $eDate = str_replace('/', '-', $eDate);
         $eDate = strtotime($eDate);
         $eDate = date('Y-m-d H:i:s', $eDate);
     } else {
         $eDate = date('Y-m-d 23:59:59', Mage::getModel('core/date')->timestamp(time()));
     }
     ###############################################################################
     $start = new Zend_Date($sDate);
     $start->setTimeZone("UTC");
     $end = new Zend_Date($eDate);
     $end->setTimeZone("UTC");
     ###############################################################################
     $from = $start->toString("Y-MM-dd HH:mm:ss");
     $to = $end->toString("Y-MM-dd HH:mm:ss");
     // Get the bestsellers product using Magento collection
     $bestSellers = Mage::getResourceModel('reports/product_collection')->addOrderedQtyAndTotal($sDate, $eDate)->addAttributeToSelect('*')->setOrder('ordered_qty');
     //echo $bestSellers->printlogquery(true);
     // Call iterator walk method with collection query string and callback method as parameters
     // Has to be used to handle massive collection instead of foreach
     Mage::getSingleton('core/resource_iterator')->walk($bestSellers->getSelect(), array(array($this, 'fillBestsellersArray')));
     // Get the most viewed products
     $mostViewed = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addViewsCount($from, $to);
     //echo $mostViewed->printlogquery(true);
     // Call iterator walk method with collection query string and callback method as parameters
     // Has to be used to handle massive collection instead of foreach
     Mage::getSingleton('core/resource_iterator')->walk($mostViewed->getSelect(), array(array($this, 'addMostViewedData')));
     // Array that will contain the data
     $arrayWorstSellers = array();
     foreach ($this->arrayBestSellers as $worstSellerProductId => $worstSellerProduct) {
         // Get Product ID
         $id = $worstSellerProduct['product_id'];
         // Get Sold Quantity and Total
         $orderedQty = $worstSellerProduct['ordered_qty'];
         $views = $worstSellerProduct['views'];
         // Load the potential parent product ids
         $parentProduct = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id);
         // If a product is an associated product
         if (!empty($parentProduct) && isset($parentProduct[0])) {
             // Get the parent configurable product id
             $productId = $parentProduct[0];
         } else {
             // Get the simple product id
             $productId = $id;
         }
         // Get all categories of this product
         $categories = Mage::getResourceModel('catalog/category_collection')->joinField('product_id', 'catalog/category_product', 'product_id', 'category_id = entity_id', null)->addAttributeToSelect('name')->addAttributeToSelect('parent_id')->addFieldToFilter('product_id', $productId);
         // Export this collection to array so we could iterate on it's elements
         $categories = $categories->exportToArray();
         // Get categories names
         foreach ($categories as $category) {
             // Get Category ID
             $categoryID = $category['entity_id'];
             // Get Category Name
             $categoryName = $category['name'];
             // If category already in the array, we add data
             if (array_key_exists($categoryID, $arrayWorstSellers)) {
                 // We update the ordered quantity
                 $arrayWorstSellers[$categoryID]['ordered_qty'] += $orderedQty;
                 // We udpate the ordered total
                 $arrayWorstSellers[$categoryID]['views'] += $views;
             } else {
                 // Else we create a new entry with the data
                 $arrayWorstSellers[$categoryID] = array('name' => $categoryName, 'ordered_qty' => $orderedQty, 'views' => $views);
             }
         }
     }
     // Obtain a list of columns to sort the array using subkeys
     $views = array();
     $qty = array();
     foreach ($arrayWorstSellers as $key => $row) {
         $views[$key] = $row['views'];
         $qty[$key] = $row['ordered_qty'];
     }
     // Sort the data with qty ascending, views descending
     // Add $arrayWorstSellers as the last parameter, to sort by the common key
     array_multisort($qty, SORT_ASC, $views, SORT_DESC, $arrayWorstSellers);
     // Convert the array to a collection
     $collection = new Varien_Data_Collection();
     foreach ($arrayWorstSellers as $category) {
         $rowObj = new Varien_Object();
         $rowObj->setData($category);
         $collection->addItem($rowObj);
     }
     $this->setCollection($collection);
     parent::_prepareCollection();
     return $this;
 }