Parcourir la source

Refactoring services #885

refactoring
Guillaume il y a 1 an
Parent
révision
b49ad98310
15 fichiers modifiés avec 618 ajouts et 674 suppressions
  1. +0
    -3
      backend/controllers/AccessController.php
  2. +3
    -5
      common/logic/Producer/Producer/ProducerBuilder.php
  3. +11
    -0
      common/logic/Producer/Producer/ProducerSolver.php
  4. +5
    -0
      common/logic/Subscription/Subscription/SubscriptionRepository.php
  5. +5
    -3
      common/logic/User/User/User.php
  6. +21
    -3
      common/logic/User/UserProducer/UserProducerBuilder.php
  7. +2
    -2
      common/logic/User/UserProducer/UserProducerRepository.php
  8. +1
    -1
      common/logic/User/UserUserGroup/UserUserGroup.php
  9. +25
    -61
      frontend/controllers/SiteController.php
  10. +3
    -9
      frontend/views/site/signup.php
  11. +93
    -94
      producer/controllers/CreditController.php
  12. +265
    -265
      producer/controllers/OrderController.php
  13. +1
    -2
      producer/controllers/ProducerBaseController.php
  14. +93
    -126
      producer/controllers/SiteController.php
  15. +90
    -100
      producer/controllers/SubscriptionController.php

+ 0
- 3
backend/controllers/AccessController.php Voir le fichier

@@ -102,9 +102,6 @@ class AccessController extends BackendController
]);
}

