Example #1
0
 /**
  * Defines if page file should be overridden
  * 
  * @param \Bitrix\Main\Event $event Event.
  * @return string|null
  */
 public static function onFileRewrite(\Bitrix\Main\Event $event)
 {
     $path = $event->getParameter('path');
     $result = null;
     if ($context = Helper::getContext()) {
         if ($context['section'] == 'B') {
             $result = Helper::getAlternative('page', $path);
         }
     }
     return $result;
 }
Example #2
0
 public function onUserSetLastActivityDate(\Bitrix\Main\Event $event)
 {
     $users = $event->getParameter(0);
     foreach ($users as $userId) {
         $cache = \Bitrix\Main\Data\Cache::createInstance();
         if ($cache->startDataCache(60, $userId, '/im/status')) {
             $mapper = \Bitrix\Replica\Mapper::getInstance();
             $map = $mapper->getByPrimaryValue("b_im_status.USER_ID", false, $userId);
             if ($map) {
                 $guid = \Bitrix\Replica\Client\User::getLocalUserGuid($userId);
                 if ($guid && $map[$guid]) {
                     $event = array("operation" => "im_status_update", "guid" => $guid);
                     \Bitrix\Replica\Log\Client::getInstance()->write($map[$guid], $event);
                 }
             }
             $cache->endDataCache(true);
         }
     }
 }
Example #3
0
 /**
  * Extend basket data.
  *
  * @param Main\Event $event			Event.
  * @return Main\EventResult
  */
 public static function extendOrderData(Main\Event $event)
 {
     $process = true;
     $resultData = array();
     $orderData = $event->getParameter('ORDER');
     $entityList = $event->getParameter('ENTITY');
     if (empty($orderData) || !is_array($orderData)) {
         $process = false;
     } else {
         if (!isset($orderData['BASKET_ITEMS']) || !is_array($orderData['BASKET_ITEMS'])) {
             $process = false;
         }
     }
     $entityData = false;
     $iblockData = false;
     if ($process && !empty($orderData['BASKET_ITEMS'])) {
         $entityData = self::prepareEntity($entityList);
         if (empty($entityData)) {
             $process = false;
         }
     }
     if ($process) {
         $productMap = array();
         $productList = array();
         $productData = array();
         $basket = array_filter($orderData['BASKET_ITEMS'], '\\Bitrix\\Catalog\\Discount\\DiscountManager::basketFilter');
         if (!empty($basket)) {
             foreach ($basket as $basketCode => $basketItem) {
                 $basketItem['PRODUCT_ID'] = (int) $basketItem['PRODUCT_ID'];
                 $productList[] = $basketItem['PRODUCT_ID'];
                 if (!isset($productMap[$basketItem['PRODUCT_ID']])) {
                     $productMap[$basketItem['PRODUCT_ID']] = array();
                 }
                 $productMap[$basketItem['PRODUCT_ID']][] =& $basket[$basketCode];
             }
             unset($basketItem, $basketCode);
             $productData = array_fill_keys($productList, array());
             $iblockData = self::getProductIblocks($productList);
             self::fillProductPropertyList($entityData, $iblockData);
         }
         if (!empty($iblockData['iblockElement'])) {
             self::getProductData($productData, $entityData, $iblockData);
         }
         if (!empty($iblockData['iblockElement'])) {
             foreach ($productData as $product => $data) {
                 if (empty($productMap[$product])) {
                     continue;
                 }
                 foreach ($productMap[$product] as &$basketItem) {
                     $basketItem['CATALOG'] = $data;
                 }
                 unset($basketItem);
             }
             unset($product, $data);
             $resultData['BASKET_ITEMS'] = $basket;
         }
         unset($basket, $productData, $productMap, $productList);
     }
     if ($process) {
         $result = new Main\EventResult(Main\EventResult::SUCCESS, $resultData, 'catalog');
     } else {
         $result = new Main\EventResult(Main\EventResult::ERROR, null, 'catalog');
     }
     unset($process, $resultData);
     return $result;
 }
