Beispiel #1
0
 public function customValidation($attribute, $params)
 {
     if ($this->emailPhone != '' && $this->orderId != '') {
         $intCustomer = null;
         $objCustomer = null;
         $objCart = null;
         $found = 0;
         //Is this a customer email address, or possible an email attached to an SRO
         if (strtolower(substr($this->orderId, 0, 2)) == "s-") {
             $objSro = Sro::model()->findByAttributes(array('customer_email_phone' => $this->emailPhone, 'ls_id' => $this->orderId));
             if (!$objSro instanceof SRO) {
                 $this->addError($this->orderId, Yii::t('yii', 'Order/Email combination not found'));
                 Yii::app()->clientScript->registerScript('orderalert', 'alert("Order/Email combination not found");');
             } else {
                 $this->orderType = CartType::sro;
             }
         } else {
             //Regular Order
             $objCustomer = Customer::LoadByEmail($this->emailPhone);
             if (!$objCustomer instanceof Customer) {
                 $this->addError($this->emailPhone, Yii::t('yii', 'Email address not found'));
                 Yii::app()->clientScript->registerScript('emailalert', 'alert("Email address not found");');
             } else {
                 $objCart = Cart::model()->findByAttributes(array('id_str' => $this->orderId, 'customer_id' => $objCustomer->id));
                 if (!$objCart instanceof Cart) {
                     $this->addError($this->orderId, Yii::t('yii', 'Order/Email combination not found'));
                     Yii::app()->clientScript->registerScript('orderalert', 'alert("Order/Email combination not found");');
                 } else {
                     $this->orderType = CartType::order;
                 }
             }
         }
     }
 }
 function actionChange()
 {
     /* count semua produk yang ada 
      * di keranjang belanja */
     $count = count(Cart::model()->findAll("cart_code=:cart_code", array(":cart_code" => Yii::app()->session['cart_code'])));
     /* looping sebanyak jumlah data produk 
      * yang ada di keranjang belanja */
     for ($i = 1; $i <= $count; $i++) {
         /* findbyPk */
         $model = Cart::model()->cache(1000)->findByPk($_POST['cart_id' . $i]);
         /* set field qty pada keranjang belanja 
          * untuk diupdate */
         $model->quantity = $_POST['quantity' . $i];
         /* simpan perubahan */
         $model->cache(1000)->save();
     }
     /* direk ke halaman index cart */
     $this->redirect(array(self::INDEX));
 }
 public function run()
 {
     $model = new LookupForm();
     if (isset($_POST['LookupForm'])) {
         $model->attributes = $_POST['LookupForm'];
         if ($model->validate()) {
             //Because our validate already checks to see if it's a valid combination, we can trust loading here and just redir
             if ($model->orderType == CartType::order) {
                 $objCustomer = Customer::LoadByEmail($model->emailPhone);
                 $objCart = Cart::model()->findByAttributes(array('id_str' => $model->orderId, 'customer_id' => $objCustomer->id));
                 Yii::app()->controller->redirect($objCart->Link);
             }
             if ($model->orderType == CartType::sro) {
                 $objSro = Sro::model()->findByAttributes(array('customer_email_phone' => $model->emailPhone, 'ls_id' => $model->orderId));
                 Yii::app()->controller->redirect($objSro->Link);
             }
         }
     }
     $this->render('index', array('model' => $model));
 }
