Skip to content

Commit

Permalink
CMSGATE-51: bitrix24 cloud changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita.mekh committed Jan 9, 2023
1 parent 6d16e09 commit 4e0094b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/esas/cmsgate/CmsConnectorBitrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public function createCmsConnectorDescriptor()
return new CmsConnectorDescriptor(
"cmsgate-bitrix-lib",
new VersionDescriptor(
"v1.18.2",
"2022-07-22"
"v1.18.3",
"2023-01-09"
),
"Cmsgate Bitrix connector",
"https://bitbucket.esas.by/projects/CG/repos/cmsgate-bitrix-lib/browse",
Expand Down
9 changes: 5 additions & 4 deletions src/esas/cmsgate/bitrix/InstallHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CFile;
use CModule;
use CSaleOrder;
use esas\cmsgate\bitrix\dto\sale\Paysystem;
use esas\cmsgate\CmsConnectorBitrix;
use esas\cmsgate\ConfigFields;
use esas\cmsgate\messenger\MessagesBitrix;
Expand Down Expand Up @@ -49,7 +50,7 @@ class InstallHelper
*/
protected $managedCModule;
/**
* @var CmsgatePaysystem[]
* @var Paysystem[]
*/
protected $installPaySystemsList;

Expand All @@ -72,7 +73,7 @@ public function addToInstallFilesList($extFile)

public function createMainPaySystem()
{
$mainPaySystem = new CmsgatePaysystem();
$mainPaySystem = new Paysystem();
$mainPaySystem
->setName(Registry::getRegistry()->getTranslator()->getConfigFieldDefault(ConfigFields::paymentMethodName()))
->setDescription(Registry::getRegistry()->getTranslator()->getConfigFieldDefault(ConfigFields::paymentMethodDetails()))
Expand All @@ -88,7 +89,7 @@ public function createAndAddMainPaySystem() {
$this->addToInstallPaySystemsList($mainPaySystem);
}

public function addToInstallPaySystemsList(CmsgatePaysystem $extPaySystem, $addFiles = true)
public function addToInstallPaySystemsList(Paysystem $extPaySystem, $addFiles = true)
{
$this->installPaySystemsList[] = $extPaySystem;
if ($addFiles) {
Expand Down Expand Up @@ -213,7 +214,7 @@ function DoUninstall()
/**
* Первоначально тут был просто вызов Manager::Add, но в таком случае не происходит загрузка логотипа, как было в CSalePaySystem::Add
* Поэтому взят пример кода из \Bitrix\Sale\PaySystem\Manager::createInnerPaySystem
* @param CmsgatePaysystem $paySystem
* @param Paysystem $paySystem
* @throws Exception
*/
public function addPaysys(&$paySystem)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php


namespace esas\cmsgate\bitrix;
namespace esas\cmsgate\bitrix\dto\sale;


class CmsgatePaysystem
class Paysystem
{
private $id;
private $name;
private $description;
private $actionFile;
private $type;
private $sort = 100;
private $logoPath;
/**
* @var boolean
*/
Expand All @@ -21,6 +22,10 @@ class CmsgatePaysystem
*/
private $main = false;

public static function newInstance() {
return new Paysystem();
}

/**
* @return mixed
*/
Expand All @@ -31,7 +36,7 @@ public function getId()

/**
* @param mixed $id
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setId($id)
{
Expand All @@ -49,7 +54,7 @@ public function getName()

/**
* @param mixed $name
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setName($name)
{
Expand All @@ -67,7 +72,7 @@ public function getDescription()

/**
* @param mixed $description
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setDescription($description)
{
Expand All @@ -85,7 +90,7 @@ public function getActionFile()

/**
* @param mixed $actionFile
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setActionFile($actionFile)
{
Expand All @@ -103,7 +108,7 @@ public function getType()

/**
* @param mixed $type
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setType($type)
{
Expand All @@ -121,7 +126,7 @@ public function getSort()

/**
* @param mixed $sort
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setSort($sort)
{
Expand All @@ -139,9 +144,9 @@ public function isActive(): bool

/**
* @param bool $active
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setActive(bool $active): CmsgatePaysystem
public function setActive(bool $active): Paysystem
{
$this->active = $active;
return $this;
Expand All @@ -159,13 +164,31 @@ public function isMain(): bool

/**
* @param bool $main
* @return CmsgatePaysystem
* @return Paysystem
*/
public function setMain(bool $main): CmsgatePaysystem
public function setMain(bool $main): Paysystem
{
$this->main = $main;
return $this;
}

/**
* @return mixed
*/
public function getLogoPath()
{
return $this->logoPath;
}

/**
* @param mixed $logoPath
* @return Paysystem
*/
public function setLogoPath($logoPath)
{
$this->logoPath = $logoPath;
return $this;
}


}
52 changes: 52 additions & 0 deletions src/esas/cmsgate/bitrix/dto/sale/PaysystemConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php


namespace esas\cmsgate\bitrix\dto\sale;


class PaysystemConverter
{

/**
* @param $paysystem Paysystem
* @return array
*/
public static function toArray($paysystem) {
$fields = array(
"NAME" => $paysystem->getName(),
"DESCRIPTION" => $paysystem->getDescription(),
"ACTION_FILE" => $paysystem->getActionFile(),
"ACTIVE" => $paysystem->isActive() ? "Y" : "N",
"ENTITY_REGISTRY_TYPE" => $paysystem->getType(), // без этого созданная платежная система не отображается в списке
"NEW_WINDOW" => "N",
"HAVE_PREPAY" => "N",
"HAVE_RESULT" => "N",
"HAVE_ACTION" => "N",
"HAVE_PAYMENT" => "Y",
"HAVE_RESULT_RECEIVE" => "Y",
// "ENCODING" => "utf-8", на системах с windows-1251 при установке из marketplace это приводит к двойной конвертации итоговой страницы и некорректоному отображению
"SORT" => $paysystem->getSort(),
);
if ($paysystem->getLogoPath() != '' && file_exists($paysystem->getLogoPath())) {
$content = file_get_contents($paysystem->getLogoPath());
$fields['LOGOTYPE'] = base64_encode($content);
}
return $fields;
}

/**
* @param $dataArray
* @return Paysystem
*/
public static function fromArray($dataArray) {
$paysystem = new Paysystem();
$paysystem
->setId($dataArray['ID'])
->setName($dataArray['NAME'])
->setActionFile($dataArray['ACTION_FILE'])
->setSort($dataArray['SORT'])
->setActive($dataArray['ACTIVE'] == 'Y')
->setType($dataArray['ENTITY_REGISTRY_TYPE']);
return $paysystem;
}
}
34 changes: 14 additions & 20 deletions src/esas/cmsgate/view/admin/ConfigFormBitrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,7 @@

class ConfigFormBitrix extends ConfigFormArray
{
private $orderStatuses;

/**
* ConfigFieldsRenderWoo constructor.
*/
public function __construct($formKey, $managedFields)
{
parent::__construct($formKey, $managedFields);
$bitrixStatusList = \Bitrix\Sale\Internals\StatusLangTable::getList(array(
'order' => array('STATUS.SORT'=>'ASC'),
'filter' => array('STATUS.TYPE'=>'O','LID'=>LANGUAGE_ID),
'select' => array('STATUS_ID','NAME'),

));
while($status=$bitrixStatusList->fetch()) {
$statusKey = $status["STATUS_ID"];
$statusName = $status["NAME"];
$this->orderStatuses[$statusKey] = new ListOption($statusKey, '[' . $statusKey . '] ' . $statusName);
}
}
protected $orderStatuses;

public function generate()
{
Expand Down Expand Up @@ -104,6 +85,19 @@ public function generateListField(ConfigFieldList $configField)
*/
public function createStatusListOptions()
{
if ($this->orderStatuses == null) {
$bitrixStatusList = \Bitrix\Sale\Internals\StatusLangTable::getList(array(
'order' => array('STATUS.SORT'=>'ASC'),
'filter' => array('STATUS.TYPE'=>'O','LID'=>LANGUAGE_ID),
'select' => array('STATUS_ID','NAME'),

));
while($status=$bitrixStatusList->fetch()) {
$statusKey = $status["STATUS_ID"];
$statusName = $status["NAME"];
$this->orderStatuses[$statusKey] = new ListOption($statusKey, '[' . $statusKey . '] ' . $statusName);
}
}
return $this->orderStatuses;
}

Expand Down

0 comments on commit 4e0094b

Please sign in to comment.