浏览代码

Option permettant de commander en tant que visiteur

refactoring
Guillaume 3 年前
父节点
当前提交
528d901b0f
共有 13 个文件被更改,包括 6525 次插入46 次删除
  1. +1
    -1
      backend/controllers/DistributionController.php
  2. +6
    -0
      backend/views/producer/update.php
  3. +2
    -1
      common/models/Producer.php
  4. +16
    -0
      console/migrations/m210318_102840_add_option_allow_order_guest.php
  5. +1
    -0
      producer/assets/VuejsOrderOrderAsset.php
  6. +87
    -34
      producer/controllers/OrderController.php
  7. 二进制
      producer/runtime/cache/96/963454f612a8b5fb4a63ba1e97f028a1.bin
  8. +6293
    -0
      producer/runtime/logs/app.log
  9. +2
    -2
      producer/views/layouts/main.php
  10. +7
    -6
      producer/views/order/confirm.php
  11. +31
    -1
      producer/views/order/order.php
  12. +4
    -0
      producer/web/js/jquery.validate.min.js
  13. +75
    -1
      producer/web/js/vuejs/order-order.js

+ 1
- 1
backend/controllers/DistributionController.php 查看文件

@@ -238,7 +238,7 @@ class DistributionController extends BackendController
}

$arrayCreditUser = [];
if (isset($order->user) && isset($order->user->userProducer)) {
if (isset($order->user) && isset($order->user->userProducer) && isset($order->user->userProducer[0])) {
$arrayCreditUser['credit'] = $order->user->userProducer[0]->credit;
}


+ 6
- 0
backend/views/producer/update.php 查看文件

@@ -283,6 +283,12 @@ $this->addBreadcrumb($this->getTitle()) ;
0 => 'Non',
1 => 'Oui'
], []); ?>

<?= $form->field($model, 'option_allow_order_guest')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
</div>
</div>


+ 2
- 1
common/models/Producer.php 查看文件

@@ -137,7 +137,7 @@ class Producer extends ActiveRecordCommon
}],
[['description', 'mentions', 'gcs', 'order_infos', 'slug', 'secret_key_payplug', 'background_color_logo', 'option_behavior_cancel_order', 'tiller_provider_token', 'tiller_restaurant_token', 'status',
'document_infos_bottom', 'document_infos_quotation', 'document_infos_invoice', 'document_infos_delivery_note', 'address', 'behavior_home_point_sale_day_list', 'behavior_order_select_distribution', 'option_payment_info', 'option_order_reference_type'], 'string'],
[['negative_balance', 'credit', 'active', 'online_payment', 'user_manage_subscription', 'option_allow_user_gift', 'use_credit_checked_default', 'tiller', 'document_display_orders_invoice', 'document_display_orders_delivery_note', 'document_display_prices_delivery_note', 'option_email_confirm', 'option_email_confirm_producer', 'option_csv_export_all_products', 'option_csv_export_by_piece', 'option_export_display_product_reference'], 'boolean'],
[['negative_balance', 'credit', 'active', 'online_payment', 'user_manage_subscription', 'option_allow_user_gift', 'use_credit_checked_default', 'tiller', 'document_display_orders_invoice', 'document_display_orders_delivery_note', 'document_display_prices_delivery_note', 'option_email_confirm', 'option_email_confirm_producer', 'option_csv_export_all_products', 'option_csv_export_by_piece', 'option_export_display_product_reference', 'option_allow_order_guest'], 'boolean'],
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code', 'type', 'credit_functioning', 'option_behavior_cancel_order', 'document_quotation_prefix', 'document_quotation_first_reference', 'document_invoice_prefix', 'document_invoice_first_reference', 'document_delivery_note_prefix', 'document_delivery_note_first_reference'], 'string', 'max' => 255],
[['free_price', 'credit_limit_reminder', 'credit_limit'], 'double'],
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
@@ -228,6 +228,7 @@ class Producer extends ActiveRecordCommon
'option_csv_export_by_piece' => 'Exporter les produits par pièce dans le fichier récapitulatif (CSV)',
'option_order_reference_type' => 'Type de référence',
'option_export_display_product_reference' => 'Afficher la référence des produits au moment de l\'export',
'option_allow_order_guest' => 'Autoriser les visiteurs à passer commande (création de compte à la fin du tunnel)',
];
}


+ 16
- 0
console/migrations/m210318_102840_add_option_allow_order_guest.php 查看文件

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

use yii\db\Migration;

class m210318_102840_add_option_allow_order_guest extends Migration
{
public function safeUp()
{
$this->addColumn('producer', 'option_allow_order_guest', Schema::TYPE_BOOLEAN);
}

public function safeDown()
{
$this->dropColumn('producer', 'option_allow_order_guest');
}
}

+ 1
- 0
producer/assets/VuejsOrderOrderAsset.php 查看文件

@@ -57,6 +57,7 @@ class VuejsOrderOrderAsset extends \common\components\MyAssetBundle
public function __construct()
{
parent::__construct() ;
$this->addAsset('js','js/jquery.validate.min.js') ;
$this->addAsset('js','js/vuejs/order-order.js') ;
}
}

+ 87
- 34
producer/controllers/OrderController.php 查看文件

@@ -48,6 +48,7 @@ use common\models\Producer;
use common\models\Order;
use common\models\UserPointSale;
use common\models\Product;
use common\models\UserProducer;
use DateTime;

class OrderController extends ProducerBaseController
@@ -56,7 +57,9 @@ class OrderController extends ProducerBaseController

public function behaviors()
{
return [
return [];

/*return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
@@ -66,11 +69,12 @@ class OrderController extends ProducerBaseController
]
],
],
];
];*/
}

public function actionOrder($id = 0, $date = '')
{

$params = [];

if ($id) {
@@ -175,12 +179,15 @@ class OrderController extends ProducerBaseController
}

if ($order->load($posts)) {

$user = User::getCurrent() ;

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

@@ -191,15 +198,48 @@ class OrderController extends ProducerBaseController
}
}
else {
// gestion user : option_allow_order_guest
if(isset($posts['user']) && $posts['user']) {

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

if(!$user) {
$user = new User ;
$user->id_producer = 0;
$password = Password::generate() ;
//$password = $posts['user']['password'] ;
$user->setPassword($password);
$user->generateAuthKey();
$user->username = $posts['user']['email'];
$user->email = $posts['user']['email'];
$user->name = $posts['user']['firstname'];
$user->lastname = $posts['user']['lastname'];
$user->phone = $posts['user']['phone'];
$user->save() ;

// liaison etablissement / user
$userProducer = new UserProducer();
$userProducer->id_user = $user->id;
$userProducer->id_producer = $idProducer;
$userProducer->credit = 0;
$userProducer->active = 1;
$userProducer->save();

$user->sendMailWelcome($password);
}
}

$order = new Order;
$order->load(Yii::$app->request->post());
$order->id_user = User::getCurrentId();
$order->id_user = $user ? $user->id : null;
$order->status = 'tmp-order';
$order->date = date('Y-m-d H:i:s');
$order->origin = Order::ORIGIN_USER;
}

$errors = $this->processForm($order);
$errors = $this->processForm($order, $user);

if (count($errors)) {
return ['status' => 'error', 'errors' => $errors];
@@ -228,7 +268,7 @@ class OrderController extends ProducerBaseController
*
* @param Commande $order
*/
public function processForm($order)
public function processForm($order, $user)
{
$posts = Yii::$app->request->post();
$productsArray = [];
@@ -298,7 +338,7 @@ class OrderController extends ProducerBaseController

$userProducer = UserProducer::searchOne([
'id_producer' => $order->distribution->id_producer,
'id_user' => User::getCurrentId()
'id_user' => $user->id
]);

// gestion point de vente
@@ -318,7 +358,7 @@ class OrderController extends ProducerBaseController
$order->changeOrderStatus('new-order', 'user');

// ajout de l'utilisateur à l'établissement
Producer::addUser(User::getCurrentId(), $distribution->id_producer);
Producer::addUser($user->id, $distribution->id_producer);

// suppression de tous les enregistrements ProductOrder
if (!is_null($order)) {
@@ -364,13 +404,13 @@ class OrderController extends ProducerBaseController
}

// lien utilisateur / point de vente
$pointSale->linkUser(User::getCurrentId());
$pointSale->linkUser($user->id);

// credit
$credit = Producer::getConfig('credit');
$creditLimit = Producer::getConfig('credit_limit');
$creditFunctioning = $pointSale->getCreditFunctioning();
$creditUser = Yii::$app->user->identity->getCredit($distribution->id_producer);
$creditUser = $user->getCredit($distribution->id_producer);
$order = Order::searchOne([
'id' => $order->id
]);
@@ -420,8 +460,6 @@ class OrderController extends ProducerBaseController
$order->changeOrderStatus('waiting-paiement-on-delivery', 'user');
}


$user = User::getCurrent() ;
$paramsEmail = [
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
@@ -438,7 +476,6 @@ class OrderController extends ProducerBaseController
]
] ;


/*
* Envoi email de confirmation
*/
@@ -547,7 +584,8 @@ class OrderController extends ProducerBaseController
'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
'credit_limit' => is_numeric($producer->credit_limit) ? $producer->credit_limit : null,
'option_allow_order_guest' => $producer->option_allow_order_guest,
];