Beispiel #4
0
 /**
  * Calculates pending order qty to count against available
  * inventory by searching for Requested or Awaiting Processing orders
  * Because we have our cart table and our documents table, we have to get both numbers
  */
 public function CalculateReservedInventory()
 {
     //Pending orders not yet converted to Invoice
     $intReservedA = $this->getDbConnection()->createCommand("SELECT SUM(qty) FROM " . CartItem::model()->tableName() . " AS a\n\t\t\t\t\tLEFT JOIN " . Cart::model()->tableName() . " AS b ON a.cart_id=b.id\n\t\t\t\t\tLEFT JOIN " . Document::model()->tableName() . " AS c ON b.document_id=c.id\n\t\t\t\t\tWHERE\n\t\t\t\t\ta.product_id=" . $this->id . " AND b.cart_type=" . CartType::order . "\n\t\t\t\t\tAND (b.status='" . OrderStatus::Requested . "' OR b.status='" . OrderStatus::AwaitingProcessing . "'\n\t\t\t\t\t\tOR b.status='" . OrderStatus::Downloaded . "')\n\t\t\t\t\tAND (c.status IS NULL OR c.status='" . OrderStatus::Requested . "');")->queryScalar();
     if (empty($intReservedA)) {
         $intReservedA = 0;
     }
     //Unattached orders (made independently in Lightspeed)
     $intReservedB = $this->getDbConnection()->createCommand("SELECT SUM(qty) from " . DocumentItem::model()->tableName() . " AS a\n\t\t\t\t\tLEFT JOIN " . Document::model()->tableName() . " AS b ON a.document_id=b.id\n\t\t\t\t\tWHERE\n\t\t\t\t\ta.product_id=" . $this->id . " AND b.order_type=" . CartType::order . "\n\t\t\t\t\tAND cart_id IS NULL AND left(order_str,3)='WO-' AND (b.status='" . OrderStatus::Requested . "');")->queryScalar();
     if (empty($intReservedB)) {
         $intReservedB = 0;
     }
     return $intReservedA + $intReservedB;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Cart the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Cart::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Document Flush
  *
  * @param string $passkey
  * @return string
  */
 public function document_flush($passkey)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     if (_xls_get_conf('DEBUG_RESET', 0) == 1) {
         Yii::log('Skipped document flush operation due to DEBUG mode', CLogger::LEVEL_WARNING, 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::OK;
     }
     try {
         SroRepair::model()->deleteAll();
         SroItem::model()->deleteAll();
         Sro::model()->deleteAll();
         Cart::model()->updateAll(array('document_id' => null));
         //We need to make Document items for anything not Invoiced manual to roll back
         $objCarts = Document::model()->findAll("order_type = :type AND (status=:status1 OR status=:status2 OR status=:status3)", array(':type' => CartType::order, ':status1' => OrderStatus::Requested, ':status2' => OrderStatus::Processed, ':status3' => OrderStatus::PartiallyReceived));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->documentItems as $item) {
                 $item->qty = 0;
                 $item->save();
                 $item->product->SetAvailableInventory();
                 $item->delete();
             }
             $objCart->delete();
         }
         //Then delete everytihing else
         DocumentItem::model()->deleteAll();
         Document::model()->deleteAll();
         Yii::app()->db->createCommand("alter table " . Document::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . DocumentItem::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . Sro::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . SroItem::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . SroRepair::model()->tableName() . " auto_increment=1;")->execute();
         //We shouldn't have anything in the cart table that's not an original order, so remove the following if they exist
         //ToDo: this shouldn't be in production because we will have removed Quote lines from _cart during install
         $objCarts = Cart::model()->findAllByAttributes(array('cart_type' => CartType::quote));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //ToDo: this shouldn't be in production because we will have removed SRO lines from _cart during install
         $objCarts = Cart::model()->findAllByAttributes(array('cart_type' => CartType::sro));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //ToDo: this shouldn't be in production because we will have removed O- from _cart during install
         //Delete anything here that's just a pure Order from LS from our Cart Table
         $objCarts = Cart::model()->findAll("cart_type = :type and id_str LIKE 'O-%'", array(':type' => CartType::order));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //Delete any Web Orders that have been reuploaded from Lightspeed already
         $objCarts = Cart::model()->findAll("cart_type = :type AND status<>:status1 AND status<>:status2 AND status<>:status3", array(':type' => CartType::order, ':status1' => OrderStatus::AwaitingPayment, ':status2' => OrderStatus::AwaitingProcessing, ':status3' => OrderStatus::Downloaded));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //Delete any carts older than our timeout that don't have a customer ID attached (since those can always be restored)
         Cart::GarbageCollect();
     } catch (Exception $e) {
         Yii::log('SOAP ERROR : In flushing document tables ' . $e, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR;
     }
     return self::OK;
 }