/**
*
*/
public function actionDelete($idUser)
{
$user = User::searchOne([

+ 3
- 5
common/logic/Producer/Producer/ProducerBuilder.php Voir le fichier

@@ -6,6 +6,7 @@ use common\helpers\Opendistrib;
use common\helpers\Password;
use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\User\User\User;
use common\logic\User\UserProducer\UserProducer;
use common\logic\User\UserProducer\UserProducerBuilder;
use common\logic\User\UserProducer\UserProducerRepository;
@@ -63,12 +64,9 @@ class ProducerBuilder extends BaseService implements BuilderInterface
/**
* Lie un utilisateur à un producteur.
*/
public function addUser(int $idUser, int $idProducer, int $bookmark = 1): UserProducer
public function addUser(User $user, Producer $producer, int $bookmark = 1): UserProducer
{
$userProducer = $this->userProducerRepository->getOne($idUser, $idProducer);
if (!$userProducer) {
$userProducer = $this->userProducerBuilder->create($idUser, $idProducer, $bookmark);
}
$userProducer = $this->userProducerBuilder->createIfNotExist($user, $producer, $bookmark);

if (!$userProducer->getActive()) {
$userProducer->setActive(1);

+ 11
- 0
common/logic/Producer/Producer/ProducerSolver.php Voir le fichier

@@ -80,6 +80,17 @@ class ProducerSolver extends BaseService implements SolverInterface
return null;
}

public function getMainContactEmail(Producer $producer): ?string
{
$contact = $this->getMainContact($producer);

if ($contact) {
return $contact->email;
}

return null;
}

public function isUpToDateWithOpendistribVersion(Producer $producer): bool
{
return $producer->latest_version_opendistrib == GlobalParam::getOpendistribVersion();

+ 5
- 0
common/logic/Subscription/Subscription/SubscriptionRepository.php Voir le fichier

@@ -26,6 +26,11 @@ class SubscriptionRepository extends BaseService implements RepositoryInterface
];
}

public function getOneById(int $id): ?Subscription
{
return Subscription::searchOne(['id' => $id]);
}

public function get()
{
return Subscription::searchAll();

+ 5
- 3
common/logic/User/User/User.php Voir le fichier

@@ -38,6 +38,8 @@

namespace common\logic\User\User;

use common\logic\Order\Order\Order;
use common\logic\User\UserUserGroup\UserUserGroup;
use common\logic\User\UserProducer\UserProducer;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
@@ -231,17 +233,17 @@ class User extends ActiveRecordCommon implements IdentityInterface

public function getUserProducer()
{
return $this->hasMany(UserProducer::className(), ['id_user' => 'id']);
return $this->hasMany(UserProducer::class, ['id_user' => 'id']);
}

public function getUserUserGroup()
{
return $this->hasMany(UserUserGroup::className(), ['id_user' => 'id']);
return $this->hasMany(UserUserGroup::class, ['id_user' => 'id']);
}

public function getOrder()
{
return $this->hasMany(Order::className(), ['id_user' => 'id']);
return $this->hasMany(Order::class, ['id_user' => 'id']);
}

public function getName(): string

+ 21
- 3
common/logic/User/UserProducer/UserProducerBuilder.php Voir le fichier

@@ -9,6 +9,7 @@ use common\logic\Order\Order\Order;
use common\logic\Producer\Producer\Producer;
use common\logic\User\CreditHistory\CreditHistory;
use common\logic\User\CreditHistory\CreditHistorySolver;
use common\logic\User\User\User;

class UserProducerBuilder extends BaseService implements BuilderInterface
{
@@ -21,12 +22,12 @@ class UserProducerBuilder extends BaseService implements BuilderInterface
$this->userProducerRepository = $this->loadService(UserProducerRepository::class);
}

public function instanciate(int $idUser, int $idProducer, int $bookmark = 1)
public function instanciate(User $user, Producer $producer, int $bookmark = 1)
{
$userProducer = new UserProducer();

$userProducer->setIdUser($idUser);
$userProducer->setIdProducer($idProducer);
$userProducer->populateUser($user);
$userProducer->populateproducer($producer);
$userProducer->setCredit(0);
$userProducer->setActive(1);
$userProducer->setBookmark($bookmark);
@@ -34,6 +35,23 @@ class UserProducerBuilder extends BaseService implements BuilderInterface
return $userProducer;
}

public function create(User $user, Producer $producer, int $bookmark = 1): UserProducer
{
$userProducer = $this->instanciate($user, $producer, $bookmark);
$userProducer->save();
return $userProducer;
}

public function createIfNotExist(User $user, Producer $producer, int $bookmark = 1): UserProducer
{
$userProducer = $this->userProducerRepository->getOne($user, $producer);
if (!$userProducer) {
$userProducer = $this->create($user, $producer, $bookmark);
}

return $userProducer;
}

public function updateCredit(CreditHistory $creditHistory): void
{
$userProducer = $this->userProducerRepository->getOne($creditHistory->getIdUser(), $creditHistory->getIdProducer());

+ 2
- 2
common/logic/User/UserProducer/UserProducerRepository.php Voir le fichier

@@ -27,12 +27,12 @@ class UserProducerRepository extends BaseService implements RepositoryInterface
]);
}

public function getBy($idUser, $active = 1, $bookmark = 1)
public function getBy(User $user, $active = 1, $bookmark = 1)
{
return UserProducer::find()
->with(['producer'])
->where([
'id_user' => $idUser,
'id_user' => $user->id,
'active' => $active,
'bookmark' => $bookmark
])

+ 1
- 1
common/logic/User/UserUserGroup/UserUserGroup.php Voir le fichier

@@ -36,7 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

namespace common\logic\User\UserGroup;
namespace common\logic\User\UserUserGroup;

use common\logic\PointSale\PointSale\PointSale;
use Yii;

+ 25
- 61
frontend/controllers/SiteController.php Voir le fichier

@@ -123,25 +123,18 @@ class SiteController extends FrontendController

/**
* Affiche la page d'accueil.
*
* @return mixed
*/
public function actionIndex()
{
$this->getLogic()->getProducerContainer()->getBuilder();

$producerRepository = $this->getLogic()->getProducerContainer()->getRepository();

return $this->render('index', [
'producerDemoAccount' => $producerRepository->getOneDemoAccount(),
'producerDemoAccount' => $this->getLogic()->getProducerContainer()
->getRepository()->getOneDemoAccount(),
'dataProviderPrices' => $this->getDataProviderPrices()
]);
}

/**
* Page de présentation des tarifs
*
* @return mixed
* Page de présentation des tarifs.
*/
public function actionPrices()
{
@@ -152,10 +145,9 @@ class SiteController extends FrontendController

public function getDataProviderPrices()
{
$producerPriceRangeRepository = $this->getLogic()->getProducerPriceRangeContainer()->getRepository();

return new ActiveDataProvider([
'query' => $producerPriceRangeRepository->query(),
'query' => $this->getLogic()->getProducerPriceRangeContainer()
->getRepository()->query(),
'pagination' => [
'pageSize' => 100,
],
@@ -164,15 +156,12 @@ class SiteController extends FrontendController

/**
* Liste les producteurs utilisant la plateforme.
*
* @return mixed
*/
public function actionProducers()
{
$producerRepository = $this->getLogic()->getProducerContainer()->getRepository();

$dataProviderProducers = new ActiveDataProvider([
'query' => $producerRepository->queryActive(),
'query' => $this->getLogic()->getProducerContainer()
->getRepository()->queryActive(),
'pagination' => [
'pageSize' => 100,
],
@@ -185,8 +174,6 @@ class SiteController extends FrontendController

/**
* Affiche la page de connexion et traite le formulaire de connexion.
*
* @return mixed
*/
public function actionLogin()
{
@@ -205,13 +192,19 @@ class SiteController extends FrontendController
$userProducerArray = $this->getLogic()
->getUserProducerContainer()
->getRepository()
->getBy(GlobalParam::getCurrentUserId());
->getBy(GlobalParam::getCurrentUser());

if ($userProducerArray
&& is_array($userProducerArray)
&& count($userProducerArray) == 1) {

return $this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $userProducerArray[0]->producer->slug]));
$urlRedirect = $this->getUrlManagerProducer()
->createAbsoluteUrl([
'site/index',
'slug_producer' => $userProducerArray[0]->producer->slug
]);

return $this->redirect($urlRedirect);
}
else {
return $this->goBack();
@@ -226,8 +219,6 @@ class SiteController extends FrontendController

/**
* Déconnecte l'utilisateur.
*
* @return mixed
*/
public function actionLogout()
{
@@ -238,8 +229,6 @@ class SiteController extends FrontendController

/**
* Affiche la page de contact et traite le formulaire s'il est soumis.
*
* @return mixed
*/
public function actionContact()
{
@@ -264,8 +253,6 @@ class SiteController extends FrontendController

/**
* Affiche la page d'inscription et traite son formulaire.
*
* @return mixed
*/
public function actionSignup()
{
@@ -309,8 +296,6 @@ class SiteController extends FrontendController
/**
* Affiche la page de demande de nouveau mot de passe.
* Traitement du formulaire.
*
* @return mixed
*/
public function actionRequestPasswordReset()
{
@@ -320,6 +305,7 @@ class SiteController extends FrontendController
if ($model->sendEmail()) {
$this->setFlash('success', 'Un lien vous permettant de réinitialiser votre mot de passe
vient d\'être envoyé sur votre boîte mail.');

return $this->goHome();
}
else {
@@ -334,10 +320,6 @@ class SiteController extends FrontendController

/**
* Met à jour le mot de passe de l'utilisateur.
*
* @param string $token
* @return mixed
* @throws BadRequestHttpException
*/
public function actionResetPassword($token)
{
@@ -362,14 +344,9 @@ class SiteController extends FrontendController
}

/**
* Affiche le formulaire de demande de code pour accéder à certains
* producteurs.
*
* @param integer $id
* @return mixed
* @throws \yii\web\HttpException
* Affiche le formulaire de demande de code pour accéder à certains producteurs.
*/
public function actionProducerCode($id)
public function actionProducerCode(int $id)
{
$producerContainer = $this->getLogic()->getProducerContainer();
$producer = $producerContainer->getRepository()->getOneById($id);
@@ -384,7 +361,7 @@ class SiteController extends FrontendController
if ($producerCodeForm->load($this->getRequest()->post())
&& $producerCodeForm->validate()) {

$producerContainer->getBuilder()->addUser(GlobalParam::getCurrentUserId(), $id);
$producerContainer->getBuilder()->addUser(GlobalParam::getCurrentUser(), $producer);

$this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]));
}
@@ -398,11 +375,8 @@ class SiteController extends FrontendController
/**
* Affiche la page de connexion / inscription pour accéder notamment au
* formulaire de commande des producteurs.
*
* @param integer $id
* @return mixed
*/
public function actionProducer($id)
public function actionProducer(int $id)
{
$loginForm = new LoginForm();
$signupForm = new SignupForm();
@@ -417,7 +391,7 @@ class SiteController extends FrontendController
if ($this->getUser()->isGuest) {
if ($loginForm->load($this->getRequest()->post()) && $loginForm->login()) {
if (!strlen($producer->code)) {
$producerContainer->getBuilder()->addUser(GlobalParam::getCurrentUserId(), $id);
$producerContainer->getBuilder()->addUser(GlobalParam::getCurrentUser(), $producer);
}

$this->redirect($returnUrl);
@@ -442,24 +416,18 @@ class SiteController extends FrontendController
}

/**
* Indique à l'utilisateur que l'espace d'un producteur est hors ligne
*
* @param integer $id
* @return mixed
* Indique à l'utilisateur que l'espace d'un producteur est hors ligne.
*/
public function actionProducerOffline($id)
public function actionProducerOffline(int $id)
{
$producerRepository = $this->getLogic()->getProducerContainer()->getRepository();

return $this->render('producer_offline', [
'producer' => $producerRepository->getOneById($id),
'producer' => $this->getLogic()->getProducerContainer()
->getRepository()->getOneById($id),
]);
}

/**
* Affiche les mentions légales.
*
* @return mixed
*/
public function actionMentions()
{
@@ -468,8 +436,6 @@ class SiteController extends FrontendController

/**
* Affiche les conditions générale de service.
*
* @return mixed
*/
public function actionCgv()
{
@@ -478,8 +444,6 @@ class SiteController extends FrontendController

/**
* Affiche les précisions concernant l'utilisation du crédit.
*
* @return string
*/
public function actionCredit()
{

+ 3
- 9
frontend/views/site/signup.php Voir le fichier

@@ -38,15 +38,14 @@ termes.

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\SignupForm */
use common\logic\Config\TaxRate\TaxRate;
use yii\helpers\ArrayHelper;

$this->setTitle('Inscription') ;
$this->setMeta('description', 'Inscrivez-vous afin de profiter des fonctionnalités de la plateforme.');

$this->params['breadcrumbs'][] = $this->title;

?>
<div class="site-signup">

@@ -86,11 +85,6 @@ $this->params['breadcrumbs'][] = $this->title;
'prompt' => '--',
])
->label('TVA à appliquer par défaut'); ?>
<!-- <?//= $form->field($model, 'free_price',[
// 'inputTemplate' => '<div class="input-group">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>',
// ])
// ->label('Prix libre HT / mois')
// ->hint('Laissez ce champs vide si vous souhaitez dans un premier temps simplement tester la plateforme. Une fois l\'outil mis en place dans votre structure, vous pourrez modifier ce coût dans la section "Mon abonnement" de votre panneau d\'administration.') ; ?>-->
<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <a class="btn btn-xs btn-default" data-toggle="modal" data-target="#modal-cgv" href="javascript:void(0);">conditions générales de service</a> et les <a class="btn btn-xs btn-default" data-toggle="modal" data-target="#modal-prices" href="javascript:void(0);">conditions tarifaires</a>.') ?>
</div>
<div id="fields-user">

+ 93
- 94
producer/controllers/CreditController.php Voir le fichier

@@ -57,22 +57,22 @@ class CreditController extends ProducerBaseController
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'stripe-verification' => ['post'],
],
]
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'stripe-verification' => ['post'],
],
]
];
}

public function actions()
{
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}

@@ -90,8 +90,8 @@ class CreditController extends ProducerBaseController
{
$producer = $this->getProducer();

if(\Yii::$app->user->isGuest) {
return $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
if (\Yii::$app->user->isGuest) {
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

$searchModel = new CreditHistorySearch();
@@ -99,9 +99,9 @@ class CreditController extends ProducerBaseController
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

$userProducer = UserProducer::searchOne([
'id_producer' => $producer->id,
'id_user' => GlobalParam::getCurrentUserId()
]);
'id_producer' => $producer->id,
'id_user' => GlobalParam::getCurrentUserId()
]);

if (strlen($returnPayment)) {
if ($returnPayment == 'success') {
@@ -113,9 +113,9 @@ class CreditController extends ProducerBaseController
}

return $this->render('history', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'creditUser' => $userProducer->credit
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'creditUser' => $userProducer->credit
]);
}

@@ -123,8 +123,8 @@ class CreditController extends ProducerBaseController
{
$producer = $this->getProducer();

if(\Yii::$app->user->isGuest) {
return $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
if (\Yii::$app->user->isGuest) {
return $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

if ($producer->online_payment || $producer->option_stripe_mode_test) {
@@ -132,48 +132,48 @@ class CreditController extends ProducerBaseController
$creditForm = new CreditForm;

if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) {
$user = User::getCurrent();
$user = GlobalParam::getCurrentUser();

\Stripe\Stripe::setApiKey(
$producer->getPrivateKeyApiStripe()
$producer->getPrivateKeyApiStripe()
);

$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [
[
'price_data' => [
'currency' => 'eur',
'product_data' => [
'name' => 'Alimentation crédit',
],
'unit_amount' => (float)$creditForm->amount * 100,
],
'quantity' => 1,
]
],
'payment_method_types' => ['card'],
'mode' => 'payment',
'customer_email' => $user->email,
'client_reference_id' => $user->id,
'payment_intent_data' => [
'metadata' => [
'user_id' => $user->id,
'producer_id' => $producer->id
],
],
'success_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'credit/history',
'returnPayment' => 'success'
]
),
'cancel_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'credit/history',
'returnPayment' => 'cancel'
]
),
]);
'line_items' => [
[
'price_data' => [
'currency' => 'eur',
'product_data' => [
'name' => 'Alimentation crédit',
],
'unit_amount' => (float)$creditForm->amount * 100,
],
'quantity' => 1,
]
],
'payment_method_types' => ['card'],
'mode' => 'payment',
'customer_email' => $user->email,
'client_reference_id' => $user->id,
'payment_intent_data' => [
'metadata' => [
'user_id' => $user->id,
'producer_id' => $producer->id
],
],
'success_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'credit/history',
'returnPayment' => 'success'
]
),
'cancel_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'credit/history',
'returnPayment' => 'cancel'
]
),
]);

header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
@@ -181,7 +181,7 @@ class CreditController extends ProducerBaseController
}

