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
2e8b98e8
authored
Apr 03, 2015
by
semenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
beeb883b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
9 deletions
+73
-9
components/Cart.php
+55
-2
controllers/BasketController.php
+16
-7
migrations/m150401_112818_create_table__shop_basket.php
+2
-0
No files found.
components/Cart.php
View file @
2e8b98e8
...
...
@@ -43,6 +43,54 @@ class Cart extends \skeeks\cms\base\Component
}
else
{
$this
->
shopFuser
=
ShopFuser
::
fetchByUser
(
\Yii
::
$app
->
cms
->
getAuthUser
());
//Если у авторизовнного пользоывателя уже есть пользователь корзины
if
(
$this
->
shopFuser
)
{
//Проверка сессии, а было ли чего то в корзине
if
(
\Yii
::
$app
->
getSession
()
->
offsetExists
(
$this
->
sessionFuserName
))
{
$fuserId
=
\Yii
::
$app
->
getSession
()
->
get
(
$this
->
sessionFuserName
);
$shopFuser
=
ShopFuser
::
find
()
->
where
([
'id'
=>
$fuserId
])
->
one
();
//Поиск юзера
/**
* @var $shopFuser ShopFuser
*/
if
(
$shopFuser
)
{
if
(
$baskets
=
$shopFuser
->
getShopBaskets
()
->
all
())
{
foreach
(
$baskets
as
$basket
)
{
$basket
->
fuser_id
=
$this
->
shopFuser
->
id
;
$basket
->
save
();
}
}
}
\Yii
::
$app
->
getSession
()
->
remove
(
$this
->
sessionFuserName
);
}
}
else
{
//Проверка сессии, а было ли чего то в корзине
if
(
\Yii
::
$app
->
getSession
()
->
offsetExists
(
$this
->
sessionFuserName
))
{
$fuserId
=
\Yii
::
$app
->
getSession
()
->
get
(
$this
->
sessionFuserName
);
$shopFuser
=
ShopFuser
::
find
()
->
where
([
'id'
=>
$fuserId
])
->
one
();
//Поиск юзера
/**
* @var $shopFuser ShopFuser
*/
if
(
$shopFuser
)
{
$shopFuser
->
user_id
=
\Yii
::
$app
->
cms
->
getAuthUser
()
->
id
;
$shopFuser
->
save
();
}
\Yii
::
$app
->
getSession
()
->
remove
(
$this
->
sessionFuserName
);
}
}
}
}
...
...
@@ -90,7 +138,7 @@ class Cart extends \skeeks\cms\base\Component
{
if
(
!
$this
->
shopFuser
)
{
return
[]
;
return
null
;
}
return
$this
->
shopFuser
->
getShopBaskets
();
...
...
@@ -103,7 +151,12 @@ class Cart extends \skeeks\cms\base\Component
*/
public
function
countBaskets
()
{
return
count
(
$this
->
getShopBaskets
());
if
(
$this
->
getShopBaskets
())
{
return
count
(
$this
->
getShopBaskets
()
->
all
());
}
return
0
;
}
...
...
controllers/BasketController.php
View file @
2e8b98e8
...
...
@@ -29,16 +29,25 @@ class BasketController extends Controller
\Yii
::
$app
->
shop
->
cart
->
loadShopFuser
();
$shopBasket
=
new
ShopBasket
([
'fuser_id'
=>
\Yii
::
$app
->
shop
->
cart
->
shopFuser
->
id
,
'name'
=>
$product_id
,
'product_id'
=>
$product_id
,
'quantity'
=>
$quantity
,
]);
$shopBasket
=
ShopBasket
::
find
()
->
where
([
'fuser_id'
=>
\Yii
::
$app
->
shop
->
cart
->
shopFuser
->
id
,
'product_id'
=>
$product_id
,
])
->
one
();
if
(
!
$shopBasket
)
{
$shopBasket
=
new
ShopBasket
([
'fuser_id'
=>
\Yii
::
$app
->
shop
->
cart
->
shopFuser
->
id
,
'name'
=>
$product_id
,
'product_id'
=>
$product_id
,
'quantity'
=>
0
,
]);
}
$shopBasket
->
quantity
=
$shopBasket
->
quantity
+
$quantity
;
$shopBasket
->
save
();
return
(
array
)
$rr
->
toArray
()
;
return
(
array
)
$rr
;
}
else
{
return
$this
->
goBack
();
...
...
migrations/m150401_112818_create_table__shop_basket.php
View file @
2e8b98e8
...
...
@@ -88,6 +88,8 @@ 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}
}
COMMENT = 'Позиция в корзине';"
);
$this
->
addForeignKey
(
...
...
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