@@ -44,6 +44,7 @@ use common\models\Product ; | |||
use common\models\User ; | |||
use common\models\ProductDistribution ; | |||
use common\models\Distribution ; | |||
use common\models\Producer ; | |||
class OrderController extends BackendController | |||
{ | |||
@@ -760,20 +761,7 @@ class OrderController extends BackendController | |||
// delete | |||
if ($order) { | |||
// remboursement si l'utilisateur a payé pour cette commande | |||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | |||
if ($amountPaid > 0.01) { | |||
$order->saveCreditHistory( | |||
CreditHistory::TYPE_REFUND, | |||
$amountPaid, | |||
Producer::getId(), | |||
$order->id_user, | |||
User::getCurrentId() | |||
); | |||
} | |||
$order->delete(); | |||
ProductOrder::deleteAll(['id_order' => $idOrder]); | |||
$order->delete() ; | |||
} | |||
return ['success'] ; |
@@ -149,6 +149,12 @@ $this->addBreadcrumb($this->getTitle()) ; | |||
0 => 'Non', | |||
1 => 'Oui', | |||
], []) ; ?> | |||
<?= $form->field($model, 'option_behavior_cancel_order') | |||
->dropDownList([ | |||
Producer::BEHAVIOR_DELETE_ORDER_DELETE => 'Suppression de la commande', | |||
Producer::BEHAVIOR_DELETE_ORDER_STATUS => 'Passage de la commande en statut "supprimé"', | |||
], []) ; ?> | |||
</div> | |||
</div> | |||
@@ -224,6 +224,33 @@ class Order extends ActiveRecordCommon | |||
} | |||
} | |||
public function delete() { | |||
// remboursement si l'utilisateur a payé pour cette commande | |||
$amountPaid = $this->getAmount(Order::AMOUNT_PAID); | |||
if ($amountPaid > 0.01) { | |||
$this->saveCreditHistory( | |||
CreditHistory::TYPE_REFUND, | |||
$amountPaid, | |||
Producer::getId(), | |||
$this->id_user, | |||
User::getCurrentId() | |||
); | |||
} | |||
// delete | |||
if(Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE || | |||
(Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) ) { | |||
ProductOrder::deleteAll(['id_order' => $this->id]); | |||
return parent::delete() ; | |||
} | |||
// status 'delete' | |||
elseif(Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) { | |||
$this->date_delete = date('Y-m-d H:i:s'); | |||
return $this->save() ; | |||
} | |||
} | |||
/** | |||
* Retourne le montant de la commande (total, payé, restant, ou en surplus). | |||
* |
@@ -83,6 +83,9 @@ class Producer extends ActiveRecordCommon | |||
self::CREDIT_FUNCTIONING_USER => 'Basée sur l\'utilisateur', | |||
]; | |||
const BEHAVIOR_DELETE_ORDER_DELETE = 'delete' ; | |||
const BEHAVIOR_DELETE_ORDER_STATUS = 'status' ; | |||
var $secret_key_payplug ; | |||
/** | |||
@@ -110,9 +113,9 @@ class Producer extends ActiveRecordCommon | |||
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | |||
} | |||
}], | |||
[['description','mentions','gcs','order_infos','slug','secret_key_payplug','background_color_logo'], 'string'], | |||
[['description','mentions','gcs','order_infos','slug','secret_key_payplug','background_color_logo','option_behavior_cancel_order'], 'string'], | |||
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription', 'option_allow_user_gift','use_credit_checked_default'], 'boolean'], | |||
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code','type','credit_functioning'], 'string', 'max' => 255], | |||
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code','type','credit_functioning','option_behavior_cancel_order'], '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'], | |||
]; | |||
@@ -153,6 +156,7 @@ class Producer extends ActiveRecordCommon | |||
'credit_limit' => 'Crédit limite', | |||
'use_credit_checked_default' => 'Cocher par défaut l\'option "Utiliser mon crédit" lors de la commande de l\'utilisateur', | |||
'background_color_logo' => 'Couleur de fond du logo', | |||
'option_behavior_cancel_order' => 'Comportement lors de la suppression d\'une commande', | |||
]; | |||
} | |||
@@ -0,0 +1,16 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\mysql\Schema; | |||
use common\models\Producer ; | |||
class m190522_091006_option_comportement_annulation_commande extends Migration { | |||
public function up() { | |||
$this->addColumn('producer', 'option_behavior_cancel_order', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_DELETE_ORDER_STATUS.'\'') ; | |||
} | |||
public function down() { | |||
$this->dropColumn('producer', 'option_behavior_cancel_order') ; | |||
} | |||
} |
@@ -425,20 +425,7 @@ class OrderController extends ProducerBaseController | |||
} | |||
if ($order && User::getCurrentId() == $order->id_user) { | |||
// remboursement | |||
if ($order->getAmount(Order::AMOUNT_PAID)) { | |||
$order->saveCreditHistory( | |||
CreditHistory::TYPE_REFUND, | |||
$order->getAmount(Order::AMOUNT_PAID), | |||
$order->distribution->id_producer, | |||
User::getCurrentId(), | |||
User::getCurrentId() | |||
); | |||
} | |||
// delete | |||
$order->date_delete = date('Y-m-d H:i:s'); | |||
$order->save() ; | |||
$order->delete() ; | |||
Yii::$app->session->setFlash('success','Votre commande a bien été annulée.') ; | |||
} | |||