return $this->render('add', [
'creditForm' => $creditForm
'creditForm' => $creditForm
]);
} else {
throw new \yii\base\UserException('Cette option est désactivée chez ce producteur.');
@@ -200,9 +200,9 @@ class CreditController extends ProducerBaseController

try {
$event = \Stripe\Webhook::constructEvent(
$payload,
$sig_header,
$producer->getPrivateKeyEndpointStripe()
$payload,
$sig_header,
$producer->getPrivateKeyEndpointStripe()
);
} catch (\UnexpectedValueException $e) {
// Invalid payload
@@ -221,10 +221,10 @@ class CreditController extends ProducerBaseController
$user = User::findOne($paymentIntentMetadata->user_id);
$idProducer = $paymentIntentMetadata->producer_id;

if(isset($paymentIntentMetadata->order_id)) {
if (isset($paymentIntentMetadata->order_id)) {
$order = Order::searchOne([
'id' => $paymentIntentMetadata->order_id
]);
'id' => $paymentIntentMetadata->order_id
]);
$pointSale = PointSale::searchOne(['id' => $order->id_point_sale]);
$distribution = DistributionModel::find()->where(['id' => $order->id_distribution])->one();
}
@@ -242,7 +242,7 @@ class CreditController extends ProducerBaseController
]
]);

if(!$creditHistoryExist) {
if (!$creditHistoryExist) {

// on crédite le crédit du client
$creditHistory = new CreditHistory();
@@ -333,38 +333,38 @@ class CreditController extends ProducerBaseController

// client
Mailjet::sendMail([
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'subject' => '['.$producer->name.'] Erreur de paiement',
'content_view_text' => '@common/mail/paymentError-text.php',
'content_view_html' => '@common/mail/paymentError-html.php',
'content_params' => [
'amount' => $amount,
'user' => $user,
'producer' => $producer,
]
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'subject' => '[' . $producer->name . '] Erreur de paiement',
'content_view_text' => '@common/mail/paymentError-text.php',
'content_view_html' => '@common/mail/paymentError-html.php',
'content_params' => [
'amount' => $amount,
'user' => $user,
'producer' => $producer,
]
]);

// producteur
if(isset($order) && $order) {
if (isset($order) && $order) {
Mailjet::sendMail([
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $contactProducer->email,
'to_name' => $contactProducer->name,
'subject' => '[' . $producer->name . '] Erreur de paiement',
'content_view_text' => '@common/mail/paymentErrorProducer-text.php',
'content_view_html' => '@common/mail/paymentErrorProducer-html.php',
'content_params' => [
'amount' => $amount,
'user' => $user,
'producer' => $producer,
'order' => $order,
'distribution' => $distribution
]
]);
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $contactProducer->email,
'to_name' => $contactProducer->name,
'subject' => '[' . $producer->name . '] Erreur de paiement',
'content_view_text' => '@common/mail/paymentErrorProducer-text.php',
'content_view_html' => '@common/mail/paymentErrorProducer-html.php',
'content_params' => [
'amount' => $amount,
'user' => $user,
'producer' => $producer,
'order' => $order,
'distribution' => $distribution
]
]);
}

break;
@@ -377,5 +377,4 @@ class CreditController extends ProducerBaseController
http_response_code(200);
die();
}

}

+ 265
- 265
producer/controllers/OrderController.php Voir le fichier

@@ -74,14 +74,14 @@ class OrderController extends ProducerBaseController

if (\Yii::$app->user->isGuest && !$producer->option_allow_order_guest) {
return $this->redirect(
Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $producer->id])
Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $producer->id])
);
}

if ($id) {
$order = Order::searchOne([
'id' => $id
]);
'id' => $id
]);
if ($order) {
if ($order->getState() == Order::STATE_OPEN) {
$params['order'] = $order;
@@ -91,9 +91,9 @@ class OrderController extends ProducerBaseController

if (strlen($date)) {
$distribution = DistributionModel::searchOne([
'date' => $date,
'id_producer' => $producer->id
]);
'date' => $date,
'id_producer' => $producer->id
]);

if ($distribution) {
$distributionsArray = DistributionModel::filterDistributionsByDateDelay([$distribution]);
@@ -116,13 +116,13 @@ class OrderController extends ProducerBaseController
$producer = $this->getProducer();

$query = Order::find()
->with('productOrder', 'pointSale', 'creditHistory')
->joinWith('distribution', 'distribution.producer')
->where([
'id_user' => Yii::$app->user->id,
'distribution.id_producer' => $producer->id
])
->params([':date_today' => date('Y-m-d')]);
->with('productOrder', 'pointSale', 'creditHistory')
->joinWith('distribution', 'distribution.producer')
->where([
'id_user' => Yii::$app->user->id,
'distribution.id_producer' => $producer->id
])
->params([':date_today' => date('Y-m-d')]);

$queryIncoming = clone $query;
$queryIncoming->andWhere('distribution.date >= :date_today')->orderBy('distribution.date ASC');
@@ -131,19 +131,19 @@ class OrderController extends ProducerBaseController
$queryPassed->andWhere('distribution.date < :date_today')->orderBy('distribution.date DESC');

$dataProviderOrders = new ActiveDataProvider([
'query' => ($type == 'incoming') ? $queryIncoming : $queryPassed,
'pagination' => [
'pageSize' => 10,
],
]);
'query' => ($type == 'incoming') ? $queryIncoming : $queryPassed,
'pagination' => [
'pageSize' => 10,
],
]);

