-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
153 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace hiqdev\yii2\cart\actions; | ||
|
||
use hiqdev\hiart\Collection; | ||
use hiqdev\yii2\cart\Module; | ||
use Yii; | ||
|
||
class AddToCartAction extends \yii\base\Action | ||
{ | ||
public $productClass; | ||
|
||
public $bulkLoad = false; | ||
|
||
public function getModule() | ||
{ | ||
return Module::getInstance(); | ||
} | ||
|
||
public function run() | ||
{ | ||
$data = null; | ||
$cart = $this->getModule()->getCart(); | ||
$request = Yii::$app->request; | ||
$collection = new Collection([ | ||
'model' => new $this->productClass | ||
]); | ||
// $data = $request->isPost ? $request->post() : $request->get(); | ||
|
||
if (!$this->bulkLoad) { | ||
$data = [$request->post() ?: $request->get()]; | ||
} | ||
|
||
if ($collection->load($data) && $collection->validate()) { | ||
foreach ($collection->models as $position) { | ||
if (!$cart->hasPosition($position->getId())) { | ||
$cart->put($position); | ||
Yii::$app->session->addFlash('success', Yii::t('app', 'Item is added to cart')); | ||
} else { | ||
Yii::$app->session->addFlash('warning', Yii::t('app', 'Item already exists in the cart')); | ||
} | ||
} | ||
} else { | ||
Yii::$app->session->addFlash('warning', Yii::t('app', 'Item does not exists')); | ||
} | ||
|
||
if ($request->isAjax) { | ||
Yii::$app->end(); | ||
} else { | ||
return $this->controller->redirect($request->referrer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
<?php | ||
|
||
namespace hipanel\modules\cart\widgets; | ||
namespace hiqdev\yii2\cart\widgets; | ||
|
||
use Yii; | ||
use hiqdev\yii2\cart\Module; | ||
|
||
class PanelTopCart extends \yii\base\Widget | ||
{ | ||
public function run() | ||
{ | ||
return $this->render('PanelTopCart_view', [ | ||
'view' => $this->getView(), | ||
'widget' => $this, | ||
'view' => $this->getView(), | ||
'cart' => $this->getModule()->getCart(), | ||
]); | ||
} | ||
|
||
public function getModule() | ||
{ | ||
return Module::getInstance(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
<?php | ||
|
||
use \Yii; | ||
use yii\helpers\Html; | ||
|
||
?> | ||
<!-- Notifications: style can be found in dropdown.less --> | ||
<li class="dropdown notifications-menu"> | ||
<a class="dropdown-toggle" data-toggle="dropdown"> | ||
<i class="fa fa-shopping-cart fa-lg"></i> | ||
<span class="label label-warning"><?= Yii::$app->cart->getCount(); ?></span> | ||
<a class="dropdown-toggle" data-toggle="dropdown"> | ||
<i class="fa fa-shopping-cart fa-lg"></i> | ||
<span class="label label-warning"><?= $cart->count ?></span> | ||
</a> | ||
<ul class="dropdown-menu"> | ||
<li class="header"> | ||
<div class="row"> | ||
<div class="col-md-6 text-bold"><?= Yii::t('app', 'Total:') ?></div> | ||
<!-- /.col-md-6 --> | ||
<div class="col-md-6 text-right"><?= Yii::$app->cart->getCost(); ?></div> | ||
<div class="col-md-6 text-right"><?= $cart->cost ?></div> | ||
<!-- /.col-md-6 --> | ||
</div> | ||
<!-- /.row --> | ||
</li> | ||
<li> | ||
<!-- inner menu: contains the actual data --> | ||
<ul class="menu"> | ||
<?php if (Yii::$app->cart->getCount() > 0) : ?> | ||
<?php foreach (Yii::$app->cart->getPositions() as $position) : ?> | ||
<?php if ($cart->count > 0) : ?> | ||
<?php foreach ($cart->positions as $position) : ?> | ||
<li> | ||
<a> | ||
<?= $position->icon ?> <?= $position->name; ?> | <?= $position->description ?> | ||
<?= $position->icon ?> <?= $position->name ?> | <?= $position->description ?> | ||
</a> | ||
</li> | ||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
<?php endforeach ?> | ||
<?php endif ?> | ||
</ul> | ||
</li> | ||
<li class="footer"><?= Html::a(Yii::t('app', 'View Cart'), '/cart/cart/index'); ?></li> | ||
<li class="footer"><?= Html::a(Yii::t('app', 'View Cart'), $widget->module->buildUrl()) ?></li> | ||
</ul> | ||
</li> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
<?php | ||
|
||
use hipanel\modules\cart\widgets\QuantityCell; | ||
use hiqdev\yii2\cart\widgets\QuantityCell; | ||
use yii\helpers\Html; | ||
|
||
?> | ||
|
||
<?= Html::beginForm('update-quantity', 'post', ['id' => $model->id]) ?> | ||
|
||
<?= Html::hiddenInput('id', $model->id) ?> | ||
|
||
<?php if ($type == QuantityCell::MODE_SELECT) : ?> | ||
<?= Html::dropDownList('quantity', $model->quantity, $model->getQuantityOptions(), ['class' => 'form-control quantity-field']) ?> | ||
<?php else : ?> | ||
<?= Html::input('number', 'quantity', $model->quantity, ['class' => 'form-control quantity-field', 'min' => 1, 'max' => 99, 'step' => 1]) ?> | ||
<?php endif; ?> | ||
<?= Html::hiddenInput('id', $model->id) ?> | ||
<?php if ($type == QuantityCell::MODE_SELECT) : ?> | ||
<?= Html::dropDownList('quantity', $model->quantity, $model->getQuantityOptions(), ['class' => 'form-control quantity-field']) ?> | ||
<?php else : ?> | ||
<?= Html::input('number', 'quantity', $model->quantity, ['class' => 'form-control quantity-field', 'min' => 1, 'max' => 99, 'step' => 1]) ?> | ||
<?php endif; ?> | ||
|
||
<?= Html::endForm() ?> |