Преглед изворни кода

Merge branch 'develop'

master^2
Guillaume пре 3 година
родитељ
комит
3cc7f8a58c
3 измењених фајлова са 120 додато и 10 уклоњено
  1. +8
    -9
      ShopBundle/Resources/views/backend/productfamily/macros.html.twig
  2. +103
    -0
      ShopBundle/Services/SmsFactorUtils.php
  3. +9
    -1
      ShopBundle/Services/UtilsManager.php

+ 8
- 9
ShopBundle/Resources/views/backend/productfamily/macros.html.twig Прегледај датотеку

@@ -1,7 +1,7 @@
{% trans_default_domain 'lcshop' %}

{% macro product_sales_statistic(productsSalesStatistic, productFamily=false) %}
{% for weekNumber, weekNumberQuantity in productsSalesStatistic %}
{% for weekNumber, weekNumberQuantity in productsSalesStatistic|reverse(true) %}
<span class="text-success"><i class="fa fa-calendar"></i> {{ weekNumber }}</span>
<span class="text-info"><i class="fa fa-shopping-basket"></i>
<strong>
@@ -22,18 +22,17 @@
{% for weekNumber, weekNumberQuantity in productsSalesStatistic['data']['total_sales']['data']|reverse(true) %}
<span class="text-success"><i class="fa fa-calendar"></i> {{ weekNumber }}</span>
<span class="text-info"><i class="fa fa-shopping-basket"></i>
<strong>
{{ weekNumberQuantity is null ? 0 : weekNumberQuantity }}
{% if productFamily and (productFamily.behaviorDisplaySale== constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_DISPLAY_SALE_BY_MEASURE')) %}
{{ productFamily.unit.unitReference }}
{% endif %}
</strong>
</span>
<strong>
{{ weekNumberQuantity is null ? 0 : weekNumberQuantity }}
{% if productFamily and (productFamily.behaviorDisplaySale== constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_DISPLAY_SALE_BY_MEASURE')) %}
{{ productFamily.unit.unitReference }}
{% endif %}
</strong>
</span>
<br/>
{% endfor %}
</button>
{% endif %}

{% endmacro product_family_sales_statistic %}



+ 103
- 0
ShopBundle/Services/SmsFactorUtils.php Прегледај датотеку

@@ -0,0 +1,103 @@
<?php

namespace Lc\ShopBundle\Services;

use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Twig\Environment;

class SmsFactorUtils
{
const TO_USER = 'to-user' ;
const CONTENT_MESSAGE = 'content-message' ;
const CONTENT_TEMPLATE = 'content-template' ;
const CONTENT_DATA = 'content-data' ;

protected $client;
protected $parameterBag;
protected $mailUtils ;
protected $utils ;
protected $templating ;

public function __construct(
HttpClientInterface $client,
ParameterBagInterface $parameterBag,
MailUtils $mailUtils,
Utils $utils,
Environment $templating
) {
$this->client = $client;
$this->parameterBag = $parameterBag;
$this->mailUtils = $mailUtils ;
$this->utils = $utils ;
$this->templating = $templating ;
}

public function send($params = [])
{
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ;

if($user) {
$phone = $this->utils->formatPhoneNumber($user->getPhone()) ;

$message = '' ;
if(isset($params[self::CONTENT_MESSAGE])) {
$message = $params[self::CONTENT_MESSAGE] ;
}
elseif(isset($params[self::CONTENT_TEMPLATE])) {
$template = $params[self::CONTENT_TEMPLATE] ;
$paramsTemplate = [] ;
if(isset($params[self::CONTENT_DATA]) && is_array($params[self::CONTENT_DATA])) {
$paramsTemplate = $params[self::CONTENT_DATA] ;
}
$message = $this->templating->render($template, $paramsTemplate) ;
}

if($this->parameterBag->get('mailjet.dev.redirect.active') == 1) {
$this->mailUtils->send([
MailUtils::SUBJECT => 'Notification par SMS à '.$phone,
MailUtils::TO_EMAIL => $user->getEmail(),
MailUtils::CONTENT_TEMPLATE => 'mail/notification',
MailUtils::CONTENT_DATA => [
'message' => $message
],
]);

return true ;
}
else {
$token = $this->parameterBag->get('smsfactor.token');
$from = $this->parameterBag->get('smsfactor.from');

if ($token && strlen($token) > 0) {

$response = $this->client->request(
'GET',
'https://api.smsfactor.com/send',
[
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json; charset=utf-8',
'Accept' => 'application/json'
],
'query' => [
'sender' => $from,
'to' => $phone,
'text' => $message,
],
]
);

return $response ;
}
else {
throw new \ErrorException('Le token SMS SmsFactor n\'est pas défini.');
}
}
}

return false;
}

}

+ 9
- 1
ShopBundle/Services/UtilsManager.php Прегледај датотеку

@@ -30,6 +30,7 @@ class UtilsManager
protected $pointLocationUtils ;
protected $sectionUtils ;
protected $mailjetSmsUtils ;
protected $smsFactorUtils ;

public function __construct(
Utils $utils,
@@ -46,7 +47,8 @@ class UtilsManager
PointLocationUtils $pointLocationUtils,
UtilsProcess $utilsProcess,
SectionUtilsInterface $sectionUtils,
MailjetSmsUtils $mailjetSmsUtils
MailjetSmsUtils $mailjetSmsUtils,
SmsFactorUtils $smsFactorUtils
)
{
$this->utils = $utils ;
@@ -64,6 +66,7 @@ class UtilsManager
$this->utilsProcess = $utilsProcess ;
$this->sectionUtils = $sectionUtils ;
$this->mailjetSmsUtils = $mailjetSmsUtils ;
$this->smsFactorUtils = $smsFactorUtils ;
}

public function getUtils(): Utils
@@ -141,4 +144,9 @@ class UtilsManager
return $this->mailjetSmsUtils ;
}

public function getSmsFactorUtils(): SmsFactorUtils
{
return $this->smsFactorUtils ;
}

}

Loading…
Откажи
Сачувај