add customer cart

This commit is contained in:
2015-10-23 20:39:10 +02:00
parent 23a0390a27
commit 0c92fdf167
11 changed files with 293 additions and 81 deletions

View File

@@ -42,7 +42,7 @@ class ProductController extends Controller
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'sale','clear-list', 'lookup'],
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup'],
'rules' => [
// allow authenticated users
[
@@ -73,6 +73,7 @@ class ProductController extends Controller
$user = User::findOne(Yii::$app->user->id );
$model->customer = $this->customer;
$model->card = $this->card;
if (Yii::$app->request->isAjax) {
@@ -97,16 +98,18 @@ class ProductController extends Controller
}
}
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers( $user ) );
$customerCart = Transfer::modelsToArray( Transfer::readCustomerCart( $this->customer ) );
$result['transfers'] = $userTransfers;
$result['customer_cart'] = $customerCart;
return $result;
}else{
// $userTransfers = Transfer::readUserSoldTransfers( $user );
$model->customerCart = Transfer::modelsToArray( Transfer::readCustomerCart($this->customer) );
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
$model->customerCart = ShoppingCart::readCustomerCart( $this->customer );
return $this->render("sale",[
'customer' => $this->customer,
@@ -122,7 +125,7 @@ class ProductController extends Controller
}
public function actionClearList(){
public function actionPayoutUserCart(){
if (Yii::$app->request->isAjax) {
$result = [];
@@ -140,6 +143,39 @@ class ProductController extends Controller
}
}
public function actionPayoutCustomerCart($number){
$cart = [];
$code = 'error';
$message = 'Hiba történt';
if (Yii::$app->request->isAjax) {
$result = [];
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$this->findByNumber($number);
if ( isset($this->customer)){
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
ShoppingCart::payout($this->customer);
$transaction->commit();
$cart = Transfer::modelsToArray( Transfer::readCustomerCart($this->customer) );
$code = 'success';
$message = 'Bevásárlókoosár fizetve: ' .$this->card->number;
} catch(Exception $e) {
$transaction->rollback();
}
}
$result['customer_cart'] = $cart;
$result['code'] = $code;
$result['message'] = $message;
return $result;
}
}