// Distributions
@@ -563,16 +601,20 @@ class OrderController extends ProducerBaseController
$json['distributions'] = $distributionsArray;

// Commandes de l'utilisateur
$ordersUserArray = Order::searchAll([
'id_user' => User::getCurrentId()
], [
'conditions' => [
'distribution.date > :date'
],
'params' => [
':date' => $dateMini
]
]);
$ordersUserArray = [] ;
if(User::getCurrentId()) {
$ordersUserArray = Order::searchAll([
'id_user' => User::getCurrentId()
], [
'conditions' => [
'distribution.date > :date'
],
'params' => [
':date' => $dateMini
]
]);
}

if (is_array($ordersUserArray) && count($ordersUserArray)) {
foreach ($ordersUserArray as &$order) {
$order = array_merge($order->getAttributes(), [
@@ -590,18 +632,25 @@ class OrderController extends ProducerBaseController
'id_user' => User::getCurrentId()
]);

$json['user'] = [
'credit' => $userProducer->credit,
'credit_active' => $userProducer->credit_active,
];
$json['user'] = false ;

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

if ($dateObject && $dateObject->format($format) === $date) {

// Commande de l'utilisateur
$orderUser = Order::searchOne([
'distribution.date' => $date,
'id_user' => User::getCurrentId(),
]);
$orderUser = false ;
if(User::getCurrentId()) {
$orderUser = Order::searchOne([
'distribution.date' => $date,
'id_user' => User::getCurrentId(),
]);
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
@@ -646,7 +695,10 @@ class OrderController extends ProducerBaseController
}
}

$favoritePointSale = User::getCurrent()->getFavoritePointSale();
$favoritePointSale = false ;
if(User::getCurrent()) {
$favoritePointSale = User::getCurrent()->getFavoritePointSale();
}

if ($favoritePointSale) {
for ($i = 0; $i < count($pointsSaleArray); $i++) {
@@ -744,8 +796,9 @@ class OrderController extends ProducerBaseController
public function actionConfirm($idOrder)
{
$order = Order::searchOne(['id' => $idOrder]);
$producer = $this->getProducer() ;

if (!$order || $order->id_user != User::getCurrentId()) {
if (!$order || ($order->id_user != User::getCurrentId() && !$producer->option_allow_order_guest)) {
throw new \yii\base\UserException('Commande introuvable.');
}


二进制
producer/runtime/cache/96/963454f612a8b5fb4a63ba1e97f028a1.bin 查看文件


+ 6293
- 0
producer/runtime/logs/app.log
文件差异内容过多而无法显示
查看文件


+ 2
- 2
producer/views/layouts/main.php 查看文件

@@ -181,13 +181,13 @@ if (!Yii::$app->user->isGuest) {
[
'label' => '<span class="glyphicon glyphicon-plus"></span> Commander',
'url' => Yii::$app->urlManager->createUrl(['order/order']),
'visible' => !Yii::$app->user->isGuest,
'visible' => $producer->option_allow_order_guest || !Yii::$app->user->isGuest,
'active' => $this->getControllerAction() == 'order/order',
],
[
'label' => '<span class="glyphicon glyphicon-plus"></span> Commander',
'url' => Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $this->context->getProducer()->id, 'return_url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/order', 'slug_producer' => $this->context->getProducer()->slug])]),
'visible' => Yii::$app->user->isGuest,
'visible' => !$producer->option_allow_order_guest && Yii::$app->user->isGuest,
'active' => $this->getControllerAction() == 'order/order',
],
[

+ 7
- 6
producer/views/order/confirm.php 查看文件

@@ -40,9 +40,8 @@ use common\models\Order ;
use common\helpers\GlobalParam ;

$this->setTitle('Confirmation de commande') ;


$producer = GlobalParam::getCurrentProducer() ;

?>

<div id="order-success">
@@ -51,10 +50,12 @@ $producer = GlobalParam::getCurrentProducer() ;
<span class="glyphicon glyphicon-ok glyphicon-big"></span>
<div class="content">
<h3>Votre commande a bien été prise en compte</h3>
<a href="<?= Yii::$app->urlManagerProducer->createUrl(['order/history']) ?>" class="btn btn-default">
<span class="glyphicon glyphicon-chevron-right"></span>
Voir toutes mes commandes
</a>
<?php if(!Yii::$app->user->isGuest): ?>
<a href="<?= Yii::$app->urlManagerProducer->createUrl(['order/history']) ?>" class="btn btn-default">
<span class="glyphicon glyphicon-chevron-right"></span>
Voir toutes mes commandes
</a>
<?php endif; ?>
</div>
<div class="clr"></div>
</div>

+ 31
- 1
producer/views/order/order.php 查看文件

@@ -302,7 +302,7 @@ $producer = GlobalParam::getCurrentProducer() ;
</template>
<template v-else>
<div class="credit">
<div v-if="producer.credit == 1 && pointSaleActive.credit == 1 && (pointSaleActive.credit_functioning != 'user' || (pointSaleActive.credit_functioning == 'user' && user.credit_active))">
<div v-if="user && producer.credit == 1 && pointSaleActive.credit == 1 && (pointSaleActive.credit_functioning != 'user' || (pointSaleActive.credit_functioning == 'user' && user.credit_active))">
<input type="checkbox" id="use-credit" v-model="useCredit" disabled="disabled" v-if="pointSaleActive.credit_functioning == 'mandatory' || (pointSaleActive.credit_functioning == 'user' && user.credit_active)" />
<input type="checkbox" id="use-credit" v-model="useCredit" v-else /> <label for="use-credit">Utiliser mon Crédit ({{ formatPrice(user.credit) }})</label>

@@ -335,6 +335,36 @@ $producer = GlobalParam::getCurrentProducer() ;
<?php endif; ?>
</div>
</div>
<div id="signup-guest" v-if="!user && producer.option_allow_order_guest">
<h3>Informations personnelles</h3>
<form action="#">
<div class="form-group field-signupguest-email required">
<label class="control-label" for="signupguest-email">Email</label>
<input type="email" id="signupguest-email" class="form-control" name="SignupForm[email]">
<p class="help-block help-block-error"></p>
</div>
<!--<div class="form-group field-signupguest-password required">
<label class="control-label" for="signupguest-password">Mot de passe</label>
<input type="password" id="signupguest-password" class="form-control" name="SignupForm[password]">
<p class="help-block help-block-error"></p>
</div>-->
<div class="form-group field-signupguest-firstname required">
<label class="control-label" for="signupguest-firstname">Prénom</label>
<input type="text" id="signupguest-firstname" class="form-control" name="SignupForm[firstname]">
<p class="help-block help-block-error"></p>
</div>
<div class="form-group field-signupguest-lastname required">
<label class="control-label" for="signupguest-lastname">Nom</label>
<input type="text" id="signupguest-lastname" class="form-control" name="SignupForm[lastname]">
<p class="help-block help-block-error"></p>
</div>
<div class="form-group field-signupguest-phone required">
<label class="control-label" for="signupguest-phone">Téléphone</label>
<input type="text" id="signupguest-phone" class="form-control" name="SignupForm[phone]">
<p class="help-block help-block-error"></p>
</div>
</form>
</div>
<div class="block-actions">
<button class="btn btn-primary" disabled="disabled" v-if="disableConfirmButton">Je confirme ma commande</button>
<button class="btn btn-primary" v-else @click="confirmClick">Je confirme ma commande</button>

+ 4
- 0
producer/web/js/jquery.validate.min.js
文件差异内容过多而无法显示
查看文件


+ 75
- 1
producer/web/js/vuejs/order-order.js 查看文件

@@ -331,6 +331,13 @@ var app = new Vue({
}
},
confirmClick: function() {

var $signupGuestForm = $('#signup-guest form') ;
if($signupGuestForm.length > 0 && !$signupGuestForm.valid()) {
$signupGuestForm.submit() ;
return false ;
}

this.disableConfirmButton = true ;
var productsArray = {} ;
@@ -340,6 +347,17 @@ var app = new Vue({
productsArray[this.products[key].id] = this.products[key].quantity_form ;
}
}

var user = false ;
if(this.producer.option_allow_order_guest && !this.user) {
user = {
email: $('#signupguest-email').val(),
password: $('#signupguest-password').val(),
firstname: $('#signupguest-firstname').val(),
lastname: $('#signupguest-lastname').val(),
phone: $('#signupguest-phone').val(),
} ;
}
axios.post('ajax-process', {
Order: {
@@ -349,7 +367,8 @@ var app = new Vue({
},
code_point_sale: this.pointsSaleCodes[this.pointSaleActive.id],
products: productsArray,
use_credit: Number(this.useCredit)
use_credit: Number(this.useCredit),
user: user
}).then(function(response) {
if(response.data.status == 'success') {
window.location.href = opendistrib_base_url(true)+'order/confirm?idOrder='+response.data.idOrder ;
@@ -391,5 +410,60 @@ var app = new Vue({
return orderedPointsSaleArray ;
}
},
updated: function () {
var app = this;
this.$nextTick(function () {
if(app.step == 'payment' && !app.user && app.producer.option_allow_order_guest) {
$("#signup-guest form").validate({
rules: {
'SignupForm[email]': {
'email': true,
'required': true,
'minlength': 8,
'maxlength': 255
},
'SignupForm[password]': {
'required': true,
'minlength': 8,
"maxlength": 255
},
'SignupForm[firstname]': {
'required': true,
'minlength': 2,
"maxlength": 255
},
'SignupForm[lastname]': {
'required': true,
'minlength': 2,
"maxlength": 255
},
'SignupForm[phone]': {
'required': true,
'minlength': 2,
"maxlength": 255
},
},
messages: {
'SignupForm[email]' : {
'required': 'Ce champs est requis.',
'email' : 'Email invalide.'
},
'SignupForm[password]' : {
'required': 'Ce champs est requis.',
},
'SignupForm[firstname]' : {
'required': 'Ce champs est requis.',
},
'SignupForm[lastname]' : {
'required': 'Ce champs est requis.',
},
'SignupForm[phone]' : {
'required': 'Ce champs est requis.',
},
}
}) ;
}
});
}
});

正在加载...
取消
保存