1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

edit options style, delete order field, edit count available bonuses

This commit is contained in:
Sergey Chazov 2020-10-09 15:19:24 +03:00
parent 6c63356e6c
commit 940c5314c0
8 changed files with 132 additions and 80 deletions

View file

@ -2984,4 +2984,15 @@ class ApiClient
$request
);
}
/**
* @return \RetailCrm\Response\ApiResponse
*/
public function getCredentials(): ApiResponse
{
return $this->client->makeRequest(
"/api/credentials",
Client::METHOD_GET
);
}
}

View file

@ -239,12 +239,6 @@ class intaro_retailcrm extends CModule
$this->addLPUserFields();
$this->addLPEvents();
try {
$this->addLPOrderProps();
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
return false;
}
if ($step == 11) {
$arResult['arSites'] = RCrmActions::SitesList();
if (count($arResult['arSites']) < 2) {
@ -1516,27 +1510,6 @@ class intaro_retailcrm extends CModule
);
}
/**
* add LP Order Props
*
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
*/
public function addLPOrderProps(): void
{
$persons = PersonTypeRepository::getCollectionByWhere(['ID']);
foreach ($persons as $person) {
$personId = $person->getID();
$groupID = $this->getGroupID($personId);
if (isset($groupID)) {
$this->addBonusField($personId, $groupID);
}
}
}
/**
* @param $fieldNames
* @param string $filedType
@ -1626,46 +1599,6 @@ class intaro_retailcrm extends CModule
}
}
/**
* @param $personID
* @param $groupID
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
*/
private function addBonusField($personID, $groupID): void
{
$bonusProp = OrderPropsRepository::getFirstByWhere(
['ID'],
[
['PERSON_TYPE_ID', '=', $personID],
['PROPS_GROUP_ID', '=', $groupID],
]
);
if ($bonusProp === null) {
CSaleOrderProps::Add(
[
"REQUIRED" => "N",
"NAME" => self::BONUS_COUNT,
"TYPE" => "TEXT",
"CODE" => "BONUS_RETAILCRM",
"USER_PROPS" => "Y",
"IS_LOCATION" => "N",
"IS_LOCATION4TAX" => "N",
"IS_EMAIL" => "N",
"IS_PROFILE_NAME" => "N",
"IS_PAYER" => "N",
'IS_FILTERED' => 'Y',
'PERSON_TYPE_ID' => $personID,
'PROPS_GROUP_ID' => $groupID,
"DEFAULT_VALUE" => 0,
"DESCRIPTION" => self::BONUS_COUNT,
]
);
}
}
/**
* add bonus pay system
*/

View file

@ -99,6 +99,7 @@ use RetailCrm\Response\ApiResponse;
* @method ApiResponse statisticUpdate()
* @method ApiResponse getSite()
* @method ApiResponse setSite($site)
* @method ApiResponse getCredentials()
*/
class ClientAdapter
{

View file

@ -102,6 +102,8 @@ class EventsHandlers
}
/**
* Обработчик события, вызываемого при обновлении заказа
*
* @param $order
* @param $arUserResult
* @param \Bitrix\Main\HttpRequest $request
@ -115,7 +117,7 @@ class EventsHandlers
$bonusInput = (int)$request->get('bonus-input');
$availableBonuses = (int)$request->get('available-bonuses');
if ($bonusInput >= $availableBonuses) {
if ($bonusInput > $availableBonuses) {
$arResult['LOYALTY']['ERROR'] = self::BONUS_ERROR_MSG;
$isBonusError = true;
}

View file

@ -0,0 +1,55 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Response\Order\Loyalty
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Response\Settings;
/**
* Class CredentialsResponse
*
* @package Intaro\RetailCrm\Model\Api\Response\Settings
*/
class CredentialsResponse
{
/**
* Результат запроса (успешный/неуспешный)
*
* @var boolean $success
*
* @Mapping\Type("boolean")
* @Mapping\SerializedName("success")
*/
public $success;
/**
* @var array $credentials
*
* @Mapping\Type("array")
* @Mapping\SerializedName("credentials")
*/
public $credentials;
/**
* @var string $siteAccess
*
* @Mapping\Type("array")
* @Mapping\SerializedName("siteAccess")
*/
public $siteAccess;
/**
* @var array $sitesAvailable
*
* @Mapping\Type("array")
* @Mapping\SerializedName("sitesAvailable")
*/
public $sitesAvailable;
}