Beispiel #7
0
 /**
  * 使用优惠券时 (绑定优惠券、计算优惠券金额)【ckeckout页面绑定优惠券、并检查优惠券的使用】
  */
 public function actionCheckCoupon()
 {
     $res = array('status' => 1, 'msg' => '');
     $sn = addslashes(trim($_REQUEST['sn']));
     $userId = $this->user_id;
     try {
         if (empty($userId)) {
             throw new Exception("用户还没有登陆,请登录!", 2);
         }
         $map = array();
         $map['coupon_sn'] = $sn;
         $info = Coupon::model()->findByAttributes($map);
         $type = 'B';
         if (empty($info)) {
             $map = array();
             $map['coupon_sn'] = $sn;
             $info = CouponType::model()->findByAttributes($map);
             $type = 'A';
             if (empty($info)) {
                 throw new Exception("优惠券错误,该券号不存在!", 0);
             }
         } else {
             if ($info['end_time'] < time()) {
                 throw new Exception("优惠券已过期!", 0);
             } elseif (empty($info['user_id']) && empty($info['order_id'])) {
                 $info->user_id = $userId;
                 $info->band_time = time();
                 $flag = $info->save();
                 if (empty($flag)) {
                     throw new Exception("优惠券绑定失败,请重试!", 0);
                 }
             } elseif ($info['user_id'] != $userId || !empty($info['order_id'])) {
                 throw new Exception("优惠券已使用或者异常!", 0);
             } elseif ($info['start_time'] > time()) {
                 throw new Exception("优惠券还未到使用日期!", 0);
             }
         }
         $list = Cart::model()->getCartList($userId);
         if (empty($list['list'])) {
             throw new Exception("购物车不能为空!", 0);
         }
         $productAmount = $list['total']['product_amount'];
         if (!empty($productAmount) && $productAmount >= $info['satisfied_amount'] || empty($info['satisfied_amount'])) {
             $finialAmount = $list['total']['product_amount'] + $list['total']['shipping_fee'] - $info['coupon_amount'];
             $res['couponsn'] = $info['coupon_sn'];
             $res['couponAmount'] = $info['coupon_amount'];
             $res['shipingFee'] = $list['total']['shipping_fee'];
             $res['finalAmount'] = $finialAmount < 0 ? 0 : $finialAmount;
         } elseif ($productAmount < $info['satisfied_amount']) {
             throw new Exception("优惠券不满足使用条件!", 0);
         }
         $couponlist = Coupon::model()->getUserUsingCouponList($userId);
         if ($type == 'A') {
             array_push($couponlist, $info->getAttributes());
         }
         $res['couponlist'] = $couponlist;
     } catch (exception $e) {
         $res['status'] = $e->getCode();
         $res['msg'] = $e->getMessage();
     }
     exit(json_encode($res));
 }
Beispiel #8
0
 /**
  * 删除购物车剩余的数据 (已经生成订单的数据)
  * @param $cartProductList
  * @return bool
  * @throws exception
  */
 protected function deleteBoughtProductData($cartProductList)
 {
     if (empty($cartProductList)) {
         throw new exception('购物车商品不能为空!');
     }
     $cardIds = array();
     foreach ($cartProductList as $row) {
         array_push($cardIds, $row['id']);
     }
     //一次删除所有的商品
     $flag = Cart::model()->deleteByPk($cardIds);
     if (empty($flag)) {
         throw new exception('删除已购商品失败!', 500);
     }
     return true;
 }
 public function actionDeleteCart()
 {
     $id = Yii::app()->request->getParam('id');
     $cart = Cart::model()->findByPk($id);
     $cart->delete();
     $this->redirect(array('/waiter/product/cartList', 'cid' => $this->companyId, 'code' => $this->seatNum));
 }
