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

add lang const in template, add request

This commit is contained in:
Sergey Chazov 2020-10-09 11:36:55 +03:00
parent 6fa3a29625
commit 6c63356e6c
9 changed files with 155 additions and 42 deletions

View file

@ -137,4 +137,9 @@ $MESS["EMPTY_BASKET_HINT"] = "#A1#Нажмите здесь#A2#, чтобы пр
$MESS["SOA_BAD_EXTENSION"] = "Неверный тип файла";
$MESS["SOA_MAX_SIZE"] = "Превышен максимальный размер файла";
$MESS["PAY_SYSTEM_PAYABLE_ERROR_DEFAULT"] = "Вы сможете оплатить заказ после того, как менеджер проверит наличие полного комплекта товаров на складе. Сразу после проверки вы получите письмо с инструкциями по оплате. Оплатить заказ можно будет в персональном разделе сайта.";
?>
$MESS["BONUS_PAYMENT"] = 'Оплата бонусами';
$MESS["HOW_MANY_BONUSES_TO_SPEND"] = 'Сколько бонусов потратить';
$MESS["BONUS_TOTAL"] = 'Всего бонусов:';
$MESS["YOU_CAN_SPEND"] = 'Можно потратить:';
$MESS["CALCULATION_ERROR"] = 'Не удалось рассчитать количество доступных бонусов.';

View file