View file

@ -66,37 +66,39 @@ class LoyaltyService
{
global $USER;
$request = new LoyaltyCalculateRequest();
$request->order->customer->id = $USER->GetID();
$request = new LoyaltyCalculateRequest();
$request->order->customer->id = $USER->GetID();
$request->order->customer->externalId = $USER->GetID();
if ($discountPrice > 0) {
$request->order->discountManualAmount = $discountPrice;
}
if ($discountPercent > 0) {
$request->order->discountManualPercent = $discountPercent;
}
$request->site = ConfigProvider::getClientId();
$client = new SettingsService();
$credentials = $client->getCredentials();
$request->site = $credentials->sitesAvailable[0];
foreach ($basketItems as $item) {
$product = new SerializedOrderProduct();
$product = new SerializedOrderProduct();
if ($item['DISCOUNT_PRICE_PERCENT'] > 0) {
$product->discountManualPercent = $item['DISCOUNT_PRICE_PERCENT'];
}
if ($item['DISCOUNT_PRICE_PERCENT'] > 0) {
$product->discountManualAmount = $item['DISCOUNT_PRICE'];
}
$product->initialPrice = $item['PRICE'];
$product->offer->externalId = $item['ID'];
$product->offer->id = $item['ID'];
$product->offer->xmlId = $item['XML_ID'];
$product->quantity = $item['QUANTITY'];
try {
$price = GroupTable::query()->setSelect(['NAME'])->where(
[
@ -104,11 +106,11 @@ class LoyaltyService
]
)->fetch();
$product->priceType->code = $price['NAME'];
$product->priceType->code = $price['NAME'];
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
AddMessage2Log('GroupTable query error: ' . $e->getMessage());
}
$request->order->items[] = $product;
$request->order->items[] = $product;
}
return $this->client->loyaltyCalculate($request);

View file

@ -0,0 +1,48 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Service
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Service;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
use Intaro\RetailCrm\Component\Json\Deserializer;
use Intaro\RetailCrm\Model\Api\Response\Settings\CredentialsResponse;
/**
* Class SettingsService
*
* @package Intaro\RetailCrm\Service
*/
class SettingsService
{
/**
* @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter
*/
private $client;
/**
* LoyaltyService constructor.
*/
public function __construct()
{
$this->client = ClientFactory::createClientAdapter();
}
/**
* @return \Intaro\RetailCrm\Model\Api\Response\Settings\CredentialsResponse
*/
public function getCredentials(): CredentialsResponse
{
$response = $this->client->getCredentials();
return Deserializer::deserializeArray($response->getResponseBody(), CredentialsResponse::class);
}
}

View file

@ -1350,7 +1350,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
<div id="loyalty_main_settings" <?php if ($loyaltyProgramToggle !== 'Y') {
echo "hidden";
} ?>>
<table>
<table width="100%">
<tr class="heading">
<td colspan="2" class="option-other-heading">
<?php echo GetMessage('LP_SALE_ORDER_AJAX_HEAD'); ?>
@ -1382,7 +1382,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</td>
</tr>
<tr>
<td width="50%" >
<td width="50%" align="center">
<input type="button" onclick="replaceDefaultSaleTemplates()" class="adm-btn-save" value="<?php echo GetMessage('LP_REPLACE_TEMPLATE'); ?>" />
</td>
<td width="50%" >