return $this->render('history', [
'dataProviderOrders' => $dataProviderOrders,
'orderOk' => Yii::$app->getRequest()->get('orderOk', false),
'cancelOk' => Yii::$app->getRequest()->get('cancelOk', false),
'type' => $type,
'countIncoming' => $queryIncoming->count(),
'countPassed' => $queryPassed->count(),
'dataProviderOrders' => $dataProviderOrders,
'orderOk' => Yii::$app->getRequest()->get('orderOk', false),
'cancelOk' => Yii::$app->getRequest()->get('cancelOk', false),
'type' => $type,
'countIncoming' => $queryIncoming->count(),
'countPassed' => $queryPassed->count(),
]);
}

@@ -155,8 +155,8 @@ class OrderController extends ProducerBaseController
public function actionRemoveProducer($id = 0)
{
$userProducer = UserProducer::find()
->where(['id_producer' => $id, 'id_user' => GlobalParam::getCurrentUserId()])
->one();
->where(['id_producer' => $id, 'id_user' => GlobalParam::getCurrentUserId()])
->one();

$userProducer->active = 0;
$userProducer->save();
@@ -187,15 +187,15 @@ class OrderController extends ProducerBaseController
$user = User::getCurrent();

$order = Order::find()
->where('id_distribution = :id_distribution')
->andWhere('id_user = :id_user')
->andWhere('id_point_sale = :id_point_sale')
->params([
':id_distribution' => $posts['Order']['id_distribution'],
':id_point_sale' => $posts['Order']['id_point_sale'],
':id_user' => $user ? $user->id : null
])
->one();
->where('id_distribution = :id_distribution')
->andWhere('id_user = :id_user')
->andWhere('id_point_sale = :id_point_sale')
->params([
':id_distribution' => $posts['Order']['id_distribution'],
':id_point_sale' => $posts['Order']['id_point_sale'],
':id_user' => $user ? $user->id : null
])
->one();

if ($order && !$order->online_payment_url) {
if ($order->id_point_sale != $posts['Order']['id_point_sale']) {
@@ -206,21 +206,21 @@ class OrderController extends ProducerBaseController
// gestion user : option_allow_order_guest
if (isset($posts['user']) && $posts['user']) {
$userIndividualExist = User::searchOne([
'email' => $posts['user']['email'],
'type' => User::TYPE_INDIVIDUAL
]);
'email' => $posts['user']['email'],
'type' => User::TYPE_INDIVIDUAL
]);

if ($userIndividualExist) {
$errorUserGuest = 'Cette adresse email est déjà utilisée, veuillez vous <a href="' . Yii::$app->urlManagerFrontend->createUrl(
['site/producer', 'id' => $idProducer]
) . '">connecter à votre compte</a> ou en utiliser une autre.';
['site/producer', 'id' => $idProducer]
) . '">connecter à votre compte</a> ou en utiliser une autre.';
return ['status' => 'error', 'errors' => [$errorUserGuest]];
}

$user = User::searchOne([
'email' => $posts['user']['email'],
'type' => User::TYPE_GUEST
]);
'email' => $posts['user']['email'],
'type' => User::TYPE_GUEST
]);

if (!$user) {
$user = new User;
@@ -258,60 +258,60 @@ class OrderController extends ProducerBaseController

if ($producer->isOnlinePaymentActiveAndTypeOrder()) {
$order = Order::searchOne([
'id' => $order->id
]);
'id' => $order->id
]);

\Stripe\Stripe::setApiKey(
$producer->getPrivateKeyApiStripe()
$producer->getPrivateKeyApiStripe()
);

$lineItems = [];
foreach ($order->productOrder as $productOrder) {
$product = $productOrder->product;
$lineItems[] = [
'price_data' => [
'currency' => 'eur',
'product_data' => [
'name' => $product->name . ' (' . $productOrder->quantity . ' ' . Product::strUnit(
$product->unit,
'wording_short',
true
) . ')',
],
'unit_amount' => $productOrder->price * 100 * $productOrder->quantity,
'price_data' => [
'currency' => 'eur',
'product_data' => [
'name' => $product->name . ' (' . $productOrder->quantity . ' ' . Product::strUnit(
$product->unit,
'wording_short',
true
) . ')',
],
'quantity' => 1,
'unit_amount' => $productOrder->price * 100 * $productOrder->quantity,
],
'quantity' => 1,
];
}

$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => $lineItems,
'payment_method_types' => ['card'],
'mode' => 'payment',
'customer_email' => $user->email,
'client_reference_id' => $user->id,
'payment_intent_data' => [
'metadata' => [
'user_id' => $user->id,
'producer_id' => $producer->id,
'order_id' => $order->id
],
],
'success_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'order/confirm',
'idOrder' => $order->id,
'returnPayment' => 'success'
]
),
'cancel_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'order/confirm',
'idOrder' => $order->id,
'returnPayment' => 'cancel'
]
),
]);
'line_items' => $lineItems,
'payment_method_types' => ['card'],
'mode' => 'payment',
'customer_email' => $user->email,
'client_reference_id' => $user->id,
'payment_intent_data' => [
'metadata' => [
'user_id' => $user->id,
'producer_id' => $producer->id,
'order_id' => $order->id
],
],
'success_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'order/confirm',
'idOrder' => $order->id,
'returnPayment' => 'success'
]
),
'cancel_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(
[
'order/confirm',
'idOrder' => $order->id,
'returnPayment' => 'cancel'
]
),
]);
$redirect = $checkout_session->url;

$order->online_payment_url = $redirect;
@@ -354,7 +354,7 @@ class OrderController extends ProducerBaseController
}

foreach ($posts['products'] as $key => $quantity) {
$product = Product::find()->where(['id' => (int)$key])->one();
$product = Product::find()->where(['id' => (int)$key])->one();
$totalQuantity += $quantity;
if ($product && $quantity) {
$productsArray[] = $product;
@@ -376,9 +376,9 @@ class OrderController extends ProducerBaseController
$errorPointSale = false;
if (isset($distribution) && $distribution) {
$pointSaleDistribution = PointSaleDistributionModel::searchOne([
'id_distribution' => $distribution->id,
'id_point_sale' => $posts['Order']['id_point_sale']
]);
'id_distribution' => $distribution->id,
'id_point_sale' => $posts['Order']['id_point_sale']
]);

if (!$pointSaleDistribution || !$pointSaleDistribution->delivery) {
$errorPointSale = true;
@@ -395,9 +395,9 @@ class OrderController extends ProducerBaseController
}

$userPointSale = UserPointSale::searchOne([
'id_user' => GlobalParam::getCurrentUserId(),
'id_point_sale' => $pointSale->id
]);
'id_user' => GlobalParam::getCurrentUserId(),
'id_point_sale' => $pointSale->id
]);

if ($pointSale->restricted_access && !$userPointSale) {
$errorPointSale = true;
@@ -408,18 +408,18 @@ class OrderController extends ProducerBaseController

if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) {
$userProducer = UserProducer::searchOne([
'id_producer' => $order->distribution->id_producer,
'id_user' => $user->id
]);
'id_producer' => $order->distribution->id_producer,
'id_user' => $user->id
]);

// gestion point de vente
$pointSale = PointSale::searchOne([
'id' => $order->id_point_sale
]);
'id' => $order->id_point_sale
]);

// commentaire point de vente
$order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ?
$pointSale->getComment() : '';
$pointSale->getComment() : '';

