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
1a234650
authored
Apr 04, 2015
by
semenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Начало разработки
parent
2e8b98e8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
16 deletions
+90
-16
assets/classes/Cart.js
+15
-1
components/Cart.php
+17
-3
components/shop/Shop.php
+4
-1
controllers/BasketController.php
+29
-0
models/ShopBasket.php
+25
-11
No files found.
assets/classes/Cart.js
View file @
1a234650
...
...
@@ -44,11 +44,13 @@
_init
:
function
()
{
this
.
ajax
=
sx
.
ajax
.
preparePostQuery
(
this
.
get
(
'backend'
)
);
this
.
ajax
=
sx
.
ajax
.
preparePostQuery
(
'/'
);
},
addProduct
:
function
(
product_id
,
quantity
)
{
this
.
ajax
.
setUrl
(
this
.
get
(
'backend-add-product'
));
this
.
ajax
.
setData
({
'product_id'
:
Number
(
product_id
),
'quantity'
:
Number
(
quantity
),
...
...
@@ -57,6 +59,18 @@
this
.
ajax
.
execute
();
},
removeBasket
:
function
(
basket_id
)
{
this
.
ajax
.
setUrl
(
this
.
get
(
'backend-remove-basket'
));
this
.
ajax
.
setData
({
'basket_id'
:
Number
(
basket_id
),
});
this
.
ajax
.
execute
();
},
update
:
function
()
{},
});
...
...
components/Cart.php
View file @
1a234650
...
...
@@ -7,6 +7,7 @@
*/
namespace
skeeks\modules\cms\shop\components
;
use
skeeks\cms\helpers\UrlHelper
;
use
skeeks\modules\cms\shop\models\ShopBasket
;
use
skeeks\modules\cms\shop\models\ShopFuser
;
use
yii\helpers\ArrayHelper
;
...
...
@@ -58,7 +59,7 @@ class Cart extends \skeeks\cms\base\Component
*/
if
(
$shopFuser
)
{
if
(
$baskets
=
$shopFuser
->
getShopBaskets
()
->
all
()
)
if
(
$baskets
=
$shopFuser
->
getShopBaskets
())
{
foreach
(
$baskets
as
$basket
)
{
...
...
@@ -134,7 +135,7 @@ class Cart extends \skeeks\cms\base\Component
/**
* @return array|\yii\db\ActiveQuery
*/
public
function
get
ShopBaskets
()
public
function
find
ShopBaskets
()
{
if
(
!
$this
->
shopFuser
)
{
...
...
@@ -145,6 +146,19 @@ class Cart extends \skeeks\cms\base\Component
}
/**
* @return ShopBasket[]
*/
public
function
getShopBaskets
()
{
if
(
!
$this
->
shopFuser
)
{
return
[];
}
return
$this
->
findShopBaskets
()
->
all
();
}
/**
* Количество позиций в коризне
*
* @return int
...
...
@@ -153,7 +167,7 @@ class Cart extends \skeeks\cms\base\Component
{
if
(
$this
->
getShopBaskets
())
{
return
count
(
$this
->
getShopBaskets
()
->
all
()
);
return
count
(
$this
->
getShopBaskets
());
}
return
0
;
...
...
components/shop/Shop.php
View file @
1a234650
...
...
@@ -68,7 +68,10 @@ class Shop extends \skeeks\cms\base\Component
return
[
'cart'
=>
[
'backend'
=>
UrlHelper
::
construct
(
'shop/basket/add-product'
)
->
toString
()
'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-clear'
=>
UrlHelper
::
construct
(
'shop/basket/clear-all'
)
->
toString
()
]
];
}
...
...
controllers/BasketController.php
View file @
1a234650
...
...
@@ -47,6 +47,35 @@ class BasketController extends Controller
$shopBasket
->
quantity
=
$shopBasket
->
quantity
+
$quantity
;
$shopBasket
->
save
();
$rr
->
success
=
true
;
$rr
->
message
=
'Позиция добавлена в корзину'
;
return
(
array
)
$rr
;
}
else
{
return
$this
->
goBack
();
}
}
public
function
actionRemoveBasket
()
{
$rr
=
new
RequestResponse
();
if
(
$rr
->
isRequestAjaxPost
())
{
$basket_id
=
\Yii
::
$app
->
request
->
post
(
'basket_id'
);
$shopBasket
=
ShopBasket
::
find
()
->
where
([
'id'
=>
$basket_id
])
->
one
();
if
(
$shopBasket
)
{
if
(
$shopBasket
->
delete
())
{
$rr
->
success
=
true
;
$rr
->
message
=
'Позиция успешно удалена'
;
}
}
return
(
array
)
$rr
;
}
else
{
...
...
models/ShopBasket.php
View file @
1a234650
...
...
@@ -10,6 +10,8 @@ use skeeks\cms\models\behaviors\HasStatus;
use
skeeks\cms\models\behaviors\HasStatusBoolean
;
use
skeeks\cms\models\Core
;
use
skeeks\modules\cms\catalog\models\Product
;
use
skeeks\modules\cms\money\Currency
;
use
skeeks\modules\cms\money\Money
;
use
\Yii
;
use
yii\helpers\ArrayHelper
;
...
...
@@ -133,29 +135,41 @@ class ShopBasket extends Core
]);
}
/**
* Стоимость этой позиции
* @return \skeeks\modules\cms\money\Money
* @return Money
*/
public
function
cost
()
public
function
price
()
{
/**
* @var Product $product
*/
$product
=
$this
->
getProduct
()
->
one
();
$money
=
$product
->
cost
();
if
(
$this
->
price
)
{
return
Money
::
fromString
((
string
)
$this
->
price
,
$this
->
currency
());
}
return
Money
::
fromString
((
string
)
0
,
$this
->
currency
());
}
$money
=
$money
->
multiply
((
int
)
$this
->
quantity
);
/**
* @return Currency
*/
public
function
currency
()
{
if
(
$currency
=
$this
->
getAttribute
(
$this
->
currency
))
{
return
Currency
::
getInstance
(
$currency
);
}
return
$money
;
return
Currency
::
getInstance
(
\Yii
::
$app
->
money
->
currency
)
;
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getProduct
()
{
return
$this
->
hasOne
(
Catalog
Product
::
className
(),
[
'id'
=>
'product_id'
]);
return
$this
->
hasOne
(
Product
::
className
(),
[
'id'
=>
'product_id'
]);
}
/**
...
...
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