Example #4
0
 public static function onAfterUpdateShipment(\Bitrix\Main\Event $event)
 {
     $result = new EventResult();
     $data = $event->getParameter('fields');
     if (!isset($data["TRACKING_NUMBER"]) && !isset($data["DELIVERY_NAME"])) {
         return $result;
     }
     $primary = $event->getParameter('id');
     $dbRes = OrderTable::getList(array('select' => array('*', 'SITE_ID' => 'ORDER.LID', 'TRADING_PLATFORM_CODE' => 'TRADING_PLATFORM.CODE', 'TRADING_PLATFORM_CLASS' => 'TRADING_PLATFORM.CLASS', 'DELIVERY_NAME' => 'SHIPMENT.DELIVERY.NAME', 'DELIVERY_ID' => 'SHIPMENT.DELIVERY_ID', 'TRACKING_NUMBER' => 'SHIPMENT.TRACKING_NUMBER'), 'filter' => array('=SHIPMENT.ID' => $primary['ID']), 'runtime' => array('SHIPMENT' => array('data_type' => 'Bitrix\\Sale\\Internals\\ShipmentTable', 'reference' => array('=this.ORDER_ID' => 'ref.ORDER_ID')))));
     if ($platformOrder = $dbRes->fetch()) {
         if (class_exists($platformOrder['TRADING_PLATFORM_CLASS']) && is_subclass_of($platformOrder['TRADING_PLATFORM_CLASS'], '\\Bitrix\\Sale\\TradingPlatform\\Platform')) {
             if ($platform = call_user_func($platformOrder['TRADING_PLATFORM_CLASS'] . '::getInstance')) {
                 $result = $platform->onAfterUpdateShipment($event, array_merge($platformOrder, array('TRACKING_NUMBER' => isset($data["TRACKING_NUMBER"]) ? $data["TRACKING_NUMBER"] : $platformOrder["TRACKING_NUMBER"], 'DELIVERY_NAME' => isset($data["DELIVERY_NAME"]) ? $data["DELIVERY_NAME"] : $platformOrder["DELIVERY_NAME"], 'DELIVERY_ID' => isset($data["DELIVERY_ID"]) ? $data["DELIVERY_ID"] : $platformOrder["DELIVERY_ID"])));
             }
         }
     }
     return $result;
 }
Example #5
0
 /**
  * @param \Bitrix\Main\Event $event
  *
  * @return \Bitrix\Main\EventResult
  */
 public function onSaleBasketItemDeleted(\Bitrix\Main\Event $event)
 {
     $originalValues = $event->getParameter('VALUES');
     if ($originalValues['FUSER_ID'] != \Bitrix\Sale\Fuser::getId(true)) {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, null, 'sale');
     }
     $allBasket = \Bitrix\Sale\Basket::loadItemsForFUser($originalValues['FUSER_ID'], SITE_ID);
     if ($allBasket) {
         $_SESSION["SALE_BASKET_PRICE"][SITE_ID] = static::getActualBasketPrice($allBasket);
     }
     return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, null, 'sale');
 }
Example #6
0
 /**
  * Set types table.
  *
  * @param Main\Event $event				Manager data.
  * @return void
  */
 protected static function initTypes(Main\Event $event)
 {
     if (self::$existCouponsManager === null) {
         self::initUseMode();
     }
     if (!self::$existCouponsManager) {
         return;
     }
     self::$types = array(self::TYPE_ONE_ROW => Sale\Internals\DiscountCouponTable::TYPE_BASKET_ROW, self::TYPE_ONE_ORDER => Sale\Internals\DiscountCouponTable::TYPE_ONE_ORDER, self::TYPE_NO_LIMIT => Sale\Internals\DiscountCouponTable::TYPE_MULTI_ORDER);
     self::$typeUnknown = $event->getParameter('COUPON_UNKNOWN');
 }
 public static function onSaleOrderPaid(Main\Event $event)
 {
     $order = $event->getParameter('ENTITY');
     if (!$order->isPaid()) {
         return;
     }
     if ($order instanceof Sale\Order) {
         $price = $order->getPrice();
         $currency = $order->getCurrency();
         if (Loader::includeModule('conversion')) {
             $context = DayContext::getEntityItemInstance('sale_order', $order->getId());
             $addMethod = defined('ADMIN_SECTION') && ADMIN_SECTION === true ? 'addCounter' : 'addDayCounter';
             $context->{$addMethod}('sale_payment_add_day', 1);
             $context->addCounter('sale_payment_add', 1);
             if ($price && $currency) {
                 $context->addCurrencyCounter('sale_payment_sum_add', $price, $currency);
             }
         }
     }
 }