@ -8186,7 +8186,8 @@ BX.namespace('BX.Sale.OrderAjaxComponent');
}
};
BX.Sale.OrderAjaxComponent.editPaySystemItems = function(paySystemNode) {
BX.Sale.OrderAjaxComponent.editPaySystemItems = function(paySystemNode)
{
if (!this.result.PAY_SYSTEM || this.result.PAY_SYSTEM.length <= 0)
return;

View file

@ -2,6 +2,7 @@
use Bitrix\Main\Loader;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Service\LoyaltyService;
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
@ -14,6 +15,19 @@ if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
Loader::includeModule('intaro.retailcrm');
$arResult['LOYALTY_STATUS'] = ConfigProvider::getLoyaltyProgramStatus();
//TODO Закомментированно до появления реального апи
//TODO добавить проверку на участие покупателя в программе лояльности (таска 68813)
/*$service = new LoyaltyService();
$calculate = $service->calculateBonus($arResult['BASKET_ITEMS'], $arResult['DISCOUNT_PRICE'], $arResult['DISCOUNT_PERCENT']);
if ($calculate->success) {
$arResult['AVAILABLE_BONUSES'] = $calculate->order->bonusesChargeTotal;
$arResult['TOTAL_BONUSES_COUNT'] = $calculate->order->loyaltyAccount->amount;
$arResult['LP_CALCULATE_SUCCESS'] = $calculate->success;
}*/
//TODO убрать заглушку после появления реальных методов
$arResult['LP_CALCULATE_SUCCESS'] = true;
$arResult['AVAILABLE_BONUSES'] = 300;
$arResult['TOTAL_BONUSES_COUNT'] = 600;
$component = $this->__component;

View file

@ -425,18 +425,18 @@ if (strlen($request->get('ORDER_ID')) > 0) {
<? endif ?>
<!-- INTARO BONUS BLOCK -->
<? if ($arResult['LOYALTY_STATUS'] === 'Y'): ?>
<? if ($arResult['LOYALTY_STATUS'] === 'Y' ): ?>
<div id="bx-soa-intaro" data-visited="true" class="bx-soa-section bx-selected">
<div class="bx-soa-section-title-container">
<h2 class="bx-soa-section-title col-sm-9">
<span class="bx-soa-section-title-count"></span> Оплата бонусами
<span class="bx-soa-section-title-count"></span><?= Loc::getMessage('BONUS_PAYMENT') ?>
</h2>
<div class="col-xs-12 col-sm-3 text-right"><a href="javascript:void(0)" class="bx-soa-editstep"><?=$arParams['MESS_EDIT']?></a></div>
</div>
<div class="bx-soa-section-content container-fluid" id="bx-soa-intaro-content">
<? if ($arResult['LP_CALCULATE_SUCCESS'] === true ): ?>
<div class="bx-soa-coupon">
<div id="bonus-msg">Сколько бонусов потратить?</div>
<div id="bonus-msg"><?= Loc::getMessage('HOW_MANY_BONUSES_TO_SPEND') ?></div>
<div class="bx-soa-coupon-block">
<div class="bx-input">
<input name='bonus-input' class="form-control" type="number" max="<?=$arResult['AVAILABLE_BONUSES']?>" id='bonus-input'>
@ -444,9 +444,12 @@ if (strlen($request->get('ORDER_ID')) > 0) {
<div id="bonus-input-error"></div>
</div>
</div>
<div>Всего бонусов: <label id="total-bonuses-count"><?=$arResult['TOTAL_BONUSES_COUNT']?></label></div>
<div>Можно применить: <label id="available-bonuses"><?=$arResult['AVAILABLE_BONUSES']?></label></div>
<div><?= Loc::getMessage('BONUS_TOTAL') ?> <label id="total-bonuses-count"><?=$arResult['TOTAL_BONUSES_COUNT']?></label></div>
<div><?= Loc::getMessage('YOU_CAN_SPEND') ?> <label id="available-bonuses"><?=$arResult['AVAILABLE_BONUSES']?></label></div>
</div>
<? else: ?>
<?= Loc::getMessage('CALCULATION_ERROR') ?>
<? endif ?>
</div>
</div>
<? endif ?>

View file

@ -13,8 +13,10 @@ namespace Intaro\RetailCrm\Component\ApiClient\Traits;
use Intaro\RetailCrm\Component\Json\Deserializer;
use Intaro\RetailCrm\Component\Json\Serializer;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\LoyaltyCalculateRequest;
use Intaro\RetailCrm\Model\Api\Request\Order\Loyalty\OrderLoyaltyApplyRequest;
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\LoyaltyCalculateResponse;
use Intaro\RetailCrm\Model\Api\Response\Order\Loyalty\OrderLoyaltyApplyResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
@ -61,4 +63,16 @@ trait LoyaltyTrait
return Deserializer::deserializeArray($response->getResponseBody(), OrderLoyaltyApplyResponse::class);
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Loyalty\LoyaltyCalculateRequest $request
* @return mixed
*/
public function loyaltyCalculate(LoyaltyCalculateRequest $request): ?LoyaltyCalculateResponse
{
$serialized = Serializer::serializeArray($request);
$response = $this->client->loyaltyOrderApply($serialized);
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyCalculateResponse::class);
}
}

View file

@ -589,7 +589,32 @@ class ConfigProvider
return self::$integrationDeliveriesMapping;
}
/**
* @return bool|string|null
*/
public static function getClientId()
{
return static::getOption(Constants::CLIENT_ID);
}
/**
* @return string|null
*/
public static function getLoyaltyProgramStatus()
{
return static::getOption(Constants::LOYALTY_PROGRAM_TOGGLE);
}
/**
* @param bool|string|null $loyaltyProgramStatus
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public static function setLoyaltyProgramStatus($loyaltyProgramStatus): void
{
static::setOption(Constants::LOYALTY_PROGRAM_TOGGLE, $loyaltyProgramStatus);
}
/**
* Wraps Bitrix \COption::GetOptionString(...)
*
@ -664,21 +689,4 @@ class ConfigProvider
{
return empty($value) && $value !== 0;
}
/**
* @return bool|string|null
*/
public static function getLoyaltyProgramStatus()
{
return static::getOption(Constants::LOYALTY_PROGRAM_TOGGLE);
}
/**
* @param bool|string|null $loyaltyProgramStatus
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public static function setLoyaltyProgramStatus($loyaltyProgramStatus): void
{
static::setOption(Constants::LOYALTY_PROGRAM_TOGGLE, $loyaltyProgramStatus);
}
}
}

View file

@ -59,15 +59,16 @@ class Constants
public const CRM_CURRENCY = 'currency';
public const CRM_ADDRESS_OPTIONS = 'address_options';
public const CRM_DIMENSIONS = 'order_dimensions';
public const PROTOCOL = 'protocol';
public const CRM_ORDER_FAILED_IDS = 'order_failed_ids';
public const PROTOCOL = 'protocol';
public const CRM_ORDER_FAILED_IDS = 'order_failed_ids';
public const CRM_CUSTOMERS_HISTORY_SINCE_ID = 'customer_history';
public const CRM_ORDER_HISTORY_DATE = 'order_history_date';
public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
public const CRM_ORDER_DIMENSIONS = 'order_dimensions';
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
public const CORPORATE_CONTRAGENT_TYPE = 'legal-entity';
public const LOYALTY_PROGRAM_TOGGLE = 'loyalty_program_toggle';
public const CRM_ORDER_HISTORY_DATE = 'order_history_date';
public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
public const CRM_ORDER_DIMENSIONS = 'order_dimensions';
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
public const CORPORATE_CONTRAGENT_TYPE = 'legal-entity';
public const LOYALTY_PROGRAM_TOGGLE = 'loyalty_program_toggle';
public const CLIENT_ID = 'client_id';
}

View file

@ -152,7 +152,7 @@ class EventsHandlers
$service = new LoyaltyService();
$response = $service->sendBonusPayment($orderId, $bonusCount);
//TODO - заглушка до появления api на стороне CRM. После появления реального апи - убрать
//TODO - заглушка до появления api на стороне CRM. После появления реального апи - убрать следующую строку
$response->success=true;
if ($response->success) {

View file

@ -9,10 +9,18 @@
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Service;
use Bitrix\Catalog\GroupTable;
use Bitrix\Main\ArgumentException;
use Bitrix\Main\ObjectPropertyException;
use Bitrix\Main\SystemException;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\LoyaltyCalculateRequest;
use Intaro\RetailCrm\Model\Api\Request\Order\Loyalty\OrderLoyaltyApplyRequest;
use Intaro\RetailCrm\Model\Api\SerializedOrderProduct;
/**
* Class LoyaltyService
@ -39,11 +47,70 @@ class LoyaltyService
* @param $bonusConunt
* @return \Intaro\RetailCrm\Model\Api\Response\Order\Loyalty\OrderLoyaltyApplyResponse|mixed|null
*/
public function sendBonusPayment($orderId, $bonusConunt){
$request = new OrderLoyaltyApplyRequest();
$request->order->id = $orderId;
public function sendBonusPayment($orderId, $bonusConunt)
{
$request = new OrderLoyaltyApplyRequest();
$request->order->id = $orderId;
$request->order->bonuses = $bonusConunt;
return $this->client->loyaltyOrderApply($request);
}
/**
* @param $basketItems
* @param $discountPrice
* @param $discountPercent
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\LoyaltyCalculateResponse|mixed|null
*/
public function calculateBonus($basketItems, $discountPrice, $discountPercent)
{
global $USER;
$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();
foreach ($basketItems as $item) {
$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(
[
['ID', '=', $item['PRICE_TYPE_ID']],
]
)->fetch();
$product->priceType->code = $price['NAME'];
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
AddMessage2Log('GroupTable query error: ' . $e->getMessage());
}
$request->order->items[] = $product;
}
return $this->client->loyaltyCalculate($request);
}
}