23 'sale_cart_add_day' => array(
'MODULE' =>
'sale',
'NAME' =>
'Added to cart goals',
'GROUP' =>
'day'),
24 'sale_cart_add' => array(
'MODULE' =>
'sale',
'NAME' =>
'Added to cart total'),
25 'sale_cart_sum_add' => array(
'MODULE' =>
'sale',
'NAME' =>
'Sum added to cart'),
27 'sale_order_add_day' => array(
'MODULE' =>
'sale',
'NAME' =>
'Placed orders goals',
'GROUP' =>
'day'),
28 'sale_order_add' => array(
'MODULE' =>
'sale',
'NAME' =>
'Placed orders total'),
29 'sale_order_sum_add' => array(
'MODULE' =>
'sale',
'NAME' =>
'Sum placed orders'),
31 'sale_payment_add_day' => array(
'MODULE' =>
'sale',
'NAME' =>
'Payments a day goals',
'GROUP' =>
'day'),
32 'sale_payment_add' => array(
'MODULE' =>
'sale',
'NAME' =>
'Payments a day total'),
33 'sale_payment_sum_add' => array(
'MODULE' =>
'sale',
'NAME' =>
'Added payment sum'),
39 $scale = array(0.5, 1, 1.5, 2, 5);
42 'SUM' =>
function ($value, $format =
null)
51 'sale_payment' => array(
58 'COUNTERS' => array(
'conversion_visit_day',
'sale_payment_add_day',
'sale_payment_add',
'sale_payment_add_cmpfb',
'sale_payment_sum_add'),
59 'CALCULATE' =>
function (array $counters)
61 $denominator = $counters[
'conversion_visit_day'] ?: 0;
62 $numerator = $counters[
'sale_payment_add_day'] ?: 0;
63 $quantity = $counters[
'sale_payment_add']+$counters[
'sale_payment_add_cmpfb'] ?: 0;
64 $sum = $counters[
'sale_payment_sum_add'] ?: 0;
67 'DENOMINATOR' => $denominator,
68 'NUMERATOR' => $numerator,
69 'QUANTITY' => $quantity,
70 'RATE' => $denominator ? $numerator / $denominator : 0,
76 'sale_order' => array(
83 'COUNTERS' => array(
'conversion_visit_day',
'sale_order_add_day',
'sale_order_add',
'sale_order_add_cmpfb',
'sale_order_sum_add'),
84 'CALCULATE' =>
function (array $counters)
86 $denominator = $counters[
'conversion_visit_day'] ?: 0;
87 $numerator = $counters[
'sale_order_add_day'] ?: 0;
88 $quantity = $counters[
'sale_order_add']+$counters[
'sale_order_add_cmpfb'] ?: 0;
89 $sum = $counters[
'sale_order_sum_add'] ?: 0;
92 'DENOMINATOR' => $denominator,
93 'NUMERATOR' => $numerator,
94 'QUANTITY' => $quantity,
95 'RATE' => $denominator ? $numerator / $denominator : 0,
101 'sale_cart' => array(
108 'COUNTERS' => array(
'conversion_visit_day',
'sale_cart_add_day',
'sale_cart_add',
'sale_cart_add_cmpfb',
'sale_cart_sum_add'),
109 'CALCULATE' =>
function (array $counters)
111 $denominator = $counters[
'conversion_visit_day'] ?: 0;
112 $numerator = $counters[
'sale_cart_add_day'] ?: 0;
113 $quantity = $counters[
'sale_cart_add']+$counters[
'sale_cart_add_cmpfb'] ?: 0;
114 $sum = $counters[
'sale_cart_sum_add'] ?: 0;
117 'DENOMINATOR' => $denominator,
118 'NUMERATOR' => $numerator,
119 'QUANTITY' => $quantity,
120 'RATE' => $denominator ? $numerator / $denominator : 0,
134 $result = \CSaleOrder::GetList(
139 '>=DATE_PAYED' => $from,
140 '<=DATE_PAYED' => $to,
144 array(
'LID',
'DATE_PAYED',
'PRICE',
'CURRENCY')
147 while ($row = $result->Fetch())
149 $day =
new DateTime($row[
'DATE_PAYED']);
152 if ($counters =& $data[$row[
'LID']][$day->format(
'Y-m-d')])
154 $counters[
'sale_payment_add_day'] += 1;
155 $counters[
'sale_payment_sum_add'] += $sum;
160 'sale_payment_add_day' => 1,
161 'sale_payment_sum_add' => $sum,
168 $result = \CSaleOrder::GetList(
172 '>=DATE_INSERT' => $from,
173 '<=DATE_INSERT' => $to,
177 array(
'LID',
'DATE_INSERT',
'PRICE',
'CURRENCY')
180 while ($row = $result->Fetch())
182 $day =
new DateTime($row[
'DATE_INSERT']);
185 if ($counters =& $data[$row[
'LID']][$day->format(
'Y-m-d')])
187 $counters[
'sale_order_add_day'] += 1;
188 $counters[
'sale_order_sum_add'] += $sum;
193 'sale_order_add_day' => 1,
194 'sale_order_sum_add' => $sum,
201 $result = \CSaleBasket::GetList(
204 '>=DATE_INSERT' => $from,
205 '<=DATE_INSERT' => $to,
209 array(
'LID',
'DATE_INSERT',
'PRICE',
'CURRENCY',
'QUANTITY')
212 while ($row = $result->Fetch())
214 $day =
new DateTime($row[
'DATE_INSERT']);
217 if ($counters =& $data[$row[
'LID']][$day->format(
'Y-m-d')])
219 $counters[
'sale_cart_add_day'] += 1;
220 $counters[
'sale_cart_sum_add'] += $sum;
225 'sale_cart_add_day' => 1,
226 'sale_cart_sum_add' => $sum,
237 foreach ($data as $siteId => $dayCounters)
240 'ATTRIBUTES' => array(
'conversion_site' => $siteId),
241 'DAY_COUNTERS' => $dayCounters,
257 if (!$event->getParameter(
'IS_NEW'))
260 $basketItem = $event->getParameter(
'ENTITY');
264 $price = $basketItem->getPrice();
265 $quantity = $basketItem->getQuantity();
266 $currency = $basketItem->getCurrency();
268 if ($quantity && Loader::includeModule(
'conversion'))
270 $context = DayContext::getSiteInstance($basketItem->getField(
'LID'));
272 $context->addDayCounter(
'sale_cart_add_day', 1);
273 $context->addCounter(
'sale_cart_add', 1);
275 if ($price*$quantity && $currency)
276 $context->addCurrencyCounter(
'sale_cart_sum_add', $price*$quantity, $currency);
285 self::$onBeforeBasketAddQuantity = (is_array($fields) && isset($fields[
'QUANTITY'])) ? $fields[
'QUANTITY'] : 0;
290 if (is_array($fields)
291 && isset($fields[
'PRICE'], $fields[
'QUANTITY'], $fields[
'CURRENCY'])
292 && self::$onBeforeBasketAddQuantity
293 && Loader::includeModule(
'conversion'))
295 $context = DayContext::getSiteInstance($fields[
'LID']);
296 $context->addDayCounter (
'sale_cart_add_day', 1);
297 $context->addCounter (
'sale_cart_add' , 1);
298 $context->addCurrencyCounter(
'sale_cart_sum_add', $fields[
'PRICE'] * self::$onBeforeBasketAddQuantity, $fields[
'CURRENCY']);
301 self::$onBeforeBasketAddQuantity = 0;
374 if (!$event->getParameter(
'IS_NEW'))
377 $order = $event->getParameter(
'ENTITY');
381 $price = $order->getPrice();
382 $currency = $order->getCurrency();
384 if (Loader::includeModule(
'conversion'))
386 $context = DayContext::getSiteInstance($order->getField(
'LID'));
388 $context->addDayCounter(
'sale_order_add_day', 1);
389 $context->addCounter(
'sale_order_add', 1);
390 $context->attachEntityItem(
'sale_order', $order->getId());
392 if ($price && $currency)
393 $context->addCurrencyCounter(
'sale_order_sum_add', $price, $currency);
400 if (Loader::includeModule(
'conversion'))
402 $context = DayContext::getSiteInstance($fields[
'LID']);
403 $context->addDayCounter (
'sale_order_add_day', 1);
404 $context->addCounter (
'sale_order_add' , 1);
405 $context->addCurrencyCounter(
'sale_order_sum_add', $fields[
'PRICE'], $fields[
'CURRENCY']);
406 $context->attachEntityItem (
'sale_order', $id);
414 $order = $event->getParameter(
'ENTITY');
415 if (Loader::includeModule(
'conversion') && $order instanceof
Sale\
Order)
417 self::updatePaidOrderConversion(
420 $order->getCurrency(),
421 Date::createFromText($order->getField(
'DATE_PAYED')),
429 if (Loader::includeModule(
'conversion') && ($row = \CSaleOrder::GetById($id)))
431 self::updatePaidOrderConversion(
435 new Date($row[
'DATE_PAYED'],
'Y-m-d H:i:s'),
451 private static function updatePaidOrderConversion($orderId, $price, $currency, $day, $isPaid)
453 $context = DayContext::getEntityItemInstance(
'sale_order', $orderId);
454 $isAdminSection = defined(
'ADMIN_SECTION') && ADMIN_SECTION ===
true;
460 $context->addCounter(
'sale_payment_add_day', 1);
464 $context->addDayCounter(
'sale_payment_add_day', 1);
467 $context->addCounter(
'sale_payment_add', 1);
468 $context->addCurrencyCounter(
'sale_payment_sum_add', $price, $currency);
474 $context->subCounter($day,
'sale_payment_add_day', 1);
478 $context->subDayCounter($day,
'sale_payment_add_day', 1);
481 $context->subCounter($day,
'sale_payment_add', 1);
482 $context->subCurrencyCounter($day,
'sale_payment_sum_add', $price, $currency);
static getBaseCurrencyUnit()
static formatToBaseCurrency($value, $format=null)
static convertToBaseCurrency($value, $currency)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static onBeforeBasketUpdate($id, $fields=null)
static onBasketDelete($id)
static onSaleOrderPaid(Main\Event $event)
static onSalePayOrder($id, $paid)
static onGenerateInitialData(Date $from, Date $to)
static $onBeforeBasketAddQuantity
static onBasketUpdate($id, $fields)
static onBasketAdd($id, $fields)
static onOrderAdd($id, array $fields)
static onSaleBasketItemSaved(Main\Event $event)
static onSaleOrderSaved(Main\Event $event)
static onBeforeBasketDelete($id)
static onGetCounterTypes()
static onBeforeBasketAdd( $fields)