use common\models\User ; | use common\models\User ; | ||||
use common\models\ProductDistribution ; | use common\models\ProductDistribution ; | ||||
use common\models\Distribution ; | use common\models\Distribution ; | ||||
use common\models\Producer ; | |||||
class OrderController extends BackendController | class OrderController extends BackendController | ||||
{ | { | ||||
// delete | // delete | ||||
if ($order) { | 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'] ; | return ['success'] ; |
0 => 'Non', | 0 => 'Non', | ||||
1 => 'Oui', | 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> | ||||
</div> | </div> | ||||
} | } | ||||
} | } | ||||
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). | * Retourne le montant de la commande (total, payé, restant, ou en surplus). | ||||
* | * |
self::CREDIT_FUNCTIONING_USER => 'Basée sur l\'utilisateur', | 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 ; | var $secret_key_payplug ; | ||||
/** | /** | ||||
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | $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'], | [['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', 'credit_limit_reminder','credit_limit'], 'double'], | ||||
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'], | ['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'], | ||||
]; | ]; | ||||
'credit_limit' => 'Crédit limite', | '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', | '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', | 'background_color_logo' => 'Couleur de fond du logo', | ||||
'option_behavior_cancel_order' => 'Comportement lors de la suppression d\'une commande', | |||||
]; | ]; | ||||
} | } | ||||
<?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') ; | |||||
} | |||||
} |
} | } | ||||
if ($order && User::getCurrentId() == $order->id_user) { | 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.') ; | Yii::$app->session->setFlash('success','Votre commande a bien été annulée.') ; | ||||
} | } | ||||