Browse Source

Initialisation d'un abonnement à partir d'une commande existante

dev
Guillaume Bourgeois 5 years ago
parent
commit
c04576ad40
1 changed files with 28 additions and 3 deletions
  1. +28
    -3
      backend/controllers/SubscriptionController.php

+ 28
- 3
backend/controllers/SubscriptionController.php View File

@@ -37,6 +37,8 @@ termes.

namespace backend\controllers;

use common\models\Order ;

class SubscriptionController extends BackendController
{
var $enableCsrfValidation = false;
@@ -80,16 +82,39 @@ class SubscriptionController extends BackendController
}

/**
* Crée une commande récurrente.
* Crée un abonnement.
*
* @return string
*/
public function actionCreate()
public function actionCreate($idOrder = 0)
{
// form
$model = new SubscriptionForm;
$model->id_producer = Producer::getId();

if($idOrder) {
$order = Order::searchOne(['id' => $idOrder]);
if ($order) {
$model->id_user = $order->id_user;
$model->username = $order->username;
$model->id_point_sale = $order->id_point_sale;
$model->date_begin = date('d/m/Y') ;
$dateDay = strtolower(date('l',strtotime($order->distribution->date))) ;
$model->$dateDay = 1 ;
$model->week_frequency = 1 ;
if($model->id_user && Producer::getConfig('credit')) {
$model->auto_payment = 1 ;
}
// produits
foreach ($order->productOrder as $productOrder) {
$model->products['product_' . $productOrder->id_product] = $productOrder->quantity;
}
} else {
throw new NotFoundHttpException('La commande est introuvable.', 404);
}
}
// produits
$productsArray = Product::searchAll() ;
@@ -115,7 +140,7 @@ class SubscriptionController extends BackendController
}

/**
* Modifie une commande récurrente.
* Modifie un abonnement.
*
* @param integer $id
* @return string

Loading…
Cancel
Save