// la commande est automatiquement réactivée lors d'une modification
$order->date_delete = null;
@@ -464,20 +464,20 @@ class OrderController extends ProducerBaseController
$productOrder->id_product = $product->id;
$productOrder->id_tax_rate = $product->taxRate->id;
$unit = (!is_null(
$order
) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit;
$coefficient = Product::$unitsArray[$unit]['coefficient'];
$order
) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit;
$coefficient = Product::$unitsArray[$unit]['coefficient'];
$quantity = ((float)$posts['products'][$product->id]) / $coefficient;
if ($availableProducts[$product->id]['quantity_max'] && $quantity > $availableProducts[$product->id]['quantity_remaining']) {
$quantity = $availableProducts[$product->id]['quantity_remaining'];
}
$productOrder->quantity = $quantity;
$productOrder->price = $product->getPrice([
'user' => User::getCurrent(),
'user_producer' => $userProducer,
'point_sale' => $pointSale,
'quantity' => $quantity
]);
'user' => User::getCurrent(),
'user_producer' => $userProducer,
'point_sale' => $pointSale,
'quantity' => $quantity
]);
$productOrder->unit = $product->unit;
$productOrder->step = $product->step;
$productOrder->save();
@@ -493,16 +493,16 @@ class OrderController extends ProducerBaseController
$creditFunctioning = $pointSale->getCreditFunctioning();
$creditUser = $user->getCredit($distribution->id_producer);
$order = Order::searchOne([
'id' => $order->id
]);
'id' => $order->id
]);
$amountPaid = $order->getAmount(Order::AMOUNT_PAID);
$amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING);

if ($credit && $pointSale->credit &&
(($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) ||
$creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY ||
($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active)
)) {
(($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) ||
$creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY ||
($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active)
)) {
$order->changeOrderStatus('waiting-paiement-by-credit', 'user');

// à payer
@@ -513,11 +513,11 @@ class OrderController extends ProducerBaseController

if ($amountRemaining > 0) {
$order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT,
$amountRemaining,
$distribution->id_producer,
GlobalParam::getCurrentUserId(),
GlobalParam::getCurrentUserId()
CreditHistory::TYPE_PAYMENT,
$amountRemaining,
$distribution->id_producer,
GlobalParam::getCurrentUserId(),
GlobalParam::getCurrentUserId()
);
$order->changeOrderStatus('paid-by-credit', 'user');
} else {
@@ -527,11 +527,11 @@ class OrderController extends ProducerBaseController
elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) {
$amountSurplus = $order->getAmount(Order::AMOUNT_SURPLUS);
$order->saveCreditHistory(
CreditHistory::TYPE_REFUND,
$amountSurplus,
$distribution->id_producer,
GlobalParam::getCurrentUserId(),
GlobalParam::getCurrentUserId()
CreditHistory::TYPE_REFUND,
$amountSurplus,
$distribution->id_producer,
GlobalParam::getCurrentUserId(),
GlobalParam::getCurrentUserId()
);
}
} else {
@@ -539,20 +539,20 @@ class OrderController extends ProducerBaseController
}

$paramsEmail = [
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'subject' => '[' . $producer->name . '] Confirmation de commande',
'content_view_text' => '@common/mail/orderConfirm-text.php',
'content_view_html' => '@common/mail/orderConfirm-html.php',
'content_params' => [
'order' => $order,
'pointSale' => $pointSale,
'distribution' => $distribution,
'user' => $user,
'producer' => $producer
]
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'subject' => '[' . $producer->name . '] Confirmation de commande',
'content_view_text' => '@common/mail/orderConfirm-text.php',
'content_view_html' => '@common/mail/orderConfirm-html.php',
'content_params' => [
'order' => $order,
'pointSale' => $pointSale,
'distribution' => $distribution,
'user' => $user,
'producer' => $producer
]
];

/*
@@ -567,8 +567,8 @@ class OrderController extends ProducerBaseController
// au producteur
$contactProducer = $producer->getMainContact();
if (Producer::getConfig('option_email_confirm_producer') && $contactProducer && strlen(
$contactProducer->email
)) {
$contactProducer->email
)) {
$paramsEmail['to_email'] = $contactProducer->email;
$paramsEmail['to_name'] = $contactProducer->name;
$paramsEmail['content_view_text'] = '@common/mail/orderConfirmProducer-text.php';
@@ -604,8 +604,8 @@ class OrderController extends ProducerBaseController
public function actionCancel($id)
{
$order = Order::searchOne([
'id' => $id
]);
'id' => $id
]);

if (!$order) {
throw new \yii\web\NotFoundHttpException('Commande introuvable');
@@ -662,32 +662,32 @@ class OrderController extends ProducerBaseController

// Producteur
$producer = Producer::searchOne([
'id' => $this->getProducer()->id
]);
'id' => $this->getProducer()->id
]);
$json['producer'] = [
'order_infos' => $producer->order_infos,
'credit' => $producer->credit,
'credit_functioning' => $producer->credit_functioning,
'use_credit_checked_default' => $producer->use_credit_checked_default,
'credit_limit' => is_numeric($producer->credit_limit) ? $producer->credit_limit : null,
'option_allow_order_guest' => $producer->option_allow_order_guest,
'option_order_entry_point' => $producer->option_order_entry_point,
'option_delivery' => $producer->option_delivery,
'online_payment' => $producer->online_payment,
'option_online_payment_type' => $producer->online_payment
'order_infos' => $producer->order_infos,
'credit' => $producer->credit,
'credit_functioning' => $producer->credit_functioning,
'use_credit_checked_default' => $producer->use_credit_checked_default,
'credit_limit' => is_numeric($producer->credit_limit) ? $producer->credit_limit : null,
'option_allow_order_guest' => $producer->option_allow_order_guest,
'option_order_entry_point' => $producer->option_order_entry_point,
'option_delivery' => $producer->option_delivery,
'online_payment' => $producer->online_payment,
'option_online_payment_type' => $producer->online_payment
];

// Distributions
$dateMini = date('Y-m-d');

$distributionsArray = DistributionModel::searchAll([
'active' => 1,
'id_producer' => $producer->id
], [
'conditions' => ['date > :date'],
'params' => [':date' => $dateMini],
'join_with' => ['pointSaleDistribution'],
]);
'active' => 1,
'id_producer' => $producer->id
], [
'conditions' => ['date > :date'],
'params' => [':date' => $dateMini],
'join_with' => ['pointSaleDistribution'],
]);
$distributionsArray = DistributionModel::filterDistributionsByDateDelay($distributionsArray);

// Filtre par point de vente
@@ -697,15 +697,15 @@ class OrderController extends ProducerBaseController
$distribution = $distributionsArray[$i];
if (Distribution::isPointSaleActive($distribution, $pointSaleId)) {
$countOrders = (int)Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSaleId
]);
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSaleId
]);
$orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId);

if (!$pointSaleCurrent->maximum_number_orders
|| ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId)
|| ($pointSaleCurrent->maximum_number_orders &&
($countOrders < $pointSaleCurrent->maximum_number_orders))) {
|| ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId)
|| ($pointSaleCurrent->maximum_number_orders &&
($countOrders < $pointSaleCurrent->maximum_number_orders))) {
$distributionsArrayFilterPointSale[] = $distribution;
}
}
@@ -720,10 +720,10 @@ class OrderController extends ProducerBaseController
$ordersUserArray = [];
if (GlobalParam::getCurrentUserId() && !$producer->isOnlinePaymentActiveAndTypeOrder()) {
$conditionsOrdersUser = [
'distribution.date > :date'
'distribution.date > :date'
];
$paramsOrdersUser = [
':date' => $dateMini
':date' => $dateMini
];

if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) {
@@ -732,19 +732,19 @@ class OrderController extends ProducerBaseController
}

$ordersUserArray = Order::searchAll([
'id_user' => GlobalParam::getCurrentUserId()
], [
'conditions' => $conditionsOrdersUser,
'params' => $paramsOrdersUser
]);
'id_user' => GlobalParam::getCurrentUserId()
], [
'conditions' => $conditionsOrdersUser,
'params' => $paramsOrdersUser
]);
}

if (is_array($ordersUserArray) && count($ordersUserArray)) {
foreach ($ordersUserArray as &$order) {
$order = array_merge($order->getAttributes(), [
'amount_total' => $order->getAmountWithTax(Order::AMOUNT_TOTAL),
'date_distribution' => $order->distribution->date,
'pointSale' => $order->pointSale->getAttributes()
'amount_total' => $order->getAmountWithTax(Order::AMOUNT_TOTAL),
'date_distribution' => $order->distribution->date,
'pointSale' => $order->pointSale->getAttributes()
]);
}
$json['orders'] = $ordersUserArray;
@@ -752,20 +752,20 @@ class OrderController extends ProducerBaseController

// User
$userProducer = UserProducer::searchOne([
'id_producer' => $producer->id,
'id_user' => GlobalParam::getCurrentUserId()
]);
'id_producer' => $producer->id,
'id_user' => GlobalParam::getCurrentUserId()
]);

if($user && !$userProducer) {
if ($user && !$userProducer) {
$userProducer = Producer::addUser($user->id, $producer->id);
}

$json['user'] = false;
if ($user && $userProducer) {
$json['user'] = [
'address' => $user->address,
'credit' => $userProducer->credit,
'credit_active' => $userProducer->credit_active,
'address' => $user->address,
'credit' => $userProducer->credit,
'credit_active' => $userProducer->credit_active,
];
}

@@ -779,51 +779,51 @@ class OrderController extends ProducerBaseController

// Commandes totales
$ordersArray = Order::searchAll([
'distribution.date' => $date,
]);
'distribution.date' => $date,
]);

// Catégories
$categoriesArray = ProductCategory::searchAll(
[],
[
'orderby' => 'product_category.position ASC',
'as_array' => true
]
$categoriesArray = ProductCategory::searchAll(
[],
[
'orderby' => 'product_category.position ASC',
'as_array' => true
]
);
$countProductsWithoutCategories = Product::searchCount([
'id_producer' => $this->getProducer()->id,
'product.active' => 1,
'product.id_product_category' => null
]);
$countProductsWithoutCategories = Product::searchCount([
'id_producer' => $this->getProducer()->id,
'product.active' => 1,
'product.id_product_category' => null
]);
if ($countProductsWithoutCategories) {
array_unshift($categoriesArray, ['id' => null, 'name' => 'Catégorie par défaut']);
}
$json['categories'] = $categoriesArray;

// Produits
$productsArray = Product::find()
->where([
'id_producer' => $this->getProducer()->id,
'product.active' => 1,
]);
$productsArray = Product::find()
->where([
'id_producer' => $this->getProducer()->id,
'product.active' => 1,
]);

$productsArray = $productsArray->joinWith([
'productDistribution' => function ($query) use (
$distribution
) {
$query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id
);
},
/*'productPointSale' => function ($query) use ($pointSaleCurrent) {
$query->andOnCondition(
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id
);
},*/
'productPrice'
])
->orderBy('product_distribution.active DESC, order ASC')
->all();
'productDistribution' => function ($query) use (
$distribution
) {
$query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id
);
},
/*'productPointSale' => function ($query) use ($pointSaleCurrent) {
$query->andOnCondition(
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id
);
},*/
'productPrice'
])
->orderBy('product_distribution.active DESC, order ASC')
->all();

