fix
This commit is contained in:
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
"prefix": "bx_discount",
|
"prefix": "bx_discount",
|
||||||
"namespace": "Bx\\Discount",
|
"namespace": "Bx\\Discount",
|
||||||
"gitUrl": "https://gitea.ixrs.ru/Bellord/bx.discount.git",
|
"gitUrl": "https://gitea.ixrs.ru/Bellord/bx.discount.git",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"date": "2026-02-04 00:00:00",
|
"date": "2026-02-05 00:00:00",
|
||||||
"deps": ["wt.core"]
|
"deps": ["wt.core"]
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ Loc::loadMessages(__FILE__);
|
|||||||
|
|
||||||
|
|
||||||
return (new GlobalMenuItem())
|
return (new GlobalMenuItem())
|
||||||
->setVisible(false)
|
//->setVisible(false)
|
||||||
->setSort(1300)
|
->setSort(1300)
|
||||||
->setTitle('Discount Table')
|
->setTitle('Discount Table')
|
||||||
->setIcon('iblock_menu_icon_iblocks')
|
->setIcon('iblock_menu_icon_iblocks')
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ return [
|
|||||||
'SHOW_EDIT_BUTTON' => 'N',
|
'SHOW_EDIT_BUTTON' => 'N',
|
||||||
'DEFAULT' => '',
|
'DEFAULT' => '',
|
||||||
],
|
],
|
||||||
|
'SPIDERS' => [
|
||||||
|
'TITLE' => 'Spiders',
|
||||||
|
'TYPE' => 'content',
|
||||||
|
'INCLUDEFILE' => Tools::removeDocRoot(__DIR__ . '/include/spiders.php'),
|
||||||
|
'SHOW_EDIT_BUTTON' => 'N',
|
||||||
|
'DEFAULT' => '',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'DOCS' => [
|
'DOCS' => [
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
* @var Wt\Core\Admin\Templater $this
|
* @var Wt\Core\Admin\Templater $this
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Bx\Discount\Agents\SpiderAgentManager;
|
use Bx\Discount\Agents\SpiderAgentCase;
|
||||||
|
|
||||||
$moduleId = $this->getAdminPage()->getModuleId();
|
$moduleId = $this->getAdminPage()->getModuleId();
|
||||||
$agentCase = new SpiderAgentManager();
|
$agentCase = new SpiderAgentCase();
|
||||||
|
|
||||||
$this->renderAgentCase($agentCase);
|
$this->renderAgentCase($agentCase);
|
||||||
@@ -8,42 +8,20 @@ $system = new System();
|
|||||||
$config = discountApp()->config();
|
$config = discountApp()->config();
|
||||||
$data = [];
|
$data = [];
|
||||||
$data['env'] = discountApp()->env();
|
$data['env'] = discountApp()->env();
|
||||||
$data['ENABLE'] = $this->getCheckTemplate($config->get('ENABLE'));
|
$data['enable'] = $this->getCheckTemplate($config->get('enable'));
|
||||||
$data['UPDATE_ELEMENT_INDEX'] = $this->getCheckTemplate($config->get('UPDATE_ELEMENT_INDEX'));
|
$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);
|
$priceTypeIdList = $config->get('catalog_group_id_list', []);
|
||||||
if($blockEntity){
|
$data['catalog_group_id_list'] = $priceTypeIdList->join(', ');
|
||||||
$data['DISCOUNT_TYPE_IBLOCK_ID'] = "[$discountTypeIBlockId] {$blockEntity->getName()}";
|
foreach ($priceTypeIdList as $priceTypeId){
|
||||||
}
|
|
||||||
}
|
|
||||||
$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);
|
$priceTypeEntity = app()->factory()->shop()->getPriceTypeFactory()->getEntityById($priceTypeId);
|
||||||
if($priceTypeEntity){
|
if($priceTypeEntity){
|
||||||
$linkTemplate = "<a href=\"/bitrix/admin/cat_group_edit.php?ID=$priceTypeId\" target=\"_blank\">$priceTypeId</a>";
|
$linkTemplate = "<a href=\"{$priceTypeEntity->getUrl()}\" target=\"_blank\">$priceTypeId</a>";
|
||||||
$data['CATALOG_GROUP_ID'] = "[$linkTemplate] {$priceTypeEntity->getName()}";
|
$data["catalog_group_id_list_$priceTypeId"] = "[$linkTemplate] {$priceTypeEntity->getName()}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data['PAGE_SIZE'] = $config->get('PAGE_SIZE');
|
$data['page_size'] = $config->get('page_size');
|
||||||
$data['RENEWAL_PERIOD'] = $config->get('RENEWAL_PERIOD');
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -52,25 +30,72 @@ $data['RENEWAL_PERIOD'] = $config->get('RENEWAL_PERIOD');
|
|||||||
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
|
||||||
}
|
}
|
||||||
?><tr><td>MAP</td><td><?php
|
?>
|
||||||
if($config->get('MAP', [])->count()){
|
</table>
|
||||||
|
<br>
|
||||||
|
|
||||||
?><table style="width: 100%;">
|
<h3>Инфоблоки</h3>
|
||||||
<tr style="font-size: 0.8em; color: #6e6e6e"><td>type</td><td>ticket item</td></tr>
|
|
||||||
<?php foreach ($config->get('MAP', []) as $type => $id){?>
|
<table cellpadding="5" border="1" style="border-collapse: collapse; width: 100%">
|
||||||
<tr><td><?= $type ?></td><td><?php
|
<tr style="font-size: 0.9em; text-align: left;">
|
||||||
if($propertyEntity){
|
<th>Config Name</th>
|
||||||
$valueFactory = $propertyEntity->getAdapter()->getValueFactory();
|
<th>Title</th>
|
||||||
$entity = $valueFactory->getEntityById($id);
|
<th>isSectionProperty</th>
|
||||||
if($entity){
|
</tr>
|
||||||
echo "[{$entity->getId()}] {$entity->getName()}";
|
<tr>
|
||||||
|
<?php
|
||||||
|
$catalogIBlockId = discountApp()->config('catalog_iblock_id', 0);
|
||||||
|
$catalogTitle = "<span class='errortext'>".($catalogIBlockId?:'Undefined'). '</span>';
|
||||||
|
$catalogEntity = app()->factory()->main()->getIBlockFactory()->getEntityById($catalogIBlockId);
|
||||||
|
if($catalogEntity){
|
||||||
|
$catalogTitle = "[{$catalogEntity->getId()}] {$catalogEntity->getName()}";
|
||||||
|
$catalogTitle = "[<a href=\"{$catalogEntity->getAdminUrl()}\" target=\"_blank\">{$catalogEntity->getId()}</a>] {$catalogEntity->getName()}";
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
<td><?='catalog_iblock_id'?></td><td><?=$catalogTitle?></td><td><?=$catalogEntity->isSectionProperty()?'Да':'Нет'?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>Mapping</h3>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
$af = app()->factory()->iBlock()->getEntityById($catalogIBlockId);
|
||||||
|
$propertyFactory = $af->getPropertyFactory();
|
||||||
|
$map = $config->get('MAP', [])->toArray();
|
||||||
|
?>
|
||||||
|
<table cellpadding="5" border="1" style="border-collapse: collapse; width: 100%">
|
||||||
|
<tr style="font-size: 0.8em; color: #6e6e6e"><td>Type</td><td>Property</td><td>PropertyValue</td></tr>
|
||||||
|
<?php
|
||||||
|
foreach ($map as $type => $typeMap){
|
||||||
|
foreach ($typeMap as $propertyCode => $propertyValue) {
|
||||||
|
\Bx\Discount\Tools::prepareMapPropertyCodeAndValue($propertyCode, $propertyValue);
|
||||||
|
|
||||||
|
$propertyEntity = $propertyFactory->getEntityByCode($propertyCode);
|
||||||
|
if($propertyEntity?->getBaseType() != 'L'){
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
?></td></tr>
|
/**
|
||||||
<?php }?>
|
* @var \Wt\Core\Collection\IBlock\PropertyEnumCollection $valueCollection
|
||||||
</table><?php
|
*/
|
||||||
} else {
|
$valueCollection = $propertyEntity->getValueCollection();
|
||||||
?><i>empty</i><?php
|
$valueEntity = $valueCollection->getByXmlId($propertyValue);
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?= $type ?></td>
|
||||||
|
<td><?php
|
||||||
|
$propertyEntity->getUrl();
|
||||||
|
$linkTemplate = "<a href=\"{$propertyEntity->getUrl()}\" target=\"_blank\">{$propertyEntity->getId()}</a>";
|
||||||
|
echo "[$linkTemplate] {$propertyEntity->getName()}";
|
||||||
|
?></td>
|
||||||
|
<td><?php
|
||||||
|
if($valueEntity){
|
||||||
|
echo "[{$valueEntity->getId()}] {$valueEntity->getName()}";
|
||||||
}
|
}
|
||||||
?></td></tr><?php
|
?></td>
|
||||||
?></table>
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}?>
|
||||||
|
</table>
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var Wt\Core\Admin\Templater $this
|
||||||
|
*/
|
||||||
|
|
||||||
|
$moduleId = $this->getAdminPage()->getModuleId();
|
||||||
|
$spider = discountApp()->service()->spider();
|
||||||
|
|
||||||
|
$this->renderSpider($spider);
|
||||||
+18
-10
@@ -2,19 +2,27 @@
|
|||||||
//$config['events']['main:OnPageStart'][] = ['Bx\\Discount\\Handlers\\SaleDiscountEditPage', 'onPageStartHandler'];
|
//$config['events']['main:OnPageStart'][] = ['Bx\\Discount\\Handlers\\SaleDiscountEditPage', 'onPageStartHandler'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'ENABLE' => false,
|
'enable' => false,
|
||||||
'UPDATE_ELEMENT_INDEX' => false,
|
'update_element_index' => false,
|
||||||
'PAGE_SIZE' => 100,
|
'page_size' => 100,
|
||||||
'RENEWAL_PERIOD' => 604800,
|
|
||||||
|
|
||||||
'CATALOG_IBLOCK_ID' => 0,
|
'catalog_iblock_id' => 0,
|
||||||
'DISCOUNT_TYPE_IBLOCK_ID' => 0,
|
'catalog_group_id_list' => [],
|
||||||
'CATALOG_GROUP_ID' => 0,
|
|
||||||
|
|
||||||
'TICKET_PROP_ID' => 0,
|
'spider' => [
|
||||||
|
'micro_task_period' => 60,
|
||||||
|
'expire' => 300,
|
||||||
|
'period' => 86400,
|
||||||
|
],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* содержит пары: Тип скидки => [ propertyCode.propertyValueXmlId, ... ]
|
||||||
|
* Тип скидки = '0' по умолчанию, если о скидке нет данных в таблице
|
||||||
|
*/
|
||||||
'MAP' => [
|
'MAP' => [
|
||||||
'A' => 0,
|
// '0' => [
|
||||||
'R' => 0,
|
// 'HIT.STOCK',
|
||||||
|
// ],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
namespace Bx\Discount\Agents;
|
namespace Bx\Discount\Agents;
|
||||||
|
|
||||||
|
use Bx\Discount\Tools;
|
||||||
use Wt\Core\Agent\AAgentCase;
|
use Wt\Core\Agent\AAgentCase;
|
||||||
|
|
||||||
class SpiderAgentManager extends AAgentCase
|
class SpiderAgentCase extends AAgentCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
@@ -33,9 +34,11 @@ class SpiderAgentManager extends AAgentCase
|
|||||||
$agent = app()->factory()->main()->getAgentFactory()->getEntityById($arAgent['ID']);
|
$agent = app()->factory()->main()->getAgentFactory()->getEntityById($arAgent['ID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Tools::isEnable()){
|
||||||
$spider = discountApp()->service()->spider();
|
$spider = discountApp()->service()->spider();
|
||||||
$spider->setAgent($agent);
|
$spider->setContext($agent);
|
||||||
$spider->next();
|
$spider->next();
|
||||||
|
}
|
||||||
|
|
||||||
return static::class . "::exec(\$arAgent);";
|
return static::class . "::exec(\$arAgent);";
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
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
|
||||||
@@ -12,18 +11,6 @@ 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' => discountApp()->module()->getVersion()]);
|
$this->getResponse()->addData(['method' => 'test', 'version' => discountApp()->module()->getVersion()]);
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,14 @@ class DiscountEntity extends AEntity
|
|||||||
return parent::getFactory(); // TODO: Change the autogenerated stub
|
return parent::getFactory(); // TODO: Change the autogenerated stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->getRaw('TYPE', '0');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DiscountFields
|
* @return DiscountFields
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Bx\Discount\Facade;
|
namespace Bx\Discount\Facade;
|
||||||
|
|
||||||
use Bx\Discount\ElementSpider;
|
use Bx\Discount\Spiders\ElementSpider;
|
||||||
use Wt\Core\Facade\AFacade;
|
use Wt\Core\Facade\AFacade;
|
||||||
|
|
||||||
class DefaultServiceFacade extends AFacade
|
class DefaultServiceFacade extends AFacade
|
||||||
@@ -13,7 +13,13 @@ class DefaultServiceFacade extends AFacade
|
|||||||
*/
|
*/
|
||||||
public function spider()
|
public function spider()
|
||||||
{
|
{
|
||||||
return $this->app->container()->make(ElementSpider::class);
|
return $this->app->container()->make(ElementSpider::class, [
|
||||||
|
discountApp()->module()->getId(),
|
||||||
|
'element',
|
||||||
|
discountApp()->config('spider.micro_task_period', 60),
|
||||||
|
discountApp()->config('spider.expire', 3600),
|
||||||
|
discountApp()->config('spider.period', 86400),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,15 @@ class DiscountFactory extends AORMFactory
|
|||||||
return parent::getEntityById($id);
|
return parent::getEntityById($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $arResult
|
||||||
|
* @return DiscountEntity
|
||||||
|
*/
|
||||||
|
public function getEntityByResult(array $arResult)
|
||||||
|
{
|
||||||
|
return parent::getEntityByResult($arResult); // TODO: Change the autogenerated stub
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $filter
|
* @param array $filter
|
||||||
* @param array $order
|
* @param array $order
|
||||||
|
|||||||
+17
-52
@@ -24,61 +24,26 @@ class ADiscount
|
|||||||
|
|
||||||
protected static function updateAdditionalDiscountData($id)
|
protected static function updateAdditionalDiscountData($id)
|
||||||
{
|
{
|
||||||
|
$discountFactory = discountApp()->factory()->main()->getDiscountFactory();
|
||||||
$depsLoaded = \Bitrix\Main\Loader::includeModule('iblock');
|
return $discountFactory->updateOrCreate([
|
||||||
if(!$depsLoaded) {
|
'=DISCOUNT_ID' => $id,
|
||||||
return;
|
], [
|
||||||
}
|
'DISCOUNT_ID' => $id,
|
||||||
|
'PRODUCT_TYPE' => (string)$_POST['PRODUCT_TYPE'],
|
||||||
$res_element = \CIBlockElement::GetList(
|
'MIN_COUNT_PROD' => (int)$_POST['MIN_COUNT_PROD'],
|
||||||
['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)
|
protected static function addAdditionalDiscountData($id)
|
||||||
{
|
{
|
||||||
$depsLoaded = \Bitrix\Main\Loader::includeModule('iblock');
|
$discountFactory = discountApp()->factory()->main()->getDiscountFactory();
|
||||||
if(!$depsLoaded) {
|
return $discountFactory->updateOrCreate([
|
||||||
return;
|
'=DISCOUNT_ID' => $id,
|
||||||
}
|
], [
|
||||||
|
'DISCOUNT_ID' => $id,
|
||||||
$el = new \CIBlockElement();
|
'PRODUCT_TYPE' => (string)$_POST['PRODUCT_TYPE'],
|
||||||
$arTypeField = [
|
'MIN_COUNT_PROD' => (int)$_POST['MIN_COUNT_PROD'],
|
||||||
'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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +69,7 @@ class ADiscount
|
|||||||
if(count($arResult) > $counter){
|
if(count($arResult) > $counter){
|
||||||
foreach($arResult as $key => $discount){
|
foreach($arResult as $key => $discount){
|
||||||
|
|
||||||
$discountViewType = Tools::getProductTypeArray($discount['ID']);
|
$discountViewType = Tools::getDiscountEntity($discount['ID']);
|
||||||
if($discountViewType['PRODUCT_TYPE'] === 'Q'){
|
if($discountViewType['PRODUCT_TYPE'] === 'Q'){
|
||||||
unset($arResult[$key]);
|
unset($arResult[$key]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ class DiscountTable extends ADataManager
|
|||||||
'autocomplete' => true,
|
'autocomplete' => true,
|
||||||
'title' => 'Id',
|
'title' => 'Id',
|
||||||
]),
|
]),
|
||||||
|
'DISCOUNT_ID' => new \Bitrix\Main\Entity\IntegerField('DISCOUNT_ID', [
|
||||||
|
'title' => 'DiscountId',
|
||||||
|
]),
|
||||||
|
'TYPE' => new \Bitrix\Main\Entity\StringField('TYPE', [
|
||||||
|
'title' => 'Type',
|
||||||
|
]),
|
||||||
'CREATED_AT' => new \Bitrix\Main\Entity\DatetimeField('CREATED_AT', [
|
'CREATED_AT' => new \Bitrix\Main\Entity\DatetimeField('CREATED_AT', [
|
||||||
'title' => 'CreatedAt',
|
'title' => 'CreatedAt',
|
||||||
'user_edit' => false,
|
'user_edit' => false,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Bx\Discount\Providers;
|
namespace Bx\Discount\Providers;
|
||||||
|
|
||||||
use Bx\Discount\ElementSpider;
|
use Bx\Discount\Spiders\ElementSpider;
|
||||||
use Wt\Core\Interfaces\IApp;
|
use Wt\Core\Interfaces\IApp;
|
||||||
use Wt\Core\Providers\ADefaultServiceProvider;
|
use Wt\Core\Providers\ADefaultServiceProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bx\Discount\Spiders;
|
||||||
|
|
||||||
|
use Bx\Discount\Tools;
|
||||||
|
use Wt\Core\Spiders\ListSpider;
|
||||||
|
|
||||||
|
class ElementSpider extends ListSpider
|
||||||
|
{
|
||||||
|
protected function do()
|
||||||
|
{
|
||||||
|
parent::do();
|
||||||
|
|
||||||
|
$catalogIBlockId = discountApp()->config('catalog_iblock_id', 0);
|
||||||
|
if(!$catalogIBlockId){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$lastId = $this->getLastId();
|
||||||
|
$ids = Tools::getElementList($lastId);
|
||||||
|
$__lastId = 0;
|
||||||
|
foreach ($ids as $id){
|
||||||
|
$__lastId = $id;
|
||||||
|
Tools::setTicketValueFromDiscount($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($ids){
|
||||||
|
$this->setLastId($__lastId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+110
-67
@@ -31,111 +31,151 @@ class Tools
|
|||||||
if(defined('SALE_DISCOUNT_MIGRATE_MODE') && SALE_DISCOUNT_MIGRATE_MODE){
|
if(defined('SALE_DISCOUNT_MIGRATE_MODE') && SALE_DISCOUNT_MIGRATE_MODE){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return discountApp()->config('ENABLE');
|
return discountApp()->config('enable', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getProductTypeArray($discountID)
|
/**
|
||||||
|
* @param $discountId
|
||||||
|
* @return Entity\DiscountEntity
|
||||||
|
*/
|
||||||
|
public static function getDiscountEntity($discountId)
|
||||||
{
|
{
|
||||||
$arProductType = [];
|
$discountFactory = discountApp()->factory()->main()->getDiscountFactory();
|
||||||
$arProductType['PRODUCT_TYPE'] = '0';
|
$discountEntity = $discountFactory->getEntityById($discountId);
|
||||||
$arProductType['MIN_COUNT_PROD'] = 0;
|
|
||||||
|
|
||||||
if(empty($discountID) || ($discountID < 0)){
|
if(!$discountEntity){
|
||||||
return $arProductType;
|
return $discountFactory->getEntityByResult([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$depsLoaded = Loader::includeModule('iblock');
|
return $discountEntity;
|
||||||
|
|
||||||
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)
|
public static function setTicketValueFromDiscount($elementId)
|
||||||
{
|
{
|
||||||
$includeModule = Loader::includeModule('catalog')
|
$includeModule = Loader::includeModule('catalog')
|
||||||
&& Loader::includeModule('iblock');
|
&& Loader::includeModule('iblock')
|
||||||
|
&& Loader::includeModule('sale');
|
||||||
if(!$includeModule) {
|
if(!$includeModule) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iBlockId = discountApp()->config('CATALOG_IBLOCK_ID');
|
$iBlockId = discountApp()->config('catalog_iblock_id');
|
||||||
$ticketPropId = discountApp()->config('TICKET_PROP_ID');
|
|
||||||
$map = discountApp()->config('MAP')->toArray();
|
$map = discountApp()->config('MAP')->toArray();
|
||||||
|
|
||||||
$rawDiscountList = \CCatalogDiscount::GetDiscount(
|
$discountList = \CCatalogDiscount::GetDiscount(
|
||||||
$elementId,
|
$elementId,
|
||||||
$iBlockId,
|
$iBlockId,
|
||||||
[], //CATALOG_GROUP_ID
|
[], //catalog_group_id_list
|
||||||
[2],
|
[2],
|
||||||
'N', // renewal
|
'N', // renewal
|
||||||
's1',
|
's1',
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
if(!is_array($discountList)){
|
||||||
$discountList = [];
|
$discountList = [];
|
||||||
foreach ($rawDiscountList as $i => $discount){
|
|
||||||
$discountId = $discount['ID'];
|
|
||||||
$arProductType = static::getProductTypeArray($discountId);
|
|
||||||
$discountList[$discountId]['PAN_SETTINGS'] = $arProductType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pre($discountList, 0);
|
$af = app()->factory()->iBlock()->getEntityById($iBlockId);
|
||||||
|
$propertyFactory = $af->getPropertyFactory();
|
||||||
$iterator = \CIBlockElement::GetPropertyValues(
|
$elementFactory = $af->getElementFactory();
|
||||||
$iBlockId,
|
$elementEntity = $elementFactory->getEntityById($elementId);
|
||||||
['ID' => $elementId],
|
if(!$elementEntity){
|
||||||
false,
|
return false;
|
||||||
['ID' => $ticketPropId]
|
}
|
||||||
);
|
$pvc = $elementEntity->getPropertyValueCollection();
|
||||||
$ticketPropValueList = [];
|
$currentPropertyValueList = [];
|
||||||
$arTicketPropValue = $iterator->Fetch();
|
foreach ($map as $type => $typeMap){
|
||||||
if($arTicketPropValue && $arTicketPropValue[$ticketPropId]){
|
foreach ($typeMap as $propertyCode => $propertyValue) {
|
||||||
$ticketPropValueList = $arTicketPropValue[$ticketPropId];
|
static::prepareMapPropertyCodeAndValue($propertyCode, $propertyValue);
|
||||||
|
|
||||||
|
$propertyEntity = $propertyFactory->getEntityByCode($propertyCode);
|
||||||
|
if($propertyEntity?->getBaseType() != 'L'){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($currentPropertyValueList[$propertyEntity->getId()])){
|
||||||
|
$pve = $pvc->getByCode($propertyCode);
|
||||||
|
$currentValue = $pve->getValue();
|
||||||
|
$currentValueCollection = collect($currentValue);
|
||||||
|
$currentPropertyValueList[$propertyEntity->getId()] = $currentValueCollection->values()->sort()->toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$currentPropertyValueList = collect($currentPropertyValueList)->sort()->toArray();
|
||||||
|
pre($currentPropertyValueList);
|
||||||
|
|
||||||
|
$newPropertyValueList = $currentPropertyValueList;
|
||||||
|
foreach ($map as $type => $typeMap){
|
||||||
|
foreach ($typeMap as $propertyCode => $propertyValue) {
|
||||||
|
static::prepareMapPropertyCodeAndValue($propertyCode, $propertyValue);
|
||||||
|
|
||||||
|
$propertyEntity = $propertyFactory->getEntityByCode($propertyCode);
|
||||||
|
if($propertyEntity?->getBaseType() != 'L'){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Wt\Core\Collection\IBlock\PropertyEnumCollection $valueCollection
|
||||||
|
*/
|
||||||
|
$valueCollection = $propertyEntity->getValueCollection();
|
||||||
|
$valueEntity = $valueCollection->getByXmlId($propertyValue);
|
||||||
|
$newPropertyValueList[$propertyEntity->getId()]
|
||||||
|
= collect($newPropertyValueList[$propertyEntity->getId()])
|
||||||
|
->deleteValue($valueEntity->getId())
|
||||||
|
->values()->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sort($ticketPropValueList);
|
|
||||||
$newTicketValue = array_diff($ticketPropValueList, $map);
|
|
||||||
|
|
||||||
foreach ($discountList as $discountId => $discount){
|
foreach ($discountList as $discountId => $discount){
|
||||||
$ticketType = $discount['PAN_SETTINGS']['PRODUCT_TYPE'];
|
$discountEntity = static::getDiscountEntity($discountId);
|
||||||
if($ticketType && $map[$ticketType]){
|
$type = $discountEntity->getType();
|
||||||
$newTicketValue[] = $map[$ticketType];
|
if(isset($map[$type]) && is_array($map[$type])){
|
||||||
|
$typeMap = $map[$type];
|
||||||
|
foreach ($typeMap as $propertyCode => $propertyValue) {
|
||||||
|
static::prepareMapPropertyCodeAndValue($propertyCode, $propertyValue);
|
||||||
|
|
||||||
|
$propertyEntity = $propertyFactory->getEntityByCode($propertyCode);
|
||||||
|
if($propertyEntity?->getBaseType() != 'L'){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Wt\Core\Collection\IBlock\PropertyEnumCollection $valueCollection
|
||||||
|
*/
|
||||||
|
$valueCollection = $propertyEntity->getValueCollection();
|
||||||
|
$valueEntity = $valueCollection->getByXmlId($propertyValue);
|
||||||
|
$newPropertyValueList[$propertyEntity->getId()]
|
||||||
|
= collect($newPropertyValueList[$propertyEntity->getId()])
|
||||||
|
->push($valueEntity->getId())
|
||||||
|
->values()->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort($newTicketValue);
|
}
|
||||||
|
pre($newPropertyValueList);
|
||||||
|
|
||||||
if($newTicketValue != $ticketPropValueList) {
|
if($newPropertyValueList != $currentPropertyValueList) {
|
||||||
\CIBlockElement::SetPropertyValuesEx($elementId, $iBlockId, [
|
pre('set');
|
||||||
$ticketPropId => $newTicketValue?:false
|
foreach ($newPropertyValueList as $propertyId => $propertyValue){
|
||||||
]);
|
if(is_array($propertyValue) && !$propertyValue){
|
||||||
|
$newPropertyValueList[$propertyId] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\CIBlockElement::SetPropertyValuesEx($elementId, $iBlockId, $newPropertyValueList);
|
||||||
|
|
||||||
if(discountApp()->config('UPDATE_ELEMENT_INDEX')){
|
if(discountApp()->config('update_element_index')){
|
||||||
\Bitrix\Iblock\PropertyIndex\Manager::updateElementIndex($iBlockId, $elementId);
|
\Bitrix\Iblock\PropertyIndex\Manager::updateElementIndex($iBlockId, $elementId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function prepareMapPropertyCodeAndValue(&$propertyCode, &$propertyValue)
|
||||||
|
{
|
||||||
|
if (is_int($propertyCode)) {
|
||||||
|
[$propertyCode, $propertyValue] = explode('.', $propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function getElementList($lastId = 0)
|
public static function getElementList($lastId = 0)
|
||||||
{
|
{
|
||||||
$includeModule = Loader::includeModule('iblock');
|
$includeModule = Loader::includeModule('iblock');
|
||||||
@@ -143,7 +183,10 @@ class Tools
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$iBlockId = discountApp()->config('CATALOG_IBLOCK_ID');
|
$iBlockId = discountApp()->config('catalog_iblock_id', 0);
|
||||||
|
if(!$iBlockId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$rs = \CIBlockElement::GetList(
|
$rs = \CIBlockElement::GetList(
|
||||||
['ID' => 'ASC'],
|
['ID' => 'ASC'],
|
||||||
@@ -155,7 +198,7 @@ class Tools
|
|||||||
],
|
],
|
||||||
false,
|
false,
|
||||||
[
|
[
|
||||||
'nTopCount' => discountApp()->config('PAGE_SIZE', 50),
|
'nTopCount' => discountApp()->config('page_size', 50),
|
||||||
],
|
],
|
||||||
['ID', 'IBLOCK_ID']
|
['ID', 'IBLOCK_ID']
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user