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
7ed9828e
authored
Apr 05, 2015
by
semenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Начало разработки
parent
84881e37
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
163 additions
and
13 deletions
+163
-13
assets/classes/Cart.js
+66
-0
assets/classes/Shop.js
+2
-0
components/Cart.php
+19
-12
components/shop/Shop.php
+1
-1
controllers/BasketController.php
+43
-0
models/ShopFuser.php
+32
-0
No files found.
assets/classes/Cart.js
View file @
7ed9828e
...
...
@@ -70,9 +70,75 @@
this
.
ajax
.
execute
();
},
updateBasket
:
function
(
basket_id
,
quantity
)
{
this
.
ajax
.
setUrl
(
this
.
get
(
'backend-update-basket'
));
this
.
ajax
.
setData
({
'basket_id'
:
Number
(
basket_id
),
'quantity'
:
Number
(
quantity
),
});
this
.
ajax
.
execute
();
},
update
:
function
()
{},
/**
* Есть ли полная корзина на странице
* @returns {boolean}
*/
hasFullCart
:
function
()
{
if
(
$
(
'#sx-cart-full'
)[
0
])
{
return
true
;
}
return
false
;
},
/**
*
* @returns {*|HTMLElement}
* @constructor
*/
JFullCart
:
function
()
{
return
$
(
'#sx-cart-full'
);
},
/**
* Есть ли полная корзина на странице
* @returns {boolean}
*/
hasCart
:
function
()
{
if
(
$
(
'#sx-cart'
)[
0
])
{
return
true
;
}
return
false
;
},
/**
*
* @returns {*|HTMLElement}
* @constructor
*/
JCart
:
function
()
{
return
$
(
'#sx-cart'
);
}
});
sx
.
classes
.
shop
.
Cart
=
sx
.
classes
.
shop
.
_Cart
.
extend
({});
...
...
assets/classes/Shop.js
View file @
7ed9828e
...
...
@@ -14,6 +14,8 @@
{
this
.
Cart
=
new
sx
.
classes
.
shop
.
Cart
(
this
.
get
(
'cart'
));
},
});
sx
.
classes
.
shop
.
App
=
sx
.
classes
.
shop
.
_App
.
extend
({});
...
...
components/Cart.php
View file @
7ed9828e
...
...
@@ -53,24 +53,14 @@ class Cart extends \skeeks\cms\base\Component
{
$fuserId
=
\Yii
::
$app
->
getSession
()
->
get
(
$this
->
sessionFuserName
);
$shopFuser
=
ShopFuser
::
find
()
->
where
([
'id'
=>
$fuserId
])
->
one
();
//Поиск юзера
/**
* @var $shopFuser ShopFuser
*/
if
(
$shopFuser
)
{
if
(
$baskets
=
$shopFuser
->
getShopBaskets
())
{
/**
* @var ShopBasket $basket
*/
foreach
(
$baskets
as
$basket
)
{
//TODO:: доработать чтобы нужно обновлять количество
$basket
->
fuser_id
=
$this
->
shopFuser
->
id
;
$basket
->
save
();
}
}
$this
->
shopFuser
->
addBaskets
(
$shopFuser
->
getShopBaskets
()
->
all
());
}
\Yii
::
$app
->
getSession
()
->
remove
(
$this
->
sessionFuserName
);
...
...
@@ -179,6 +169,23 @@ class Cart extends \skeeks\cms\base\Component
/**
* @return int
*/
public
function
countProducts
()
{
$result
=
0
;
if
(
$baskets
=
$this
->
getShopBaskets
())
{
foreach
(
$baskets
as
$basket
)
{
$result
=
$result
+
$basket
->
quantity
;
}
}
return
$result
;
}
/**
* Стоимость корзины.
*
* @return \skeeks\modules\cms\money\Money
...
...
components/shop/Shop.php
View file @
7ed9828e
...
...
@@ -78,7 +78,7 @@ class Shop extends \skeeks\cms\base\Component
[
'backend-add-product'
=>
UrlHelper
::
construct
(
'shop/basket/add-product'
)
->
toString
(),
'backend-remove-basket'
=>
UrlHelper
::
construct
(
'shop/basket/remove-basket'
)
->
toString
(),
'backend-update-basket'
=>
UrlHelper
::
construct
(
'shop/basket/update'
)
->
toString
(),
'backend-update-basket'
=>
UrlHelper
::
construct
(
'shop/basket/update
-basket
'
)
->
toString
(),
'backend-clear'
=>
UrlHelper
::
construct
(
'shop/basket/clear-all'
)
->
toString
()
]
];
...
...
controllers/BasketController.php
View file @
7ed9828e
...
...
@@ -97,4 +97,46 @@ class BasketController extends Controller
return
$this
->
goBack
();
}
}
public
function
actionUpdateBasket
()
{
$rr
=
new
RequestResponse
();
if
(
$rr
->
isRequestAjaxPost
())
{
$basket_id
=
(
int
)
\Yii
::
$app
->
request
->
post
(
'basket_id'
);
$quantity
=
(
int
)
\Yii
::
$app
->
request
->
post
(
'quantity'
);
$shopBasket
=
ShopBasket
::
find
()
->
where
([
'id'
=>
$basket_id
])
->
one
();
if
(
$shopBasket
)
{
if
(
$quantity
>
0
)
{
$shopBasket
->
quantity
=
$quantity
;
if
(
$shopBasket
->
save
())
{
$rr
->
success
=
true
;
$rr
->
message
=
'Позиция успешно обновлена'
;
$shopBasket
->
recalculate
();
}
}
else
{
if
(
$shopBasket
->
delete
())
{
$rr
->
success
=
true
;
$rr
->
message
=
'Позиция успешно удалена'
;
}
}
}
return
(
array
)
$rr
;
}
else
{
return
$this
->
goBack
();
}
}
}
\ No newline at end of file
models/ShopFuser.php
View file @
7ed9828e
...
...
@@ -123,4 +123,35 @@ class ShopFuser extends Core
return
$this
->
hasMany
(
ShopBasket
::
className
(),
[
'fuser_id'
=>
'id'
]);
}
/**
* Добавить корзины этому пользователю
*
* @param ShopBasket[] $baskets
* @return $this
*/
public
function
addBaskets
(
$baskets
=
[])
{
/**
* @var $currentBasket ShopBasket
*/
foreach
(
$baskets
as
$basket
)
{
//Если в корзине которую необходимо добавить продукт такой же который уже есть у текущего пользователя, то нужно обновить количество.
if
(
$currentBasket
=
$this
->
getShopBaskets
()
->
andWhere
([
'product_id'
=>
$basket
->
product_id
])
->
one
())
{
$currentBasket
->
quantity
=
$currentBasket
->
quantity
+
$basket
->
quantity
;
$currentBasket
->
save
();
$basket
->
delete
();
$currentBasket
->
recalculate
();
}
else
{
$basket
->
fuser_id
=
$this
->
id
;
$basket
->
save
();
}
}
return
$this
;
}
}
\ No newline at end of file
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