/** * @return string|\yii\web\Response * @throws BadRequestHttpException */ public function actionSetCurrency() { if (!Yii::$app->request->isPost) { throw new BadRequestHttpException(); } $code = Yii::$app->request->post('code'); $currency = CurrencyHelper::get($code); if ($currency) { CurrencyHelper::change($currency->code); } if (!Yii::$app->request->isAjax) { $returnUrl = Yii::$app->request->post('returnUrl'); if (isset($returnUrl)) { return $this->redirect($returnUrl); } else { return $this->redirect(Url::home()); } } return Json::encode(1); }
<?php use app\helpers\CurrencyHelper; use yii\bootstrap\Nav; use yii\helpers\Url; $all = CurrencyHelper::all(); $current = CurrencyHelper::current()->code; $items = []; foreach ($all as $currency) { $items[] = ['label' => $currency->symbol, 'url' => '#', 'active' => $currency->code == $current, 'linkOptions' => ['data-id' => $currency->code]]; } Nav::begin(['encodeLabels' => false, 'items' => $items, 'options' => ['class' => 'currencies navbar-nav pull-right', 'data-action' => Url::to(['/shop/set-currency'])]]); Nav::end();
<?php use app\helpers\CurrencyHelper; use app\modules\checkout\models\Cart; use yii\bootstrap\Nav; use yii\helpers\Url; $cart = Cart::get(); Nav::begin(['encodeLabels' => false, 'items' => [['label' => "<strong>" . CurrencyHelper::format($cart->total) . "</strong> ( {$cart->totalCount} )", 'url' => null], ['label' => '<i class="glyphicon glyphicon-shopping-cart"></i>', 'active' => true, 'url' => Url::to(['/checkout/cart/index'])]], 'options' => ['class' => 'mini-cart navbar-nav pull-right']]); Nav::end();
use yii\helpers\Url; /** @var ProductObject $product */ $url = Url::to(['product/view', 'slug' => $product->model->slug]); ?> <div class="col-md-3"> <div class="thumbnail"> <a class="image" href="<?php echo $url; ?> "> <?php echo Html::img($product->thumb(300, 300)); ?> </a> <p class="caption"> <?php echo Html::a($product->model->name, $url); ?> </p> <p class="price"><?php echo CurrencyHelper::format($product->model->price); ?> </p> <div class="rating"> <?php echo Rating::widget(['name' => "Product[{$product->model->id}]rating", 'value' => $product->model->rating, 'readonly' => true]); ?> </div> </div> </div>
/** * @return string * @throws \yii\base\InvalidConfigException */ public function actionRefresh() { CurrencyHelper::refreshRates(); return $this->getListView(); }
/** * Places a new order */ public function api_place_order() { $cart = Cart::get(); $address = OrderAddress::get(); $order = new Order(); $order->setAttributes($address->attributes); $order->user_id = \Yii::$app->user->id; $order->currency_code = CurrencyHelper::current()->code; $order->discount = CurrencyHelper::convert($cart->discount); $order->status = Order::STATUS_NEW; try { if ($cart->total <= 0) { throw new Exception("Order with zero or less total can not be placed, ID={$order->id}"); } if (!$order->save()) { throw new Exception("Unable to save order, ID={$order->id}"); } foreach ($cart->lines as $line) { $orderLine = new OrderData(); $orderLine->quantity = $line->quantity; $orderLine->product_id = $line->product_id; $orderLine->price = CurrencyHelper::convert($line->price); $order->link('orderLines', $orderLine); } $this->reduceStocks($order); $cart->clear(); } catch (Exception $e) { \Yii::warning($e->getMessage()); return false; } $this->sendOrderEmail($order, $order->email); return $order; }
?> "> <?php echo Html::img($product->thumb(64, 64)); ?> </a> </td> <td><?php echo Html::a($product->name, ['/product/view', 'slug' => $product->slug]); ?> </td> <td><?php echo CurrencyHelper::format($line->price, $order->currency_code, false); ?> </td> <td><?php echo $line->quantity; ?> </td> <td><?php echo CurrencyHelper::format($line->subtotal, $order->currency_code, false); ?> </td> </tr> <?php } ?> </tbody> </table> <?php echo BackLink::widget(['title' => Yii::t('app', 'Order list'), 'url' => ['/checkout/order/list'], 'options' => ['class' => 'btn btn-primary']]);
<span><?php echo CurrencyHelper::format($cart->discount); ?> </span> </div> </div> <?php } ?> <div class="total"> <div> <?php echo Yii::t('app', 'Total'); ?> <span><?php echo CurrencyHelper::format($cart->total); ?> </span> </div> </div> <div class="pull-right"> <?php $form = ActiveForm::begin(['action' => Url::to(['/checkout/cart/clear'])]); ?> <?php echo Html::submitButton(Yii::t('app', 'Clear'), ['class' => 'btn btn-default']); ?> <?php echo Html::a(Yii::t('app', 'Checkout'), ['/checkout/order/address'], ['class' => 'btn btn-primary']); ?> <?php
?> <tr> <td><?php echo $order->id; ?> </td> <td><?php echo $order->name; ?> </td> <td><?php echo $order->address; ?> </td> <td><?php echo CurrencyHelper::format($order->total, $order->currency_code, false); ?> </td> <td><?php echo Yii::$app->formatter->asDatetime($order->created_at); ?> </td> <td><?php echo $order->getStatusText(); ?> </td> <td><?php echo Html::a(Yii::t('app', 'Details'), ['/checkout/order/view', 'token' => $order->token], ['class' => 'btn btn-default']); ?> </td> </tr>