Skip to content

Commit

Permalink
Work at cart
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Oct 27, 2015
1 parent c041e59 commit 1e49467
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public function actionAdd()
throw new NotFoundHttpException();
}

public function actionUpdateQuantity($id, $quantity)
{
$position = Yii::$app->cart->getPositionById($id);
if ($position) {
Yii::$app->cart->update($position, $quantity);
Yii::$app->end();
}
}

public function actionClear()
{
Yii::$app->cart->removeAll();
Expand Down
9 changes: 7 additions & 2 deletions src/grid/QuantityColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use hiqdev\xeditable\grid\XEditableColumn;
use hiqdev\xeditable\widgets\XEditable;
use Yii;
use yii\helpers\Url;

class QuantityColumn extends XEditableColumn
{
Expand All @@ -16,6 +17,7 @@ class QuantityColumn extends XEditableColumn
public function init()
{
$this->pluginOptions['mode'] = 'inline';

if ($this->xEditableType === null) {
$this->pluginOptions['type'] = 'number';
} else {
Expand All @@ -28,9 +30,12 @@ public function init()
*/
protected function renderDataCellContent($model, $key, $index)
{
if ($this->xEditableType == 'select') {
$this->pluginOptions = ArrayHelper::merge(['source' => $model->getQuantityOptions()], $this->pluginOptions);
$quantityOptions = $model->getQuantityOptions();
$xEditableVariant = ['select', 'checklist', 'typeahead', 'select2'];
if (in_array($this->xEditableType, $xEditableVariant) || !empty($quantityOptions)) {
$this->pluginOptions = ArrayHelper::merge(['source' => $quantityOptions], $this->pluginOptions);
}
$this->pluginOptions['url'] = ['update-quantity', 'id' => $model->id, 'quantity' => $model->quantity];

return Yii::createObject(ArrayHelper::merge([
'class' => XEditable::className(),
Expand Down
9 changes: 5 additions & 4 deletions src/views/cart/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
],
[
'class' => QuantityColumn::className(),
'attribute' => 'quantity',
// 'class' => 'hiqdev\xeditable\grid\XEditableColumn',
'xEditableType' => 'select',
'widgetOptions' => [
'scenario' => 'some-scenario',
]
'attribute' => 'quantity',
'pluginOptions' => [
'url' => 'set-description',
],
],
'price',
'actions' => [
Expand Down

0 comments on commit 1e49467

Please sign in to comment.