Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
skeeks
/
cms-module-shop
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b170adf9
authored
Apr 13, 2015
by
semenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Начало разработки
parent
8558a8fe
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
21 deletions
+124
-21
components/Cart.php
+1
-1
controllers/BackendController.php
+83
-18
controllers/BasketController.php
+1
-0
migrations/m150401_112818_create_table__shop_basket.php
+1
-1
views/admin-shop-order/index.php
+37
-0
views/cart-form.php
+1
-1
No files found.
components/Cart.php
View file @
b170adf9
...
...
@@ -136,7 +136,7 @@ class Cart extends \skeeks\cms\base\Component
return
null
;
}
return
$this
->
shopFuser
->
getShopBaskets
();
return
$this
->
shopFuser
->
getShopBaskets
()
->
where
([
'order_id'
=>
null
])
;
}
/**
...
...
controllers/BackendController.php
View file @
b170adf9
...
...
@@ -7,10 +7,14 @@
*/
namespace
skeeks\modules\cms\shop\controllers
;
use
skeeks\cms\base\Controller
;
use
skeeks\cms\helpers\RequestResponse
;
use
skeeks\modules\cms\form\models\Form
;
use
skeeks\modules\cms\form\models\FormField
;
use
skeeks\modules\cms\form\models\FormSendMessage
;
use
skeeks\modules\cms\shop\models\ShopOrder
;
use
skeeks\modules\cms\shop\models\ShopPersonType
;
use
yii\base\Exception
;
use
yii\base\UserException
;
use
yii\filters\VerbFilter
;
use
yii\helpers\ArrayHelper
;
use
yii\web\Response
;
...
...
@@ -46,23 +50,48 @@ class BackendController extends Controller
*/
public
function
actionCreateOrder
()
{
if
(
\Yii
::
$app
->
request
->
isAjax
&&
!
\Yii
::
$app
->
request
->
isPjax
)
{
if
(
\Yii
::
$app
->
request
->
isAjax
&&
!
\Yii
::
$app
->
request
->
isPjax
)
{
\Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$response
=
[
'success'
=>
false
,
'message'
=>
'Произошла ошибка'
,
];
$rr
=
new
RequestResponse
();
try
{
if
(
!
$formId
=
\Yii
::
$app
->
request
->
post
(
Form
::
FROM_PARAM_ID_NAME
))
{
throw
new
UserException
(
'Не найден параметр формы'
);
}
if
(
$formId
=
\Yii
::
$app
->
request
->
post
(
Form
::
FROM_PARAM_ID_NAME
))
{
/**
* @var $modelForm Form
*/
$modelForm
=
Form
::
find
()
->
where
([
'id'
=>
$formId
])
->
one
();
$modelForm
=
Form
::
find
()
->
where
([
'id'
=>
$formId
])
->
one
();
$model
=
$modelForm
->
createValidateModel
();
if
(
$model
->
load
(
\Yii
::
$app
->
request
->
post
())
&&
$model
->
validate
())
{
$shopPersonTypeId
=
(
int
)
\Yii
::
$app
->
request
->
post
(
'shopPersonType'
);
if
(
!
$shopPersonTypeId
)
{
throw
new
UserException
(
'Не передан параметр тип плательщика'
);
}
$shopPersonType
=
ShopPersonType
::
findOne
(
$shopPersonTypeId
);
if
(
!
$shopPersonType
)
{
throw
new
UserException
(
'Не указан плательщик'
);
}
$model
=
$modelForm
->
createValidateModel
();
if
(
!
$model
->
email
)
{
throw
new
UserException
(
'Не указан email.'
);
}
if
(
$model
->
load
(
\Yii
::
$app
->
request
->
post
())
&&
$model
->
validate
())
{
if
(
!
\Yii
::
$app
->
shop
->
cart
->
countProducts
())
{
throw
new
UserException
(
'Нет товаров в корзине.'
);
}
//Пользователь авторизован или нет.
...
...
@@ -71,15 +100,41 @@ class BackendController extends Controller
}
else
{
$user
=
\Yii
::
$app
->
cms
->
getAuthUser
();
}
$cost
=
\Yii
::
$app
->
shop
->
cart
->
cost
();
$currency
=
$cost
->
getCurrency
();
//Создание нового заказа
$shopOrder
=
new
ShopOrder
([
''
'person_type_id'
=>
$shopPersonType
->
id
,
'price'
=>
$cost
->
getAmount
()
/
$currency
->
getSubUnit
(),
'currency'
=>
(
string
)
$currency
,
'user_id'
=>
$user
->
id
,
]);
if
(
!
$shopOrder
->
save
())
{
$result
=
[];
$errors
=
$shopOrder
->
getErrors
();
foreach
(
$errors
as
$errorData
)
{
$result
[]
=
implode
(
', '
,
$errorData
);
}
throw
new
UserException
(
'Не получилось оформить заказ: '
.
implode
(
'; '
,
$result
));
}
//Переписать позиции корзины
if
(
$shopBaskets
=
\Yii
::
$app
->
shop
->
cart
->
getShopBaskets
())
{
foreach
(
$shopBaskets
as
$shopBasket
)
{
$shopBasket
->
order_id
=
$shopOrder
->
id
;
$shopBasket
->
save
();
}
}
//Отправка сообщения с формы
//Все проверки прошли, формируем модель отправленного сообщения и сохраняем ее
...
...
@@ -95,18 +150,27 @@ class BackendController extends Controller
{
$modelFormSendMessage
->
notify
();
$response
[
'success'
]
=
true
;
$response
[
'message'
]
=
'Успешно отправлена'
;
}
else
{
$response
[
'message'
]
=
'Не удалось сохранить сообщение в базу'
;
$rr
->
success
=
true
;
$rr
->
message
=
'Успешно отправлена'
;
}
else
{
$rr
->
message
=
'Не удалось сохранить сообщение в базу'
;
}
}
else
{
$response
[
'message'
]
=
'Форма заполнена неправильно'
;
}
else
{
$rr
->
message
=
'Форма заполнена неправильно'
;
}
return
$response
;
}
catch
(
\Exception
$e
)
{
$rr
->
message
=
$e
->
getMessage
();
}
return
(
array
)
$rr
;
}
}
}
\ No newline at end of file
controllers/BasketController.php
View file @
b170adf9
...
...
@@ -45,6 +45,7 @@ class BasketController extends Controller
$shopBasket
=
ShopBasket
::
find
()
->
where
([
'fuser_id'
=>
\Yii
::
$app
->
shop
->
cart
->
shopFuser
->
id
,
'product_id'
=>
$product_id
,
'order_id'
=>
null
,
])
->
one
();
if
(
!
$shopBasket
)
...
...
migrations/m150401_112818_create_table__shop_basket.php
View file @
b170adf9
...
...
@@ -88,7 +88,7 @@ class m150401_112818_create_table__shop_basket extends Migration
$this
->
execute
(
"ALTER TABLE
{
{%shop_basket}
}
ADD INDEX(deducted);"
);
$this
->
execute
(
"ALTER TABLE
{
{%shop_basket}
}
ADD INDEX(custom_price);"
);
$this
->
execute
(
"ALTER TABLE
{
{%shop_basket}
}
ADD UNIQUE(fuser_id,product_id);"
);
$this
->
execute
(
"ALTER TABLE
{
{%shop_basket}
}
ADD UNIQUE(fuser_id,product_id
,order_id
);"
);
$this
->
execute
(
"ALTER TABLE
{
{%shop_basket}
}
COMMENT = 'Позиция в корзине';"
);
...
...
views/admin-shop-order/index.php
0 → 100644
View file @
b170adf9
<?php
/**
* index
*
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010-2014 SkeekS (Sx)
* @date 30.10.2014
* @since 1.0.0
*/
use
skeeks\cms\modules\admin\widgets\GridView
;
/* @var $this yii\web\View */
/* @var $searchModel common\models\searchs\Game */
/* @var $dataProvider yii\data\ActiveDataProvider */
$dataProvider
->
sort
->
defaultOrder
=
[
'active'
=>
SORT_DESC
,
];
?>
<?=
GridView
::
widget
([
'dataProvider'
=>
$dataProvider
,
'filterModel'
=>
$searchModel
,
'columns'
=>
[
[
'class'
=>
\skeeks\cms\modules\admin\grid\ActionColumn
::
className
(),
'controller'
=>
$controller
],
'name'
,
[
'class'
=>
\skeeks\cms\grid\BooleanColumn
::
className
(),
'attribute'
=>
'active'
],
],
]);
?>
views/cart-form.php
View file @
b170adf9
...
...
@@ -13,7 +13,7 @@ use skeeks\modules\cms\form\widgets\ActiveForm;
?>
<?php
$form
=
ActiveForm
::
begin
([
'modelForm'
=>
$model
->
modelForm
,
'action'
=>
\skeeks\cms\helpers\UrlHelper
::
construct
(
'shop/backend/create-order'
)
->
toString
(),
'action'
=>
\skeeks\cms\helpers\UrlHelper
::
construct
(
'shop/backend/create-order'
)
->
toString
(),
]);
?>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment