fix
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
<?
|
<?php
|
||||||
$MESS['MAIN_OPTIONS_PARAMETERS'] = 'Общие';
|
$MESS['MAIN_OPTIONS_PARAMETERS'] = 'Общие';
|
||||||
+2
-3
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use \Bitrix\Main\Localization\Loc;
|
use Bitrix\Main\Localization\Loc;
|
||||||
use Wt\Core\Admin\GlobalMenuItem;
|
use Wt\Core\Admin\GlobalMenuItem;
|
||||||
|
|
||||||
Loc::loadMessages(__FILE__);
|
Loc::loadMessages(__FILE__);
|
||||||
|
|
||||||
|
|
||||||
return (new GlobalMenuItem())
|
return (new GlobalMenuItem())
|
||||||
->setSort(10)
|
->setSort(10)
|
||||||
->setTitle('Discount Main');
|
->setTitle('Discount');
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
use Bx\Discount\ORM\DiscountTable;
|
use Bx\Discount\ORM\DiscountTable;
|
||||||
use Wt\Core\Admin\TableRowAdminPage;
|
use Wt\Core\Admin\TableRowAdminPage;
|
||||||
|
|
||||||
|
|
||||||
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_before.php');
|
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_before.php');
|
||||||
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_after.php');
|
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_after.php');
|
||||||
/**
|
/**
|
||||||
@@ -15,6 +14,4 @@ $AdminPageTableRow = new TableRowAdminPage($ormTable, $_REQUEST, '/bitrix/admin/
|
|||||||
$AdminPageTableRow->checkPermission();
|
$AdminPageTableRow->checkPermission();
|
||||||
$AdminPageTableRow->start();
|
$AdminPageTableRow->start();
|
||||||
|
|
||||||
\CJSCore::Init('jquery');
|
|
||||||
|
|
||||||
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin.php');
|
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin.php');
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Wt\Core\Admin\SiteSettingsAdminPage;
|
use Wt\Core\Admin\SiteSettingsAdminPage;
|
||||||
|
use Wt\Core\Tools;
|
||||||
|
|
||||||
IncludeModuleLangFile(__FILE__);
|
IncludeModuleLangFile(__FILE__);
|
||||||
|
|
||||||
@@ -12,17 +13,17 @@ return [
|
|||||||
'MAIN' => [
|
'MAIN' => [
|
||||||
'TITLE' => 'Общие сведения',
|
'TITLE' => 'Общие сведения',
|
||||||
'OPTIONS' => [
|
'OPTIONS' => [
|
||||||
'ENABLE' => [
|
|
||||||
'TITLE' => 'Enable module',
|
|
||||||
'TYPE' => 'checkbox',
|
|
||||||
'DEFAULT' => 'N',
|
|
||||||
'HINT' => '',
|
|
||||||
],
|
|
||||||
'CONFIG' => [
|
'CONFIG' => [
|
||||||
'TITLE' => 'Конфигурационные данные',
|
'TITLE' => 'Config',
|
||||||
'HINT' => '',
|
|
||||||
'TYPE' => 'content',
|
'TYPE' => 'content',
|
||||||
'INCLUDEFILE' => \Wt\Core\Tools::removeDocRoot(__DIR__ . '/include/config.php'),
|
'INCLUDEFILE' => Tools::removeDocRoot(__DIR__ . '/include/config.php'),
|
||||||
|
'SHOW_EDIT_BUTTON' => 'N',
|
||||||
|
'DEFAULT' => '',
|
||||||
|
],
|
||||||
|
'AGENTS' => [
|
||||||
|
'TITLE' => 'Агенты',
|
||||||
|
'TYPE' => 'content',
|
||||||
|
'INCLUDEFILE' => Tools::removeDocRoot(__DIR__ . '/include/agents.php'),
|
||||||
'SHOW_EDIT_BUTTON' => 'N',
|
'SHOW_EDIT_BUTTON' => 'N',
|
||||||
'DEFAULT' => '',
|
'DEFAULT' => '',
|
||||||
],
|
],
|
||||||
@@ -34,7 +35,7 @@ return [
|
|||||||
'DOCUMENTATION' => [
|
'DOCUMENTATION' => [
|
||||||
'TITLE' => 'Documentation',
|
'TITLE' => 'Documentation',
|
||||||
'TYPE' => 'content',
|
'TYPE' => 'content',
|
||||||
'INCLUDEFILE' => \Wt\Core\Tools::removeDocRoot(__DIR__ . '/include/documentation.php'),
|
'INCLUDEFILE' => Tools::removeDocRoot(__DIR__ . '/include/documentation.php'),
|
||||||
'SHOW_EDIT_BUTTON' => 'N',
|
'SHOW_EDIT_BUTTON' => 'N',
|
||||||
'DEFAULT' => '',
|
'DEFAULT' => '',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var Wt\Core\Admin\Templater $this
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Bx\Discount\Agents\SpiderAgentManager;
|
||||||
|
|
||||||
|
$moduleId = $this->getAdminPage()->getModuleId();
|
||||||
|
$agentCase = new SpiderAgentManager();
|
||||||
|
|
||||||
|
$this->renderAgentCase($agentCase);
|
||||||
@@ -2,10 +2,48 @@
|
|||||||
/**
|
/**
|
||||||
* @var Wt\Core\Admin\Templater $this
|
* @var Wt\Core\Admin\Templater $this
|
||||||
*/
|
*/
|
||||||
$moduleId = $this->getAdminPage()->getModuleId();
|
use Wt\Core\Support\System;
|
||||||
$app = app()::getInstance($moduleId);
|
|
||||||
|
$system = new System();
|
||||||
|
$config = discountApp()->config();
|
||||||
$data = [];
|
$data = [];
|
||||||
$data['env'] = $app->env();
|
$data['env'] = discountApp()->env();
|
||||||
|
$data['ENABLE'] = $this->getCheckTemplate($config->get('ENABLE'));
|
||||||
|
$data['UPDATE_ELEMENT_INDEX'] = $this->getCheckTemplate($config->get('UPDATE_ELEMENT_INDEX'));
|
||||||
|
$data['DISCOUNT_TYPE_IBLOCK_ID'] = $discountTypeIBlockId = $config->get('DISCOUNT_TYPE_IBLOCK_ID');
|
||||||
|
if($discountTypeIBlockId){
|
||||||
|
$blockEntity = app()->factory()->main()->getIBlockFactory()->getEntityById($discountTypeIBlockId);
|
||||||
|
if($blockEntity){
|
||||||
|
$data['DISCOUNT_TYPE_IBLOCK_ID'] = "[$discountTypeIBlockId] {$blockEntity->getName()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['CATALOG_IBLOCK_ID'] = $catalogIBlockId = $config->get('CATALOG_IBLOCK_ID');
|
||||||
|
if($catalogIBlockId){
|
||||||
|
$blockEntity = app()->factory()->main()->getIBlockFactory()->getEntityById($catalogIBlockId);
|
||||||
|
if($blockEntity){
|
||||||
|
$data['CATALOG_IBLOCK_ID'] = "[$catalogIBlockId] {$blockEntity->getName()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['TICKET_PROP_ID'] = $ticketPropId = $config->get('TICKET_PROP_ID');
|
||||||
|
$propertyEntity = null;
|
||||||
|
if($ticketPropId){
|
||||||
|
$blockAFactory = app()->factory()->iBlock()->getEntityById($catalogIBlockId);
|
||||||
|
if($blockAFactory){
|
||||||
|
$propertyEntity = $blockAFactory->getPropertyFactory()->getEntityById($ticketPropId);
|
||||||
|
$linkTemplate = "<a href=\"/bitrix/admin/iblock_edit_property.php?ID=$ticketPropId&lang=ru&IBLOCK_ID=$catalogIBlockId\" target=\"_blank\">$ticketPropId</a>";
|
||||||
|
$data['TICKET_PROP_ID'] = "[$linkTemplate] {$propertyEntity->getName()} ({$propertyEntity->getFullType()})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['CATALOG_GROUP_ID'] = $priceTypeId = $config->get('CATALOG_GROUP_ID');
|
||||||
|
if($priceTypeId){
|
||||||
|
$priceTypeEntity = app()->factory()->shop()->getPriceTypeFactory()->getEntityById($priceTypeId);
|
||||||
|
if($priceTypeEntity){
|
||||||
|
$linkTemplate = "<a href=\"/bitrix/admin/cat_group_edit.php?ID=$priceTypeId\" target=\"_blank\">$priceTypeId</a>";
|
||||||
|
$data['CATALOG_GROUP_ID'] = "[$linkTemplate] {$priceTypeEntity->getName()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['PAGE_SIZE'] = $config->get('PAGE_SIZE');
|
||||||
|
$data['RENEWAL_PERIOD'] = $config->get('RENEWAL_PERIOD');
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -14,36 +52,25 @@ $data['env'] = $app->env();
|
|||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
?><tr><td><?= $key ?></td><td><?= $value ?></td></tr><?php
|
?><tr><td><?= $key ?></td><td><?= $value ?></td></tr><?php
|
||||||
}
|
}
|
||||||
?></table>
|
?><tr><td>MAP</td><td><?php
|
||||||
<br><?php
|
if($config->get('MAP', [])->count()){
|
||||||
|
|
||||||
?><table cellpadding="5" border="1" style="border-collapse: collapse; width: 100%">
|
?><table style="width: 100%;">
|
||||||
<tr>
|
<tr style="font-size: 0.8em; color: #6e6e6e"><td>type</td><td>ticket item</td></tr>
|
||||||
<?php
|
<?php foreach ($config->get('MAP', []) as $type => $id){?>
|
||||||
$initPhpSrc = getLocalPath('php_interface/init.php', BX_PERSONAL_ROOT);
|
<tr><td><?= $type ?></td><td><?php
|
||||||
$src = $app->module()->getSrc();
|
if($propertyEntity){
|
||||||
$html = "<div style=\"font-family: monospace; font-size: 0.9em; white-space: pre; color: grey;\">if(file_exists(\$_SERVER['DOCUMENT_ROOT'] . '$src/init.php'))
|
$valueFactory = $propertyEntity->getAdapter()->getValueFactory();
|
||||||
include_once \$_SERVER['DOCUMENT_ROOT'] . '$src/init.php';</div>";
|
$entity = $valueFactory->getEntityById($id);
|
||||||
?>
|
if($entity){
|
||||||
<td>
|
echo "[{$entity->getId()}] {$entity->getName()}";
|
||||||
<?=$this->getCheckTemplate($app->isIncludeFileToInitPhp())?>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Модуль подключен в init.php
|
|
||||||
</td>
|
|
||||||
<td width="50%">
|
|
||||||
<?php
|
|
||||||
if($initPhpSrc){
|
|
||||||
?><a target="_blank" href="/bitrix/admin/fileman_file_edit.php?path=<?=urlencode($initPhpSrc)?>&full_src=Y">
|
|
||||||
<?=$initPhpSrc?>
|
|
||||||
</a><?php
|
|
||||||
} else {
|
|
||||||
?>init.php отсутствует<?php
|
|
||||||
}
|
}
|
||||||
?>
|
}
|
||||||
<br>
|
?></td></tr>
|
||||||
<?=$html?>
|
<?php }?>
|
||||||
</td>
|
</table><?php
|
||||||
</tr>
|
} else {
|
||||||
</table>
|
?><i>empty</i><?php
|
||||||
<br>
|
}
|
||||||
|
?></td></tr><?php
|
||||||
|
?></table>
|
||||||
@@ -1 +1,26 @@
|
|||||||
Документация
|
<a href="/bitrix/admin/cat_discount_admin.php?lang=ru" target="_blank">Catalog: Скидки</a>
|
||||||
|
<br>
|
||||||
|
<a href="/bitrix/admin/sale_discount.php?lang=ru" target="_blank">Sale: Скидки</a>
|
||||||
|
<br>
|
||||||
|
<a href="/bitrix/admin/iblock_list_admin.php?IBLOCK_ID=24&type=system_settings&lang=ru&find_section_section=0&SECTION_ID=0&apply_filter=Y" target="_blank">Таблица с типами скидкок</a>
|
||||||
|
<br>
|
||||||
|
<a href="/bitrix/admin/perfmon_table.php?PAGEN_1=1&SIZEN_1=20&lang=ru&set_filter=Y&adm_filter_applied=0&table_name=b_option&find=bx.discount&find_type=MODULE_ID" target="_blank">Таблица c настройками паука</a>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div class="adm-info-message-wrap">
|
||||||
|
<div class="adm-info-message">
|
||||||
|
Перед <a href="/bitrix/admin/sale_discount_catalog_migrator.php" target="_blank">миграцией</a> важно сохранить ID скидок <br>
|
||||||
|
bitrix/modules/sale/admin/discount_catalog_migrator.php:377<br>
|
||||||
|
DiscountCatalogMigrator::migrateDiscounts<br>
|
||||||
|
в $newData добавить ID
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<code style="font-family: monospace;white-space: pre;">
|
||||||
|
$newData = array(
|
||||||
|
'ID' => $discount['ID'],
|
||||||
|
'XML_ID' => $discount['XML_ID'],
|
||||||
|
...
|
||||||
|
);
|
||||||
|
</code>
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
<?
|
<?php
|
||||||
$MESS['CONTEXT_PROFILE_DELETE_CONFIRM'] = 'Удалить %s?';
|
$MESS['CONTEXT_PROFILE_DELETE_CONFIRM'] = 'Удалить %s?';
|
||||||
@@ -7,5 +7,5 @@ Loc::loadMessages(__FILE__);
|
|||||||
|
|
||||||
return (new GlobalMenuItem())
|
return (new GlobalMenuItem())
|
||||||
->setSort(5)
|
->setSort(5)
|
||||||
->setTitle('Settings')
|
->setTitle('settings')
|
||||||
->setUrl();
|
->setUrl();
|
||||||
+50
-10
@@ -1,21 +1,61 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//$config['events']['main:OnPageStart'][] = ['Bx\\Discount\\Handlers\\SaleDiscountEditPage', 'onPageStartHandler'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'MainAbstractFactory' => [
|
'ENABLE' => false,
|
||||||
'Bx\Discount\Factory\DiscountFactory' => ['cache' => ['hit'], 'is_collection_query' => true],
|
'UPDATE_ELEMENT_INDEX' => false,
|
||||||
|
'PAGE_SIZE' => 100,
|
||||||
|
'RENEWAL_PERIOD' => 604800,
|
||||||
|
|
||||||
|
'CATALOG_IBLOCK_ID' => 0,
|
||||||
|
'DISCOUNT_TYPE_IBLOCK_ID' => 0,
|
||||||
|
'CATALOG_GROUP_ID' => 0,
|
||||||
|
|
||||||
|
'TICKET_PROP_ID' => 0,
|
||||||
|
'MAP' => [
|
||||||
|
'A' => 0,
|
||||||
|
'R' => 0,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
'events' => [
|
'events' => [
|
||||||
'main:OnPageStart' => [
|
'main:OnBeforeProlog' => ['Bx\\Discount\\Handlers\\SaleDiscountEditPage', 'onPageStartHandler'],
|
||||||
['Bx\Discount\Handlers\Autoloader', 'onPageStart'],
|
|
||||||
|
|
||||||
|
'sale:DiscountOnBeforeAdd' => ['Bx\Discount\Handlers\SaleDiscount', 'onBeforeAdd'],
|
||||||
|
'sale:DiscountOnAfterAdd' => [
|
||||||
|
['Bx\Discount\Handlers\SaleDiscount', 'onAfterAdd'],
|
||||||
|
['Bx\Discount\Handlers\SpiderHandler', 'saleDiscountOnAfterAdd'],
|
||||||
],
|
],
|
||||||
'main:OnProlog' => [
|
'sale:DiscountOnBeforeUpdate' => ['Bx\Discount\Handlers\SaleDiscount', 'onBeforeUpdate'],
|
||||||
['Bx\Discount\Handlers\Autoloader', 'onProlog'],
|
'sale:DiscountOnAfterUpdate' => [
|
||||||
|
['Bx\Discount\Handlers\SaleDiscount', 'onAfterUpdate'],
|
||||||
|
['Bx\Discount\Handlers\SpiderHandler', 'saleDiscountOnAfterUpdate'],
|
||||||
],
|
],
|
||||||
'main:OnEpilog' => [
|
'sale:DiscountOnBeforeDelete' => ['Bx\Discount\Handlers\SaleDiscount', 'onBeforeDelete'],
|
||||||
['Bx\Discount\Handlers\Autoloader', 'onEpilog'],
|
'sale:DiscountOnAfterDelete' => [
|
||||||
|
['Bx\Discount\Handlers\SaleDiscount', 'onAfterDelete'],
|
||||||
|
['Bx\Discount\Handlers\SpiderHandler', 'saleDiscountOnAfterDelete'],
|
||||||
],
|
],
|
||||||
'main:OnBeforeProlog' => [
|
|
||||||
['Bx\Discount\Handlers\Autoloader', 'onBeforeProlog'],
|
|
||||||
|
'catalog:OnBeforeDiscountAdd' => ['Bx\Discount\Handlers\CatalogDiscount', 'onBeforeAdd'],
|
||||||
|
'catalog:OnDiscountAdd' => [
|
||||||
|
['Bx\Discount\Handlers\CatalogDiscount', 'onAfterAdd'],
|
||||||
|
['Bx\Discount\Handlers\SpiderHandler', 'saleDiscountOnAfterAdd'],
|
||||||
],
|
],
|
||||||
|
'catalog:OnBeforeDiscountUpdate' => ['Bx\Discount\Handlers\CatalogDiscount', 'onBeforeUpdate'],
|
||||||
|
'catalog:OnDiscountUpdate' => [
|
||||||
|
['Bx\Discount\Handlers\CatalogDiscount', 'onAfterUpdate'],
|
||||||
|
['Bx\Discount\Handlers\SpiderHandler', 'saleDiscountOnAfterUpdate'],
|
||||||
],
|
],
|
||||||
|
'catalog:OnBeforeDiscountDelete' => ['Bx\Discount\Handlers\CatalogDiscount', 'onBeforeDelete'],
|
||||||
|
'catalog:OnDiscountDelete' => [
|
||||||
|
['Bx\Discount\Handlers\CatalogDiscount', 'onAfterDelete'],
|
||||||
|
['Bx\Discount\Handlers\SpiderHandler', 'saleDiscountOnAfterDelete'],
|
||||||
|
],
|
||||||
|
'catalog:OnGetDiscountResult' => [
|
||||||
|
['Bx\Discount\Handlers\CatalogDiscount', 'onGetDiscountResult'],
|
||||||
|
],
|
||||||
|
]
|
||||||
];
|
];
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Agents;
|
||||||
|
|
||||||
|
use Wt\Core\Agent\AAgentCase;
|
||||||
|
|
||||||
|
class SpiderAgentManager extends AAgentCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAgentConfig()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'exec' => [
|
||||||
|
'NEXT_EXEC' => $this->getNextExecLater(1),
|
||||||
|
'MODULE_ID' => discountApp()->module()->getId(),
|
||||||
|
'AGENT_INTERVAL' => 60,
|
||||||
|
'IS_PERIOD' => 'Y',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function exec($arAgent)
|
||||||
|
{
|
||||||
|
ini_set('max_execution_time', 0);
|
||||||
|
ini_set('memory_limit', -1);
|
||||||
|
@set_time_limit(0);
|
||||||
|
|
||||||
|
|
||||||
|
$agent = null;
|
||||||
|
if (is_array($arAgent) && $arAgent['ID']) {
|
||||||
|
$agent = app()->factory()->main()->getAgentFactory()->getEntityById($arAgent['ID']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$spider = discountApp()->service()->spider();
|
||||||
|
$spider->setAgent($agent);
|
||||||
|
$spider->next();
|
||||||
|
|
||||||
|
return static::class . "::exec(\$arAgent);";
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
-1
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Bx\Discount\Ajax;
|
namespace Bx\Discount\Ajax;
|
||||||
|
|
||||||
|
use Bx\Discount\Agents\SpiderAgentManager;
|
||||||
use Wt\Core\Ajax\AAjaxHandler;
|
use Wt\Core\Ajax\AAjaxHandler;
|
||||||
|
|
||||||
class BxDiscount extends AAjaxHandler
|
class BxDiscount extends AAjaxHandler
|
||||||
@@ -11,9 +12,21 @@ class BxDiscount extends AAjaxHandler
|
|||||||
$this->getResponse()->addData(['method' => 'ajaxStart']);
|
$this->getResponse()->addData(['method' => 'ajaxStart']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function spiderAgentDelete()
|
||||||
|
{
|
||||||
|
$agentManager = new SpiderAgentManager();
|
||||||
|
$agentManager->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function spiderAgentAdd()
|
||||||
|
{
|
||||||
|
$agentManager = new SpiderAgentManager();
|
||||||
|
$agentManager->add();
|
||||||
|
}
|
||||||
|
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
$this->getResponse()->addData(['method' => 'test', 'version' => app()::getInstance('bx.discount')->module()->getVersion()]);
|
$this->getResponse()->addData(['method' => 'test', 'version' => discountApp()->module()->getVersion()]);
|
||||||
return $this->getResponse();
|
return $this->getResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount;
|
||||||
|
|
||||||
|
use Wt\Core\Entity\AgentEntity;
|
||||||
|
|
||||||
|
class ElementSpider
|
||||||
|
{
|
||||||
|
protected $agent;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function next()
|
||||||
|
{
|
||||||
|
if(!$this->canDo()){
|
||||||
|
if($this->isDataExpired()){
|
||||||
|
$this->reset();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lastId = $this->getLastId();
|
||||||
|
if($lastId == 0){
|
||||||
|
$this->setBeginTimestamp();
|
||||||
|
}
|
||||||
|
$iBlockId = discountApp()->config('CATALOG_IBLOCK_ID');
|
||||||
|
$ids = Tools::getElementList($lastId);
|
||||||
|
if(count($ids) == 0){
|
||||||
|
$this->setEndTimestamp();
|
||||||
|
}
|
||||||
|
$__lastId = 0;
|
||||||
|
foreach ($ids as $id){
|
||||||
|
$__lastId = $id;
|
||||||
|
Tools::setTicketValueFromDiscount($id);
|
||||||
|
}
|
||||||
|
$this->setLastId($__lastId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canDo()
|
||||||
|
{
|
||||||
|
$resetTimestamp = $this->getResetTimestamp();
|
||||||
|
$spiderBeginTimestamp = $this->getBeginTimestamp();
|
||||||
|
$spiderEndTimestamp = $this->getEndTimestamp();
|
||||||
|
|
||||||
|
return ($resetTimestamp > $spiderEndTimestamp)
|
||||||
|
|| ($resetTimestamp > $spiderBeginTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDataExpired()
|
||||||
|
{
|
||||||
|
$spiderEndTimestamp = $this->getEndTimestamp();
|
||||||
|
$renewalPeriod = discountApp()->config('RENEWAL_PERIOD');
|
||||||
|
return $spiderEndTimestamp + $renewalPeriod < time();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastId()
|
||||||
|
{
|
||||||
|
return (int)discountApp()->setting()->get('last_id', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLastId($lastId)
|
||||||
|
{
|
||||||
|
discountApp()->setting()->set('last_id', (int)$lastId);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBeginTimestamp()
|
||||||
|
{
|
||||||
|
discountApp()->setting()->set('spider_begin_timestamp', time());
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBeginTimestamp()
|
||||||
|
{
|
||||||
|
return (int)discountApp()->setting()->get('spider_begin_timestamp', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEndTimestamp()
|
||||||
|
{
|
||||||
|
discountApp()->setting()->set('spider_end_timestamp', time());
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEndTimestamp()
|
||||||
|
{
|
||||||
|
return (int)discountApp()->setting()->get('spider_end_timestamp', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResetTimestamp()
|
||||||
|
{
|
||||||
|
discountApp()->setting()->set('spider_reset_timestamp', time());
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResetTimestamp()
|
||||||
|
{
|
||||||
|
return (int)discountApp()->setting()->get('spider_reset_timestamp', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset()
|
||||||
|
{
|
||||||
|
$this->setLastId(0);
|
||||||
|
$this->setResetTimestamp();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAgent($agent)
|
||||||
|
{
|
||||||
|
$this->agent = $agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return AgentEntity|null
|
||||||
|
*/
|
||||||
|
public function getAgent()
|
||||||
|
{
|
||||||
|
return $this->agent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,18 @@
|
|||||||
|
|
||||||
namespace Bx\Discount\Facade;
|
namespace Bx\Discount\Facade;
|
||||||
|
|
||||||
|
use Bx\Discount\ElementSpider;
|
||||||
use Wt\Core\Facade\AFacade;
|
use Wt\Core\Facade\AFacade;
|
||||||
|
|
||||||
class DefaultServiceFacade extends AFacade
|
class DefaultServiceFacade extends AFacade
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ElementSpider
|
||||||
|
*/
|
||||||
|
public function spider()
|
||||||
|
{
|
||||||
|
return $this->app->container()->make(ElementSpider::class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Handlers;
|
||||||
|
|
||||||
|
use Bitrix\Main\Entity\Event;
|
||||||
|
use Bx\Discount\Tools;
|
||||||
|
|
||||||
|
class ADiscount
|
||||||
|
{
|
||||||
|
protected static array $lang = [
|
||||||
|
'EMPTY_PRODUCT_TYPE' => 'Не выбран тип визуального представления скидки на сайте'
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function getLang($code)
|
||||||
|
{
|
||||||
|
return static::$lang[$code];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function isValidData()
|
||||||
|
{
|
||||||
|
return isset($_POST['PRODUCT_TYPE']) && $_POST['PRODUCT_TYPE'] !== '0' && $_POST['PRODUCT_TYPE'] !== '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static function updateAdditionalDiscountData($id)
|
||||||
|
{
|
||||||
|
|
||||||
|
$depsLoaded = \Bitrix\Main\Loader::includeModule('iblock');
|
||||||
|
if(!$depsLoaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$res_element = \CIBlockElement::GetList(
|
||||||
|
['SORT' => 'ASC'],
|
||||||
|
['IBLOCK_ID' => discountApp()->config('DISCOUNT_TYPE_IBLOCK_ID'), 'NAME' => $id],
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
['ID', 'NAME', 'PROPERTY_TYPE']
|
||||||
|
);
|
||||||
|
$res_element_count = $res_element->SelectedRowsCount();
|
||||||
|
if($res_element_count){
|
||||||
|
$obElement = $res_element->GetNext();
|
||||||
|
\CIBlockElement::SetPropertyValuesEx(
|
||||||
|
$obElement['ID'],
|
||||||
|
discountApp()->config('DISCOUNT_TYPE_IBLOCK_ID'),
|
||||||
|
[
|
||||||
|
'TYPE' => $_POST['PRODUCT_TYPE'],
|
||||||
|
'MIN_COUNT_PROD' => $_POST['MIN_COUNT_PROD']
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$el = new \CIBlockElement();
|
||||||
|
$arTypeField = [
|
||||||
|
'IBLOCK_ID' => discountApp()->config('DISCOUNT_TYPE_IBLOCK_ID'),
|
||||||
|
'NAME' => $id,
|
||||||
|
'PROPERTY_VALUES' => [
|
||||||
|
'TYPE' => $_POST['PRODUCT_TYPE'],
|
||||||
|
'MIN_COUNT_PROD' => $_POST['MIN_COUNT_PROD'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$el->Add($arTypeField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function addAdditionalDiscountData($id)
|
||||||
|
{
|
||||||
|
$depsLoaded = \Bitrix\Main\Loader::includeModule('iblock');
|
||||||
|
if(!$depsLoaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$el = new \CIBlockElement();
|
||||||
|
$arTypeField = [
|
||||||
|
'IBLOCK_ID' => discountApp()->config('DISCOUNT_TYPE_IBLOCK_ID'),
|
||||||
|
'NAME' => $id,
|
||||||
|
'PROPERTY_VALUES' => [
|
||||||
|
'TYPE' => $_POST['PRODUCT_TYPE'],
|
||||||
|
'MIN_COUNT_PROD' => $_POST['MIN_COUNT_PROD'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$r = $el->Add($arTypeField);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Немного бреда с седых времен
|
||||||
|
* я хз что тут происходит
|
||||||
|
* коммент от старого разработчика: при поиске оптимальной цены на товар не учитываем скидки типа "От кол-ва"
|
||||||
|
* @see /local/php_interface/include/events.php [git history]
|
||||||
|
* @see BxDiscount [old functions]
|
||||||
|
*
|
||||||
|
* Желательно избавиться от функционала Q !!!
|
||||||
|
*
|
||||||
|
* @param $arResult
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function onGetDiscountResult(&$arResult)
|
||||||
|
{
|
||||||
|
global $scriptType;
|
||||||
|
$counter = 1;
|
||||||
|
if($scriptType === 'XML_EXPORT'){
|
||||||
|
$counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($arResult) > $counter){
|
||||||
|
foreach($arResult as $key => $discount){
|
||||||
|
|
||||||
|
$discountViewType = Tools::getProductTypeArray($discount['ID']);
|
||||||
|
if($discountViewType['PRODUCT_TYPE'] === 'Q'){
|
||||||
|
unset($arResult[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Handlers;
|
||||||
|
|
||||||
|
use Bx\Discount\Tools;
|
||||||
|
|
||||||
|
class CatalogDiscount extends ADiscount
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function onBeforeAdd(&$arFields)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!static::isValidData()){
|
||||||
|
global $APPLICATION;
|
||||||
|
$APPLICATION->ThrowException(
|
||||||
|
static::getLang('EMPTY_PRODUCT_TYPE')
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onAfterAdd($id, $arFields)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Tools::isSaleDiscountEditPage()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!Tools::isValidRequestData()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::updateAdditionalDiscountData($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onBeforeUpdate($id, &$arFields)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$isSaleDiscountEditPage = Tools::isSaleDiscountEditPage();
|
||||||
|
if(!$isSaleDiscountEditPage){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!static::isValidData()){
|
||||||
|
global $APPLICATION;
|
||||||
|
$APPLICATION->ThrowException(static::$lang['EMPTY_PRODUCT_TYPE'], $id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onAfterUpdate($id, $arFields)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Tools::isSaleDiscountEditPage()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(!Tools::isValidRequestData()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::updateAdditionalDiscountData($id);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onBeforeDelete($id)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onAfterDelete($id)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Handlers;
|
||||||
|
|
||||||
|
use Bitrix\Main\Entity\Event;
|
||||||
|
use Bx\Discount\Tools;
|
||||||
|
|
||||||
|
class SaleDiscount extends ADiscount
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function onBeforeAdd(Event $event)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $event->getParameter("id");
|
||||||
|
|
||||||
|
if(is_array($id))
|
||||||
|
$id = $id["ID"];
|
||||||
|
|
||||||
|
$entity = $event->getEntity();
|
||||||
|
$entityDataClass = $entity->GetDataClass();
|
||||||
|
$eventType = $event->getEventType();
|
||||||
|
$arParameters = $event->getParameters();
|
||||||
|
|
||||||
|
$result = new \Bitrix\Main\Entity\EventResult();
|
||||||
|
if(!static::isValidData()){
|
||||||
|
$result->addError(
|
||||||
|
new \Bitrix\Main\Entity\EntityError(static::$lang['EMPTY_PRODUCT_TYPE'])
|
||||||
|
);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onAfterAdd(Event $event)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $event->getParameter('id');
|
||||||
|
|
||||||
|
if(is_array($id))
|
||||||
|
$id = $id['ID'];
|
||||||
|
|
||||||
|
$entity = $event->getEntity();
|
||||||
|
$entityDataClass = $entity->GetDataClass();
|
||||||
|
$eventType = $event->getEventType();
|
||||||
|
$arParameters = $event->getParameters();
|
||||||
|
|
||||||
|
if(!Tools::isSaleDiscountEditPage()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!Tools::isValidRequestData()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static::addAdditionalDiscountData($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onBeforeUpdate(Event $event)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $event->getParameter('id');
|
||||||
|
|
||||||
|
if(is_array($id))
|
||||||
|
$id = $id['ID'];
|
||||||
|
|
||||||
|
$entity = $event->getEntity();
|
||||||
|
$entityDataClass = $entity->GetDataClass();
|
||||||
|
$eventType = $event->getEventType();
|
||||||
|
$arParameters = $event->getParameters();
|
||||||
|
$arFields = $event->getParameter('fields');
|
||||||
|
$isSaleDiscountEditPage = Tools::isSaleDiscountEditPage();
|
||||||
|
if(!$isSaleDiscountEditPage){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//dd($id);
|
||||||
|
//$event->setParameter("fields",$arFields);
|
||||||
|
|
||||||
|
$result = new \Bitrix\Main\Entity\EventResult();
|
||||||
|
if(!static::isValidData()){
|
||||||
|
$result->addError(
|
||||||
|
new \Bitrix\Main\Entity\EntityError(static::$lang['EMPTY_PRODUCT_TYPE'])
|
||||||
|
);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onAfterUpdate(Event $event)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $event->getParameter('id');
|
||||||
|
|
||||||
|
if(is_array($id))
|
||||||
|
$id = $id['ID'];
|
||||||
|
|
||||||
|
$entity = $event->getEntity();
|
||||||
|
$entityDataClass = $entity->GetDataClass();
|
||||||
|
$eventType = $event->getEventType();
|
||||||
|
$arParameters = $event->getParameters();
|
||||||
|
$arFields = $event->getParameter('fields');
|
||||||
|
|
||||||
|
if(!Tools::isSaleDiscountEditPage()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!Tools::isValidRequestData()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::updateAdditionalDiscountData($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onBeforeDelete(Event $event)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $event->getParameter('id');
|
||||||
|
|
||||||
|
if(is_array($id))
|
||||||
|
$id = $id['ID'];
|
||||||
|
|
||||||
|
$entity = $event->getEntity();
|
||||||
|
$entityDataClass = $entity->GetDataClass();
|
||||||
|
$eventType = $event->getEventType();
|
||||||
|
$arParameters = $event->getParameters();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onAfterDelete(Event $event)
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $event->getParameter('id');
|
||||||
|
|
||||||
|
if(is_array($id))
|
||||||
|
$id = $id['ID'];
|
||||||
|
|
||||||
|
$entity = $event->getEntity();
|
||||||
|
$entityDataClass = $entity->GetDataClass();
|
||||||
|
$eventType = $event->getEventType();
|
||||||
|
$arParameters = $event->getParameters();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Handlers;
|
||||||
|
|
||||||
|
use Bitrix\Main\Page\Asset;
|
||||||
|
use Bitrix\Main\Page\AssetLocation;
|
||||||
|
use Bx\Discount\Tools;
|
||||||
|
use Wt\Core\Templater\Shell;
|
||||||
|
|
||||||
|
class SaleDiscountEditPage
|
||||||
|
{
|
||||||
|
public static function onPageStartHandler()
|
||||||
|
{
|
||||||
|
if(!Tools::isEnable()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$isSaleDiscountEditPage = Tools::isSaleDiscountEditPage();
|
||||||
|
if(!$isSaleDiscountEditPage){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$discountID = 0;
|
||||||
|
$copy = false;
|
||||||
|
if (isset($_REQUEST['ID']))
|
||||||
|
{
|
||||||
|
$discountID = (int)$_REQUEST['ID'];
|
||||||
|
if ($discountID < 0)
|
||||||
|
$discountID = 0;
|
||||||
|
}
|
||||||
|
if ($discountID > 0)
|
||||||
|
{
|
||||||
|
$copy = (isset($_REQUEST['action']) && (string)$_REQUEST['action'] == 'copy');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Handlers;
|
||||||
|
|
||||||
|
class SpiderHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function saleDiscountOnAfterAdd()
|
||||||
|
{
|
||||||
|
static::resetSpider();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function saleDiscountOnAfterUpdate()
|
||||||
|
{
|
||||||
|
static::resetSpider();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function saleDiscountOnAfterDelete()
|
||||||
|
{
|
||||||
|
static::resetSpider();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function resetSpider()
|
||||||
|
{
|
||||||
|
discountApp()->service()->spider()->reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Bx\Discount\Providers;
|
namespace Bx\Discount\Providers;
|
||||||
|
|
||||||
|
use Bx\Discount\ElementSpider;
|
||||||
use Wt\Core\Interfaces\IApp;
|
use Wt\Core\Interfaces\IApp;
|
||||||
use Wt\Core\Providers\ADefaultServiceProvider;
|
use Wt\Core\Providers\ADefaultServiceProvider;
|
||||||
|
|
||||||
@@ -15,5 +16,6 @@ class DefaultServiceProvider extends ADefaultServiceProvider
|
|||||||
$container = $this->app->container();
|
$container = $this->app->container();
|
||||||
$config = $this->app->config();
|
$config = $this->app->config();
|
||||||
|
|
||||||
|
$container->singleton(ElementSpider::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+222
@@ -0,0 +1,222 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount;
|
||||||
|
|
||||||
|
use Bitrix\Main\Loader;
|
||||||
|
use CSite;
|
||||||
|
|
||||||
|
class Tools
|
||||||
|
{
|
||||||
|
public static function isSaleDiscountEditPage()
|
||||||
|
{
|
||||||
|
$isAdminSection = defined('ADMIN_SECTION') && ADMIN_SECTION;
|
||||||
|
|
||||||
|
if(!$isAdminSection) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CSite::InDir('/bitrix/admin/sale_discount_edit.php')
|
||||||
|
// || CSite::InDir('/bitrix/admin/sale_discount.php') // деактивация
|
||||||
|
|| CSite::InDir('/bitrix/admin/cat_discount_edit.php')
|
||||||
|
|| CSite::InDir('/bitrix/admin/cat_discount.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isValidRequestData()
|
||||||
|
{
|
||||||
|
return isset($_POST['PRODUCT_TYPE']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isEnable()
|
||||||
|
{
|
||||||
|
if(defined('SALE_DISCOUNT_MIGRATE_MODE') && SALE_DISCOUNT_MIGRATE_MODE){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return discountApp()->config('ENABLE');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getProductTypeArray($discountID)
|
||||||
|
{
|
||||||
|
$arProductType = [];
|
||||||
|
$arProductType['PRODUCT_TYPE'] = '0';
|
||||||
|
$arProductType['MIN_COUNT_PROD'] = 0;
|
||||||
|
|
||||||
|
if(empty($discountID) || ($discountID < 0)){
|
||||||
|
return $arProductType;
|
||||||
|
}
|
||||||
|
|
||||||
|
$depsLoaded = Loader::includeModule('iblock');
|
||||||
|
|
||||||
|
if(!$depsLoaded) {
|
||||||
|
return $arProductType;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iBlockId = discountApp()->config('DISCOUNT_TYPE_IBLOCK_ID');
|
||||||
|
|
||||||
|
if(!$iBlockId){
|
||||||
|
return $arProductType;
|
||||||
|
}
|
||||||
|
|
||||||
|
$res_element = \CIBlockElement::GetList(
|
||||||
|
['SORT' => 'ASC'],
|
||||||
|
['IBLOCK_ID' => $iBlockId, '=NAME' => $discountID],
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
['ID', 'NAME', 'PROPERTY_TYPE', 'PROPERTY_MIN_COUNT_PROD']
|
||||||
|
);
|
||||||
|
$res_element_count = $res_element->SelectedRowsCount();
|
||||||
|
if($res_element_count){
|
||||||
|
$obElement = $res_element->GetNext(true, false);
|
||||||
|
$arProductType['PRODUCT_TYPE'] = (string)$obElement['PROPERTY_TYPE_VALUE'];
|
||||||
|
$arProductType['MIN_COUNT_PROD'] = (int)$obElement['PROPERTY_MIN_COUNT_PROD_VALUE'];
|
||||||
|
}
|
||||||
|
return $arProductType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setTicketValueFromDiscount($elementId)
|
||||||
|
{
|
||||||
|
$includeModule = Loader::includeModule('catalog')
|
||||||
|
&& Loader::includeModule('iblock');
|
||||||
|
if(!$includeModule) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iBlockId = discountApp()->config('CATALOG_IBLOCK_ID');
|
||||||
|
$ticketPropId = discountApp()->config('TICKET_PROP_ID');
|
||||||
|
$map = discountApp()->config('MAP')->toArray();
|
||||||
|
|
||||||
|
$rawDiscountList = \CCatalogDiscount::GetDiscount(
|
||||||
|
$elementId,
|
||||||
|
$iBlockId,
|
||||||
|
[], //CATALOG_GROUP_ID
|
||||||
|
[2],
|
||||||
|
'N', // renewal
|
||||||
|
's1',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
$discountList = [];
|
||||||
|
foreach ($rawDiscountList as $i => $discount){
|
||||||
|
$discountId = $discount['ID'];
|
||||||
|
$arProductType = static::getProductTypeArray($discountId);
|
||||||
|
$discountList[$discountId]['PAN_SETTINGS'] = $arProductType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pre($discountList, 0);
|
||||||
|
|
||||||
|
$iterator = \CIBlockElement::GetPropertyValues(
|
||||||
|
$iBlockId,
|
||||||
|
['ID' => $elementId],
|
||||||
|
false,
|
||||||
|
['ID' => $ticketPropId]
|
||||||
|
);
|
||||||
|
$ticketPropValueList = [];
|
||||||
|
$arTicketPropValue = $iterator->Fetch();
|
||||||
|
if($arTicketPropValue && $arTicketPropValue[$ticketPropId]){
|
||||||
|
$ticketPropValueList = $arTicketPropValue[$ticketPropId];
|
||||||
|
}
|
||||||
|
sort($ticketPropValueList);
|
||||||
|
$newTicketValue = array_diff($ticketPropValueList, $map);
|
||||||
|
|
||||||
|
foreach ($discountList as $discountId => $discount){
|
||||||
|
$ticketType = $discount['PAN_SETTINGS']['PRODUCT_TYPE'];
|
||||||
|
if($ticketType && $map[$ticketType]){
|
||||||
|
$newTicketValue[] = $map[$ticketType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort($newTicketValue);
|
||||||
|
|
||||||
|
if($newTicketValue != $ticketPropValueList) {
|
||||||
|
\CIBlockElement::SetPropertyValuesEx($elementId, $iBlockId, [
|
||||||
|
$ticketPropId => $newTicketValue?:false
|
||||||
|
]);
|
||||||
|
|
||||||
|
if(discountApp()->config('UPDATE_ELEMENT_INDEX')){
|
||||||
|
\Bitrix\Iblock\PropertyIndex\Manager::updateElementIndex($iBlockId, $elementId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getElementList($lastId = 0)
|
||||||
|
{
|
||||||
|
$includeModule = Loader::includeModule('iblock');
|
||||||
|
if(!$includeModule) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$iBlockId = discountApp()->config('CATALOG_IBLOCK_ID');
|
||||||
|
|
||||||
|
$rs = \CIBlockElement::GetList(
|
||||||
|
['ID' => 'ASC'],
|
||||||
|
[
|
||||||
|
'IBLOCK_ID' => $iBlockId,
|
||||||
|
'>ID' => $lastId,
|
||||||
|
'ACTIVE' => 'Y',
|
||||||
|
'GLOBAL_ACTIVE' => 'Y'
|
||||||
|
],
|
||||||
|
false,
|
||||||
|
[
|
||||||
|
'nTopCount' => discountApp()->config('PAGE_SIZE', 50),
|
||||||
|
],
|
||||||
|
['ID', 'IBLOCK_ID']
|
||||||
|
);
|
||||||
|
$elements = [];
|
||||||
|
while($ar = $rs->Fetch()){
|
||||||
|
$elements[$ar['ID']] = $ar['ID'];
|
||||||
|
}
|
||||||
|
return $elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Удаление записей которые ссылаются на отсутствующие элементы
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function removeOldTypeValuesFromCatalogDiscount()
|
||||||
|
{
|
||||||
|
$includeModule = Loader::includeModule('catalog')
|
||||||
|
&& Loader::includeModule('iblock');
|
||||||
|
if(!$includeModule) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$typeIBlockId = discountApp()->config('DISCOUNT_TYPE_IBLOCK_ID');
|
||||||
|
|
||||||
|
$typeAFactory = app()->factory()->iBlock()->getEntityById($typeIBlockId);
|
||||||
|
$typeCollection = $typeAFactory->getElementFactory()->cache([])->getCollection([], [], ['ID', 'NAME']);
|
||||||
|
|
||||||
|
|
||||||
|
// \Bitrix\Sale\Internals\DiscountTable::getList()
|
||||||
|
$result = \CCatalogDiscount::GetList();
|
||||||
|
$list = [];
|
||||||
|
while($ar = $result->Fetch()){
|
||||||
|
/**
|
||||||
|
* Как пример не брать! Тут скидки дикие!
|
||||||
|
*/
|
||||||
|
$list[$ar['ID']] = $ar;
|
||||||
|
}
|
||||||
|
|
||||||
|
$removeList = [];
|
||||||
|
foreach ($typeCollection as $entity){
|
||||||
|
$discountId = $entity->getName();
|
||||||
|
if(!$list[$discountId]){
|
||||||
|
/**
|
||||||
|
* remove iblock element - discount type
|
||||||
|
*/
|
||||||
|
$removeList[] = $entity->getId();
|
||||||
|
$r = \CIBlockElement::Delete($entity->getId());
|
||||||
|
if(!$r){
|
||||||
|
global $APPLICATION;
|
||||||
|
pre("ERROR REMOVE {$entity->getId()}:" . $APPLICATION->LAST_ERROR?$APPLICATION->LAST_ERROR->GetString():'last_error_error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$removeCount = count($removeList);
|
||||||
|
pre("remove {$removeCount} / {$typeCollection->count()} = " . ($typeCollection->count() - $removeCount));
|
||||||
|
pre('REMOVE ID LIST [TYPES]');
|
||||||
|
pre($removeList);
|
||||||
|
|
||||||
|
pre('DISCOUNT IDS ' . count($list));
|
||||||
|
pre(array_keys($list));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user