10if (Loader::includeModule(
'sender'))
12 class TargetSaleMailConnector
extends \Bitrix\Sender\Connector
14 public function getName()
19 public function getCode()
24 public function getData()
26 $productIds = array();
28 if (is_array($this->getFieldValue(
'PRODUCTS')) && count($this->getFieldValue(
'PRODUCTS')))
30 $productIds = array_values($this->getFieldValue(
'PRODUCTS'));
33 $userProducts = array();
35 foreach ($productIds as $productId)
37 $response = \Bitrix\Sale\Bigdata\Cloud::getPotentialConsumers($productId);
39 if (!empty($response[
'users']))
41 foreach ($response[
'users'] as $userId)
43 $userProducts[(string) $userId][] = $productId;
50 if (!empty($userProducts))
52 $result = \Bitrix\Main\UserTable::getList(array(
53 'select' => array(
'USER_ID' =>
'ID',
'NAME',
'EMAIL'),
55 '=ID' => array_keys($userProducts)
59 while ($row = $result->fetch())
61 $row[
'PRODUCTS'] = $userProducts[$row[
'USER_ID']];
70 public static function getPersonalizeList()
75 'NAME' =>
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_PRODUCTS_TITLE'),
76 'DESC' =>
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_PRODUCTS_DESC')
81 public function getForm()
84 $html =
'<div id="send_bigdata_pcons_list_%CONNECTOR_NUM%" style="margin-bottom: 20px">';
87 $html .=
'<input type="hidden" id="send_bigdata_changeform_dummy_%CONNECTOR_NUM%" name="'.$this->getFieldName(
'RND').
'" value="">';
94 function deleteProduct_%CONNECTOR_NUM%(id)
96 var li = BX('send_bigdata_pcons_list_%CONNECTOR_NUM%_e' + id);
99 BX('send_bigdata_changeform_dummy_%CONNECTOR_NUM%').value = Math.random();
100 BX.fireEvent(BX('send_bigdata_changeform_dummy_%CONNECTOR_NUM%'), 'change');
104 function catchProduct_%CONNECTOR_NUM%(e)
107 if (BX('send_bigdata_pcons_list_%CONNECTOR_NUM%_e'+e.id))
112 // check if there is already limit
115 var currentCount = BX.findChildren(BX('send_bigdata_pcons_list_%CONNECTOR_NUM%'), {tag: 'li'}).length;
117 if (currentCount >= limit)
120 var obPopupWin = BX.PopupWindowManager.create('sender_select_products_limit_%CONNECTOR_NUM%', null, {
127 closeIcon: {top: '10px', right: '10px'}
130 obPopupWin.setTitleBar({
132 'span', {html: '<b>' + '".\CUtil::JSEscape(
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_SELECT_LIMIT_TITLE')).
"' + '</b>', 'props': {'className': 'access-title-bar'}}
136 var msg = '".\CUtil::JSEscape(
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_SELECT_LIMIT_MSG')).
"';
137 msg = msg.replace('#LIMIT#', limit);
139 obPopupWin.setContent(msg);
140 obPopupWin.setButtons([new BX.PopupWindowButton({
141 text: '".\CUtil::JSEscape(
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_SELECT_LIMIT_CLOSE')).
"',
142 events: {click: function(){
143 this.popupWindow.close();
153 var fieldName = \"{$this->getFieldName('PRODUCTS[]')}\".replace(\"\[\]\", \"[\"+e.id+\"]\");
154 var itemElement = document.createElement('li');
155 var title = e.name + ' (' + e.id + ') ';
157 itemElement.id = 'send_bigdata_pcons_list_%CONNECTOR_NUM%_e'+e.id;
158 itemElement.innerHTML = title + ' [ <a href=\"#\" onclick=\"deleteProduct_%CONNECTOR_NUM%('+e.id+'); return false;\">'+'".\CUtil::JSEscape(
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_SELECT_DEL')).
"'+'</a> ]';
159 itemElement.innerHTML += '<input type=\"hidden\" name=\"'+fieldName+'\" value=\"'+e.id+'\"> ';
161 BX('send_bigdata_pcons_list_%CONNECTOR_NUM%').appendChild(itemElement);
164 function AddProductSearch_%CONNECTOR_NUM%()
166 var productPopup = new BX.CDialog({
167 content_url: '/bitrix/tools/sale/product_search_dialog.php?lang=".LANGUAGE_ID.
"&caller=sender_target_sale&func_name=catchProduct_%CONNECTOR_NUM%',
168 height: Math.max(500, window.innerHeight-400),
169 width: Math.max(800, window.innerWidth-400),
176 BX.addCustomEvent(productPopup, 'onBeforeWindowClose', function(){
177 BX.fireEvent(BX('send_bigdata_changeform_dummy_%CONNECTOR_NUM%'), 'change');
184 <button onclick='AddProductSearch_%CONNECTOR_NUM%(); return false;'>".htmlspecialcharsbx(
Loc::getMessage(
'SALE_BIGDATA_TARGET_CONNECTOR_SELECT_TITLE')).
"</button>
187 if ($this->getFieldValue(
'PRODUCTS'))
192 $result = \Bitrix\Iblock\ElementTable::getList(array(
193 'select' => array(
'ID',
'NAME'),
194 'filter' => array(
'=ID' => $this->getFieldValue(
'PRODUCTS'))
197 while ($row = $result->fetch())
199 $titles[(int) $row[
'ID']] = $row[
'NAME'];
203 $html .=
"<script>".PHP_EOL;
205 foreach ($this->getFieldValue(
'PRODUCTS') as
$productId)
207 $html .=
'catchProduct_%CONNECTOR_NUM%('.\CUtil::PhpToJSObject(array(
209 'name' => $titles[(
int) $productId]
214 $html .=
"</script>";
220 public static function onConnectorList()
222 $arData[
'CONNECTOR'] = __CLASS__;
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)