add customer cart
This commit is contained in:
@@ -20,6 +20,7 @@ use common\models\Discount;
|
||||
use common\models\Transfer;
|
||||
use common\models\User;
|
||||
use common\models\UserSoldItem;
|
||||
use common\models\ShoppingCart;
|
||||
|
||||
/**
|
||||
* ProductController implements the CRUD actions for Product model.
|
||||
@@ -71,6 +72,8 @@ class ProductController extends Controller
|
||||
|
||||
$user = User::findOne(Yii::$app->user->id );
|
||||
|
||||
$model->customer = $this->customer;
|
||||
|
||||
if (Yii::$app->request->isAjax) {
|
||||
|
||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||
@@ -103,6 +106,7 @@ class ProductController extends Controller
|
||||
|
||||
// $userTransfers = Transfer::readUserSoldTransfers( $user );
|
||||
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
||||
$model->customerCart = ShoppingCart::readCustomerCart( $this->customer );
|
||||
|
||||
return $this->render("sale",[
|
||||
'customer' => $this->customer,
|
||||
@@ -112,7 +116,7 @@ class ProductController extends Controller
|
||||
'currencies' => $currencies,
|
||||
'accounts' => $accounts,
|
||||
'discounts' => $discounts,
|
||||
'userTransfers' => $userTransfers
|
||||
'userTransfers' => $userTransfers,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ use common\models\Account;
|
||||
use common\models\Discount;
|
||||
use common\models\Currency;
|
||||
use common\models\UserSoldItem;
|
||||
use common\models\Sale;
|
||||
use common\models\ShoppingCart;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
@@ -42,8 +44,12 @@ class ProductSaleForm extends Model
|
||||
public $account;
|
||||
public $currency;
|
||||
public $discount;
|
||||
public $customer;
|
||||
|
||||
public $transfer;
|
||||
public $sale;
|
||||
|
||||
public $customerCart;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -121,21 +127,32 @@ class ProductSaleForm extends Model
|
||||
|
||||
public function save(){
|
||||
if ( $this->validate() ){
|
||||
$this->saveSale();
|
||||
$this->saveTransfer();
|
||||
$this->saveProduct();
|
||||
$this->appendToSoldList();
|
||||
$this->appendToUserCart();
|
||||
$this->appendToCustomerCart();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// protected function applyDiscount(){
|
||||
// Discount::applyDiscount($this->, $discount);
|
||||
// }
|
||||
|
||||
protected function saveSale(){
|
||||
$this->sale = Sale::createSale($this->account, $this->discount, $this->currency, $this->count, $this->product);
|
||||
/*
|
||||
*/
|
||||
$this->sale->status = Sale::STATUS_PAID;
|
||||
if ( isset($this->comment)){
|
||||
$this->sale->comment = $this->comment;
|
||||
}
|
||||
$this->sale->id_user = Yii::$app->user->id;
|
||||
$this->sale->save();
|
||||
}
|
||||
|
||||
protected function saveTransfer(){
|
||||
|
||||
$this->transfer = Transfer::createProductTransfer($this->account, $this->discount, $this->currency, $this->count, $this->product);
|
||||
$this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product);
|
||||
/*
|
||||
*/
|
||||
$this->transfer->status = Transfer::STATUS_PAID;
|
||||
@@ -151,7 +168,7 @@ class ProductSaleForm extends Model
|
||||
$this->product->save();
|
||||
}
|
||||
|
||||
public function isAppendToList(){
|
||||
public function isAppendToUserCart(){
|
||||
$result = false;
|
||||
if ( isset( $this->append_to_sold_list ) && $this->append_to_sold_list == 'append' ){
|
||||
$result = true;
|
||||
@@ -159,12 +176,28 @@ class ProductSaleForm extends Model
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function appendToSoldList(){
|
||||
if ( $this->isAppendToList() ){
|
||||
public function appendToUserCart(){
|
||||
if ( $this->isAppendToUserCart() ){
|
||||
$item = new UserSoldItem();
|
||||
$item->id_transfer = $this->transfer->id_transfer;
|
||||
$item->id_user = Yii::$app->user->id;
|
||||
$item->save(false);
|
||||
}
|
||||
}
|
||||
public function isAppendToCustomerCart(){
|
||||
$result = false;
|
||||
if ( isset( $this->add_to_customer ) && $this->add_to_customer == 'append' ){
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function appendToCustomerCart(){
|
||||
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
|
||||
$item = new ShoppingCart();
|
||||
$item->id_customer = $this->customer->id_customer;
|
||||
$item->id_sale = $this->sale->id_sale;
|
||||
$item->save(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
frontend/views/product/_customer_cart.php
Normal file
36
frontend/views/product/_customer_cart.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
use yii\bootstrap\Html;
|
||||
?>
|
||||
|
||||
|
||||
<h1><?php echo Yii::t('frontend/product','Customer cart')?></h1>
|
||||
<div class="row">
|
||||
<div class='col-md-12 '>
|
||||
<div class="customer-cart">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<?php echo Yii::t('frontend/product', 'Product name')?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo Yii::t('frontend/product', 'Count')?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo Yii::t('frontend/product', 'Currency')?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo Yii::t('frontend/product', 'Item Price')?>
|
||||
</th>
|
||||
<th>
|
||||
<?php echo Yii::t('frontend/product', 'Total Price')?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo Html::a(Yii::t('frontend/product', "Fizetve"),null,[ 'id' => 'btn_paid', 'class' => 'btn btn-primary' ]) ?>
|
||||
@@ -97,11 +97,14 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class='col-md-5'>
|
||||
<div class='col-md-4'>
|
||||
<?php echo Html::a(Yii::t("frontend/product","Sell product"),null,['class' => 'btn btn-success', 'id' => 'btn_sell'] );?>
|
||||
</div>
|
||||
<div class='col-md-7'>
|
||||
<?php echo Html::a(Yii::t("frontend/product","Sell product and add to total"),null,['class' => 'btn btn-success', 'id' => 'btn_sell_append'] );?>
|
||||
<div class='col-md-4'>
|
||||
<?php echo Html::a(Yii::t("frontend/product","To cart"),null,['class' => 'btn btn-success', 'id' => 'btn_sell_append'] );?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?php echo Html::a(Yii::t("frontend/product","Write up"),null,['class' => 'btn btn-success', 'id' => 'btn_add_to_customer_cart'] );?>
|
||||
</div>
|
||||
</div>
|
||||
<?php ActiveForm::end(); ?>
|
||||
@@ -74,11 +74,17 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
||||
<div class='row '>
|
||||
<div class='col-md-6 product-form'>
|
||||
<h1><?php echo Yii::t('frontend/product','Sell product')?></h1>
|
||||
<?php echo $this->render('_sale_form' ,['model' =>$model , 'lookupModel' =>$lookupModel, 'currencies' => $currencies, 'accounts' => $accounts,'discounts' => $discounts,]) ?>
|
||||
<?php echo $this->render('_sale_form' ,['model' =>$model , 'lookupModel' =>$lookupModel, 'currencies' => $currencies, 'accounts' => $accounts,'discounts' => $discounts ]) ?>
|
||||
</div>
|
||||
<div class='col-md-6'>
|
||||
<?php echo $this->render('_customer_cart' ) ?>
|
||||
|
||||
<h1><?php echo Yii::t('frontend/product','Cart')?></h1>
|
||||
<?php echo $this->render('_sold_items' ) ?>
|
||||
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_paid', 'class' => 'btn btn-primary' ]) ?>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,7 @@ function ProductSell(o){
|
||||
/**list of sold items by current user*/
|
||||
sold_items: [],
|
||||
discounts: [],
|
||||
customer_cart: []
|
||||
};
|
||||
|
||||
init();
|
||||
@@ -37,6 +38,7 @@ function ProductSell(o){
|
||||
addBehaviorCountChangedListener();
|
||||
addBehaviourDisocuntChanged();
|
||||
createUserSoldItemsTable();
|
||||
createCustomerCartTable();
|
||||
addBehaviourBtnPaid();
|
||||
productChanged();
|
||||
addDocumentKeypressedListener();
|
||||
@@ -269,6 +271,10 @@ function ProductSell(o){
|
||||
function addBehaviourBtnSellAndAppendToBill(){
|
||||
$('#btn_sell_append').on('click',submitSellAndAppend);
|
||||
}
|
||||
|
||||
function addBehaviourBtnAddToCustomerCart(){
|
||||
$('#btn_add_to_customer_cart').on('click',submitAddToCustomerCart);
|
||||
}
|
||||
|
||||
function submitSell(){
|
||||
$('#productsaleform-append_to_sold_list').val('');
|
||||
@@ -280,6 +286,11 @@ function ProductSell(o){
|
||||
}
|
||||
|
||||
|
||||
function submitAddToCustomerCart(){
|
||||
$('#productsaleform-append_to_sold_list').val('append');
|
||||
$('#product_form').submit();
|
||||
}
|
||||
|
||||
function refreshSoldUseritems(){
|
||||
$('.sold-items-container').transferList('option','transfers' , app.defaults.sold_items );
|
||||
}
|
||||
@@ -364,6 +375,11 @@ function ProductSell(o){
|
||||
'transfers' : app.defaults.sold_items
|
||||
});
|
||||
}
|
||||
function createCustomerCartTable(){
|
||||
$('.customer-cart').transferList({
|
||||
'transfers' : app.defaults.customer_cart
|
||||
});
|
||||
}
|
||||
|
||||
function findDiscount(id_discount){
|
||||
var discount;
|
||||
|
||||
Reference in New Issue
Block a user