protected function getEditForm() { //New dialog box init, so load our initial data $strCode = Yii::app()->getRequest()->getParam('code'); $intRow = Yii::app()->getRequest()->getParam('id'); $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode)); if (!$objWishlist->Visible) { _xls_404(); } $objWishrow = WishlistItem::model()->findByAttributes(array('id' => $intRow, 'registry_id' => $objWishlist->id)); $arrReturn = array('action' => 'update', 'code' => $objWishlist->gift_code, 'id' => $objWishrow->id, 'qty' => $objWishrow->qty, 'qty_received' => $objWishrow->qty_received, 'priority' => $objWishrow->priority, 'comment' => $objWishrow->comment); echo json_encode($arrReturn); }
/** * Remove all items from the cart * @return bool */ public function clearCart() { if ($this->model->cart_type != CartType::cart) { return false; } unset(Yii::app()->session['checkout.cache']); unset(Yii::app()->session[MultiCheckoutForm::$sessionKey]); $this->clearCachedShipping(); foreach ($this->cartItems as $item) { if (!is_null($item->wishlist_item)) { WishlistItem::model()->updateByPk($item->wishlist_item, array('cart_item_id' => null)); } $item->delete(); } $this->model->fk_promo_id = null; $this->model->save(); $this->model->refresh(); $this->recalculateAndSave(); $this->model->refresh(); return true; }
/** * Product lookup and optional delete, shows inventory numbers */ public function actionProducts() { if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) { if ($_POST['name'] == 'code' && $_POST['value'] == "") { $items = CartItem::model()->findAll("product_id=" . $_POST['pk'] . " AND (cart_type=" . CartType::order . " OR cart_type=" . CartType::awaitpayment . ")"); if ($items) { echo "You cannot delete a product that has been used on an order"; } else { _dbx("set foreign_key_checks=0;"); Product::model()->updateAll(array('image_id' => null), 'id =' . $_POST['pk']); Images::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductRelated::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductRelated::model()->deleteAllByAttributes(array('related_id' => $_POST['pk'])); ProductTags::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductQtyPricing::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductText::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); WishlistItem::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); TaskQueue::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); Product::model()->deleteByPk($_POST['pk']); _dbx("set foreign_key_checks=1;"); echo "delete"; } } else { echo Yii::t('admin', 'You cannot change a product code here. Delete the code to remove it manually from the Web Store database'); } } else { $model = new Product(); if (isset($_GET['q'])) { $model->code = $_GET['q']; } $this->render("products", array('model' => $model)); } }
/** * Update the Quantity of an Item in the cart * Then force recalculation of Cart values * @param int $intItemId * @param int $intQuantity * @return string[]|true|void|CartItem */ public function UpdateItemQuantity($objItem, $intQuantity) { if ($intQuantity <= 0) { if ($objItem->wishlist_item > 0) { WishlistItem::model()->updateByPk($objItem->wishlist_item, array('cart_item_id' => null)); } $objItem->delete(); return true; } if ($intQuantity == $objItem->qty) { return; } if (_xls_get_conf('PRICE_REQUIRE_LOGIN', 0) == 1 && Yii::app()->user->isGuest) { return array('errorId' => 'notLoggedIn', 'errorMessage' => Yii::t('cart', 'You must log in before Adding to Cart.')); } if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0) < Product::InventoryAllowBackorders && $intQuantity > $objItem->qty && $objItem->product->inventoried && $objItem->product->inventory_avail < $intQuantity) { if (_xls_get_conf('INVENTORY_DISPLAY', 0) == 0) { $availQty = null; } else { $availQty = $objItem->product->inventory_avail; } return array('errorId' => 'invalidQuantity', 'errorMessage' => Yii::t('cart', 'Your chosen quantity is not available for ordering. Please come back and order later.'), 'availQty' => $availQty); } // qty discount? $arrtmp = ProductQtyPricing::model()->findAllByAttributes(array('product_id' => $objItem->product_id, 'pricing_level' => 1), array('order' => 'qty ASC')); $tmpprice = 0; foreach ($arrtmp as $tmp) { $tmpprice = $intQuantity >= $tmp->qty ? $tmp->price : $tmpprice; } $objItem->discount = $tmpprice > 0 ? $objItem->sell_base - $tmpprice : 0; $objItem->qty = $intQuantity; $objItem->save(); $this->recalculateAndSave(); return $objItem; }
/** * Ajax receiver function to Add To Cart. * This function adds to the cart and then returns a JSON encoded string of * the cart contents. This is typically used by the Cart Display widget. * This routine will always send back all the info, but some people may * choose to only have some details like the total and item count display. */ public function actionAddToCart() { if (Yii::app()->request->isAjaxRequest) { $intProductId = Yii::app()->getRequest()->getParam('id'); $strSize = Yii::app()->getRequest()->getParam('product_size'); $strColor = Yii::app()->getRequest()->getParam('product_color'); if (isset($strSize) || isset($strColor)) { // We passed a size and or color selection, so get the right item $objProduct = Product::LoadChildProduct($intProductId, $strSize, $strColor); if ($objProduct instanceof Product) { $intProductId = $objProduct->id; } } $intQty = Yii::app()->getRequest()->getParam('qty'); $intWishId = Yii::app()->getRequest()->getParam('wishid'); if (!isset($intWishId)) { $intWishId = null; } $intCount = Yii::app()->shoppingcart->item_count; $intRowId = Yii::app()->shoppingcart->addProduct($intProductId, $intQty, $intWishId); if ($intRowId) { if (!is_numeric($intRowId)) { //We got back an error message, not a rowid if (is_array($intRowId)) { $message = $intRowId['errorMessage']; } else { $message = $intRowId; } Yii::log("Error attempting to add product " . $intProductId . ": " . $message, 'error', 'application . ' . __CLASS__ . " . " . __FUNCTION__); $arrReturn['action'] = "alert"; $arrReturn['errormsg'] = Yii::t('global', $message); } else { Yii::log("Added item " . $intProductId . " as cart_items id " . $intRowId, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $objCart = Yii::app()->shoppingcart; $objCartItem = CartItem::model()->findByPk($intRowId); //If this was a result of a Wish List add, update that record if (!is_null($intWishId)) { WishlistItem::model()->updateByPk($intWishId, array('cart_item_id' => $intRowId)); } $arrReturn['action'] = "success"; $arrReturn['totalItemCount'] = Yii::app()->shoppingcart->totalItemCount; if ($intWishId !== null) { $arrReturn['purchaseStatus'] = WishlistItem::model()->findByPk($intWishId)->PurchaseStatus; } $strCartfile = Yii::app()->getRequest()->getParam('cart'); $strCartfile = empty($strCartfile) ? "_sidecart" : $strCartfile; $arrReturn['shoppingcart'] = $this->renderPartial('/site/' . $strCartfile, array('objCartItem' => $objCartItem), true); } $this->renderJSON($arrReturn); } else { Yii::log("Error attempting to add product " . $intProductId . " for qty " . $intQty, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } } }