Ejemplo n.º 1
0
 public static function catchCatalogOrder($orderId, $arFields, $arOrder, $isNew)
 {
     if (!static::isOn()) {
         return;
     }
     if (!$isNew) {
         // only new orders
         return;
     }
     $data = static::getOrderInfo($orderId);
     // catalog items only
     if (empty($data['products'])) {
         return;
     }
     // add bxuid
     $data['bx_user_id'] = static::getBxUserId();
     if (empty($data['bx_user_id']) && !empty($data['user_id'])) {
         $orderUser = UserTable::getRow(array('select' => array('BX_USER_ID'), 'filter' => array('=ID' => $data['user_id'])));
         if (!empty($orderUser) && !empty($orderUser['BX_USER_ID'])) {
             $data['bx_user_id'] = $orderUser['BX_USER_ID'];
         }
     }
     // add general info
     $data['paid'] = '0';
     $data['domain'] = Context::getCurrent()->getServer()->getHttpHost();
     $data['date'] = date(DATE_ISO8601);
     // add debug info
     global $USER;
     $data['real_user_id'] = $USER->getId() ?: 0;
     $data['cookie_size'] = count($_COOKIE);
     $data['is_admin'] = (int) $USER->IsAdmin();
     $data['admin_section'] = (int) (defined('ADMIN_SECTION') && ADMIN_SECTION);
     $data['admin_panel'] = (int) \CTopPanel::shouldShowPanel();
     // try to guess unnatural orders
     $data['artificial_order'] = (int) ($data['user_id'] != $data['real_user_id'] || !$data['cookie_size'] || $data['is_admin'] || $data['admin_section'] || $data['admin_panel']);
     CounterDataTable::add(array('TYPE' => 'order', 'DATA' => $data));
     // set bxuid to the order
     if (!empty($data['bx_user_id'])) {
         // if sale version is fresh enough
         if (OrderTable::getEntity()->hasField('BX_USER_ID')) {
             OrderTable::update($data['order_id'], array('BX_USER_ID' => $data['bx_user_id']));
         }
     }
 }