Example #8
0
 /**
  * @param \Bitrix\Main\Event $event
  * @return void
  */
 public static function onAfterPostingSendRecipient(\Bitrix\Main\Event $event)
 {
     $data = $event->getParameter(0);
     if (!$data || !$data['SEND_RESULT'] || empty($data['POSTING']['MAILING_CHAIN_ID'])) {
         return;
     }
     $chainId = $data['POSTING']['MAILING_CHAIN_ID'];
     $dataRecipient = $data['RECIPIENT'];
     static $mailingParams = array();
     if (!isset($mailingParams[$chainId])) {
         $mailingParams[$chainId] = array();
         $childChainDb = MailingChainTable::getList(array('select' => array('ID', 'MAILING_ID', 'PARENT_ID', 'POSTING_ID'), 'filter' => array('=MAILING.ACTIVE' => 'Y', '=IS_TRIGGER' => 'Y', '=STATUS' => array(MailingChainTable::STATUS_WAIT, MailingChainTable::STATUS_SEND), '=PARENT_ID' => $chainId)));
         while ($childChain = $childChainDb->fetch()) {
             // add posting
             $postingAddDb = PostingTable::add(array('MAILING_ID' => $childChain['MAILING_ID'], 'MAILING_CHAIN_ID' => $childChain['ID']));
             if (!$postingAddDb->isSuccess()) {
                 continue;
             }
             $mailingParams[$chainId][] = array('POSTING_ID' => $postingAddDb->getId(), 'CHAIN' => $childChain);
         }
     }
     if (empty($mailingParams[$chainId])) {
         return;
     }
     foreach ($mailingParams[$chainId] as $mailingParamsItem) {
         $postingId = $mailingParamsItem['POSTING_ID'];
         $childChain = $mailingParamsItem['CHAIN'];
         // check email as unsubscribed
         if (Subscription::isUnsubscibed($childChain['MAILING_ID'], $data['RECIPIENT']['EMAIL'])) {
             continue;
         }
         $recipient = array('POSTING_ID' => $postingId);
         $recipient['STATUS'] = PostingRecipientTable::SEND_RESULT_NONE;
         $recipient['EMAIL'] = $dataRecipient['EMAIL'];
         if (!empty($dataRecipient['FIELDS'])) {
             $recipient['FIELDS'] = $dataRecipient['FIELDS'];
         }
         if (!empty($dataRecipient['ROOT_ID'])) {
             $recipient['ROOT_ID'] = $dataRecipient['ROOT_ID'];
         } else {
             $recipient['ROOT_ID'] = $dataRecipient['ID'];
         }
         if (!empty($dataRecipient['NAME'])) {
             $recipient['NAME'] = $dataRecipient['NAME'];
         }
         if (!empty($dataRecipient['USER_ID'])) {
             $recipient['USER_ID'] = $dataRecipient['USER_ID'];
         }
         // add recipient
         PostingTable::addRecipient($recipient, true);
         if (empty($mailingParams[$chainId]['CHAIN']['POSTING_ID'])) {
             $chainUpdateDb = MailingChainTable::update(array('ID' => $childChain['ID']), array('POSTING_ID' => $postingId));
             if ($chainUpdateDb->isSuccess()) {
                 $mailingParams[$chainId]['CHAIN']['POSTING_ID'] = $postingId;
             }
         }
     }
 }
Example #9
0
 /**
  * OnAfterRecentAdd event handler.
  * Sends "subscribe" message for b_im_message changes to peer database.
  *
  * @param \Bitrix\Main\Event $event Event object.
  *
  * @return void
  * @see \Bitrix\Im\Replica\StatusHandler::handleStatusRebindOperation
  */
 public function OnAfterRecentAdd(\Bitrix\Main\Event $event)
 {
     $userId = $event->getParameter('user_id');
     if (!$userId) {
         return;
     }
     $userGuid = \Bitrix\Replica\Client\User::getRemoteUserGuid($userId);
     if (!$userGuid) {
         return;
     }
     $mapper = \Bitrix\Replica\Mapper::getInstance();
     $map = $mapper->getByPrimaryValue("b_user.ID", false, $userId);
     if (!$map) {
         return;
     }
     $guid = key($map);
     $targetNode = current($map[$guid]);
     $domainId = getNameByDomain();
     $event = array("operation" => "im_status_rebind", "guid" => $userGuid . "@" . $targetNode, "nodes" => array($domainId), "ts" => time(), "ip" => \Bitrix\Main\Application::getInstance()->getContext()->getServer()->get('REMOTE_ADDR'));
     \Bitrix\Replica\Log\Client::getInstance()->write(array($targetNode), $event);
 }