Beispiel #10
0
 /**
  * Because visitor gift purchases are on a time limit to complete, remove any pending incomplete purchases
  */
 public static function garbageCollect()
 {
     $intResetHours = _xls_get_conf('RESET_GIFT_REGISTRY_PURCHASE_STATUS', 6);
     if ($intResetHours < 1) {
         // Cannot set to 0.
         $intResetHours = 1;
     }
     $cutoffDate = date('YmdHis', strtotime("-" . $intResetHours . " hours"));
     $arrProducts = Yii::app()->db->createCommand('SELECT * FROM ' . Cart::model()->tableName() . ' WHERE cart_type=' . CartType::cart . ' ORDER BY id DESC')->query();
     while (($arrItem = $arrProducts->read()) !== false) {
         $objCart = Cart::model()->findByPk($arrItem['id']);
         //Go through outstanding carts and see if we have any expiring gift items
         foreach ($objCart->cartItems as $item) {
             if (!is_null($item->wishlist_item)) {
                 $cartCustomerId = is_null($objCart->customer_id) ? 0 : $objCart->customer_id;
                 //Wish list item was purchased by a visitor
                 if (isset($item->wishlistItem->registry) && $cartCustomerId != $item->wishlistItem->registry->customer_id) {
                     if (date('YmdHis', strtotime($item->datetime_mod) < $cutoffDate)) {
                         $objMessage = new CartMessages();
                         $objMessage->cart_id = $objCart->id;
                         $objMessage->message = Yii::t('cart', 'You attempted to purchase the product {product} as a gift from the wish list for {wishname}. However, because wish list gift purchases must be completed within {hours} hour(s), the item has been removed from your cart. If it is still available on the wish list, it can be re-added.', array('{wishname}' => $item->wishlistItem->registry->customer->fullname, '{product}' => $item->product->Title, '{hours}' => $intResetHours));
                         $objMessage->save();
                         $item->wishlist_item = null;
                         $item->save();
                         $item->wishlistItem->cart_item_id = null;
                         $item->wishlistItem->save();
                         $item->delete();
                         $objCart->refresh();
                         $objCart->updateCountAndSubtotal();
                         $objCart->updateTotal();
                         $objCart->save();
                     }
                 }
             }
         }
     }
 }
Beispiel #11
0
 public static function printCartGoods($companyId, $code, $reprint = false)
 {
     $orderProducts = Cart::getCartProducts($companyId, $code);
     $siteNo = SiteNo::model()->find('dpid=:companyId and code=:code and delete_flag=0', array(':companyId' => $companyId, ':code' => $code));
     $site = Site::model()->findByPk($siteNo->site_id);
     $siteType = SiteType::model()->findByPk($site->type_id);
     $listData = array();
     foreach ($orderProducts as $product) {
         $key = $product['department_id'];
         if (!isset($listData[$key])) {
             $listData[$key] = '';
         }
         if (!$listData[$key]) {
             if ($reprint) {
                 $listData[$key] .= str_pad('丢单重打', 48, ' ', STR_PAD_BOTH) . '<br>';
             }
             $listData[$key] .= str_pad('座号:' . $siteType->name . ' ' . $site->serial, 48, ' ', STR_PAD_BOTH) . '<br>';
             $listData[$key] .= str_pad('时间:' . date('Y-m-d H:i:s', time()), 30, ' ') . str_pad('人数:' . $siteNo->number, 10, ' ') . '<br>';
             $listData[$key] .= str_pad('', 48, '-') . '<br>';
             $listData[$key] .= str_pad('菜品', 20, ' ') . str_pad('数量', 20, ' ') . '<br>';
         }
         $listData[$key] .= str_pad($product['product_name'], 20, ' ') . str_pad($product['product_num'], 20, ' ') . '<br>';
     }
     foreach ($listData as $departmentId => $listString) {
         $department = Department::model()->findByPk($departmentId);
         if (!$department->printer_id) {
             if (Yii::app()->request->isAjaxRequest) {
                 echo Yii::app()->end(array('status' => false, 'msg' => '请关联打印机'));
             } else {
                 return array('status' => false, 'msg' => '请关联打印机');
             }
         }
         $printer = Printer::model()->findByPk($department->printer_id);
         $listKey = $companyId . '_' . $printer->ip_address;
         $listString .= str_pad('打印机:' . $department->name, 48, ' ') . '<br>';
         //$listString .=str_pad('点菜员:'.$);
         $list = new ARedisList($listKey);
         if ($department->list_no) {
             for ($i = 0; $i < $department->list_no; $i++) {
                 if ($reprint) {
                     $list->add($listString);
                 } else {
                     $list->unshift($listString);
                 }
                 $channel = new ARedisChannel($companyId . '_PD');
                 $channel->publish($listKey);
             }
         }
     }
     $cart = Cart::model()->deleteAll('dpid=:companyId and code=:code', array(':companyId' => $companyId, ':code' => $code));
     if (Yii::app()->request->isAjaxRequest) {
         echo Yii::app()->end(json_encode(array('status' => true, 'msg' => '')));
     } else {
         return array('status' => true, 'msg' => '');
     }
 }
