change cart to plain post from ajax
This commit is contained in:
@@ -85,5 +85,11 @@ class Helper
|
||||
}
|
||||
|
||||
|
||||
public static function fixAsciiChars($in){
|
||||
$out = str_replace("ö", "0", $in);
|
||||
$out = str_replace("Ö", "0", $in);
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "card".
|
||||
@@ -67,7 +68,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
public function validateAscii($attribute,$params){
|
||||
if ( !$this->hasErrors($this->$attribute)){
|
||||
$this->$attribute = str_replace("ö", "0", $this->$attribute);
|
||||
$this->attribute = Helper::fixAsciiChars($this->attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "product".
|
||||
@@ -51,6 +52,12 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
[['barcode'], 'unique' ],
|
||||
];
|
||||
}
|
||||
|
||||
public function validateAscii($attribute,$params){
|
||||
if ( !$this->hasErrors($this->$attribute)){
|
||||
$this->attribute = Helper::fixAsciiChars($this->attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
||||
@@ -63,19 +63,26 @@ class ShoppingCart extends \yii\db\ActiveRecord
|
||||
return $transfers;
|
||||
}
|
||||
|
||||
public static function payout( $customer) {
|
||||
public static function payout( $customer, $idTransfers) {
|
||||
//apply transfer object
|
||||
//delete cart
|
||||
$sql = "UPDATE transfer AS t
|
||||
INNER JOIN shopping_cart AS s ON t.id_transfer = s.id_transfer
|
||||
SET t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
|
||||
SET t.paid_by = ".\Yii::$app->user->id.", t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
|
||||
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID
|
||||
. " and s.id_customer = " . $customer->id_customer ;
|
||||
. " and s.id_customer = " . $customer->id_customer
|
||||
. " and t.id_transfer in ( '" . implode("','", $idTransfers )."' )";
|
||||
|
||||
$q1 = Yii::$app->db->createCommand($sql);
|
||||
$q1->execute();
|
||||
|
||||
ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
|
||||
// ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
|
||||
|
||||
if ( isset($idTransfers) ){
|
||||
ShoppingCart::deleteAll(['and' ,['id_customer' => $customer->id_customer] ,['in','id_transfer',$idTransfers] ]);
|
||||
}else{
|
||||
ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -541,7 +541,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
if ( !RoleDefinition::isAdmin() ){
|
||||
$query->innerJoin("user_account_assignment", 'transfer.id_account = user_account_assignment.id_account' );
|
||||
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
|
||||
|
||||
}
|
||||
$query->innerJoin("account", 'transfer.id_account = account.id_account' );
|
||||
$query->andWhere(['account.type' => Account::TYPE_ALL]);
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $idAccount,
|
||||
|
||||
@@ -89,19 +89,27 @@ class UserSoldItem extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* @param common\models\User $user
|
||||
* */
|
||||
public static function payout( $user ) {
|
||||
public static function payout( $user, $idTransfers = null ) {
|
||||
//apply transfer object
|
||||
//delete cart
|
||||
$sql = "UPDATE transfer AS t
|
||||
INNER JOIN user_sold_item AS s ON t.id_transfer = s.id_transfer
|
||||
SET t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
|
||||
SET t.paid_by = ".$user->id.", t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
|
||||
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID
|
||||
. " and s.id_user =" . $user->id ;
|
||||
|
||||
if ( isset($idTransfers)){
|
||||
$sql .= " and t.id_transfer in ( '" . implode("','", $idTransfers )."' )";
|
||||
}
|
||||
|
||||
$q1 = Yii::$app->db->createCommand($sql);
|
||||
$q1->execute();
|
||||
|
||||
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
|
||||
if ( isset($idTransfers) ){
|
||||
UserSoldItem::deleteAll(['and' ,['id_user' => Yii::$app->user->id] ,['in','id_transfer',$idTransfers] ]);
|
||||
}else{
|
||||
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user