$productsArrayFilter = [];

@@ -837,16 +837,16 @@ class OrderController extends ProducerBaseController
$indexProduct = 0;
foreach ($productsArrayFilter as $key => &$product) {
$product = array_merge(
$product->getAttributes(),
[
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($user, $pointSaleCurrent),
'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'],
]
$product->getAttributes(),
[
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($user, $pointSaleCurrent),
'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'],
]
);

$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient'];
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient'];

if (is_null($product['photo'])) {
$product['photo'] = '';
@@ -856,8 +856,8 @@ class OrderController extends ProducerBaseController
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray);
$product['quantity_ordered'] = $quantityOrder;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder;
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit_ref'] = Product::strUnit($product['unit'], 'wording_short', true);
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit_ref'] = Product::strUnit($product['unit'], 'wording_short', true);

if ($orderUser) {
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true);
@@ -866,13 +866,13 @@ class OrderController extends ProducerBaseController
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit;
foreach ($orderUser->productOrder as $productOrder) {
if ($productOrder->id_product == $product['id']) {
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true);
$product['wording_unit'] = Product::strUnit($productOrder->unit, 'wording_unit', true);
$product['step'] = $productOrder->step;
}
}
} else {
$product['quantity_form'] = 0;
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
$product['wording_unit'] = Product::strUnit($product['unit'], 'wording_unit', true);
}
$product['coefficient_unit'] = $coefficient_unit;

@@ -895,8 +895,8 @@ class OrderController extends ProducerBaseController
$orderUser = false;
if (GlobalParam::getCurrentUserId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => GlobalParam::getCurrentUserId(),
'distribution.date' => $date,
'id_user' => GlobalParam::getCurrentUserId(),
];

if ($pointSaleId) {
@@ -912,8 +912,8 @@ class OrderController extends ProducerBaseController

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

@@ -926,48 +926,48 @@ class OrderController extends ProducerBaseController

if ($distribution) {
$pointsSaleArray = $pointsSaleArray->joinWith([
'pointSaleDistribution' => function ($query) use (
$distribution
) {
$query->where(
[
'id_distribution' => $distribution->id,
'delivery' => 1
]
);
}
]);
'pointSaleDistribution' => function ($query) use (
$distribution
) {
$query->where(
[
'id_distribution' => $distribution->id,
'delivery' => 1
]
);
}
]);
}

if (GlobalParam::getCurrentUserId()) {
$pointsSaleArray = $pointsSaleArray->with([
'userPointSale' => function ($query) {
$query->onCondition(
['id_user' => GlobalParam::getCurrentUserId()]
);
}
]);
'userPointSale' => function ($query) {
$query->onCondition(
['id_user' => GlobalParam::getCurrentUserId()]
);
}
]);
}

$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer])
->andWhere(
'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))'
)
->params([':id_user' => GlobalParam::getCurrentUserId()])
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC')
->all();
->andWhere(
'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))'
)
->params([':id_user' => GlobalParam::getCurrentUserId()])
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC')
->all();

$creditFunctioningProducer = Producer::getConfig('credit_functioning');
$position = 0;

foreach ($pointsSaleArray as &$pointSale) {
$pointSale = array_merge($pointSale->getAttributes(), [
'pointSaleDistribution' => [
'id_distribution' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->id_distribution : false,
'id_point_sale' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->id_point_sale : false,
'delivery' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->delivery : false,
],
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '')
'pointSaleDistribution' => [
'id_distribution' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->id_distribution : false,
'id_point_sale' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->id_point_sale : false,
'delivery' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->delivery : false,
],
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '')
]);
if ($pointSale['code'] && strlen($pointSale['code'])) {
$pointSale['code'] = '***';
@@ -978,9 +978,9 @@ class OrderController extends ProducerBaseController

if ($distribution) {
$pointSale['count_orders'] = (int)Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSale['id']
]);
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSale['id']
]);
}

$pointSale['position'] = $position;
@@ -1020,8 +1020,8 @@ class OrderController extends ProducerBaseController
}

return $this->render('confirm', [
'order' => $order,
'returnPayment' => $returnPayment
'order' => $order,
'returnPayment' => $returnPayment
]);
}


+ 1
- 2
producer/controllers/ProducerBaseController.php Voir le fichier