Beispiel #12
0
 /**
  * Return an array of pending orders containing 'id_str' and 'datetime_cre' fields.
  *
  * @return array pending orders
  */
 public static function getPendingOrders()
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'id_str,datetime_cre';
     $criteria->condition = 'cart_type = :cart_type AND downloaded = :downloaded';
     $criteria->params = array('cart_type' => CartType::order, 'downloaded' => 0);
     $pendingOrders = Cart::model()->findAll($criteria);
     $returnOrders = array();
     foreach ($pendingOrders as $order) {
         array_push($returnOrders, array('id_str' => $order['id_str'], 'datetime_cre' => $order['datetime_cre']));
     }
     return $returnOrders;
 }
 /**
  * Ajax update function for any grid changes
  */
 public function actionUpdate()
 {
     $pk = Yii::app()->getRequest()->getPost('pk');
     $name = Yii::app()->getRequest()->getPost('name');
     $value = Yii::app()->getRequest()->getPost('value');
     Cart::model()->updateByPk($pk, array($name => $value));
     if ($name == "downloaded" && $value == 0) {
         $objCart = Cart::model()->findByPk($pk);
         $objEvent = new CEventOrder('CartController', 'onCreateOrder', $objCart->id_str);
         _xls_raise_events('CEventOrder', $objEvent);
     }
     echo "success";
 }
 /**
  * Update an individual order as downloaded
  * @param string $passkey
  * @param string $strId
  * @param int $intDownloaded
  * @return string
  * @throws SoapFault
  * @soap
  */
 public function update_order_downloaded_status_by_id($passkey, $strId, $intDownloaded)
 {
     self::check_passkey($passkey);
     try {
         $objCart = Cart::LoadByIdStr($strId);
         if ($objCart === null) {
             throw new WsSoapException("Cart with ID '" . $strId . "' was not found");
         }
         Cart::model()->updateByPk($objCart->id, array('downloaded' => $intDownloaded, 'status' => OrderStatus::Downloaded));
     } catch (WsSoapException $wsse) {
         $strMsg = "update_order_downloaded_status_by_id " . $wsse;
         Yii::log("SOAP ERROR : {$strMsg}", CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN);
     } catch (Exception $ex) {
         $strMsg = "Unknown error while trying to update downloaded status for the cart with ID '" . $strId . "'";
         Yii::log("SOAP ERROR : {$strMsg}", CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN);
     }
     return self::OK;
 }
Beispiel #15
0
 public function actionUpdatestatus()
 {
     if (!empty($_POST['id'])) {
         $id = $_POST['id'];
         $value = $_POST['val'];
         $cartModel = Cart::model()->findByPk($id);
         if (!empty($cartModel)) {
             $cartModel->cart_order_status = $value;
             $cartModel->save();
         }
         echo 'success';
     } else {
         echo 'error';
     }
     exit;
 }
