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
84881e37
authored
Apr 04, 2015
by
semenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
1a234650
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
126 additions
and
4 deletions
+126
-4
components/Cart.php
+18
-0
components/shop/Shop.php
+10
-2
components/shop/_form.php
+7
-0
controllers/BasketController.php
+17
-2
controllers/CartController.php
+31
-0
models/ShopBasket.php
+41
-0
views/cart/index.php
+2
-0
No files found.
components/Cart.php
View file @
84881e37
...
...
@@ -61,8 +61,12 @@ class Cart extends \skeeks\cms\base\Component
{
if
(
$baskets
=
$shopFuser
->
getShopBaskets
())
{
/**
* @var ShopBasket $basket
*/
foreach
(
$baskets
as
$basket
)
{
//TODO:: доработать чтобы нужно обновлять количество
$basket
->
fuser_id
=
$this
->
shopFuser
->
id
;
$basket
->
save
();
}
...
...
@@ -174,6 +178,11 @@ class Cart extends \skeeks\cms\base\Component
}
/**
* Стоимость корзины.
*
* @return \skeeks\modules\cms\money\Money
*/
public
function
cost
()
{
$money
=
\Yii
::
$app
->
money
->
newMoney
();
...
...
@@ -183,6 +192,14 @@ class Cart extends \skeeks\cms\base\Component
return
$money
;
}
if
(
$baskets
=
$this
->
getShopBaskets
())
{
foreach
(
$baskets
as
$basket
)
{
$money
=
$money
->
add
(
$basket
->
price
());
}
}
return
$money
;
}
}
\ No newline at end of file
components/shop/Shop.php
View file @
84881e37
...
...
@@ -22,6 +22,11 @@ class Shop extends \skeeks\cms\base\Component
public
$email
=
'admin@skeeks.com'
;
/**
* @var int
*/
public
$allowBuyWhithoutQuantity
=
1
;
/**
* @var Cart
*/
public
$cart
=
null
;
...
...
@@ -39,7 +44,8 @@ class Shop extends \skeeks\cms\base\Component
{
return
[
'name'
=>
'Интернет-магазин'
,
'name'
=>
'Интернет-магазин'
,
];
}
...
...
@@ -47,13 +53,15 @@ class Shop extends \skeeks\cms\base\Component
{
return
ArrayHelper
::
merge
(
parent
::
rules
(),
[
[[
'email'
],
'email'
],
[[
'allowBuyWhithoutQuantity'
],
'integer'
],
]);
}
public
function
attributeLabels
()
{
return
ArrayHelper
::
merge
(
parent
::
attributeLabels
(),
[
'email'
=>
'Email отдела продаж'
,
'email'
=>
'Email отдела продаж'
,
'allowBuyWhithoutQuantity'
=>
'Разрешить покупку при отсутствии товара'
,
]);
}
...
...
components/shop/_form.php
View file @
84881e37
...
...
@@ -16,6 +16,13 @@ use skeeks\cms\widgets\base\hasModelsSmart\ActiveForm;
<?=
$form
->
fieldSet
(
'Основное'
);
?>
<?=
$form
->
field
(
$model
,
'email'
)
->
textInput
()
->
hint
(
''
);
?>
<?=
$form
->
field
(
$model
,
'allowBuyWhithoutQuantity'
)
->
widget
(
\skeeks\widget\chosen\Chosen
::
className
(),
[
'items'
=>
\Yii
::
$app
->
formatter
->
booleanFormat
,
'allowDeselect'
=>
false
]
);
?>
<?=
$form
->
fieldSetEnd
();
?>
<?=
$form
->
buttonsCreateOrUpdate
(
$model
);
?>
...
...
controllers/BasketController.php
View file @
84881e37
...
...
@@ -11,13 +11,18 @@ use skeeks\cms\base\Controller;
use
skeeks\cms\helpers\RequestResponse
;
use
skeeks\modules\cms\shop\models\ShopBasket
;
use
skeeks\modules\cms\shop\models\ShopFuser
;
use
skeeks\modules\cms\catalog\models\Product
;
/**
* Class ShopController
* @package skeeks\modules\cms\shop\controllers
*/
class
BasketController
extends
Controller
{
/**
* Добавление продукта в корзину.
*
* @return array|\yii\web\Response
*/
public
function
actionAddProduct
()
{
$rr
=
new
RequestResponse
();
...
...
@@ -27,6 +32,14 @@ class BasketController extends Controller
$product_id
=
\Yii
::
$app
->
request
->
post
(
'product_id'
);
$quantity
=
\Yii
::
$app
->
request
->
post
(
'quantity'
);
$product
=
Product
::
find
()
->
where
([
'id'
=>
$product_id
])
->
one
();
if
(
!
$product
)
{
$rr
->
message
=
'Товар не найден, возможно его только что удалили.'
;
return
(
array
)
$rr
;
}
\Yii
::
$app
->
shop
->
cart
->
loadShopFuser
();
$shopBasket
=
ShopBasket
::
find
()
->
where
([
...
...
@@ -38,7 +51,7 @@ class BasketController extends Controller
{
$shopBasket
=
new
ShopBasket
([
'fuser_id'
=>
\Yii
::
$app
->
shop
->
cart
->
shopFuser
->
id
,
'name'
=>
$product
_id
,
'name'
=>
$product
->
name
,
'product_id'
=>
$product_id
,
'quantity'
=>
0
,
]);
...
...
@@ -47,6 +60,8 @@ class BasketController extends Controller
$shopBasket
->
quantity
=
$shopBasket
->
quantity
+
$quantity
;
$shopBasket
->
save
();
$shopBasket
->
recalculate
();
$rr
->
success
=
true
;
$rr
->
message
=
'Позиция добавлена в корзину'
;
...
...
controllers/CartController.php
0 → 100644
View file @
84881e37
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 03.04.2015
*/
namespace
skeeks\modules\cms\shop\controllers
;
use
skeeks\cms\base\Controller
;
use
skeeks\cms\helpers\RequestResponse
;
use
skeeks\modules\cms\shop\models\ShopBasket
;
use
skeeks\modules\cms\shop\models\ShopFuser
;
use
skeeks\modules\cms\catalog\models\Product
;
/**
* Class CartController
* @package skeeks\modules\cms\shop\controllers
*/
class
CartController
extends
Controller
{
/**
* @return array|\yii\web\Response
*/
public
function
actionIndex
()
{
//\Yii::$app->shop->cart;
return
$this
->
render
(
'index'
);
}
}
\ No newline at end of file
models/ShopBasket.php
View file @
84881e37
...
...
@@ -163,6 +163,20 @@ class ShopBasket extends Core
}
protected
$_product
=
null
;
/**
* @return Product
*/
public
function
product
()
{
if
(
$this
->
_product
===
null
)
{
$this
->
_product
=
$this
->
getProduct
()
->
one
();
}
return
$this
->
_product
;
}
/**
* @return \yii\db\ActiveQuery
...
...
@@ -205,4 +219,30 @@ class ShopBasket extends Core
}
/**
* Обновить позицию.
*
* @return $this
*/
public
function
recalculate
()
{
/**
* @var $product Product
*/
$product
=
$this
->
getProduct
()
->
one
();
if
(
!
$product
)
{
return
$this
;
}
$cost
=
$product
->
cost
();
//цена продукта
$money
=
$cost
->
multiply
(
$this
->
quantity
);
//умножаем на количество
$this
->
price
=
$money
->
getAmount
()
/
$money
->
getCurrency
()
->
getSubUnit
();
$this
->
currency
=
(
string
)
$money
->
getCurrency
();
$this
->
save
();
return
$this
;
}
}
\ No newline at end of file
views/cart/index.php
0 → 100644
View file @
84881e37
sdfg
\ 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