@@ -887,6 +887,11 @@ class OrderController extends BackendController | |||
if($order && $processCredit) { | |||
$order->processCredit() ; | |||
} | |||
// lien utilisateur / point de vente | |||
if($idUser && $pointSale) { | |||
$pointSale->linkUser($idUser) ; | |||
} | |||
} | |||
return ['success'] ; |
@@ -343,4 +343,27 @@ class PointSale extends ActiveRecordCommon | |||
{ | |||
return $this->credit_functioning ? $this->credit_functioning : Producer::getConfig('credit_functioning') ; | |||
} | |||
/** | |||
* Lie un utilisateur au point de vente. | |||
* | |||
* @param integer $idUser | |||
*/ | |||
public function linkUser($idUser) | |||
{ | |||
if($idUser) { | |||
$userPointSale = UserPointSale::find() | |||
->where([ | |||
'id_user' => $idUser, | |||
'id_point_sale' => $this->id | |||
])->one() ; | |||
if(!$userPointSale) { | |||
$userPointSale = new UserPointSale ; | |||
$userPointSale->id_user = $idUser ; | |||
$userPointSale->id_point_sale = $this->id ; | |||
$userPointSale->save() ; | |||
} | |||
} | |||
} | |||
} |
@@ -202,6 +202,12 @@ class Subscription extends ActiveRecordCommon | |||
$order->save(); | |||
// liaison utilisateur / point de vente | |||
if($order->id_user) { | |||
$pointSale = PointSale::findOne($this->id_point_sale) ; | |||
$pointSale->linkUser($order->id_user) ; | |||
} | |||
// produits | |||
$amountTotal = 0; | |||
$productsAdd = false; |
@@ -328,6 +328,9 @@ class OrderController extends ProducerBaseController | |||
$productOrder->save(); | |||
} | |||
} | |||
// lien utilisateur / point de vente | |||
$pointSale->linkUser(User::getCurrentId()) ; | |||
// credit | |||
$credit = Producer::getConfig('credit'); |