public function actionAddQty() { $id = Yii::$app->request->get('id'); $qty = Yii::$app->request->get('qty'); $qty = !$qty ? 1 : $qty; $reservationinfo = Reservationinfo::find()->select('reservationinfo.*')->leftJoin('objreservation', 'reservationinfo.objreservation_id = objreservation.id')->where(['=', 'reservationinfo.id', $id])->one(); $session = Yii::$app->session; $session->open(); $card = new Cart(); $card->addQty($reservationinfo, $qty); $this->view->title = 'Корзина'; $model = new Orders(); return $this->render('view', compact('session', 'model')); }
function delProduct($id) { if (isset($_SESSION['cart'][$id])) { unset($_SESSION['cart'][$id]); } $_SESSION['total_price'] = Cart::totalPrice($_SESSION['cart']); $_SESSION['total_count'] = Cart::allCount($_SESSION['cart']); // getCart(); }
public function actionYoucart() { $cart = new Cart(); $cartArray = $cart->getProductData(); return $this->render('index', ['cartArray' => $cartArray]); }
<?php use common\models\I18n; use frontend\models\Cart; use frontend\models\Product; use yii\helpers\Html; use yii\helpers\Url; is_object($cart = Yii::$app->session->get('cart')) or $cart = new Cart(); ?> <div id="cartPage"> <?php if (count($cart->data) > 0) { ?> <h1><?php echo I18n::t('Your cart'); ?> </h1> <!--<form id="orderForm" method="POST" action="<?php echo Url::to(['purchase-order/index']); ?> ">--> <form id="orderForm"> <fieldset> <table> <?php $totalValue = I18n::currency($cart->totalValue()); foreach ($cart->data as $item) { $p = $item['product']; $qty = $item['quantity']; ?> <tr class="tr_product">
<?php use common\models\I18n; use frontend\models\Cart; use frontend\models\GeneralInfo; use frontend\models\ProductCategory; use yii\helpers\Url; is_object($cart = Yii::$app->session->get('cart')) or $cart = new Cart(); ?> <hgroup> <div id="htop" style="z-index: 90;"> <div id="headCenter"> <div> <a class="logo_block" title="<?php echo Yii::$app->name; ?> " href="<?php echo Yii::$app->params['frontend_url']; ?> "></a> </div> <div style="width:50%;float:left"> <a id="showhMenu" title="<?php echo I18n::t('Shop'); ?> " href="javascript:void(0)"><?php echo mb_convert_case(I18n::t('Shop'), MB_CASE_UPPER, "UTF-8"); ?> </a> </div> <div style="width:50%;float:left">
public function actionInsertorderdata() { $userId = Yii::$app->session->get(FVariable::$session_userId_str); if (!$userId) { return $this->redirect(FVariable::$siteLogin_view); } $addressId = intval(Yii::$app->request->post("addressId")); $TotalPrice = floatval(Yii::$app->request->post("TotalPrice")); $order = new Order(); $cart = new Cart(); $cartList = $cart->findById($userId); if (!$cartList) { return $this->redirect(FVariable::$home_view); } $allMoney = ""; foreach ($cartList as $mk => $mv) { $allMoney += $mv['count'] * $mv['productPrice']; } if ($TotalPrice != $allMoney) { $TotalPrice = $allMoney; } $orderNo = Tool::getOrderNumber(); $connection = Yii::$app->getDb(); $transaction = $connection->beginTransaction(); try { $orderDetail = new OrderDetail(); $orderData = $order->insertOrder($orderNo, $TotalPrice, GlobalArray::$orderStateConstantArray['waitPay'], GlobalArray::$orderPayMethodConstantArray['alipay'], GlobalArray::$orderComeFromConstantArray['WEB'], $userId, $addressId); $orderId = Yii::$app->db->getLastInsertID(); $cartDetail = $cart->findByIdIs($userId); if (!$cartDetail) { return $this->redirect(FVariable::$home_view); } $detailArr = []; foreach ($cartDetail as $k => $v) { $new = []; $new[0] = $orderId; $new[1] = $v['productId']; $new[2] = $v['count']; $new[3] = $v['money']; $detailArr[$k] = $new; } $orderDetail->insertOrderDetail($detailArr); $product = new Product(); $orderDetailFind = $orderDetail->findByOrderIdProduct($orderId); foreach ($orderDetailFind as $k => $v) { $productSelect = $product->findByProductId($v['productId']); $productStock = $productSelect->productStock; $productSales = $productSelect->productSales; $detailArrCount = $productStock - $v['productCount']; $productSales = $productSales + $v['productCount']; $product->UpdateByStock($v['productId'], $detailArrCount, $productSales); } $cart->findByIdDelCartAll($userId); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); throw $e; } $this->redirect(Yii::$app->urlManager->createUrl([FVariable::$userOrderpayment_view, 'id' => $orderId])); }
public function findByIdDelCartAgain($arr, $userId) { $CartDelAgain = Cart::deleteAll(['and', 'userId=' . $userId, ['not in', 'id', $arr]]); if (!$CartDelAgain) { return false; } return $CartDelAgain; }
<?php use frontend\models\Cart; use common\models\I18n; use frontend\models\PurchaseOrder; use yii\helpers\Html; use yii\web\View; /* @var $this View */ /* @var $model PurchaseOrder */ $this->title = I18n::t('Purchase order details'); $this->params['breadcrumbs'][] = ['label' => 'Purchase Orders', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; is_object($cart = Yii::$app->session->get('cart')) or $cart = new Cart(); ?> <div class="purchase-order-create form_container"> <h1><?php echo Html::encode($this->title); ?> </h1> <table style="width:100%;margin:1em 0;background:#ccc;box-sizing:border-box;text-align:center;line-height:2em" cellpadding="5px" cellspacing="1px"> <thead style="background:#eee"> <tr> <th><?php echo I18n::t('Product name'); ?> </th> <th><?php echo I18n::t('Unit price'); ?> </th>