@@ -103,9 +103,8 @@ class ProducerBaseController extends CommonController
/**
* Retourne le producteur courant.
*
*/
public function getProducer()
public function getProducer() : Producer
{
if($this->producer) {
return $this->producer ;

+ 93
- 126
producer/controllers/SiteController.php Voir le fichier

@@ -40,9 +40,11 @@ namespace producer\controllers;

use common\forms\ContactForm;
use common\helpers\GlobalParam;
use common\logic\User\User\User;
use common\logic\User\UserProducer\UserProducer;
use common\models\ProductCategory;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Product\Product\Product;
use common\logic\Product\ProductCategory\ProductCategory;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;

class SiteController extends ProducerBaseController
{
@@ -58,28 +60,25 @@ class SiteController extends ProducerBaseController
public function actions()
{
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}

/**
* Affiche et gère les erreurs.
*
* @return mixed
*/
public function actionError()
{
$exception = Yii::$app->errorHandler->exception;
$exception = \Yii::$app->errorHandler->exception;

if ($exception !== null) {
if ($exception->getMessage() == 'Producteur introuvable') {
Yii::$app->getResponse()->redirect(
Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true])
\Yii::$app->getResponse()->redirect(
\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true])
)->send();
return;
} else {
return $this->render('error', ['exception' => $exception]);
}
@@ -88,78 +87,73 @@ class SiteController extends ProducerBaseController

/**
* Affiche la page d'accueil des producteurs comprenant une image, une
* description, la liste des points de vente et les produits
*
* @return ProducerView
* description, la liste des points de vente et les produits.
*/
public function actionIndex()
{
// points de vente
$dataProviderPointsSale = new ActiveDataProvider([
'query' => PointSale::find()
->where([
'id_producer' => $this->getProducer(
)->id,
'restricted_access' => 0,
'status' => 1
])->orderBy(
'code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC'
//'default DESC, is_bread_box ASC, name ASC'
),
'pagination' => [
'pageSize' => 50,
],
'sort' => false,
]);
'query' => PointSale::find()
->where([
'id_producer' => $this->getProducer()->id,
'restricted_access' => 0,
'status' => 1
])->orderBy(
'code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC'
),
'pagination' => [
'pageSize' => 50,
],
'sort' => false,
]);

// produits
$categoriesArray = ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']);
$categoriesArray = ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']);
$dataProviderProductsByCategories = [];
foreach ($categoriesArray as $category) {
$dataProviderProductsByCategories[$category->id] = new ActiveDataProvider([
'query' => Product::find()
->andWhere([
'id_producer' => $this->getProducer(
)->id,
'active' => true,
])
->andWhere(
'product.id_product_category = :id_product_category'
)
->params(
[':id_product_category' => $category->id]
)
->orderBy(
'order ASC'
),
'pagination' => [
'pageSize' => 500,
],
'sort' => false,
]);
'query' => Product::find()
->andWhere([
'id_producer' => $this->getProducer()->id,
'active' => true,
])
->andWhere(
'product.id_product_category = :id_product_category'
)
->params(
[':id_product_category' => $category->id]
)
->orderBy(
'order ASC'
),
'pagination' => [
'pageSize' => 500,
],
'sort' => false,
]);
}

$queryProducts = Product::find()
->andWhere([
'id_producer' => $this->getProducer()->id,
'active' => true,
'id_product_category' => null,
])
->orderBy('order ASC');
$queryProducts = Product::find()
->andWhere([
'id_producer' => $this->getProducer()->id,
'active' => true,
'id_product_category' => null,
])
->orderBy('order ASC');

$dataProviderProducts = new ActiveDataProvider([
'query' => $queryProducts,
'pagination' => [
'pageSize' => 500,
],
'sort' => false,
]);
'query' => $queryProducts,
'pagination' => [
'pageSize' => 500,
],
'sort' => false,
]);

$products = $queryProducts->all();
foreach ($dataProviderProductsByCategories as $dataProvider) {
$products = array_merge(
$products,
$dataProvider->query->all()
$products,
$dataProvider->query->all()
);
}

@@ -176,49 +170,42 @@ class SiteController extends ProducerBaseController
}

return $this->render('index', [
'dataProviderProductsByCategories' => $dataProviderProductsByCategories,
'dataProviderPointsSale' => $dataProviderPointsSale,
'dataProviderProducts' => $dataProviderProducts,
'hasProductPhoto' => $hasProductPhoto,
'hasProductWeight' => $hasProductWeight,
'categories' => $categoriesArray,
'dataProviderProductsByCategories' => $dataProviderProductsByCategories,
'dataProviderPointsSale' => $dataProviderPointsSale,
'dataProviderProducts' => $dataProviderProducts,
'hasProductPhoto' => $hasProductPhoto,
'hasProductWeight' => $hasProductWeight,
'categories' => $categoriesArray,
]);
}

/**
* Affiche et traite le formulaire de contact dédié aux producteurs
*
* @return ProducerView
* Affiche et traite le formulaire de contact dédié aux producteurs.
*/
public function actionContact()
{
$model = new ContactForm();
$producer = $this->getProducer();

if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$isSent = false;
if (is_array($producer->contact)) {
$email = '';
$contact = $producer->getMainContact();
if ($contact) {
$email = $contact->email;
}

$email = $this->getLogic()->getProducerContainer()->getSolver()->getMainContactEmail($producer);
if (strlen($email) && $model->sendEmail($email)) {
$isSent = true;
}
}

if ($isSent) {
Yii::$app->session->setFlash('success', 'Votre message a bien été envoyé.');
$this->setFlash('success', 'Votre message a bien été envoyé.');
} else {
Yii::$app->session->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.');
$this->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.');
}

return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -226,51 +213,33 @@ class SiteController extends ProducerBaseController
/**
* Ajoute ou supprime un producteur des favoris de l'utilisateur.
* Redirige vers la page d'accueil du producteur.
*
* @param $action 'add' ou 'delete'
*/
public function actionBookmarks($action)
public function actionBookmarks(string $action)
{
$producer = $this->getProducer();
$userProducer = UserProducer::find()
->where([
'id_user' => GlobalParam::getCurrentUserId(),
'id_producer' => $producer->id
])
->one();

if (!$userProducer) {
$userProducer = $this->getLogic()->getProducerContainer()->getBuilder()->addUser(GlobalParam::getCurrentUserId(), $producer->id);
}

if ($userProducer) {
if ($action == 'add') {
$userProducer->bookmark = 1;
Yii::$app->session->setFlash(
'success',
'Le producteur <strong>' . Html::encode(
$producer->name
) . '</strong> vient d\'être ajouté à vos favoris.'
);
} else {
$userProducer->bookmark = 0;
Yii::$app->session->setFlash(
'success',
'Le producteur <strong>' . Html::encode(
$producer->name
) . '</strong> vient d\'être supprimé de vos favoris.'
);
}
$userProducer->save();
$userProducer = $this->getLogic()->getUserProducerContainer()
->getBuilder()->createIfNotExist(GlobalParam::getCurrentUser(), $producer);

if ($action == 'add') {
$userProducer->bookmark = 1;
$this->setFlash(
'success',
'Le producteur <strong>' . Html::encode($producer->name) . '</strong> vient d\'être ajouté à vos favoris.'
);
} else {
$userProducer->bookmark = 0;
$this->setFlash(
'success',
'Le producteur <strong>' . Html::encode($producer->name) . '</strong> vient d\'être supprimé de vos favoris.'
);
}
$userProducer->save();

$this->redirect(['site/index']);
return $this->redirect(['site/index']);
}

/**
* Affiche les mentions légales du producteur.
*
* @return ProducerView
*/
public function actionMentions()
{
@@ -281,14 +250,12 @@ class SiteController extends ProducerBaseController
}

return $this->render('mentions', [
'producer' => $producer
'producer' => $producer
]);
}

/**
* Affiche les conditions générales de vente du producteur.
*
* @return ProducerView
*/
public function actionGcs()
{
@@ -299,7 +266,7 @@ class SiteController extends ProducerBaseController
}

return $this->render('gcs', [
'producer' => $producer
'producer' => $producer
]);
}
}

+ 90
- 100
producer/controllers/SubscriptionController.php Voir le fichier

@@ -38,11 +38,16 @@

namespace producer\controllers;

use common\helpers\Debug;
use common\forms\SubscriptionForm;
use common\helpers\GlobalParam;
use common\logic\User\User\User;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Product\Product\Product;
use common\logic\Subscription\ProductSubscription\ProductSubscription;
use common\logic\Subscription\Subscription\SubscriptionSearch;
use common\logic\User\UserProducer\UserProducer;
use yii\base\UserException;
use yii\filters\AccessControl;
use yii\web\NotFoundHttpException;

class SubscriptionController extends ProducerBaseController
{
@@ -51,108 +56,100 @@ class SubscriptionController extends ProducerBaseController
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
]
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['@'],
]
],
],
];
}