Beispiel #16
0
 /**
  * Relations.
  *
  * @return array Relations.
  */
 public function relations()
 {
     return array('user' => array(self::BELONGS_TO, User::model()->tableName(), 'user_id'), 'assigned' => array(self::BELONGS_TO, User::model()->tableName(), 'assigned_id'), 'cart' => array(self::BELONGS_TO, Cart::model()->tableName(), 'cart_id'));
 }
 /**
  * The "thank you" page, which also serves as the receipt page.
  *
  * This page contains a form which allows a guest customer to turn their
  * account into a normal one.
  *
  * @return void
  * @throws CHttpException
  */
 public function actionThankyou()
 {
     $strLink = Yii::app()->getRequest()->getQuery('linkid');
     // Redirect to homepage if there is no link id.
     if (empty($strLink)) {
         $this->redirect($this->createAbsoluteUrl("/", array(), 'http'));
     }
     // redirect to old receipt in the rare case Web Store is back on an old theme
     if (Yii::app()->theme->info->advancedCheckout === false) {
         $this->redirect($this->createAbsoluteUrl('/cart/receipt', array('getuid' => $strLink)));
     }
     $objCart = Cart::model()->findByAttributes(array('linkid' => $strLink));
     if ($objCart instanceof Cart === false) {
         _xls_404();
     }
     // Send any emails we may still have.
     Checkout::sendEmails($objCart->id);
     $customer = Customer::model()->findByPk(Yii::app()->user->id);
     // In order to upgrade from GUEST to NORMAL_USER there mustn't already
     // be a normal user with this email address.
     $registeredCustomerWithSameEmail = null;
     if ($customer !== null) {
         $registeredCustomerWithSameEmail = Customer::model()->findByAttributes(array('record_type' => Customer::NORMAL_USER, 'email' => $customer->email));
     }
     // Whether to show the createNewAccount section.
     // SSL is required for this, but is enforced by CheckoutController::beforeAction.
     $canCreateNewAccount = $customer !== null && $objCart !== null && $objCart->customer !== null && $customer->id === $objCart->customer->id && CPropertyValue::ensureInteger($customer->record_type) === Customer::GUEST && $registeredCustomerWithSameEmail === null;
     // Whether to show the "your account has been created" message.
     $showAccountCreated = false;
     // Possibility for guests to register for normal account.
     if ($canCreateNewAccount) {
         $customer->scenario = Customer::SCENARIO_UPDATEPASSWORD;
         if (isset($_POST['Customer'])) {
             $customer->password = $_POST['Customer']['password'];
             $customer->password_repeat = $_POST['Customer']['password_repeat'];
             $customer->record_type = Customer::NORMAL_USER;
             $customer->allow_login = Customer::NORMAL_USER;
             if ($customer->validate() === true) {
                 $customer->save();
                 $showAccountCreated = true;
                 $canCreateNewAccount = false;
             } else {
                 $this->checkoutForm->addErrors($customer->getErrors());
             }
         }
     }
     $this->layout = '/layouts/checkout-confirmation';
     $this->render('thankyou', array('cart' => $objCart, 'model' => $customer, 'showCreateNewAccount' => $canCreateNewAccount, 'showAccountCreated' => $showAccountCreated, 'arrError' => $this->formatErrors()));
 }
Beispiel #18
0
 /**
  * Merge a document (i.e. quote) into the current cart.
  * @param null $objDocument
  * @return bool
  */
 public function loginQuote($objDocument = null)
 {
     if (is_null($objDocument)) {
         return;
     }
     $cartid = Yii::app()->user->getState('cartid');
     if (empty($cartid)) {
         $this->createCart();
     }
     $arrPastItems = $objDocument->documentItems;
     // Merge in items from our quote to the cart.
     if (count($arrPastItems) > 0) {
         foreach ($arrPastItems as $objItem) {
             $objProduct = Product::model()->findbyPk($objItem->product_id);
             $retVal = $this->model->AddProduct($objProduct, $objItem->qty, CartType::quote, $objItem->gift_registry_item, $objItem->description, $objItem->sell, $objItem->discount);
             if (is_string($retVal) && strlen($retVal) > 5) {
                 return $retVal;
             }
         }
     }
     $this->model->document_id = $objDocument->id;
     $this->model->datetime_cre = new CDbExpression('NOW()');
     //Reset time to current time
     if (!$this->model->save()) {
         Yii::log("Error saving cart " . print_r($this->model->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
     $this->recalculateAndSave();
     $this->_model = Cart::model()->findByPk($this->id);
     $this->assignCustomer(Yii::app()->user->id);
     return true;
 }
 private function addQuantity($product_id, $cart_code = '', $quantity = '')
 {
     /* model Cart findBy attributes product_id dan cart_code */
     $modelCart = Cart::model()->findByAttributes(array('product_id' => $product_id, 'cart_code' => $cart_code));
     /* jika ada didalam keranjang belanja */
     if (count($modelCart) > 0) {
         /* maka update qty nya */
         $modelCart->quantity += $quantity;
         /* simpan dan return true */
         $modelCart->save();
         return TRUE;
     } else {
         /* lain dari itu return false */
         return FALSE;
     }
 }
 public function actionSslclear()
 {
     $strLink = Yii::app()->getRequest()->getQuery('getuid');
     $objCart = Cart::model()->findByAttributes(array('linkid' => $strLink));
     if ($objCart->customer->record_type == Customer::GUEST) {
         Yii::app()->user->logout();
     }
     //Redirect to our receipt, we're done
     Yii::app()->shoppingcart->releaseCart();
     Yii::app()->shoppingcart->clearCart();
     self::redirectToReceipt($strLink);
 }