public static function onGenerateInitialData(Date $from, Date $to)
 {
     $data = array();
     // 1. Payments
     $result = \CSaleOrder::GetList(array(), array('PAYED' => 'Y', 'CANCELED' => 'N', '>=DATE_PAYED' => $from, '<=DATE_PAYED' => $to), false, false, array('LID', 'DATE_PAYED', 'PRICE', 'CURRENCY'));
     while ($row = $result->Fetch()) {
         $day = new DateTime($row['DATE_PAYED']);
         $sum = Utils::convertToBaseCurrency($row['PRICE'], $row['CURRENCY']);
         if ($counters =& $data[$row['LID']][$day->format('Y-m-d')]) {
             $counters['sale_payment_add_day'] += 1;
             $counters['sale_payment_sum_add'] += $sum;
         } else {
             $counters = array('sale_payment_add_day' => 1, 'sale_payment_sum_add' => $sum);
         }
     }
     // 2. Orders
     $result = \CSaleOrder::GetList(array(), array('CANCELED' => 'N', '>=DATE_INSERT' => $from, '<=DATE_INSERT' => $to), false, false, array('LID', 'DATE_INSERT', 'PRICE', 'CURRENCY'));
     while ($row = $result->Fetch()) {
         $day = new DateTime($row['DATE_INSERT']);
         $sum = Utils::convertToBaseCurrency($row['PRICE'], $row['CURRENCY']);
         if ($counters =& $data[$row['LID']][$day->format('Y-m-d')]) {
             $counters['sale_order_add_day'] += 1;
             $counters['sale_order_sum_add'] += $sum;
         } else {
             $counters = array('sale_order_add_day' => 1, 'sale_order_sum_add' => $sum);
         }
     }
     // 3. Cart
     $result = \CSaleBasket::GetList(array(), array('>=DATE_INSERT' => $from, '<=DATE_INSERT' => $to), false, false, array('LID', 'DATE_INSERT', 'PRICE', 'CURRENCY', 'QUANTITY'));
     while ($row = $result->Fetch()) {
         $day = new DateTime($row['DATE_INSERT']);
         $sum = Utils::convertToBaseCurrency($row['PRICE'] * $row['QUANTITY'], $row['CURRENCY']);
         if ($counters =& $data[$row['LID']][$day->format('Y-m-d')]) {
             $counters['sale_cart_add_day'] += 1;
             $counters['sale_cart_sum_add'] += $sum;
         } else {
             $counters = array('sale_cart_add_day' => 1, 'sale_cart_sum_add' => $sum);
         }
     }
     // Result
     unset($counters);
     $result = array();
     foreach ($data as $siteId => $dayCounters) {
         $result[] = array('ATTRIBUTES' => array('conversion_site' => $siteId), 'DAY_COUNTERS' => $dayCounters);
     }
     return $result;
 }
Ejemplo n.º 2
0
 /** Add currency value to counter. If counter not exists set counter to value.
  * @param string           $name     - counter name
  * @param int|float|string $value    - numeric value
  * @param string           $currency - currency code (eg: RUB)
  */
 public function addCurrencyCounter($name, $value, $currency)
 {
     $this->addCounter($name, Utils::convertToBaseCurrency($value, $currency));
 }
Ejemplo n.º 3
0
 /** @deprecated */
 public static function convertToBaseCurrency($value, $currency)
 {
     return Utils::convertToBaseCurrency($value, $currency);
 }