/**
* Liste les commandes récurrente du producteur.
*
* @return string
* Liste les abonnements de l'utilisateur.
*/
public function actionIndex()
{
if(\Yii::$app->user->isGuest) {
if (\Yii::$app->user->isGuest) {
$producer = $this->getProducer();
return $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

$searchModel = new SubscriptionSearch;
$searchModel = new SubscriptionSearch();
$searchModel->id_user = GlobalParam::getCurrentUserId();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}

public function actionAjaxProcess()
{
// form
$model = new SubscriptionForm;
$subscriptionRepository = $this->getLogic()->getSubscriptionContainer()->getRepository();
$model = new SubscriptionForm();
$model->id_producer = GlobalParam::getCurrentProducerId();
$model->id_user = GlobalParam::getCurrentUserId();

$posts = Yii::$app->request->post();
$posts = \Yii::$app->request->post();

$idSubscription = (int)$posts['idSubscription'];
$isUpdate = false;
if ($idSubscription) {
$subscription = Subscription::findOne($idSubscription);
$subscription = $subscriptionRepository->getOneById($idSubscription);

if ($subscription) {
$model->id = $idSubscription;
$isUpdate = true;
}
}

if ($model->load($posts) && $model->validate()
&& $model->save()) {
$subscription = Subscription::searchOne([
'id' => $model->id
]);
if ($model->load($posts) && $model->validate() && $model->save()) {

$subscription = $subscriptionRepository->getOneById($model->id);
$subscription->updateIncomingDistributions($isUpdate);

if ($isUpdate) {
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié');
$this->setFlash('success', 'Abonnement modifié');
} else {
Yii::$app->getSession()->setFlash('success', 'Abonnement ajouté');
$this->setFlash('success', 'Abonnement ajouté');
}
}
}

/**
* Crée une commande récurrente.
*
* @return string
*/
public function actionForm($id = 0)
public function actionForm(int $id = 0)
{
if(\Yii::$app->user->isGuest) {
if (\Yii::$app->user->isGuest) {
$producer = $this->getProducer();
return $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

return $this->render('form', [
'idSubscription' => (int)$id
'idSubscription' => (int) $id
]);
}

/**
* Modifie une commande récurrente.
*
* @param integer $id
* @return string
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
if(\Yii::$app->user->isGuest) {
if (\Yii::$app->user->isGuest) {
$producer = $this->getProducer();
return $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

// form
$subscriptionRepository = $this->getLogic()->getSubscriptionContainer()->getRepository();
$model = new SubscriptionForm;
$subscription = Subscription::findOne($id);
$subscription = $subscriptionRepository->getOneById($id);

if ($subscription) {
$model->id = $id;
$model->id_producer = $subscription->id_producer;
@@ -175,9 +172,9 @@ class SubscriptionController extends ProducerBaseController
$model->week_frequency = $subscription->week_frequency;

// produits
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $model->id
]);
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $model->id
]);

foreach ($arrayProductsSubscription as $productSubscription) {
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity;
@@ -186,25 +183,25 @@ class SubscriptionController extends ProducerBaseController
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404);
}

// produits
$productsArray = Product::searchAll();
$productsArray = $this->getLogic()->getProductContainer()->getRepository()->get();

if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
if (!strlen($model->date_end)) {
$model->date_end = null;
}
if ($model->save()) {
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié');
$this->setFlash('success', 'Abonnement modifié');

$subscription = $subscriptionRepository->getOneById($model->id);
$matchedDistributionsArray = $subscriptionRepository->searchMatchedIncomingDistributions($subscription);

$subscription = Subscription::findOne($model->id);
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions();
if (count($matchedDistributionsArray)) {
return $this->redirect(
[
'subscription/update-distributions',
'idSubscription' => $subscription->id,
'update' => true
]
[
'subscription/update-distributions',
'idSubscription' => $subscription->id,
'update' => true
]
);
} else {
return $this->redirect(['subscription/index']);
@@ -213,30 +210,27 @@ class SubscriptionController extends ProducerBaseController
}

return $this->render('update', [
'model' => $model,
'productsArray' => $productsArray
'model' => $model,
'productsArray' => $productsArray
]);
}

/**
* Supprime un abonnement
*
* @param integer $id
* Supprime un abonnement.
*/
public function actionDelete($id)
{
if(\Yii::$app->user->isGuest) {
if (\Yii::$app->user->isGuest) {
$producer = $this->getProducer();
return $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
return $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

$subscription = Subscription::searchOne([
'id' => $id
]);
ProductSubscription::deleteAll(['id_subscription' => $id]);
$subscription = $this->getLogic()->getSubscriptionContainer()->getRepository()->getOneById($id);
ProductSubscription::deleteAll(['id_subscription' => $id]);
$subscription->deleteOrdersIncomingDistributions();
$subscription->delete();
Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé');
\Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé');

return $this->redirect(['subscription/index']);
}

@@ -247,16 +241,16 @@ class SubscriptionController extends ProducerBaseController

$user = GlobalParam::getCurrentUser();
$userProducer = UserProducer::searchOne([
'id_user' => GlobalParam::getCurrentUserId()
]);
'id_user' => GlobalParam::getCurrentUserId()
]);
$pointSale = false;

if ($idSubscription > 0) {
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $idSubscription
]);
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $idSubscription
]);

$subscription = Subscription::findOne($idSubscription);
$subscription = $this->getLogic()->getSubscriptionContainer()->getRepository()->getOneById($idSubscription);

if ($subscription) {
if ($subscription->id_point_sale) {
@@ -266,34 +260,34 @@ class SubscriptionController extends ProducerBaseController
}

// Produits
$productsArray = Product::searchAll();
$productsArray = Product::searchAll();
$indexProduct = 0;
foreach ($productsArray as &$product) {
$quantity = 0;
$coefficientUnit = Product::$unitsArray[$product->unit]['coefficient'];
$coefficientUnit = Product::$unitsArray[$product->unit]['coefficient'];
if (isset($arrayProductsSubscription) && count($arrayProductsSubscription)) {
foreach ($arrayProductsSubscription as $productSubscription) {
if ($product->id == $productSubscription->id_product) {
$coefficientUnit = Product::$unitsArray[$productSubscription->product->unit]['coefficient'];
$coefficientUnit = Product::$unitsArray[$productSubscription->product->unit]['coefficient'];
$quantity = $productSubscription->quantity * $coefficientUnit;
}
}
}

$product = array_merge(
$product->getAttributes(),
[
'index' => $indexProduct++,
'quantity_form' => $quantity,
'coefficient_unit' => $coefficientUnit,
'wording_unit' => Product::strUnit($product->unit, 'wording_unit', true),
'wording_short' => Product::strUnit($product->unit, 'wording_short'),
'price_with_tax' => $product->getPriceWithTax([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale
]),
]
$product->getAttributes(),
[
'index' => $indexProduct++,
'quantity_form' => $quantity,
'coefficient_unit' => $coefficientUnit,
'wording_unit' => Product::strUnit($product->unit, 'wording_unit', true),
'wording_short' => Product::strUnit($product->unit, 'wording_short'),
'price_with_tax' => $product->getPriceWithTax([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale
]),
]
);
}

@@ -302,7 +296,7 @@ class SubscriptionController extends ProducerBaseController
$pointsSaleArray = PointSale::searchAll();
foreach ($pointsSaleArray as &$pointSale) {
$pointSale = array_merge($pointSale->getAttributes(), [
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '')
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '')
]);
if ($pointSale['code'] && strlen($pointSale['code'])) {
$pointSale['code'] = '***';
@@ -312,9 +306,9 @@ class SubscriptionController extends ProducerBaseController
$params['points_sale'] = $pointsSaleArray;

if ($idSubscription > 0) {
$subscription = Subscription::searchOne([
'id' => $idSubscription
]);
$subscription = Subscription::searchOne([
'id' => $idSubscription
]);

if (!$subscription || $subscription->id_user != GlobalParam::getCurrentUserId()) {
throw new UserException('Abonnement introuvable');
@@ -328,10 +322,6 @@ class SubscriptionController extends ProducerBaseController

/**
* Vérifie le code saisi pour un point de vente.
*
* @param integer $idPointSale
* @param string $code
* @return boolean
*/
public function actionAjaxValidateCodePointSale($idPointSale, $code)
{

Chargement…
Annuler
Enregistrer