add customer cart
This commit is contained in:
parent
23a0390a27
commit
0c92fdf167
@ -9,7 +9,7 @@ use Yii;
|
|||||||
*
|
*
|
||||||
* @property integer $id_shopping_cart
|
* @property integer $id_shopping_cart
|
||||||
* @property integer $id_customer
|
* @property integer $id_customer
|
||||||
* @property integer $id_sale
|
* @property integer $id_transfer
|
||||||
*/
|
*/
|
||||||
class ShoppingCart extends \yii\db\ActiveRecord
|
class ShoppingCart extends \yii\db\ActiveRecord
|
||||||
{
|
{
|
||||||
@ -27,7 +27,7 @@ class ShoppingCart extends \yii\db\ActiveRecord
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['id_customer', 'id_sale'], 'integer']
|
[['id_customer', 'id_transfer'], 'integer']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,28 +39,43 @@ class ShoppingCart extends \yii\db\ActiveRecord
|
|||||||
return [
|
return [
|
||||||
'id_shopping_cart' => Yii::t('common/shopping-cart', 'Id Shopping Cart'),
|
'id_shopping_cart' => Yii::t('common/shopping-cart', 'Id Shopping Cart'),
|
||||||
'id_customer' => Yii::t('common/shopping-cart', 'Id Customer'),
|
'id_customer' => Yii::t('common/shopping-cart', 'Id Customer'),
|
||||||
'id_sale' => Yii::t('common/shopping-cart', 'Id Sale'),
|
'id_transfer' => Yii::t('common/shopping-cart', 'Id Transfer'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSale(){
|
public function getTransfer(){
|
||||||
$this->hasOne(Sale::className(), ['id_sale' => 'id_sale']);
|
return $this->hasOne(Transfer::className(), ['id_transfer' => 'id_transfer']);
|
||||||
}
|
}
|
||||||
public function getProduct(){
|
public function getProduct(){
|
||||||
$this->hasOne(Product::className(), ['id_product' => 'id_product'])->via('sale');
|
return $this->hasOne(Product::className(), ['id_product' => 'id_product'])->via('transfer');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $customer common\models\Customer
|
* @param $customer common\models\Customer
|
||||||
* */
|
* */
|
||||||
public static function readCustomerCart($customer = null){
|
public static function readCustomerCart($customer = null){
|
||||||
$sales = [];
|
$transfers = [];
|
||||||
if ( isset($customer)){
|
if ( isset($customer)){
|
||||||
$query = ShoppingCart::find()->andWhere( ['id_customer' => $customer->id_customer] );
|
$query = ShoppingCart::find()->andWhere( ['id_customer' => $customer->id_customer] );
|
||||||
$query->with('product');
|
$query->with('product');
|
||||||
$sales = $query->all();
|
$transfers = $query->all();
|
||||||
}
|
}
|
||||||
return $sales;
|
return $transfers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function payout( $customer) {
|
||||||
|
//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
|
||||||
|
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID;
|
||||||
|
|
||||||
|
$q1 = Yii::$app->db->createCommand($sql);
|
||||||
|
$q1->execute();
|
||||||
|
|
||||||
|
ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,6 +144,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
|||||||
return $this->hasOne( UserSoldItem::className(), ["id_transfer" =>"id_transfer" ] );
|
return $this->hasOne( UserSoldItem::className(), ["id_transfer" =>"id_transfer" ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCustomerCart(){
|
||||||
|
return $this->hasOne( ShoppingCart::className(), ["id_transfer" =>"id_transfer" ] );
|
||||||
|
}
|
||||||
|
|
||||||
public function getSale(){
|
public function getSale(){
|
||||||
return $this->hasOne( Sale::className(), ["id_sale" =>"id_object" ] ) ;
|
return $this->hasOne( Sale::className(), ["id_sale" =>"id_object" ] ) ;
|
||||||
}
|
}
|
||||||
@ -398,6 +402,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
|||||||
|
|
||||||
return $transfers;
|
return $transfers;
|
||||||
}
|
}
|
||||||
|
public static function readCustomerCart($customer){
|
||||||
|
$transfers = [];
|
||||||
|
|
||||||
|
if ( isset($customer) ){
|
||||||
|
$query = Transfer::find();
|
||||||
|
$query->innerJoinWith('customerCart');
|
||||||
|
$query->andWhere(['shopping_cart.id_customer' => $customer->id_customer ]);
|
||||||
|
$transfers = $query->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transfers;
|
||||||
|
}
|
||||||
|
|
||||||
public static function types( ) {
|
public static function types( ) {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m151021_204300_alter__table__shopping_cart__alter__column__id_sale__to__id_transfer extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->renameColumn("shopping_cart", "id_sale", "id_transfer");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
echo "m151021_204300_alter__table__sale__alter__column__id_sale__to__id_transfer cannot be reverted.\n";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Use safeUp/safeDown to run migration code within a transaction
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
@ -42,7 +42,7 @@ class ProductController extends Controller
|
|||||||
],
|
],
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => \yii\filters\AccessControl::className(),
|
'class' => \yii\filters\AccessControl::className(),
|
||||||
'only' => [ 'sale','clear-list', 'lookup'],
|
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup'],
|
||||||
'rules' => [
|
'rules' => [
|
||||||
// allow authenticated users
|
// allow authenticated users
|
||||||
[
|
[
|
||||||
@ -73,6 +73,7 @@ class ProductController extends Controller
|
|||||||
$user = User::findOne(Yii::$app->user->id );
|
$user = User::findOne(Yii::$app->user->id );
|
||||||
|
|
||||||
$model->customer = $this->customer;
|
$model->customer = $this->customer;
|
||||||
|
$model->card = $this->card;
|
||||||
|
|
||||||
if (Yii::$app->request->isAjax) {
|
if (Yii::$app->request->isAjax) {
|
||||||
|
|
||||||
@ -98,15 +99,17 @@ 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['transfers'] = $userTransfers;
|
||||||
|
$result['customer_cart'] = $customerCart;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
// $userTransfers = Transfer::readUserSoldTransfers( $user );
|
// $userTransfers = Transfer::readUserSoldTransfers( $user );
|
||||||
|
$model->customerCart = Transfer::modelsToArray( Transfer::readCustomerCart($this->customer) );
|
||||||
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
||||||
$model->customerCart = ShoppingCart::readCustomerCart( $this->customer );
|
|
||||||
|
|
||||||
return $this->render("sale",[
|
return $this->render("sale",[
|
||||||
'customer' => $this->customer,
|
'customer' => $this->customer,
|
||||||
@ -122,7 +125,7 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionClearList(){
|
public function actionPayoutUserCart(){
|
||||||
|
|
||||||
if (Yii::$app->request->isAjax) {
|
if (Yii::$app->request->isAjax) {
|
||||||
$result = [];
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,35 @@ use common\models\ShoppingCart;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ContactForm is the model behind the contact form.
|
* ContactForm is the model behind the contact form.
|
||||||
|
*
|
||||||
|
* @property integer $id_product
|
||||||
|
* @property integer $count
|
||||||
|
* @property integer $id_currency
|
||||||
|
* @property integer $id_discount
|
||||||
|
* @property string $comment
|
||||||
|
* @property string $barcode
|
||||||
|
* @property string $product_number
|
||||||
|
* @property integer $sale_price
|
||||||
|
* @property string $product_name
|
||||||
|
* @property common\models\Account[] $accounts
|
||||||
|
* @property common\models\Currency[] $currencies
|
||||||
|
* @property common\models\Discount[] $discounts
|
||||||
|
* @property common\models\Product $product
|
||||||
|
* @property common\models\Account $account
|
||||||
|
* @property common\models\Currency $currency
|
||||||
|
* @property common\models\Discount $discount
|
||||||
|
* @property common\models\Customer $customer
|
||||||
|
* @property common\models\Card $card
|
||||||
|
* @property common\models\Transfer $transfer
|
||||||
|
* @property common\models\Sale $sale
|
||||||
|
* @property common\models\ShoppingCart[] $customerCart
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class ProductSaleForm extends Model
|
class ProductSaleForm extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
public $append_to_sold_list;
|
public $cart;
|
||||||
|
|
||||||
public $id_product;
|
public $id_product;
|
||||||
public $count;
|
public $count;
|
||||||
@ -45,6 +69,7 @@ class ProductSaleForm extends Model
|
|||||||
public $currency;
|
public $currency;
|
||||||
public $discount;
|
public $discount;
|
||||||
public $customer;
|
public $customer;
|
||||||
|
public $card;
|
||||||
|
|
||||||
public $transfer;
|
public $transfer;
|
||||||
public $sale;
|
public $sale;
|
||||||
@ -60,7 +85,7 @@ class ProductSaleForm extends Model
|
|||||||
[['id_product','count','id_account'], 'required'],
|
[['id_product','count','id_account'], 'required'],
|
||||||
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
|
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
|
||||||
[['comment'], 'string' ,'max' => 255],
|
[['comment'], 'string' ,'max' => 255],
|
||||||
[['append_to_sold_list'], 'string' ,'max' => 10],
|
[['cart'], 'string' ,'max' => 20],
|
||||||
[['id_product' ], 'validateProduct'],
|
[['id_product' ], 'validateProduct'],
|
||||||
[['count' ], 'validateCount'],
|
[['count' ], 'validateCount'],
|
||||||
[['id_currency' ], 'validateCurrency'],
|
[['id_currency' ], 'validateCurrency'],
|
||||||
@ -127,11 +152,21 @@ class ProductSaleForm extends Model
|
|||||||
|
|
||||||
public function save(){
|
public function save(){
|
||||||
if ( $this->validate() ){
|
if ( $this->validate() ){
|
||||||
|
$connection = \Yii::$app->db;
|
||||||
|
$transaction = $connection->beginTransaction();
|
||||||
|
try {
|
||||||
$this->saveSale();
|
$this->saveSale();
|
||||||
$this->saveTransfer();
|
$this->saveTransfer();
|
||||||
$this->saveProduct();
|
$this->saveProduct();
|
||||||
$this->appendToUserCart();
|
$this->appendToUserCart();
|
||||||
$this->appendToCustomerCart();
|
$this->appendToCustomerCart();
|
||||||
|
$transaction->commit();
|
||||||
|
return true;
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$transaction->rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -139,10 +174,8 @@ class ProductSaleForm extends Model
|
|||||||
|
|
||||||
|
|
||||||
protected function saveSale(){
|
protected function saveSale(){
|
||||||
|
|
||||||
$this->sale = Sale::createSale($this->account, $this->discount, $this->currency, $this->count, $this->product );
|
$this->sale = Sale::createSale($this->account, $this->discount, $this->currency, $this->count, $this->product );
|
||||||
/*
|
|
||||||
*/
|
|
||||||
$this->sale->status = Sale::STATUS_PAID;
|
|
||||||
if ( isset($this->comment)){
|
if ( isset($this->comment)){
|
||||||
$this->sale->comment = $this->comment;
|
$this->sale->comment = $this->comment;
|
||||||
}
|
}
|
||||||
@ -151,11 +184,14 @@ class ProductSaleForm extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function saveTransfer(){
|
protected function saveTransfer(){
|
||||||
|
$status = Transfer::STATUS_PAID;
|
||||||
|
if ( $this->isAppendToUserCart() ){
|
||||||
|
$status = Transfer::STATUS_NOT_PAID;
|
||||||
|
}else if ( $this->isAppendToCustomerCart() ){
|
||||||
|
$status = Transfer::STATUS_NOT_PAID;
|
||||||
|
}
|
||||||
|
|
||||||
$this->transfer = Transfer::createProductTransfer($this->sale,$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,$status);
|
||||||
/*
|
|
||||||
*/
|
|
||||||
$this->transfer->status = Transfer::STATUS_PAID;
|
|
||||||
if ( isset($this->comment)){
|
if ( isset($this->comment)){
|
||||||
$this->transfer->comment = $this->comment;
|
$this->transfer->comment = $this->comment;
|
||||||
}
|
}
|
||||||
@ -170,7 +206,7 @@ class ProductSaleForm extends Model
|
|||||||
|
|
||||||
public function isAppendToUserCart(){
|
public function isAppendToUserCart(){
|
||||||
$result = false;
|
$result = false;
|
||||||
if ( isset( $this->append_to_sold_list ) && $this->append_to_sold_list == 'append' ){
|
if ( isset( $this->cart ) && $this->cart == 'user' ){
|
||||||
$result = true;
|
$result = true;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
@ -186,17 +222,19 @@ class ProductSaleForm extends Model
|
|||||||
}
|
}
|
||||||
public function isAppendToCustomerCart(){
|
public function isAppendToCustomerCart(){
|
||||||
$result = false;
|
$result = false;
|
||||||
if ( isset( $this->add_to_customer ) && $this->add_to_customer == 'append' ){
|
if ( isset( $this->cart ) && $this->cart == 'customer' ){
|
||||||
$result = true;
|
$result = true;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function appendToCustomerCart(){
|
public function appendToCustomerCart(){
|
||||||
|
// print_r("cart: ".$this->cart );
|
||||||
|
// print_r("customer:: ".$this->customer );
|
||||||
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
|
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
|
||||||
$item = new ShoppingCart();
|
$item = new ShoppingCart();
|
||||||
$item->id_customer = $this->customer->id_customer;
|
$item->id_customer = $this->customer->id_customer;
|
||||||
$item->id_sale = $this->sale->id_sale;
|
$item->id_transfer = $this->transfer->id_transfer;
|
||||||
$item->save(false);
|
$item->save(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,4 +33,4 @@ use yii\bootstrap\Html;
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php echo Html::a(Yii::t('frontend/product', "Fizetve"),null,[ 'id' => 'btn_paid', 'class' => 'btn btn-primary' ]) ?>
|
<?php echo Html::a(Yii::t('frontend/product', "Fizetve"),null,[ 'id' => 'btn_pay_customer_cart', 'class' => 'btn btn-primary' ]) ?>
|
||||||
@ -69,7 +69,8 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
|
|||||||
]
|
]
|
||||||
); ?>
|
); ?>
|
||||||
<?php echo Html::activeHiddenInput($model, 'id_product') ?>
|
<?php echo Html::activeHiddenInput($model, 'id_product') ?>
|
||||||
<?php echo Html::activeHiddenInput($model, 'append_to_sold_list') ?>
|
<?php echo Html::activeHiddenInput($model, 'cart') ?>
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class='col-md-12'>
|
<div class='col-md-12'>
|
||||||
@ -104,7 +105,11 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
|
|||||||
<?php echo Html::a(Yii::t("frontend/product","To cart"),null,['class' => 'btn btn-success', 'id' => 'btn_sell_append'] );?>
|
<?php echo Html::a(Yii::t("frontend/product","To cart"),null,['class' => 'btn btn-success', 'id' => 'btn_sell_append'] );?>
|
||||||
</div>
|
</div>
|
||||||
<div class='col-md-4'>
|
<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'] );?>
|
<?php
|
||||||
|
if ( isset($model->card) ){
|
||||||
|
echo Html::a(Yii::t("frontend/product","Write up"),null,['class' => 'btn btn-success', 'id' => 'btn_add_to_customer_cart'] );
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php ActiveForm::end(); ?>
|
<?php ActiveForm::end(); ?>
|
||||||
@ -3,10 +3,10 @@ use yii\bootstrap\Html;
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<h1><?php echo Yii::t('frontend/product','User Cart')?></h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class='col-md-12 '>
|
<div class='col-md-12 '>
|
||||||
<div class="sold-items-container">
|
<div class="user-cart">
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -33,3 +33,4 @@ use yii\bootstrap\Html;
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary' ]) ?>
|
||||||
@ -19,8 +19,12 @@ ProductSellAsset::register($this);
|
|||||||
$options = [];
|
$options = [];
|
||||||
|
|
||||||
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
|
||||||
$options['clear_list_url'] = Url::toRoute(['product/clear-list']);
|
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart']);
|
||||||
$options['sold_items'] = $userTransfers;
|
$options['user_cart'] = $userTransfers;
|
||||||
|
if ( isset($model->card) ){
|
||||||
|
$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $model->card->number]);
|
||||||
|
$options['customer_cart'] = $model->customerCart;
|
||||||
|
}
|
||||||
$options['discounts'] = Discount::modelsToArray($discounts);
|
$options['discounts'] = Discount::modelsToArray($discounts);
|
||||||
|
|
||||||
|
|
||||||
@ -77,14 +81,10 @@ $this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
|
|||||||
<?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>
|
||||||
<div class='col-md-6'>
|
<div class='col-md-6'>
|
||||||
|
<?php if ( isset($card) ){ ?>
|
||||||
<?php echo $this->render('_customer_cart' ) ?>
|
<?php echo $this->render('_customer_cart' ) ?>
|
||||||
|
<?php }?>
|
||||||
<h1><?php echo Yii::t('frontend/product','Cart')?></h1>
|
<?php echo $this->render('_user_cart' ) ?>
|
||||||
<?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>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,24 +3,31 @@ function ProductSell(o){
|
|||||||
/**reference for the instance*/
|
/**reference for the instance*/
|
||||||
var app = this;
|
var app = this;
|
||||||
/**currently loaded product*/
|
/**currently loaded product*/
|
||||||
var product = null;
|
this.product = null;
|
||||||
|
|
||||||
this.defaults = {
|
this.defaults = {
|
||||||
/**id of filter text*/
|
/**id of filter text*/
|
||||||
selector_filter_text: '#filter_text',
|
selector_filter_text: '#filter_text',
|
||||||
|
/**selector for customer cart container*/
|
||||||
|
selector_customer_cart: '.customer-cart',
|
||||||
|
selector_user_cart: '.user-cart',
|
||||||
|
selector_btn_pay_customer_cart: '#btn_pay_customer_cart',
|
||||||
|
selector_btn_pay_user_cart: '#btn_pay_user_cart',
|
||||||
|
url_pay_customer_card: '-',
|
||||||
/** ajax url for lookup service*/
|
/** ajax url for lookup service*/
|
||||||
lookup_product_url: '',
|
lookup_product_url: '',
|
||||||
/**mark list paid url*/
|
/**mark list paid url*/
|
||||||
clear_list_url: '',
|
url_pay_user_cart: '',
|
||||||
/**the id of form*/
|
/**the id of form*/
|
||||||
selector_form: '#product_form',
|
selector_form: '#product_form',
|
||||||
/**form contains error text*/
|
/**form contains error text*/
|
||||||
form_invalid: 'Az ürlap hibákat tartalmaz',
|
form_invalid: 'Az ürlap hibákat tartalmaz',
|
||||||
message_paid: 'Tételek fizetve',
|
message_paid: 'Tételek fizetve',
|
||||||
/**list of sold items by current user*/
|
/**list of sold items by current user*/
|
||||||
sold_items: [],
|
user_cart: [],
|
||||||
discounts: [],
|
discounts: [],
|
||||||
customer_cart: []
|
customer_cart: [],
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
@ -30,20 +37,60 @@ function ProductSell(o){
|
|||||||
app.keyDate = null;
|
app.keyDate = null;
|
||||||
app.keySeq = '';
|
app.keySeq = '';
|
||||||
app.enterPressed = 0;
|
app.enterPressed = 0;
|
||||||
addBehaviourBtnSell();
|
|
||||||
addBehaviourBtnSellAndAppendToBill();
|
addSellBehaiours();
|
||||||
addBehaviorAjaxSubmit();
|
|
||||||
setFocus();
|
setFocus();
|
||||||
addEnterPressedBehaviours();
|
|
||||||
addBehaviorCountChangedListener();
|
addListenerBehaviours();
|
||||||
addBehaviourDisocuntChanged();
|
|
||||||
createUserSoldItemsTable();
|
createCarts();
|
||||||
createCustomerCartTable();
|
|
||||||
addBehaviourBtnPaid();
|
addPayoutButtons();
|
||||||
|
|
||||||
productChanged();
|
productChanged();
|
||||||
addDocumentKeypressedListener();
|
addDocumentKeypressedListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* payout out user or customer cart
|
||||||
|
* */
|
||||||
|
function addPayoutButtons(){
|
||||||
|
addBehaviourPayoutUserCart();
|
||||||
|
addBehaviourPayoutCustomerCart();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* display user and customer cart on page load
|
||||||
|
* */
|
||||||
|
function createCarts(){
|
||||||
|
createUserCartTable();
|
||||||
|
createCustomerCartTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add change and enter pressed listeners
|
||||||
|
* */
|
||||||
|
function addListenerBehaviours(){
|
||||||
|
addEnterPressedBehaviours();
|
||||||
|
addBehaviorCountChangedListener();
|
||||||
|
addBehaviourDisocuntChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sell a product. there are three type of sell:
|
||||||
|
* - sell inmadietly
|
||||||
|
* - sell and put it to user cart
|
||||||
|
* - sell and put it to customer cart
|
||||||
|
* */
|
||||||
|
function addSellBehaiours(){
|
||||||
|
addBehaviourBtnSell();
|
||||||
|
addBehaviourBtnSellAndAppendToBill();
|
||||||
|
addBehaviourBtnAddToCustomerCart();
|
||||||
|
|
||||||
|
addBehaviorAjaxSubmit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function addBehaviourDisocuntChanged(){
|
function addBehaviourDisocuntChanged(){
|
||||||
$("#productsaleform-id_discount").change(refreshCalculatedValues);
|
$("#productsaleform-id_discount").change(refreshCalculatedValues);
|
||||||
}
|
}
|
||||||
@ -103,6 +150,9 @@ function ProductSell(o){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add traversing between input elements on enter key pressed
|
||||||
|
* */
|
||||||
function addEnterPressedBehaviours(){
|
function addEnterPressedBehaviours(){
|
||||||
addBehaviorEnterPressedListener();
|
addBehaviorEnterPressedListener();
|
||||||
addBehaviorCountEnterPressedListener();
|
addBehaviorCountEnterPressedListener();
|
||||||
@ -277,24 +327,20 @@ function ProductSell(o){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function submitSell(){
|
function submitSell(){
|
||||||
$('#productsaleform-append_to_sold_list').val('');
|
$('#productsaleform-cart').val('');
|
||||||
$('#product_form').submit();
|
$('#product_form').submit();
|
||||||
}
|
}
|
||||||
function submitSellAndAppend(){
|
function submitSellAndAppend(){
|
||||||
$('#productsaleform-append_to_sold_list').val('append');
|
$('#productsaleform-cart').val('user');
|
||||||
$('#product_form').submit();
|
$('#product_form').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function submitAddToCustomerCart(){
|
function submitAddToCustomerCart(){
|
||||||
$('#productsaleform-append_to_sold_list').val('append');
|
$('#productsaleform-cart').val('customer');
|
||||||
$('#product_form').submit();
|
$('#product_form').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshSoldUseritems(){
|
|
||||||
$('.sold-items-container').transferList('option','transfers' , app.defaults.sold_items );
|
|
||||||
}
|
|
||||||
|
|
||||||
function addBehaviorAjaxSubmit(){
|
function addBehaviorAjaxSubmit(){
|
||||||
|
|
||||||
$('body').on('afterValidate', '#product_form', function () {
|
$('body').on('afterValidate', '#product_form', function () {
|
||||||
@ -327,8 +373,10 @@ function ProductSell(o){
|
|||||||
refreshCalculatedValues();
|
refreshCalculatedValues();
|
||||||
$("#filter_text").val('');
|
$("#filter_text").val('');
|
||||||
setFocus();
|
setFocus();
|
||||||
app.defaults.sold_items = response.transfers;
|
app.defaults.user_cart = response.transfers;
|
||||||
refreshSoldItemsList();
|
app.defaults.customer_cart = response.customer_cart;
|
||||||
|
refreshUserCart();
|
||||||
|
refreshCustomerCart();
|
||||||
}else if ( response.code == 'invalid'){
|
}else if ( response.code == 'invalid'){
|
||||||
if ( response.errors ){
|
if ( response.errors ){
|
||||||
$.each(response.errors, function (key, value){
|
$.each(response.errors, function (key, value){
|
||||||
@ -347,21 +395,24 @@ function ProductSell(o){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function refreshSoldItemsList(){
|
function refreshUserCart(){
|
||||||
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
|
$(app.defaults.selector_user_cart).transferList( 'option', 'transfers' , app.defaults.user_cart );
|
||||||
|
}
|
||||||
|
function refreshCustomerCart(){
|
||||||
|
$(app.defaults.selector_customer_cart ).transferList( 'option', 'transfers' , app.defaults.customer_cart );
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBehaviourBtnPaid( ){
|
function addBehaviourPayoutUserCart( ){
|
||||||
$('#btn_paid').on('click',function(){
|
$( app.defaults.selector_btn_pay_user_cart ).on('click',function(){
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: app.defaults.clear_list_url,
|
url: app.defaults.url_pay_user_cart,
|
||||||
type: 'post',
|
type: 'post',
|
||||||
data: {},
|
data: {},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if ( response.code == 'success'){
|
if ( response.code == 'success'){
|
||||||
app.defaults.sold_items= response.transfers;
|
app.defaults.user_cart = response.transfers;
|
||||||
refreshSoldItemsList();
|
refreshUserCart();
|
||||||
$.notify(app.defaults.message_paid, { 'type' : 'success' });
|
$.notify(app.defaults.message_paid, { 'type' : 'success' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -369,14 +420,35 @@ function ProductSell(o){
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function addBehaviourPayoutCustomerCart( ){
|
||||||
|
$( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){
|
||||||
|
alert('ok');
|
||||||
|
$.ajax({
|
||||||
|
url: app.defaults.url_pay_customer_card,
|
||||||
|
type: 'post',
|
||||||
|
data: {},
|
||||||
|
success: function (response) {
|
||||||
|
if ( response.code == 'success'){
|
||||||
|
app.defaults.customer_cart = response.customer_cart;
|
||||||
|
refreshCustomerCart();
|
||||||
|
}
|
||||||
|
$.notify(response.message, { 'type' : response.code });
|
||||||
|
},
|
||||||
|
error: function(){
|
||||||
|
alert('Hiba történt');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function createUserSoldItemsTable(){
|
function createUserCartTable(){
|
||||||
$('.sold-items-container').transferList({
|
$(app.defaults.selector_user_cart).transferList({
|
||||||
'transfers' : app.defaults.sold_items
|
'transfers' : app.defaults.user_cart
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function createCustomerCartTable(){
|
function createCustomerCartTable(){
|
||||||
$('.customer-cart').transferList({
|
$(app.defaults.selector_customer_cart).transferList({
|
||||||
'transfers' : app.defaults.customer_cart
|
'transfers' : app.defaults.customer_cart
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,7 +136,6 @@ $.widget( "fitness.transferList", {
|
|||||||
self._refresh();
|
self._refresh();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// base
|
// base
|
||||||
this._super(key, value);
|
this._super(key, value);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user